OpenCV for Unity 2.6.5
Enox Software / Please refer to OpenCV official document ( http://docs.opencv.org/4.10.0/index.html ) for the details of the argument of the method.
Loading...
Searching...
No Matches
OpenCVForUnity.UnityUtils.Helper.ARHelper Class Reference

A helper component for managing AR (Augmented Reality) functionalities. More...

Public Types

enum  UpdateTarget {
  ARGameObject ,
  ARCamera
}
 UpdateTarget Type. More...
 

Public Member Functions

virtual void CalculateARMatrix ()
 Calculate ARMatrix from set parameters.
 
virtual void Dispose ()
 Releases all resource used by the ARHelper.
 
virtual Matrix4x4 GetARMatrix ()
 Get ARMatrix.
 
Mat GetCamMatrix ()
 Get camMatrix.
 
virtual MatOfDouble GetDistCoeffs ()
 Get distCoeffs.
 
virtual Mat GetRvec ()
 Get rvec.
 
virtual Mat GetTvec ()
 Get tvec.
 
virtual void Initialize ()
 Initializes the ARHelper.
 
virtual void Initialize (int screenWidth, int screenHeight, int imageWidth, int imageHeight, double[] camMatrixValues=null, double[] distCoeffsValues=null, Vector2[] imagePoints=null, Vector3[] objectPoints=null)
 Initializes the ARHelper.
 
virtual bool IsInitialized ()
 Indicates whether this instance has been initialized.
 
virtual void ResetUpdateTargetTransform ()
 Resets the Transform of updateTarget to its initial value at the time the Initialize() method is called.
 
virtual void SetCamMatrix (Mat camMatrix)
 Set camMatrix.
 
virtual void SetDistCoeffs (MatOfDouble distCoeffs)
 Set distCoeffs.
 
virtual void UpdateTransform ()
 Update the Transform of UpdateTarget using ARMatrix.
 

Public Attributes

Camera arCamera
 Target AR Camera.
 
GameObject arGameObject
 Target AR GameObject.
 
bool calculateARMatrixInLateUpdate = true
 If true, the CalculateARMatrix() method is automatically called in the LateUpdate() method; if false, you must call it yourself.
 
Vector2[] imagePoints
 Specify the imagePoints argument to the Calib3d.solvePnP() method.
 
Vector3[] objectPoints
 Specify the objectPoints argument to the Calib3d.solvePnP() method.
 
float positionLowPassParam = 4f
 Position parameter of LowPassFilter (Value in meters)
 
bool rightHandedCoordinates = false
 Enable this flag if the object point is a right-hand coordinate system (OpenCV).
 
float rotationLowPassParam = 2f
 Rotation parameter of LowPassFilter (Value in degrees)
 
UpdateTarget updateTarget
 Update Target.
 
bool updateTransformInLateUpdate = true
 If true, the UpdateTransform() method is automatically called in the LateUpdate() method; if false, you must call it yourself.
 
bool useLowPassFilter = false
 When enabled, LowPassFilter suppresses noise.
 

Protected Member Functions

virtual void OnDestroy ()
 Raises the destroy event.
 
virtual void OnValidate ()
 

Protected Attributes

double[] _camMatrixValues = null
 
double[] _distCoeffsValues = null
 
int _imageHeight = 480
 
int _imageWidth = 640
 
int _screenHeight = 480
 
int _screenWidth = 640
 
bool hasInitDone = false
 Indicates whether this instance has been initialized.
 

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 int screenHeight [get, set]
 Set the height of screen.
 
virtual int screenWidth [get, set]
 Set the width of screen.
 

Detailed Description

A helper component for managing AR (Augmented Reality) functionalities.

The ARHelper class simplifies AR-related calculations such as object pose estimation and Transform updates by specifying the objectPoints, imagePoints, camMatrix, and distCoeff for OpenCV's solvePnP() method. This class provides the following features:

  • Configuring and updating Transforms for AR GameObject and AR Camera
  • Calculating and applying AR matrices
  • Low-pass filtering for pose stabilization
  • Calculating and managing camera parameters

Attach this component to a GameObject to enable AR functionality:

// Example usage of the ARHelper component
ARHelper arHelper = gameObject.AddComponent<ARHelper>();
arHelper.Initialize(1920, 1080, 640, 480);
arHelper.imagePoints = imagePointsMatOfPoint2f.toVector2Array();
arHelper.objectPoints = objectPointsMatOfPoint3f.toVector3Array();
arHelper.CalculateARMatrix();
arHelper.UpdateTransform();
A helper component for managing AR (Augmented Reality) functionalities.
Definition ARHelper.cs:41
virtual void Initialize()
Initializes the ARHelper.
Definition ARHelper.cs:427
virtual void UpdateTransform()
Update the Transform of UpdateTarget using ARMatrix.
Definition ARHelper.cs:771
virtual void CalculateARMatrix()
Calculate ARMatrix from set parameters.
Definition ARHelper.cs:658

Member Enumeration Documentation

◆ UpdateTarget

UpdateTarget Type.

Enumerator
ARGameObject 
ARCamera 

Member Function Documentation

◆ CalculateARMatrix()

virtual void OpenCVForUnity.UnityUtils.Helper.ARHelper.CalculateARMatrix ( )
virtual

Calculate ARMatrix from set parameters.

◆ Dispose()

virtual void OpenCVForUnity.UnityUtils.Helper.ARHelper.Dispose ( )
virtual

Releases all resource used by the ARHelper.

◆ GetARMatrix()

virtual Matrix4x4 OpenCVForUnity.UnityUtils.Helper.ARHelper.GetARMatrix ( )
virtual

Get ARMatrix.

Returns
AR Matrix

◆ GetCamMatrix()

Mat OpenCVForUnity.UnityUtils.Helper.ARHelper.GetCamMatrix ( )

Get camMatrix.

Returns

◆ GetDistCoeffs()

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

Get distCoeffs.

Returns

◆ GetRvec()

virtual Mat OpenCVForUnity.UnityUtils.Helper.ARHelper.GetRvec ( )
virtual

Get rvec.

Returns

◆ GetTvec()

virtual Mat OpenCVForUnity.UnityUtils.Helper.ARHelper.GetTvec ( )
virtual

Get tvec.

Returns

◆ Initialize() [1/2]

virtual void OpenCVForUnity.UnityUtils.Helper.ARHelper.Initialize ( )
virtual

Initializes the ARHelper.

◆ Initialize() [2/2]

virtual void OpenCVForUnity.UnityUtils.Helper.ARHelper.Initialize ( int screenWidth,
int screenHeight,
int imageWidth,
int imageHeight,
double[] camMatrixValues = null,
double[] distCoeffsValues = null,
Vector2[] imagePoints = null,
Vector3[] objectPoints = null )
virtual

Initializes the ARHelper.

◆ IsInitialized()

virtual bool OpenCVForUnity.UnityUtils.Helper.ARHelper.IsInitialized ( )
virtual

Indicates whether this instance has been initialized.

Returns
true, if this instance has been initialized, false otherwise.

◆ OnDestroy()

virtual void OpenCVForUnity.UnityUtils.Helper.ARHelper.OnDestroy ( )
protectedvirtual

Raises the destroy event.

◆ OnValidate()

virtual void OpenCVForUnity.UnityUtils.Helper.ARHelper.OnValidate ( )
protectedvirtual

◆ ResetUpdateTargetTransform()

virtual void OpenCVForUnity.UnityUtils.Helper.ARHelper.ResetUpdateTargetTransform ( )
virtual

Resets the Transform of updateTarget to its initial value at the time the Initialize() method is called.

◆ SetCamMatrix()

virtual void OpenCVForUnity.UnityUtils.Helper.ARHelper.SetCamMatrix ( Mat camMatrix)
virtual

Set camMatrix.

Parameters
camMatrix

◆ SetDistCoeffs()

virtual void OpenCVForUnity.UnityUtils.Helper.ARHelper.SetDistCoeffs ( MatOfDouble distCoeffs)
virtual

Set distCoeffs.

Parameters
distCoeffs

◆ UpdateTransform()

virtual void OpenCVForUnity.UnityUtils.Helper.ARHelper.UpdateTransform ( )
virtual

Update the Transform of UpdateTarget using ARMatrix.

Member Data Documentation

◆ _camMatrixValues

double [] OpenCVForUnity.UnityUtils.Helper.ARHelper._camMatrixValues = null
protected

◆ _distCoeffsValues

double [] OpenCVForUnity.UnityUtils.Helper.ARHelper._distCoeffsValues = null
protected

◆ _imageHeight

int OpenCVForUnity.UnityUtils.Helper.ARHelper._imageHeight = 480
protected

◆ _imageWidth

int OpenCVForUnity.UnityUtils.Helper.ARHelper._imageWidth = 640
protected

◆ _screenHeight

int OpenCVForUnity.UnityUtils.Helper.ARHelper._screenHeight = 480
protected

◆ _screenWidth

int OpenCVForUnity.UnityUtils.Helper.ARHelper._screenWidth = 640
protected

◆ arCamera

Camera OpenCVForUnity.UnityUtils.Helper.ARHelper.arCamera

Target AR Camera.

◆ arGameObject

GameObject OpenCVForUnity.UnityUtils.Helper.ARHelper.arGameObject

Target AR GameObject.

◆ calculateARMatrixInLateUpdate

bool OpenCVForUnity.UnityUtils.Helper.ARHelper.calculateARMatrixInLateUpdate = true

If true, the CalculateARMatrix() method is automatically called in the LateUpdate() method; if false, you must call it yourself.

◆ hasInitDone

bool OpenCVForUnity.UnityUtils.Helper.ARHelper.hasInitDone = false
protected

Indicates whether this instance has been initialized.

◆ imagePoints

Vector2 [] OpenCVForUnity.UnityUtils.Helper.ARHelper.imagePoints

Specify the imagePoints argument to the Calib3d.solvePnP() method.

◆ objectPoints

Vector3 [] OpenCVForUnity.UnityUtils.Helper.ARHelper.objectPoints

Specify the objectPoints argument to the Calib3d.solvePnP() method.

◆ positionLowPassParam

float OpenCVForUnity.UnityUtils.Helper.ARHelper.positionLowPassParam = 4f

Position parameter of LowPassFilter (Value in meters)

◆ rightHandedCoordinates

bool OpenCVForUnity.UnityUtils.Helper.ARHelper.rightHandedCoordinates = false

Enable this flag if the object point is a right-hand coordinate system (OpenCV).

◆ rotationLowPassParam

float OpenCVForUnity.UnityUtils.Helper.ARHelper.rotationLowPassParam = 2f

Rotation parameter of LowPassFilter (Value in degrees)

◆ updateTarget

UpdateTarget OpenCVForUnity.UnityUtils.Helper.ARHelper.updateTarget

Update Target.

◆ updateTransformInLateUpdate

bool OpenCVForUnity.UnityUtils.Helper.ARHelper.updateTransformInLateUpdate = true

If true, the UpdateTransform() method is automatically called in the LateUpdate() method; if false, you must call it yourself.

◆ useLowPassFilter

bool OpenCVForUnity.UnityUtils.Helper.ARHelper.useLowPassFilter = false

When enabled, LowPassFilter suppresses noise.

Property Documentation

◆ camMatrixValues

virtual double [] OpenCVForUnity.UnityUtils.Helper.ARHelper.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.ARHelper.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.ARHelper.imageHeight
getset

Set the height of image.

◆ imageWidth

virtual int OpenCVForUnity.UnityUtils.Helper.ARHelper.imageWidth
getset

Set the width of image.

◆ screenHeight

virtual int OpenCVForUnity.UnityUtils.Helper.ARHelper.screenHeight
getset

Set the height of screen.

◆ screenWidth

virtual int OpenCVForUnity.UnityUtils.Helper.ARHelper.screenWidth
getset

Set the width of screen.


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