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
preview를 렌더링할 때 사용하는 Matrix4x4 타입의 행렬입니다. 기기의 원본 이미지는 기기의 방향과 관계 없이 항상 동일한 방향의 이미지가 전달 되므로, displayMatrix를 이용하여 기기의 방향에 맞게 preview를 회전시킵니다.
ARFrame frame = new ARFrame();
frame.displayMatrix = eventArgs.displayMatrix ?? Matrix4x4.identity;