OpenCV for Unity 2.6.4
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.AsyncGPUReadback2MatHelper Class Reference

A helper component class for efficiently converting Unity Texture objects, such as RenderTexture and external texture format Texture2D, to OpenCV Mat format using AsyncGPUReadback. More...

Public Member Functions

virtual bool DidUpdateThisFrame ()
 Indicates whether the readback buffer of the frame has been updated.
 
virtual void Dispose ()
 Releases all resource used by the AsyncGPUReadback2MatHelper object.
 
virtual Source2MatHelperColorFormat GetBaseColorFormat ()
 Returns the readback buffer base color format.
 
virtual string GetDeviceName ()
 Return the active image device name.
 
virtual int GetHeight ()
 Returns the readback buffer height.
 
virtual Mat GetMat ()
 Get the mat of the current frame.
 
virtual Texture GetSourceTexture ()
 Returns the Source Texture.
 
virtual int GetWidth ()
 Returns the readback buffer width.
 
virtual void Initialize (bool autoPlay=true)
 Initializes this instance.
 
virtual void Initialize (Texture sourceTexture, bool autoPlay=true)
 Initialize this instance.
 
virtual bool IsInitialized ()
 Indicates whether this instance has been initialized.
 
virtual bool IsPaused ()
 Indicates whether the readback is paused.
 
virtual bool IsPlaying ()
 Indicates whether the readback is currently playing.
 
virtual void Pause ()
 Pauses the readback.
 
virtual void Play ()
 Starts the readback.
 
virtual void Stop ()
 Stops the readback.
 
- Public Member Functions inherited from OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper

Protected Member Functions

virtual IEnumerator _Initialize ()
 Initializes this instance by coroutine.
 
virtual void CancelInitCoroutine ()
 Cancel Init Coroutine.
 
virtual void LateUpdate ()
 
virtual void OnDestroy ()
 Raises the destroy event.
 
virtual void ReleaseResources ()
 To release the resources.
 
virtual void Update ()
 

Protected Attributes

UnityEvent _onDisposed
 UnityEvent that is triggered when this instance is disposed.
 
Source2MatHelperErrorUnityEvent _onErrorOccurred
 UnityEvent that is triggered when this instance is error Occurred.
 
UnityEvent _onInitialized
 UnityEvent that is triggered when this instance is initialized.
 
Source2MatHelperColorFormat _outputColorFormat = Source2MatHelperColorFormat.RGBA
 Select the output color format.
 
Texture _sourceTexture
 Set the source texture.
 
int _timeoutFrameCount = 1500
 The number of frames before the initialization process times out.
 
bool autoPlayAfterInitialize
 If set to true play after completion of initialization.
 
Source2MatHelperColorFormat baseColorFormat = Source2MatHelperColorFormat.RGBA
 The base color format.
 
Mat baseMat
 The base mat.
 
bool didUpdateImageBufferInCurrentFrame = false
 
bool didUpdateThisFrame = false
 
Mat frameMat
 The frame mat.
 
bool hasInitDone = false
 Indicates whether this instance has been initialized.
 
IEnumerator initCoroutine
 The initialization coroutine.
 
bool isInitWaiting = false
 Indicates whether this instance is waiting for initialization to complete.
 
bool isPlaying = false
 Indicates whether this instance has been initialized.
 
Texture2D texture
 The texture.
 
bool useAsyncGPUReadback
 The useAsyncGPUReadback.
 

Properties

UnityEvent onDisposed [get, set]
 
Source2MatHelperErrorUnityEvent onErrorOccurred [get, set]
 
UnityEvent onInitialized [get, set]
 
virtual Source2MatHelperColorFormat outputColorFormat [get, set]
 
virtual Texture sourceTexture [get, set]
 
virtual int timeoutFrameCount [get, set]
 
- Properties inherited from OpenCVForUnity.UnityUtils.Helper.ITextureSource2MatHelper
- Properties inherited from OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper

Detailed Description

A helper component class for efficiently converting Unity Texture objects, such as RenderTexture and external texture format Texture2D, to OpenCV Mat format using AsyncGPUReadback.

The AsyncGPUReadback2MatHelper class leverages AsyncGPUReadback to efficiently process texture data from Unity Texture classes that do not support direct pixel access through methods like GetPixels. This includes RenderTexture and certain externally provided Texture2D formats. The class transfers the texture data asynchronously to the CPU and converts it to an OpenCV Mat object for further processing.

By utilizing AsyncGPUReadback, this component optimizes resource usage and reduces CPU load, making it ideal for real-time image processing applications that involve complex textures.

Note: By setting outputColorFormat to RGBA processing that does not include extra color conversion is performed.

Attach this component to a GameObject and call GetMat() to retrieve the latest frame as a Mat object. The helper class manages asynchronous readback operations and ensures efficient texture data conversion suitable for image processing in Unity.

Member Function Documentation

◆ _Initialize()

virtual IEnumerator OpenCVForUnity.UnityUtils.Helper.AsyncGPUReadback2MatHelper._Initialize ( )
protectedvirtual

Initializes this instance by coroutine.

◆ CancelInitCoroutine()

virtual void OpenCVForUnity.UnityUtils.Helper.AsyncGPUReadback2MatHelper.CancelInitCoroutine ( )
protectedvirtual

Cancel Init Coroutine.

◆ DidUpdateThisFrame()

virtual bool OpenCVForUnity.UnityUtils.Helper.AsyncGPUReadback2MatHelper.DidUpdateThisFrame ( )
virtual

Indicates whether the readback buffer of the frame has been updated.

Returns
true, if the readback buffer has been updated false otherwise.

Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.

◆ Dispose()

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

Releases all resource used by the AsyncGPUReadback2MatHelper object.

Call Dispose when you are finished using the AsyncGPUReadback2MatHelper. The Dispose method leaves the AsyncGPUReadback2MatHelper in an unusable state. After calling Dispose, you must release all references to the AsyncGPUReadback2MatHelper so the garbage collector can reclaim the memory that the AsyncGPUReadback2MatHelper was occupying.

Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.

◆ GetBaseColorFormat()

virtual Source2MatHelperColorFormat OpenCVForUnity.UnityUtils.Helper.AsyncGPUReadback2MatHelper.GetBaseColorFormat ( )
virtual

Returns the readback buffer base color format.

Returns
The readback buffer base color format.

Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.

◆ GetDeviceName()

virtual string OpenCVForUnity.UnityUtils.Helper.AsyncGPUReadback2MatHelper.GetDeviceName ( )
virtual

Return the active image device name.

Returns
The active image device name.

Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.

◆ GetHeight()

virtual int OpenCVForUnity.UnityUtils.Helper.AsyncGPUReadback2MatHelper.GetHeight ( )
virtual

Returns the readback buffer height.

Returns
The readback buffer height.

Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.

◆ GetMat()

virtual Mat OpenCVForUnity.UnityUtils.Helper.AsyncGPUReadback2MatHelper.GetMat ( )
virtual

Get the mat of the current frame.

The Mat object's type is 'CV_8UC4' or 'CV_8UC3' or 'CV_8UC1' (ColorFormat is determined by the outputColorFormat setting). Please do not dispose of the returned mat as it will be reused.

Returns
The mat of the current frame.

Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.

◆ GetSourceTexture()

virtual Texture OpenCVForUnity.UnityUtils.Helper.AsyncGPUReadback2MatHelper.GetSourceTexture ( )
virtual

Returns the Source Texture.

Returns
The Source Texture.

◆ GetWidth()

virtual int OpenCVForUnity.UnityUtils.Helper.AsyncGPUReadback2MatHelper.GetWidth ( )
virtual

Returns the readback buffer width.

Returns
The readback buffer width.

Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.

◆ Initialize() [1/2]

virtual void OpenCVForUnity.UnityUtils.Helper.AsyncGPUReadback2MatHelper.Initialize ( bool autoPlay = true)
virtual

Initializes this instance.

Parameters
autoPlayIf set to true play after completion of initialization.

Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.

◆ Initialize() [2/2]

virtual void OpenCVForUnity.UnityUtils.Helper.AsyncGPUReadback2MatHelper.Initialize ( Texture sourceTexture,
bool autoPlay = true )
virtual

Initialize this instance.

Parameters
sourceTextureSource Texture.
autoPlayIf set to true play after completion of initialization.

◆ IsInitialized()

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

Indicates whether this instance has been initialized.

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

Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.

◆ IsPaused()

virtual bool OpenCVForUnity.UnityUtils.Helper.AsyncGPUReadback2MatHelper.IsPaused ( )
virtual

Indicates whether the readback is paused.

Returns
true, if the readback is playing, false otherwise.

Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.

◆ IsPlaying()

virtual bool OpenCVForUnity.UnityUtils.Helper.AsyncGPUReadback2MatHelper.IsPlaying ( )
virtual

Indicates whether the readback is currently playing.

Returns
true, if the readback is playing, false otherwise.

Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.

◆ LateUpdate()

virtual void OpenCVForUnity.UnityUtils.Helper.AsyncGPUReadback2MatHelper.LateUpdate ( )
protectedvirtual

◆ OnDestroy()

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

Raises the destroy event.

◆ Pause()

virtual void OpenCVForUnity.UnityUtils.Helper.AsyncGPUReadback2MatHelper.Pause ( )
virtual

Pauses the readback.

Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.

◆ Play()

virtual void OpenCVForUnity.UnityUtils.Helper.AsyncGPUReadback2MatHelper.Play ( )
virtual

Starts the readback.

Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.

◆ ReleaseResources()

virtual void OpenCVForUnity.UnityUtils.Helper.AsyncGPUReadback2MatHelper.ReleaseResources ( )
protectedvirtual

To release the resources.

◆ Stop()

virtual void OpenCVForUnity.UnityUtils.Helper.AsyncGPUReadback2MatHelper.Stop ( )
virtual

Stops the readback.

Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.

◆ Update()

virtual void OpenCVForUnity.UnityUtils.Helper.AsyncGPUReadback2MatHelper.Update ( )
protectedvirtual

Member Data Documentation

◆ _onDisposed

UnityEvent OpenCVForUnity.UnityUtils.Helper.AsyncGPUReadback2MatHelper._onDisposed
protected

UnityEvent that is triggered when this instance is disposed.

◆ _onErrorOccurred

Source2MatHelperErrorUnityEvent OpenCVForUnity.UnityUtils.Helper.AsyncGPUReadback2MatHelper._onErrorOccurred
protected

UnityEvent that is triggered when this instance is error Occurred.

◆ _onInitialized

UnityEvent OpenCVForUnity.UnityUtils.Helper.AsyncGPUReadback2MatHelper._onInitialized
protected

UnityEvent that is triggered when this instance is initialized.

◆ _outputColorFormat

Source2MatHelperColorFormat OpenCVForUnity.UnityUtils.Helper.AsyncGPUReadback2MatHelper._outputColorFormat = Source2MatHelperColorFormat.RGBA
protected

Select the output color format.

◆ _sourceTexture

Texture OpenCVForUnity.UnityUtils.Helper.AsyncGPUReadback2MatHelper._sourceTexture
protected

Set the source texture.

◆ _timeoutFrameCount

int OpenCVForUnity.UnityUtils.Helper.AsyncGPUReadback2MatHelper._timeoutFrameCount = 1500
protected

The number of frames before the initialization process times out.

◆ autoPlayAfterInitialize

bool OpenCVForUnity.UnityUtils.Helper.AsyncGPUReadback2MatHelper.autoPlayAfterInitialize
protected

If set to true play after completion of initialization.

◆ baseColorFormat

Source2MatHelperColorFormat OpenCVForUnity.UnityUtils.Helper.AsyncGPUReadback2MatHelper.baseColorFormat = Source2MatHelperColorFormat.RGBA
protected

The base color format.

◆ baseMat

Mat OpenCVForUnity.UnityUtils.Helper.AsyncGPUReadback2MatHelper.baseMat
protected

The base mat.

◆ didUpdateImageBufferInCurrentFrame

bool OpenCVForUnity.UnityUtils.Helper.AsyncGPUReadback2MatHelper.didUpdateImageBufferInCurrentFrame = false
protected

◆ didUpdateThisFrame

bool OpenCVForUnity.UnityUtils.Helper.AsyncGPUReadback2MatHelper.didUpdateThisFrame = false
protected

◆ frameMat

Mat OpenCVForUnity.UnityUtils.Helper.AsyncGPUReadback2MatHelper.frameMat
protected

The frame mat.

◆ hasInitDone

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

Indicates whether this instance has been initialized.

◆ initCoroutine

IEnumerator OpenCVForUnity.UnityUtils.Helper.AsyncGPUReadback2MatHelper.initCoroutine
protected

The initialization coroutine.

◆ isInitWaiting

bool OpenCVForUnity.UnityUtils.Helper.AsyncGPUReadback2MatHelper.isInitWaiting = false
protected

Indicates whether this instance is waiting for initialization to complete.

◆ isPlaying

bool OpenCVForUnity.UnityUtils.Helper.AsyncGPUReadback2MatHelper.isPlaying = false
protected

Indicates whether this instance has been initialized.

◆ texture

Texture2D OpenCVForUnity.UnityUtils.Helper.AsyncGPUReadback2MatHelper.texture
protected

The texture.

◆ useAsyncGPUReadback

bool OpenCVForUnity.UnityUtils.Helper.AsyncGPUReadback2MatHelper.useAsyncGPUReadback
protected

The useAsyncGPUReadback.

Property Documentation

◆ onDisposed

UnityEvent OpenCVForUnity.UnityUtils.Helper.AsyncGPUReadback2MatHelper.onDisposed
getset

◆ onErrorOccurred

Source2MatHelperErrorUnityEvent OpenCVForUnity.UnityUtils.Helper.AsyncGPUReadback2MatHelper.onErrorOccurred
getset

◆ onInitialized

UnityEvent OpenCVForUnity.UnityUtils.Helper.AsyncGPUReadback2MatHelper.onInitialized
getset

◆ outputColorFormat

virtual Source2MatHelperColorFormat OpenCVForUnity.UnityUtils.Helper.AsyncGPUReadback2MatHelper.outputColorFormat
getset

◆ sourceTexture

virtual Texture OpenCVForUnity.UnityUtils.Helper.AsyncGPUReadback2MatHelper.sourceTexture
getset

◆ timeoutFrameCount

virtual int OpenCVForUnity.UnityUtils.Helper.AsyncGPUReadback2MatHelper.timeoutFrameCount
getset

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