|
OpenCV for Unity 3.0.1
Enox Software / Please refer to OpenCV official document ( http://docs.opencv.org/4.12.0/index.html ) for the details of the argument of the method.
|
OpenCV AR utilities. More...
Classes | |
| struct | PoseData |
Static Public Member Functions | |
| static Matrix4x4 | CalculateCameraMatrixValuesFromProjectionMatrix (Matrix4x4 projectionMatrix, float width, float height) |
| Calculates OpenCV-style intrinsic camera parameters (camera matrix values) from a Unity-compatible projection matrix. | |
| static float | CalculateDistance (float frustumSize, float fov) |
| Calculate distance. https://docs.unity3d.com/Manual/FrustumSizeAtDistance.html. | |
| static float | CalculateFOVAngle (float frustumSize, float distance) |
| Calculate FOV angle. https://docs.unity3d.com/Manual/FrustumSizeAtDistance.html. | |
| static float | CalculateFrustumSize (float distance, float fov) |
| Calculate frustum size. https://docs.unity3d.com/Manual/FrustumSizeAtDistance.html. | |
| static Matrix4x4 | CalculateProjectionMatrixFromCameraMatrixValues (float fx, float fy, float cx, float cy, float width, float height, float near=0.01f, float far=2000f) |
| Calculates a projection matrix from OpenCV-style camera intrinsic parameters, suitable for use as Camera.projectionMatrix in Unity. | |
| static void | ComposeMatrix (Vector3 localPosition, Quaternion localRotation, Vector3 localScale, out Matrix4x4 matrix) |
| Compose TRS matrix from position, rotation and scale. | |
| static PoseData | ConvertMatrixToPoseData (ref Matrix4x4 matrix) |
| Converts transform matrix to PoseData. | |
| static Matrix4x4 | ConvertPoseDataToMatrix (ref PoseData poseData, bool toLeftHandCoordinateSystem=false) |
| Converts PoseData to transform matrix. | |
| static Quaternion | ConvertRvecToRot (double[] rvec) |
| Converts rvec value to rotation transform. | |
| static Quaternion | ConvertRvecToRot (Mat rvec) |
| Converts rvec value to rotation transform. | |
| static PoseData | ConvertRvecTvecToPoseData (double[] rvec, double[] tvec) |
| Converts rvec and tvec value to PoseData. | |
| static PoseData | ConvertRvecTvecToPoseData (Mat rvec, Mat tvec) |
| Converts rvec and tvec value to PoseData. | |
| static Vector3 | ConvertTvecToPos (double[] tvec) |
| Converts tvec value to position transform. | |
| static Vector3 | ConvertTvecToPos (Mat tvec) |
| Converts tvec value to position transform. | |
| static Dictionary< int, PoseData > | CreatePoseDataDict (int[] ids, double[] rvecs, double[] tvecs) |
| Creates pose data dictionary. | |
| static void | DecomposeMatrix (ref Matrix4x4 matrix, out Vector3 localPosition, out Quaternion localRotation, out Vector3 localScale) |
| Extract position, rotation and scale from TRS matrix. | |
| static Quaternion | ExtractRotationFromMatrix (ref Matrix4x4 matrix) |
| Extract rotation quaternion from transform matrix. | |
| static Vector3 | ExtractScaleFromMatrix (ref Matrix4x4 matrix) |
| Extract scale from transform matrix. | |
| static Vector3 | ExtractTranslationFromMatrix (ref Matrix4x4 matrix) |
| Extract translation from transform matrix. | |
| static void | LowpassPoseData (ref PoseData oldPose, ref PoseData newPose, float posThreshold, float rotThreshold) |
| Performs a lowpass check on the position and rotation in newPose, comparing them to oldPose. | |
| static void | LowpassPoseDataDict (Dictionary< int, PoseData > oldDict, Dictionary< int, PoseData > newDict, float posThreshold, float rotThreshold) |
| Performs a lowpass check on the position and rotation of each marker in newDict, comparing them to those in oldDict. | |
| static void | SafeDrawFrameAxes (Mat image, Mat cameraMatrix, Mat distCoeffs, Mat rvec, Mat tvec, float length, int thickness=3) |
| Safe version of drawFrameAxes that prevents hang or crashes when tvec has zero or near-zero Z component. Draw axes of the world/object coordinate system from pose estimation. | |
| static void | SetTransformFromMatrix (Transform transform, ref Matrix4x4 matrix) |
| Set transform component from TRS matrix. | |
| static void | SmoothingFilterPoseData (ref PoseData oldPose, ref PoseData newPose, float positionSmoothingFactor, float rotationSmoothingFactor) |
| Performs smoothing filter on the position and rotation in newPose using exponential moving average. | |
| static void | SmoothingFilterPoseDataDict (Dictionary< int, PoseData > oldDict, Dictionary< int, PoseData > newDict, float positionSmoothingFactor, float rotationSmoothingFactor) |
| Performs smoothing filter on the position and rotation of each marker in newDict using exponential moving average. | |
OpenCV AR utilities.
|
static |
Calculates OpenCV-style intrinsic camera parameters (camera matrix values) from a Unity-compatible projection matrix.
Converts from Unity's left-handed camera coordinate system (Z-forward, Y-up) (used by Camera.projectionMatrix) to OpenCV's right-handed camera coordinate system (Z-forward, Y-down).
This effectively reverses the operation performed by CalculateProjectionMatrixFromCameraMatrixValues.
| projectionMatrix | A Unity camera projection matrix. |
| width | Image width in pixels. |
| height | Image height in pixels. |
|
static |
Calculate distance. https://docs.unity3d.com/Manual/FrustumSizeAtDistance.html.
| frustumHeight | One side size of a frustum. |
| fov | Field of view. (horizontal or vertical direction) |
|
static |
Calculate FOV angle. https://docs.unity3d.com/Manual/FrustumSizeAtDistance.html.
| frustumHeight | One side size of a frustum. |
| distance | Distance. |
|
static |
Calculate frustum size. https://docs.unity3d.com/Manual/FrustumSizeAtDistance.html.
| distance | Distance. |
| fov | Field of view. (horizontal or vertical direction) |
|
static |
Calculates a projection matrix from OpenCV-style camera intrinsic parameters, suitable for use as Camera.projectionMatrix in Unity.
Converts from the right-handed OpenCV camera coordinate system (Z-forward, Y-down) to Unity's left-handed camera coordinate system (Z-forward, Y-up).
The resulting matrix can be directly assigned to Camera.projectionMatrix, regardless of the rendering backend (OpenGL ES, Vulkan, or DirectX).
This effectively reverses the operation performed by CalculateCameraMatrixValuesFromProjectionMatrix.
| fx | Focal length in pixels along the X axis. |
| fy | Focal length in pixels along the Y axis. |
| cx | Principal point (image center) X coordinate in pixels. |
| cy | Principal point (image center) Y coordinate in pixels. |
| width | Image width in pixels. |
| height | Image height in pixels. |
| near | Near clipping plane distance. |
| far | Far clipping plane distance. |
|
static |
Compose TRS matrix from position, rotation and scale.
| localPosition | Position. |
| localRotation | Rotation. |
| localScale | Scale. |
| matrix | Transform matrix. |
|
static |
|
static |
Converts PoseData to transform matrix.
| poseData | PoseData. |
| toLeftHandCoordinateSystem | When true, converts the transformation matrix from OpenCV's right-handed coordinate system to Unity's left-handed coordinate system by inverting the Y-axis. This option must be enabled (set to true) when applying a pose calculated by OpenCV to a Unity object. When false (default), returns the matrix without coordinate system conversion. |
|
static |
Converts rvec value to rotation transform.
| tvec | Rvec. |
|
static |
Converts rvec value to rotation transform.
| tvec | Rvec. |
|
static |
|
static |
Converts tvec value to position transform.
| tvec | Tvec. |
|
static |
Converts tvec value to position transform.
| tvec | Tvec. |
|
static |
Creates pose data dictionary.
| ids | ids. |
| rvecs | Rvecs. |
| tvecs | Tvecs. |
|
static |
Extract position, rotation and scale from TRS matrix.
| matrix | Transform matrix. This parameter is passed by reference to improve performance; no changes will be made to it. |
| localPosition | Position. |
| localRotation | Rotation. |
| localScale | Scale. |
|
static |
Extract rotation quaternion from transform matrix.
| matrix | Transform matrix. This parameter is passed by reference to improve performance; no changes will be made to it. |
|
static |
Extract scale from transform matrix.
| matrix | Transform matrix. This parameter is passed by reference to improve performance; no changes will be made to it. |
|
static |
Extract translation from transform matrix.
| matrix | Transform matrix. This parameter is passed by reference to improve performance; no changes will be made to it. |
|
static |
Performs a lowpass check on the position and rotation of each marker in newDict, comparing them to those in oldDict.
| oldDict | Old dictionary. |
| newDict | New dictionary. |
| posThreshold | Position threshold. |
| rotThreshold | Rotation threshold. |
|
static |
Safe version of drawFrameAxes that prevents hang or crashes when tvec has zero or near-zero Z component. Draw axes of the world/object coordinate system from pose estimation.
| image | Input/output image. It must have 1 or 3 channels. The number of channels is not altered. |
| cameraMatrix | Input 3x3 floating-point matrix of camera intrinsic parameters. \(\cameramatrix{A}\) |
| distCoeffs | Input vector of distortion coefficients \(\distcoeffs\). If the vector is empty, the zero distortion coefficients are assumed. |
| rvec | Rotation vector (see Rodrigues ) that, together with tvec, brings points from the model coordinate system to the camera coordinate system. |
| tvec | Translation vector. |
| length | Length of the painted axes in the same unit than tvec (usually in meters). |
| thickness | Line thickness of the painted axes. |
OX is drawn in red, OY in green and OZ in blue. It includes safety checks to prevent crashes when tvec has invalid Z values.
|
static |
Set transform component from TRS matrix.
| transform | Transform component. |
| matrix | Transform matrix. This parameter is passed by reference to improve performance; no changes will be made to it. |
|
static |
Performs smoothing filter on the position and rotation in newPose using exponential moving average.
|
static |
Performs smoothing filter on the position and rotation of each marker in newDict using exponential moving average.
| oldDict | Old dictionary. |
| newDict | New dictionary. |
| positionSmoothingFactor | Position smoothing factor (0.0 = no filtering, 1.0 = maximum filtering). |
| rotationSmoothingFactor | Rotation smoothing factor (0.0 = no filtering, 1.0 = maximum filtering). |