A class that manages AR camera parameters and updates the projection matrix. This class utilizes camera calibration data to correct object positioning in AR space and provides functionalities for integrating with an OpenCV-based AR system.
More...
|
virtual void | Dispose () |
| Disposes resources. This method is called when OnDestroy() is called.
|
|
virtual Mat | GetCamMatrix () |
| Get camMatrix.
|
|
virtual MatOfDouble | GetDistCoeffs () |
| Get distCoeffs.
|
|
virtual void | Initialize () |
| Initializes resources and sets the initial values. This method is called when Awake() is called.
|
|
virtual void | SetARCameraParameters (int screenWidth, int screenHeight, int imageWidth, int imageHeight, Vector2 translation, Vector2 scale, double[] camMatrixValues=null, double[] distCoeffsValues=null) |
| Sets the AR camera parameters and updates the projection matrix.
|
|
virtual void | SetCamMatrix (Mat camMatrix) |
| Set camMatrix.
|
|
virtual void | SetCamMatrixValuesFromImageSize () |
| Set normalized CamMatrixValues calculated from image size. The calculated values are a simplified camera matrix with a unit aspect ratio and normalized parameters.
|
|
virtual void | SetDistCoeffs (MatOfDouble distCoeffs) |
| Set distCoeffs.
|
|
virtual void | UpdateProjectionMatrix () |
| Updates the projection matrix of the AR camera based on the current parameters.
|
|
|
virtual void | Awake () |
| Awake is called when the script instance is being loaded.
|
|
virtual Matrix4x4 | CalculateProjectionMatrixFromCameraMatrixValuesWithTranslationAndScale (float fx, float fy, float cx, float cy, float width, float height, float near, float far, Vector2 translation, Vector2 scale, float screenWidth, float screenHeight) |
| Calculate the projection matrix from camera matrix values with additional translation and scaling adjustments. Converts from the OpenCV coordinate system to the OpenGL coordinate system, accounting for aspect ratio differences between the image and the screen, as well as custom translation and scaling.
|
|
virtual void | CopyCamMatrixToCamMatrixValues (Mat camMatrix) |
|
virtual void | CopyDistCoeffsToDistCoeffsValues (MatOfDouble distCoeffs) |
|
virtual void | OnDestroy () |
| Called when the MonoBehaviour will be destroyed. This method is used to release resources and perform cleanup operations.
|
|
virtual void | OnValidate () |
| Called when the script is loaded or a value is changed in the Inspector. Ensures that the screen and image dimensions are within valid ranges, validates the camera matrix and distortion coefficients arrays, and updates the projection matrix.
|
|
virtual double[] | ValidateArraySize (double[] array, int maxSize) |
| Restricts the size of the array.
|
|
|
virtual double[] | CamMatrixValues [get, set] |
| Specifies the initial value of camMatrix used for camera calibration. If the number of elements in this array is less than 9, it is automatically calculated from the Screen's Width and Height and the Image's Width and Height.
|
|
virtual double[] | DistCoeffsValues [get, set] |
| Specifies the initial value of distCoeffs used for camera calibration. If the number of elements in this array is less than 5, all elements are set to 0.
|
|
virtual int | ImageHeight [get, set] |
| Set the height of image.
|
|
virtual int | ImageWidth [get, set] |
| Set the width of image.
|
|
virtual Vector2 | Scale [get, set] |
| Set the scale vector.
|
|
virtual int | ScreenHeight [get, set] |
| Set the height of screen.
|
|
virtual int | ScreenWidth [get, set] |
| Set the width of screen.
|
|
virtual Vector2 | Translation [get, set] |
| Set the translation vector.
|
|
A class that manages AR camera parameters and updates the projection matrix. This class utilizes camera calibration data to correct object positioning in AR space and provides functionalities for integrating with an OpenCV-based AR system.
- Configures screen and image dimensions and calculates the appropriate projection matrix.
- Manages the intrinsic camera parameters (camera matrix) and lens distortion coefficients.
- Supports object position estimation using OpenCV's camera model.
- Updates the camera's projection matrix to apply the correct perspective transformation.
- Works with
ARHelper
to provide data for correcting the position and orientation of ARGameObject
.
◆ Awake()
virtual void OpenCVForUnity.UnityUtils.Helper.ARCamera.Awake |
( |
| ) |
|
|
protectedvirtual |
Awake is called when the script instance is being loaded.
◆ CalculateProjectionMatrixFromCameraMatrixValuesWithTranslationAndScale()
virtual Matrix4x4 OpenCVForUnity.UnityUtils.Helper.ARCamera.CalculateProjectionMatrixFromCameraMatrixValuesWithTranslationAndScale |
( |
float | fx, |
|
|
float | fy, |
|
|
float | cx, |
|
|
float | cy, |
|
|
float | width, |
|
|
float | height, |
|
|
float | near, |
|
|
float | far, |
|
|
Vector2 | translation, |
|
|
Vector2 | scale, |
|
|
float | screenWidth, |
|
|
float | screenHeight ) |
|
protectedvirtual |
Calculate the projection matrix from camera matrix values with additional translation and scaling adjustments. Converts from the OpenCV coordinate system to the OpenGL coordinate system, accounting for aspect ratio differences between the image and the screen, as well as custom translation and scaling.
- Parameters
-
fx | Focal length x. |
fy | Focal length y. |
cx | Image center point x.(principal point x) |
cy | Image center point y.(principal point y) |
width | Image width. |
height | Image height. |
near | The near clipping plane distance. |
far | The far clipping plane distance. |
translation | Translation applied to the projection matrix. The x and y components represent offsets in normalized screen coordinates. |
scale | Scaling factors for the projection matrix. The x and y components represent scaling in the horizontal and vertical directions. |
screenWidth | Screen width in pixels. |
screenHeight | Screen height in pixels. |
- Returns
- A Matrix4x4 representing the adjusted projection matrix.
◆ CopyCamMatrixToCamMatrixValues()
virtual void OpenCVForUnity.UnityUtils.Helper.ARCamera.CopyCamMatrixToCamMatrixValues |
( |
Mat | camMatrix | ) |
|
|
protectedvirtual |
◆ CopyDistCoeffsToDistCoeffsValues()
virtual void OpenCVForUnity.UnityUtils.Helper.ARCamera.CopyDistCoeffsToDistCoeffsValues |
( |
MatOfDouble | distCoeffs | ) |
|
|
protectedvirtual |
◆ Dispose()
virtual void OpenCVForUnity.UnityUtils.Helper.ARCamera.Dispose |
( |
| ) |
|
|
virtual |
Disposes resources. This method is called when OnDestroy() is called.
◆ GetCamMatrix()
virtual Mat OpenCVForUnity.UnityUtils.Helper.ARCamera.GetCamMatrix |
( |
| ) |
|
|
virtual |
◆ GetDistCoeffs()
virtual MatOfDouble OpenCVForUnity.UnityUtils.Helper.ARCamera.GetDistCoeffs |
( |
| ) |
|
|
virtual |
◆ Initialize()
virtual void OpenCVForUnity.UnityUtils.Helper.ARCamera.Initialize |
( |
| ) |
|
|
virtual |
Initializes resources and sets the initial values. This method is called when Awake() is called.
◆ OnDestroy()
virtual void OpenCVForUnity.UnityUtils.Helper.ARCamera.OnDestroy |
( |
| ) |
|
|
protectedvirtual |
Called when the MonoBehaviour will be destroyed. This method is used to release resources and perform cleanup operations.
◆ OnValidate()
virtual void OpenCVForUnity.UnityUtils.Helper.ARCamera.OnValidate |
( |
| ) |
|
|
protectedvirtual |
Called when the script is loaded or a value is changed in the Inspector. Ensures that the screen and image dimensions are within valid ranges, validates the camera matrix and distortion coefficients arrays, and updates the projection matrix.
◆ SetARCameraParameters()
virtual void OpenCVForUnity.UnityUtils.Helper.ARCamera.SetARCameraParameters |
( |
int | screenWidth, |
|
|
int | screenHeight, |
|
|
int | imageWidth, |
|
|
int | imageHeight, |
|
|
Vector2 | translation, |
|
|
Vector2 | scale, |
|
|
double[] | camMatrixValues = null, |
|
|
double[] | distCoeffsValues = null ) |
|
virtual |
Sets the AR camera parameters and updates the projection matrix.
- Parameters
-
screenWidth | The width of the screen. |
screenHeight | The height of the screen. |
imageWidth | The width of the image. |
imageHeight | The height of the image. |
translation | The translation vector applied to the projection matrix. |
scale | The scaling factors for the projection matrix. |
camMatrixValues | Optional initial values for the camera matrix used for calibration. If camMatrixValues.Length is less than CAMMATRIXVALUES_MIN_SIZE then camMatrixValues is calculated and set based on the values of imageWidth and imageWidth. |
distCoeffsValues | Optional initial values for the distortion coefficients used for calibration. If distCoeffsValues.Length is less than DISTCOEFFSVALUES_MIN_SIZE then distCoeffsValues is calculated and set based on the values of imageWidth and imageWidth. |
◆ SetCamMatrix()
virtual void OpenCVForUnity.UnityUtils.Helper.ARCamera.SetCamMatrix |
( |
Mat | camMatrix | ) |
|
|
virtual |
Set camMatrix.
- Parameters
-
◆ SetCamMatrixValuesFromImageSize()
virtual void OpenCVForUnity.UnityUtils.Helper.ARCamera.SetCamMatrixValuesFromImageSize |
( |
| ) |
|
|
virtual |
Set normalized CamMatrixValues calculated from image size. The calculated values are a simplified camera matrix with a unit aspect ratio and normalized parameters.
◆ SetDistCoeffs()
virtual void OpenCVForUnity.UnityUtils.Helper.ARCamera.SetDistCoeffs |
( |
MatOfDouble | distCoeffs | ) |
|
|
virtual |
Set distCoeffs.
- Parameters
-
◆ UpdateProjectionMatrix()
virtual void OpenCVForUnity.UnityUtils.Helper.ARCamera.UpdateProjectionMatrix |
( |
| ) |
|
|
virtual |
Updates the projection matrix of the AR camera based on the current parameters.
◆ ValidateArraySize()
virtual double[] OpenCVForUnity.UnityUtils.Helper.ARCamera.ValidateArraySize |
( |
double[] | array, |
|
|
int | maxSize ) |
|
protectedvirtual |
Restricts the size of the array.
- Parameters
-
array | The target array. |
maxSize | The maximum size. |
- Returns
- The array after applying the size restriction.
◆ _cachedCamera
Camera OpenCVForUnity.UnityUtils.Helper.ARCamera._cachedCamera |
|
protected |
◆ _camMatrix
Mat OpenCVForUnity.UnityUtils.Helper.ARCamera._camMatrix |
|
protected |
◆ _camMatrixValues
double [] OpenCVForUnity.UnityUtils.Helper.ARCamera._camMatrixValues = null |
|
protected |
◆ _distCoeffs
MatOfDouble OpenCVForUnity.UnityUtils.Helper.ARCamera._distCoeffs |
|
protected |
◆ _distCoeffsValues
double [] OpenCVForUnity.UnityUtils.Helper.ARCamera._distCoeffsValues = null |
|
protected |
◆ _imageHeight
int OpenCVForUnity.UnityUtils.Helper.ARCamera._imageHeight = 480 |
|
protected |
◆ _imageWidth
int OpenCVForUnity.UnityUtils.Helper.ARCamera._imageWidth = 640 |
|
protected |
◆ _scale
Vector2 OpenCVForUnity.UnityUtils.Helper.ARCamera._scale = Vector2.one |
|
protected |
◆ _screenHeight
int OpenCVForUnity.UnityUtils.Helper.ARCamera._screenHeight = 480 |
|
protected |
◆ _screenWidth
int OpenCVForUnity.UnityUtils.Helper.ARCamera._screenWidth = 640 |
|
protected |
◆ _translation
Vector2 OpenCVForUnity.UnityUtils.Helper.ARCamera._translation = Vector2.zero |
|
protected |
◆ CAMMATRIXVALUES_MAX_SIZE
const int OpenCVForUnity.UnityUtils.Helper.ARCamera.CAMMATRIXVALUES_MAX_SIZE = 9 |
|
staticprotected |
◆ CAMMATRIXVALUES_MIN_SIZE
const int OpenCVForUnity.UnityUtils.Helper.ARCamera.CAMMATRIXVALUES_MIN_SIZE = 9 |
|
staticprotected |
◆ DISTCOEFFSVALUES_MAX_SIZE
const int OpenCVForUnity.UnityUtils.Helper.ARCamera.DISTCOEFFSVALUES_MAX_SIZE = 14 |
|
staticprotected |
◆ DISTCOEFFSVALUES_MIN_SIZE
const int OpenCVForUnity.UnityUtils.Helper.ARCamera.DISTCOEFFSVALUES_MIN_SIZE = 5 |
|
staticprotected |
◆ CamMatrixValues
virtual double [] OpenCVForUnity.UnityUtils.Helper.ARCamera.CamMatrixValues |
|
getset |
Specifies the initial value of camMatrix used for camera calibration. If the number of elements in this array is less than 9, it is automatically calculated from the Screen's Width and Height and the Image's Width and Height.
◆ DistCoeffsValues
virtual double [] OpenCVForUnity.UnityUtils.Helper.ARCamera.DistCoeffsValues |
|
getset |
Specifies the initial value of distCoeffs used for camera calibration. If the number of elements in this array is less than 5, all elements are set to 0.
◆ ImageHeight
virtual int OpenCVForUnity.UnityUtils.Helper.ARCamera.ImageHeight |
|
getset |
◆ ImageWidth
virtual int OpenCVForUnity.UnityUtils.Helper.ARCamera.ImageWidth |
|
getset |
◆ Scale
virtual Vector2 OpenCVForUnity.UnityUtils.Helper.ARCamera.Scale |
|
getset |
◆ ScreenHeight
virtual int OpenCVForUnity.UnityUtils.Helper.ARCamera.ScreenHeight |
|
getset |
Set the height of screen.
◆ ScreenWidth
virtual int OpenCVForUnity.UnityUtils.Helper.ARCamera.ScreenWidth |
|
getset |
◆ Translation
virtual Vector2 OpenCVForUnity.UnityUtils.Helper.ARCamera.Translation |
|
getset |
Set the translation vector.
The documentation for this class was generated from the following file:
- OpenCVForUnity/Assets/OpenCVForUnity/org/opencv/_unity/Helper/ARHelper/ARCamera.cs