ARFrame
ARFrameはPoseTrackerが使用する標準Frameデータです。毎フレームARFrameを生成してPoseTrackerに渡すとVLSDKのロジックが実行されます。ARFoundationを使用するARFoundationPoseTrackerの場合、次のような方法でARFrameを生成します。
protected ARFrame CreateARFrame(ARCameraFrameEventArgs eventArgs)
{
ARFrame frame = new ARFrame();
frame.texture = GetCameraPreviewTexture();
frame.localPosition = m_ARCamera.transform.localPosition;
frame.localRotation = m_ARCamera.transform.localRotation;
AquireCameraIntrinsic(out float fx, out float fy, out float cx, out float cy);
frame.intrinsic = new ARIntrinsic(fx, fy, cx, cy);
frame.projMatrix = eventArgs.projectionMatrix ?? Camera.main.projectionMatrix;
frame.displayMatrix = eventArgs.displayMatrix ?? Matrix4x4.identity;
frame.displayMatrix = MakeDisplayMatrix(frame.displayMatrix);
return frame;
}
Properties
| Property | Type | Description |
|---|---|---|
| texture | Texture | 現在フレームのカメラ画像テクスチャ |
| localPosition | Vector3 | 現在フレームのカメラの位置 |
| localRotation | Quaternion | 現在フレームのカメラの回転 |
| intrinsic | ARIntrinsic | 撮影したカメラの内部パラメータ。fx、fy、cx、cyで構成される |
| projMatrix | Matrix4x4 | 3Dオブジェクトのレンダリングに使用する投影行列 |
| displayMatrix | Matrix4x4 | カメラ元画像をデバイスの向きに合わせて回転させる行列 |
| yuvBuffer | UnityYuvCpuImage? | YUV画像バッファ |
| disposable | UnityAction | YUV画像バッファ使用時に呼び出すカメラメモリ解放コールバック |
フィールド別の割り当て方法
texture
カメラの画像を保存するフィールドです。Texture型またはUnityYuvCpuImage?型のいずれかを選択して使用します。
ARFrame frame = new ARFrame();
frame.texture = GetCameraTexture();
YUV画像を使用する場合はtextureフィールドに値を割り当てず、yuvBufferとdisposableフィールドに値を割り当てます。YUV画像機能はAndroidYuv420_888とIosYpCbCr420_8BiPlanarFullRangeフォーマットのみサポートします。
ARFrame frame = new ARFrame();
UnityYuvCpuImage? yuvBuffer = new UnityYuvCpuImage();
var yPlane = image.GetPlane(0);
var uPlane = image.GetPlane(1);
var vPlane = image.GetPlane(2);
yuvBuffer.width = image.width;
yuvBuffer.height = image.height;
yuvBuffer.format = image.format;
yuvBuffer.numberOfPlanes = image.planeCount;
yuvBuffer.yPixels = new IntPtr(yPlane.data.GetUnsafePtr());
yuvBuffer.yLength = yPlane.data.Length;
yuvBuffer.yRowStride = yPlane.rowStride;
yuvBuffer.yPixelStride = yPlane.pixelStride;
yuvBuffer.uPixels = new IntPtr(uPlane.data.GetUnsafePtr());
yuvBuffer.uLength = uPlane.data.Length;
yuvBuffer.uRowStride = uPlane.rowStride;
yuvBuffer.uPixelStride = uPlane.pixelStride;
yuvBuffer.vPixels = new IntPtr(vPlane.data.GetUnsafePtr());
yuvBuffer.vLength = vPlane.data.Length;
yuvBuffer.vRowStride = vPlane.rowStride;
yuvBuffer.vPixelStride = vPlane.pixelStride;
yuvBuffer.rotationMode = YuvRotationMode.YUV_ROTATION_90;
frame.yuvBuffer = yuvBuffer;
frame.disposable = () => { image.Dispose(); };
localPosition, localRotation
デバイスのVIO pose情報を入力します。ARフレームワークによってCamera.mainのtransformが自動的に更新される場合、m_ARCameraのlocalPositionとlocalRotationを割り当てます。
ARFrame frame = new ARFrame();
frame.localPosition = m_ARCamera.localPosition;
frame.localRotation = m_ARCamera.localRotation;
必ずlocalPositionとlocalRotationを割り当ててください。positionとrotationを割り当てるとVLSDKが正常に動作しません。
intrinsic
デバイスカメラの内部パラメータを保存するフィールドです。ARIntrinsicのインスタンスを生成して割り当てます。
ARFrame frame = new ARFrame();
frame.intrinsic = new ARIntrinsic(fx: 900.0f, fy: 900.0f, cx: 640.0f, cy: 320.0f);
projMatrix
3Dオブジェクトをレンダリングするときに使用するMatrix4x4型の投影行列です。
ARFrame frame = new ARFrame();
frame.projMatrix = eventArgs.projectionMatrix ?? Camera.main.projectionMatrix;
displayMatrix
プレビューをレンダリングするときに使用するMatrix4x4型の行列です。デバイスの元画像はデバイスの向きに関わらず常に同じ向きの画像が渡されるため、displayMatrixを使用してデバイスの向きに合わせてプレビューを回転させます。
ARFrame frame = new ARFrame();
frame.displayMatrix = eventArgs.displayMatrix ?? Matrix4x4.identity;