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.
|
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 |
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.
|
protectedvirtual |
Initializes this instance by coroutine.
|
protectedvirtual |
Cancel Init Coroutine.
|
virtual |
Indicates whether the readback buffer of the frame has been updated.
true
, if the readback buffer has been updated false
otherwise.Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.
|
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.
|
virtual |
Returns the readback buffer base color format.
Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.
|
virtual |
Return the active image device name.
Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.
|
virtual |
Returns the readback buffer height.
Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.
|
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.
Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.
|
virtual |
Returns the Source Texture.
|
virtual |
Returns the readback buffer width.
Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.
|
virtual |
Initializes this instance.
autoPlay | If set to true play after completion of initialization. |
Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.
|
virtual |
Initialize this instance.
sourceTexture | Source Texture. |
autoPlay | If set to true play after completion of initialization. |
|
virtual |
Indicates whether this instance has been initialized.
true
, if this instance has been initialized, false
otherwise.Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.
|
virtual |
Indicates whether the readback is paused.
true
, if the readback is playing, false
otherwise.Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.
|
virtual |
Indicates whether the readback is currently playing.
true
, if the readback is playing, false
otherwise.Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.
|
protectedvirtual |
|
protectedvirtual |
Raises the destroy event.
|
virtual |
Pauses the readback.
Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.
|
virtual |
Starts the readback.
Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.
|
protectedvirtual |
To release the resources.
|
virtual |
Stops the readback.
Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.
|
protectedvirtual |
|
protected |
UnityEvent that is triggered when this instance is disposed.
|
protected |
UnityEvent that is triggered when this instance is error Occurred.
|
protected |
UnityEvent that is triggered when this instance is initialized.
|
protected |
Select the output color format.
|
protected |
Set the source texture.
|
protected |
The number of frames before the initialization process times out.
|
protected |
If set to true play after completion of initialization.
|
protected |
The base color format.
|
protected |
The base mat.
|
protected |
|
protected |
|
protected |
The frame mat.
|
protected |
Indicates whether this instance has been initialized.
|
protected |
The initialization coroutine.
|
protected |
Indicates whether this instance is waiting for initialization to complete.
|
protected |
Indicates whether this instance has been initialized.
|
protected |
The texture.
|
protected |
The useAsyncGPUReadback.
|
getset |
|
getset |
|
getset |
|
getset |
|
getset |
|
getset |