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.ARGameObject Class Reference

Represents an augmented reality (AR) object that integrates with the ARCamera. This class manages solving Perspective-n-Point (PnP) problems, handling AR matrix transformations, and detecting whether the object is within the AR camera's viewport. More...

Public Types

enum  Calib3dSolvePnPFlagsMode {
  SOLVEPNP_ITERATIVE = Calib3d.SOLVEPNP_ITERATIVE ,
  SOLVEPNP_EPNP = Calib3d.SOLVEPNP_EPNP ,
  SOLVEPNP_P3P = Calib3d.SOLVEPNP_P3P ,
  SOLVEPNP_AP3P = Calib3d.SOLVEPNP_AP3P ,
  SOLVEPNP_DLS = Calib3d.SOLVEPNP_DLS ,
  SOLVEPNP_UPNP = Calib3d.SOLVEPNP_UPNP ,
  SOLVEPNP_IPPE = Calib3d.SOLVEPNP_IPPE ,
  SOLVEPNP_IPPE_SQUARE = Calib3d.SOLVEPNP_IPPE_SQUARE ,
  SOLVEPNP_SQPNP = Calib3d.SOLVEPNP_SQPNP ,
  SOLVEPNP_ITERATIVE_THEN_EPNP
}
 Enum to set flags for solvePnP. More...
 

Public Member Functions

virtual void CalculateARMatrix (ARHelper arHelper)
 Calculate ARMatrix from set parameters.
 
virtual void Dispose ()
 Disposes resources. This method is called when OnDestroy() is called.
 
virtual Matrix4x4 GetARMatrix ()
 Get ARMatrix.
 
virtual Mat GetRvec ()
 Get rvec.
 
virtual Mat GetTvec ()
 Get tvec.
 
virtual void Initialize ()
 Initializes resources and sets the initial values. This method is called when Awake() is called.
 
virtual bool IsARGameObjectInARCameraViewport ()
 Is the ARGameObject in the ARCameraViewport? This flag is updated when CalculateARMatrix() is called.
 
virtual void ResetImagePointsAndObjectPoints ()
 Reset the imagePoints and objectPoints.
 
virtual void UpdateTransform (ARHelper arHelper)
 Update the Transform of UpdateTarget using ARMatrix.
 

Protected Member Functions

virtual void Awake ()
 Awake is called when the script instance is being loaded.
 
virtual bool IsARGameObjectInARCameraViewport (Mat tvec, Matrix4x4 projectionMatrix)
 Determines whether an AR game object is within the AR camera's viewport.
 
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.
 

Protected Attributes

bool _applyXaxisInversionToARMatrix = false
 
bool _applyYaxisInversionToARMatrix = false
 
bool _applyZaxisInversionToARMatrix = false
 
int _arCameraEventCount = 0
 The number of frames to wait for the ARCamera event to fire.
 
Matrix4x4 _arMatrix
 The transformation matrix for AR.
 
bool _changedARMatrix = false
 The flag that indicates whether the ARMatrix has changed.
 
bool _changedSolvePnpPoints = false
 The flag that indicates whether the SolvePnP points have changed.
 
int _delayFrameOnEnterARCameraViewportEvent = 0
 
int _delayFrameOnExitARCameraViewportEvent = 0
 
Vector2[] _imagePoints = null
 
Matrix4x4 _invertXMatrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(-1, 1, 1))
 The matrix that inverts the X axis.
 
Matrix4x4 _invertYMatrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(1, -1, 1))
 The matrix that inverts the Y axis.
 
Matrix4x4 _invertZMatrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(1, 1, -1))
 The matrix that inverts the Z axis.
 
bool _isARGameObjectInARCameraViewport = false
 Is the ARGameObject in the ARCameraViewport? This flag is updated when CalculateARMatrix() is called.
 
bool _leftHandedCoordinates = false
 
Vector2 _ndcXRange = new Vector2(-1.0f, 1.0f)
 
Vector2 _ndcYRange = new Vector2(-1.0f, 1.0f)
 
Vector2 _ndcZRange = new Vector2(0.0f, 1.0f)
 
Vector3[] _objectPoints = null
 
PoseData _oldPoseData
 The old pose data.
 
UnityEvent< ARHelper, ARCamera, ARGameObject_onEnterARCameraViewport
 
UnityEvent< ARHelper, ARCamera, ARGameObject_onExitARCameraViewport
 
float _positionLowPassParam = 4f
 
float _rotationLowPassParam = 2f
 
Mat _rvec
 The rvec Mat for Calib3d.solvePnP().
 
Calib3dSolvePnPFlagsMode _solvePnPFlagsMode = Calib3dSolvePnPFlagsMode.SOLVEPNP_ITERATIVE_THEN_EPNP
 
float _solvePnPRefineLMMovementThreshold = 100
 
Matrix4x4 _transformMatrix
 The transformation matrix from poseData.
 
Mat _tvec
 The tvec Mat for Calib3d.solvePnP().
 
bool _useLowPassFilter = false
 
bool _useSolvePnPRefineLM = false
 

Properties

virtual bool ApplyXaxisInversionToARMatrix [get, set]
 Apply X-axis inversion to ARMatrix.
 
virtual bool ApplyYaxisInversionToARMatrix [get, set]
 Apply Y-axis inversion to ARMatrix.
 
virtual bool ApplyZaxisInversionToARMatrix [get, set]
 Apply Z-axis inversion to ARMatrix.
 
virtual int DelayFrameOnEnterARCameraViewportEvent [get, set]
 Invoke UnityEvent onEnterARCameraViewport only when the ARGameObject is in the ARCamera viewport for the specified number of consecutive frames. Prevents frequent notifications due to noise.
 
virtual int DelayFrameOnExitARCameraViewportEvent [get, set]
 Invoke UnityEvent onEnterARCameraViewport only when the ARGameObject is outside the ARCamera viewport for the specified number of consecutive frames. Prevents frequent notifications due to noise.
 
virtual Vector2[] ImagePoints [get, set]
 Specify the imagePoints argument to the Calib3d.solvePnP() method.
 
virtual bool LeftHandedCoordinates [get, set]
 Enable this flag if the object point is a left-hand coordinate system (Unity).
 
virtual Vector2 NdcXRange [get, set]
 Defines the valid range for the X coordinate in NDC space. Used in IsARGameObjectInARCameraViewport method for viewport visibility checks.
 
virtual Vector2 NdcYRange [get, set]
 Defines the valid range for the Y coordinate in NDC space. Used in IsARGameObjectInARCameraViewport method for viewport visibility checks.
 
virtual Vector2 NdcZRange [get, set]
 Defines the valid range for the Z coordinate in NDC space. Used in IsARGameObjectInARCameraViewport method for viewport visibility checks.
 
virtual Vector3[] ObjectPoints [get, set]
 Specify the objectPoints argument to the Calib3d.solvePnP() method.
 
virtual UnityEvent< ARHelper, ARCamera, ARGameObjectOnEnterARCameraViewport [get, set]
 UnityEvent notified when the ARGameObject enters the viewport of the ARCamera.
 
virtual UnityEvent< ARHelper, ARCamera, ARGameObjectOnExitARCameraViewport [get, set]
 UnityEvent notified when the ARGameObject exits the viewport of the ARCamera.
 
virtual float PositionLowPassParam [get, set]
 Position parameter of LowPassFilter (Value in meters)
 
virtual float RotationLowPassParam [get, set]
 Rotation parameter of LowPassFilter (Value in degrees)
 
virtual Calib3dSolvePnPFlagsMode SolvePnPFlagsMode [get, set]
 Specify the flags argument to the Calib3d.solvePnP() method.
 
virtual float SolvePnPRefineLMMovementThreshold [get, set]
 If useSolvePnPRefineLM is true, the Calib3d.solvePnPRefineLM() method is called if the difference between the tvec of the current frame and that of the previous frame is greater than the specified threshold.
 
virtual bool UseLowPassFilter [get, set]
 When enabled, LowPassFilter suppresses noise.
 
virtual bool UseSolvePnPRefineLM [get, set]
 If this flag is set to true, the Calib3d.solvePnPRefineLM() method is called after the Calib3d.solvePnPnP() method to optimize the results.
 

Detailed Description

Represents an augmented reality (AR) object that integrates with the ARCamera. This class manages solving Perspective-n-Point (PnP) problems, handling AR matrix transformations, and detecting whether the object is within the AR camera's viewport.

  • Utilizes OpenCV's solvePnP methods to estimate the object's 3D position from 2D image points.
  • Supports multiple solvePnP flags and an optional refinement process using solvePnPRefineLM.
  • Provides options for coordinate system transformations and noise reduction via a low-pass filter.
  • Triggers events when the object enters or exits the AR camera viewport.
  • Updates the object's transform based on computed AR matrices.

Member Enumeration Documentation

◆ Calib3dSolvePnPFlagsMode

Enum to set flags for solvePnP.

Enumerator
SOLVEPNP_ITERATIVE 
SOLVEPNP_EPNP 
SOLVEPNP_P3P 
SOLVEPNP_AP3P 
SOLVEPNP_DLS 
SOLVEPNP_UPNP 
SOLVEPNP_IPPE 
SOLVEPNP_IPPE_SQUARE 
SOLVEPNP_SQPNP 
SOLVEPNP_ITERATIVE_THEN_EPNP 

Iterative method is called first, then EPNP is called.

Member Function Documentation

◆ Awake()

virtual void OpenCVForUnity.UnityUtils.Helper.ARGameObject.Awake ( )
protectedvirtual

Awake is called when the script instance is being loaded.

◆ CalculateARMatrix()

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

Calculate ARMatrix from set parameters.

◆ Dispose()

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

Disposes resources. This method is called when OnDestroy() is called.

◆ GetARMatrix()

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

Get ARMatrix.

Returns
AR Matrix

◆ GetRvec()

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

Get rvec.

Returns

◆ GetTvec()

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

Get tvec.

Returns

◆ Initialize()

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

Initializes resources and sets the initial values. This method is called when Awake() is called.

◆ IsARGameObjectInARCameraViewport() [1/2]

virtual bool OpenCVForUnity.UnityUtils.Helper.ARGameObject.IsARGameObjectInARCameraViewport ( )
virtual

Is the ARGameObject in the ARCameraViewport? This flag is updated when CalculateARMatrix() is called.

Returns

◆ IsARGameObjectInARCameraViewport() [2/2]

virtual bool OpenCVForUnity.UnityUtils.Helper.ARGameObject.IsARGameObjectInARCameraViewport ( Mat tvec,
Matrix4x4 projectionMatrix )
protectedvirtual

Determines whether an AR game object is within the AR camera's viewport.

Parameters
tvecThe translation vector (tvec) representing the object's position in the camera coordinate system.
projectionMatrixThe projection matrix to transform the position.
Returns
True if the object is in the viewport; otherwise, false.

◆ OnDestroy()

virtual void OpenCVForUnity.UnityUtils.Helper.ARGameObject.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.ARGameObject.OnValidate ( )
protectedvirtual

Called when the script is loaded or a value is changed in the Inspector.

◆ ResetImagePointsAndObjectPoints()

virtual void OpenCVForUnity.UnityUtils.Helper.ARGameObject.ResetImagePointsAndObjectPoints ( )
virtual

Reset the imagePoints and objectPoints.

◆ UpdateTransform()

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

Update the Transform of UpdateTarget using ARMatrix.

Member Data Documentation

◆ _applyXaxisInversionToARMatrix

bool OpenCVForUnity.UnityUtils.Helper.ARGameObject._applyXaxisInversionToARMatrix = false
protected

◆ _applyYaxisInversionToARMatrix

bool OpenCVForUnity.UnityUtils.Helper.ARGameObject._applyYaxisInversionToARMatrix = false
protected

◆ _applyZaxisInversionToARMatrix

bool OpenCVForUnity.UnityUtils.Helper.ARGameObject._applyZaxisInversionToARMatrix = false
protected

◆ _arCameraEventCount

int OpenCVForUnity.UnityUtils.Helper.ARGameObject._arCameraEventCount = 0
protected

The number of frames to wait for the ARCamera event to fire.

◆ _arMatrix

Matrix4x4 OpenCVForUnity.UnityUtils.Helper.ARGameObject._arMatrix
protected

The transformation matrix for AR.

◆ _changedARMatrix

bool OpenCVForUnity.UnityUtils.Helper.ARGameObject._changedARMatrix = false
protected

The flag that indicates whether the ARMatrix has changed.

◆ _changedSolvePnpPoints

bool OpenCVForUnity.UnityUtils.Helper.ARGameObject._changedSolvePnpPoints = false
protected

The flag that indicates whether the SolvePnP points have changed.

◆ _delayFrameOnEnterARCameraViewportEvent

int OpenCVForUnity.UnityUtils.Helper.ARGameObject._delayFrameOnEnterARCameraViewportEvent = 0
protected

◆ _delayFrameOnExitARCameraViewportEvent

int OpenCVForUnity.UnityUtils.Helper.ARGameObject._delayFrameOnExitARCameraViewportEvent = 0
protected

◆ _imagePoints

Vector2 [] OpenCVForUnity.UnityUtils.Helper.ARGameObject._imagePoints = null
protected

◆ _invertXMatrix

Matrix4x4 OpenCVForUnity.UnityUtils.Helper.ARGameObject._invertXMatrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(-1, 1, 1))
protected

The matrix that inverts the X axis.

◆ _invertYMatrix

Matrix4x4 OpenCVForUnity.UnityUtils.Helper.ARGameObject._invertYMatrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(1, -1, 1))
protected

The matrix that inverts the Y axis.

◆ _invertZMatrix

Matrix4x4 OpenCVForUnity.UnityUtils.Helper.ARGameObject._invertZMatrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(1, 1, -1))
protected

The matrix that inverts the Z axis.

◆ _isARGameObjectInARCameraViewport

bool OpenCVForUnity.UnityUtils.Helper.ARGameObject._isARGameObjectInARCameraViewport = false
protected

Is the ARGameObject in the ARCameraViewport? This flag is updated when CalculateARMatrix() is called.

◆ _leftHandedCoordinates

bool OpenCVForUnity.UnityUtils.Helper.ARGameObject._leftHandedCoordinates = false
protected

◆ _ndcXRange

Vector2 OpenCVForUnity.UnityUtils.Helper.ARGameObject._ndcXRange = new Vector2(-1.0f, 1.0f)
protected

◆ _ndcYRange

Vector2 OpenCVForUnity.UnityUtils.Helper.ARGameObject._ndcYRange = new Vector2(-1.0f, 1.0f)
protected

◆ _ndcZRange

Vector2 OpenCVForUnity.UnityUtils.Helper.ARGameObject._ndcZRange = new Vector2(0.0f, 1.0f)
protected

◆ _objectPoints

Vector3 [] OpenCVForUnity.UnityUtils.Helper.ARGameObject._objectPoints = null
protected

◆ _oldPoseData

PoseData OpenCVForUnity.UnityUtils.Helper.ARGameObject._oldPoseData
protected

The old pose data.

◆ _onEnterARCameraViewport

UnityEvent<ARHelper, ARCamera, ARGameObject> OpenCVForUnity.UnityUtils.Helper.ARGameObject._onEnterARCameraViewport
protected

◆ _onExitARCameraViewport

UnityEvent<ARHelper, ARCamera, ARGameObject> OpenCVForUnity.UnityUtils.Helper.ARGameObject._onExitARCameraViewport
protected

◆ _positionLowPassParam

float OpenCVForUnity.UnityUtils.Helper.ARGameObject._positionLowPassParam = 4f
protected

◆ _rotationLowPassParam

float OpenCVForUnity.UnityUtils.Helper.ARGameObject._rotationLowPassParam = 2f
protected

◆ _rvec

Mat OpenCVForUnity.UnityUtils.Helper.ARGameObject._rvec
protected

The rvec Mat for Calib3d.solvePnP().

◆ _solvePnPFlagsMode

Calib3dSolvePnPFlagsMode OpenCVForUnity.UnityUtils.Helper.ARGameObject._solvePnPFlagsMode = Calib3dSolvePnPFlagsMode.SOLVEPNP_ITERATIVE_THEN_EPNP
protected

◆ _solvePnPRefineLMMovementThreshold

float OpenCVForUnity.UnityUtils.Helper.ARGameObject._solvePnPRefineLMMovementThreshold = 100
protected

◆ _transformMatrix

Matrix4x4 OpenCVForUnity.UnityUtils.Helper.ARGameObject._transformMatrix
protected

The transformation matrix from poseData.

◆ _tvec

Mat OpenCVForUnity.UnityUtils.Helper.ARGameObject._tvec
protected

The tvec Mat for Calib3d.solvePnP().

◆ _useLowPassFilter

bool OpenCVForUnity.UnityUtils.Helper.ARGameObject._useLowPassFilter = false
protected

◆ _useSolvePnPRefineLM

bool OpenCVForUnity.UnityUtils.Helper.ARGameObject._useSolvePnPRefineLM = false
protected

Property Documentation

◆ ApplyXaxisInversionToARMatrix

virtual bool OpenCVForUnity.UnityUtils.Helper.ARGameObject.ApplyXaxisInversionToARMatrix
getset

Apply X-axis inversion to ARMatrix.

◆ ApplyYaxisInversionToARMatrix

virtual bool OpenCVForUnity.UnityUtils.Helper.ARGameObject.ApplyYaxisInversionToARMatrix
getset

Apply Y-axis inversion to ARMatrix.

◆ ApplyZaxisInversionToARMatrix

virtual bool OpenCVForUnity.UnityUtils.Helper.ARGameObject.ApplyZaxisInversionToARMatrix
getset

Apply Z-axis inversion to ARMatrix.

◆ DelayFrameOnEnterARCameraViewportEvent

virtual int OpenCVForUnity.UnityUtils.Helper.ARGameObject.DelayFrameOnEnterARCameraViewportEvent
getset

Invoke UnityEvent onEnterARCameraViewport only when the ARGameObject is in the ARCamera viewport for the specified number of consecutive frames. Prevents frequent notifications due to noise.

◆ DelayFrameOnExitARCameraViewportEvent

virtual int OpenCVForUnity.UnityUtils.Helper.ARGameObject.DelayFrameOnExitARCameraViewportEvent
getset

Invoke UnityEvent onEnterARCameraViewport only when the ARGameObject is outside the ARCamera viewport for the specified number of consecutive frames. Prevents frequent notifications due to noise.

◆ ImagePoints

virtual Vector2 [] OpenCVForUnity.UnityUtils.Helper.ARGameObject.ImagePoints
getset

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

◆ LeftHandedCoordinates

virtual bool OpenCVForUnity.UnityUtils.Helper.ARGameObject.LeftHandedCoordinates
getset

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

◆ NdcXRange

virtual Vector2 OpenCVForUnity.UnityUtils.Helper.ARGameObject.NdcXRange
getset

Defines the valid range for the X coordinate in NDC space. Used in IsARGameObjectInARCameraViewport method for viewport visibility checks.

◆ NdcYRange

virtual Vector2 OpenCVForUnity.UnityUtils.Helper.ARGameObject.NdcYRange
getset

Defines the valid range for the Y coordinate in NDC space. Used in IsARGameObjectInARCameraViewport method for viewport visibility checks.

◆ NdcZRange

virtual Vector2 OpenCVForUnity.UnityUtils.Helper.ARGameObject.NdcZRange
getset

Defines the valid range for the Z coordinate in NDC space. Used in IsARGameObjectInARCameraViewport method for viewport visibility checks.

◆ ObjectPoints

virtual Vector3 [] OpenCVForUnity.UnityUtils.Helper.ARGameObject.ObjectPoints
getset

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

◆ OnEnterARCameraViewport

virtual UnityEvent<ARHelper, ARCamera, ARGameObject> OpenCVForUnity.UnityUtils.Helper.ARGameObject.OnEnterARCameraViewport
getset

UnityEvent notified when the ARGameObject enters the viewport of the ARCamera.

◆ OnExitARCameraViewport

virtual UnityEvent<ARHelper, ARCamera, ARGameObject> OpenCVForUnity.UnityUtils.Helper.ARGameObject.OnExitARCameraViewport
getset

UnityEvent notified when the ARGameObject exits the viewport of the ARCamera.

◆ PositionLowPassParam

virtual float OpenCVForUnity.UnityUtils.Helper.ARGameObject.PositionLowPassParam
getset

Position parameter of LowPassFilter (Value in meters)

◆ RotationLowPassParam

virtual float OpenCVForUnity.UnityUtils.Helper.ARGameObject.RotationLowPassParam
getset

Rotation parameter of LowPassFilter (Value in degrees)

◆ SolvePnPFlagsMode

virtual Calib3dSolvePnPFlagsMode OpenCVForUnity.UnityUtils.Helper.ARGameObject.SolvePnPFlagsMode
getset

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

◆ SolvePnPRefineLMMovementThreshold

virtual float OpenCVForUnity.UnityUtils.Helper.ARGameObject.SolvePnPRefineLMMovementThreshold
getset

If useSolvePnPRefineLM is true, the Calib3d.solvePnPRefineLM() method is called if the difference between the tvec of the current frame and that of the previous frame is greater than the specified threshold.

◆ UseLowPassFilter

virtual bool OpenCVForUnity.UnityUtils.Helper.ARGameObject.UseLowPassFilter
getset

When enabled, LowPassFilter suppresses noise.

◆ UseSolvePnPRefineLM

virtual bool OpenCVForUnity.UnityUtils.Helper.ARGameObject.UseSolvePnPRefineLM
getset

If this flag is set to true, the Calib3d.solvePnPRefineLM() method is called after the Calib3d.solvePnPnP() method to optimize the results.


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