CameraParameters Class

这个类型是C#语言的 EasyAR Sense API: CameraParameters 。页面中部分描述可能与Unity环境无关。

部分Sense接口已经封装成Unity组件,直接使用可能是不必要的。

Description

camera参数,包括图像大小、焦距、主点、camera类型和camera相对设备自然方向的旋转角度。


Methods

size

C#

public virtual Vec2I size()

图像大小。

focalLength

C#

public virtual Vec2F focalLength()

焦距。相机的等效光心到CCD平面的距离除以宽高两个方向的单位像素密度。单位为像素。

principalPoint

C#

public virtual Vec2F principalPoint()

主点。相机的主光轴在CCD平面上的交点到图像左上角的像素坐标。单位为像素。

cameraModelType

C#

public virtual CameraModelType cameraModelType()

相机模型。

cameraDeviceType

C#

public virtual CameraDeviceType cameraDeviceType()

相机设备类型。默认camera、后置camera或前置camera。桌面设备均为默认camera,移动设备区分后置camera和前置camera。

cameraOrientation

C#

public virtual int cameraOrientation()

camera图像在设备的自然方向上显示时需要顺时针旋转的角度。范围为[0, 360)。

Android手机和部分Android平板为90度。

Android眼镜和部分Android平板为0度。

现有iOS设备均为90度。

createWithDefaultIntrinsics

C#

public static CameraParameters createWithDefaultIntrinsics( Vec2I imageSize, CameraDeviceType cameraDeviceType, int cameraOrientation)

以默认相机内参创建CameraParameters。默认相机内参(焦距、主点)根据图像大小自动计算,但并不是特别准确。

createWithCustomIntrinsics

C#

public static CameraParameters createWithCustomIntrinsics( Vec2I imageSize, List<float> cameraParamList, CameraModelType cameraModel, CameraDeviceType cameraDeviceType, int cameraOrientation)

使用自定义相机内参创建CameraParameters。需要指定相机内参(焦距、主点、畸变系数)以及相机模型。相机模型支持参考CameraModelType。

getResized

C#

public virtual CameraParameters getResized( Vec2I imageSize)

获取相机图像大小改变后的等效CameraParameters。

imageOrientation

C#

public virtual int imageOrientation(int screenRotation)

计算图像需要相对于屏幕进行顺时针旋转以和屏幕对齐所需要的角度。

screenRotation为屏幕图像相对于自然方向顺时针旋转的角度。

对于iOS,有

  • UIInterfaceOrientationPortrait: screenRotation = 0

  • UIInterfaceOrientationLandscapeRight: screenRotation = 90

  • UIInterfaceOrientationPortraitUpsideDown: screenRotation = 180

  • UIInterfaceOrientationLandscapeLeft: screenRotation = 270

对于Android,有

  • Surface.ROTATION_0: screenRotation = 0

  • Surface.ROTATION_90: screenRotation = 90

  • Surface.ROTATION_180: screenRotation = 180

  • Surface.ROTATION_270: screenRotation = 270

imageHorizontalFlip

C#

public virtual bool imageHorizontalFlip(bool manualHorizontalFlip)

计算图像是否需要左右翻转。图像渲染时,先进行旋转,再进行翻转。当cameraDeviceType为前置摄像头时,会自动进行翻转,可在此基础上,传入manualHorizontalFlip再叠加一次手动翻转。

projection

C#

public virtual Matrix44F projection(float nearPlane, float farPlane, float viewportAspectRatio, int screenRotation, bool combiningFlip, bool manualHorizontalFlip)

计算渲染虚拟物体所需要的透视投影矩阵,将camera坐标系下的点变换到剪裁坐标系([-1, 1]^4)中(包括绕z轴的旋转)。透视投影矩阵的形式和OpenGL相同,为矩阵右边乘以点的齐次坐标的列向量,而非Direct3D的矩阵左边乘以点的齐次坐标的列向量。但数据的排列方式为row-major,与OpenGL的column-major相反。剪裁坐标系和单位化设备坐标系的定义与OpenGL默认相同。

imageProjection

C#

public virtual Matrix44F imageProjection(float viewportAspectRatio, int screenRotation, bool combiningFlip, bool manualHorizontalFlip)

计算渲染摄像机背景图像所需要的正交投影矩阵,将图像矩形坐标系下([-1, 1]^2)的点变换到剪裁坐标系([-1, 1]^4)中(包括绕z轴的旋转),未定义的两维保持不变。正交投影矩阵的形式和OpenGL相同,为矩阵右边乘以点的齐次坐标,而非Direct3D的矩阵左边乘以点的齐次坐标。但数据的排列方式为row-major,与OpenGL的column-major相反。剪裁坐标系和单位化设备坐标系的定义与OpenGL默认相同。

screenCoordinatesFromImageCoordinates

C#

public virtual Vec2F screenCoordinatesFromImageCoordinates(float viewportAspectRatio, int screenRotation, bool combiningFlip, bool manualHorizontalFlip, Vec2F imageCoordinates)

从图像坐标系([0, 1]^2)变换到屏幕坐标系([0, 1]^2),两个坐标系均x朝右、y朝下,原点在左上角。

imageCoordinatesFromScreenCoordinates

C#

public virtual Vec2F imageCoordinatesFromScreenCoordinates(float viewportAspectRatio, int screenRotation, bool combiningFlip, bool manualHorizontalFlip, Vec2F screenCoordinates)

从屏幕坐标系([0, 1]^2)变换到图像坐标系([0, 1]^2),两个坐标系均x朝右、y朝下,原点在左上角。

equalsTo

C#

public virtual bool equalsTo(CameraParameters other)

判断两组参数是否相等。