OpenCV for Unity 3.0.0
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.
Loading...
Searching...
No Matches
OpenCVForUnity.UnityUtils.Helper.ARCamera Class Reference

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...

Public Member Functions

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.
 

Protected Member Functions

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.
 

Protected Attributes

Camera _cachedCamera
 
Mat _camMatrix
 
double[] _camMatrixValues = null
 
MatOfDouble _distCoeffs
 
double[] _distCoeffsValues = null
 
int _imageHeight = 480
 
int _imageWidth = 640
 
Vector2 _scale = Vector2.one
 
int _screenHeight = 480
 
int _screenWidth = 640
 
Vector2 _translation = Vector2.zero
 

Static Protected Attributes

const int CAMMATRIXVALUES_MAX_SIZE = 9
 
const int CAMMATRIXVALUES_MIN_SIZE = 9
 
const int DISTCOEFFSVALUES_MAX_SIZE = 14
 
const int DISTCOEFFSVALUES_MIN_SIZE = 5
 

Properties

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.
 

Detailed Description

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.

Member Function Documentation

◆ 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
fxFocal length x.
fyFocal length y.
cxImage center point x.(principal point x)
cyImage center point y.(principal point y)
widthImage width.
heightImage height.
nearThe near clipping plane distance.
farThe far clipping plane distance.
translationTranslation applied to the projection matrix. The x and y components represent offsets in normalized screen coordinates.
scaleScaling factors for the projection matrix. The x and y components represent scaling in the horizontal and vertical directions.
screenWidthScreen width in pixels.
screenHeightScreen 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

Get camMatrix.

Returns

◆ GetDistCoeffs()

virtual MatOfDouble OpenCVForUnity.UnityUtils.Helper.ARCamera.GetDistCoeffs ( )
virtual

Get distCoeffs.

Returns

◆ 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
screenWidthThe width of the screen.
screenHeightThe height of the screen.
imageWidthThe width of the image.
imageHeightThe height of the image.
translationThe translation vector applied to the projection matrix.
scaleThe scaling factors for the projection matrix.
camMatrixValuesOptional 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.
distCoeffsValuesOptional 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
camMatrix

◆ 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
distCoeffs

◆ 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
arrayThe target array.
maxSizeThe maximum size.
Returns
The array after applying the size restriction.

Member Data Documentation

◆ _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

Property Documentation

◆ 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

Set the height of image.

◆ ImageWidth

virtual int OpenCVForUnity.UnityUtils.Helper.ARCamera.ImageWidth
getset

Set the width of image.

◆ Scale

virtual Vector2 OpenCVForUnity.UnityUtils.Helper.ARCamera.Scale
getset

Set the scale vector.

◆ ScreenHeight

virtual int OpenCVForUnity.UnityUtils.Helper.ARCamera.ScreenHeight
getset

Set the height of screen.

◆ ScreenWidth

virtual int OpenCVForUnity.UnityUtils.Helper.ARCamera.ScreenWidth
getset

Set the width of screen.

◆ Translation

virtual Vector2 OpenCVForUnity.UnityUtils.Helper.ARCamera.Translation
getset

Set the translation vector.


The documentation for this class was generated from the following file: