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.
|
A helper component class for obtaining video frames from a file using Unity's VideoPlayer
and converting them to OpenCV Mat
format.
More...
Public Member Functions | |
virtual bool | DidUpdateThisFrame () |
Use this to check if the Mat has changed since the last frame. Since it would not make sense to do expensive video processing in each Update call, check this value before doing any processing. | |
virtual void | Dispose () |
Releases all resource used by the UnityVideoPlayer2MatHelper object. | |
virtual Source2MatHelperColorFormat | GetBaseColorFormat () |
Return the video base color format. | |
virtual string | GetDeviceName () |
Return the active video device name. | |
virtual float | GetFPS () |
Return the video framerate. | |
virtual int | GetFrameCount () |
Return the number of frames in the current video content. | |
virtual int | GetFrameIndex () |
Return the video frame index. | |
virtual float | GetFramePosRatio () |
Return the relative position of the video file: 0=start of the film, 1=end of the film. | |
virtual int | GetHeight () |
Return the video height. | |
virtual Mat | GetMat () |
Get the mat of the current frame. | |
virtual VideoPlayer | GetVideoPlayer () |
Return the VideoCapture instance. | |
virtual int | GetWidth () |
Return the video width. | |
virtual void | Initialize (bool autoPlay=true) |
Initialize this instance. | |
virtual void | Initialize (string requestedVideoFilePath, bool autoPlay=true) |
Initialize this instance. | |
virtual bool | IsInitialized () |
Indicate whether this instance has been initialized. | |
virtual bool | IsPaused () |
Indicate whether the video is paused. | |
virtual bool | IsPlaying () |
Indicate whether the video is currently playing. | |
virtual void | Pause () |
Pause the video. | |
virtual void | Play () |
Start the video. | |
virtual void | SetFrameIndex (int index) |
Set the video frame index. | |
virtual void | SetFramePosRatio (float ratio) |
Set the relative position of the video file: 0=start of the film, 1=end of the film. | |
virtual void | Stop () |
Stop the video. | |
Public Member Functions inherited from OpenCVForUnity.UnityUtils.Helper.IVideoSource2MatHelper | |
Public Member Functions inherited from OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper |
Protected Member Functions | |
virtual IEnumerator | _Initialize () |
Initialize this instance by coroutine. | |
virtual IEnumerator | _WaitForEndOfFrameCoroutine () |
virtual void | CancelInitCoroutine () |
Cancel Init Coroutine. | |
virtual void | CancelWaitForEndOfFrameCoroutine () |
Cancel WaitForEndOfFrame Coroutine. | |
virtual void | ErrorReceived (VideoPlayer source, string message) |
virtual void | FrameReady (VideoPlayer vp, long frameIndex) |
virtual void | OnCompleteReadback (AsyncGPUReadbackRequest request, long frameIndex) |
virtual void | OnDestroy () |
Raises the destroy event. | |
virtual void | OnValidate () |
virtual void | PrepareCompleted (VideoPlayer vp) |
virtual void | ReleaseResources () |
To release the resources. | |
Protected Attributes | |
bool | _loop = true |
UnityEvent | _onDisposed |
Source2MatHelperErrorUnityEvent | _onErrorOccurred |
UnityEvent | _onInitialized |
Source2MatHelperColorFormat | _outputColorFormat = Source2MatHelperColorFormat.RGBA |
string | _requestedVideoFilePath = string.Empty |
int | _timeoutFrameCount = 1500 |
AsyncGPUReadbackRequest | asyncGPUReadbackRequestBuffer |
asyncGPUReadbackRequestBuffer | |
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 | didUpdateThisFrame = false |
Whether the mat that can be obtained with the GetMat method has been updated in this frame. This flag is changed after waiting until WaitForEndOfFrame in the coroutine. | |
long | frameIndex |
The frame index. | |
long | frameIndexBuffer |
frameIndexBuffer | |
Mat | frameMat |
The frame mat. | |
IEnumerator | getFilePathCoroutine |
The get file path coroutine. | |
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. | |
Texture2D | texture2DBuffer |
texture2DBuffer. | |
bool | useAsyncGPUReadback |
The useAsyncGPUReadback. | |
VideoPlayer | videoPlayer |
The videoPlayer. | |
IEnumerator | waitForEndOfFrameCoroutine |
The waitForEndOfFrameCoroutine. | |
Properties | |
virtual bool | loop [get, set] |
Indicate whether to play this video in a loop. | |
UnityEvent | onDisposed [get, set] |
UnityEvent that is triggered when this instance is disposed. | |
Source2MatHelperErrorUnityEvent | onErrorOccurred [get, set] |
UnityEvent that is triggered when this instance is error Occurred. | |
UnityEvent | onInitialized [get, set] |
UnityEvent that is triggered when this instance is initialized. | |
virtual Source2MatHelperColorFormat | outputColorFormat [get, set] |
Select the output color format. | |
virtual string | requestedVideoFilePath [get, set] |
Set the video file path, relative to the starting point of the "StreamingAssets" folder, or absolute path. | |
virtual int | timeoutFrameCount [get, set] |
The number of frames before the initialization process times out. | |
Properties inherited from OpenCVForUnity.UnityUtils.Helper.IVideoSource2MatHelper | |
Properties inherited from OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper |
A helper component class for obtaining video frames from a file using Unity's VideoPlayer
and converting them to OpenCV Mat
format.
The UnityVideoPlayer2MatHelper
class uses Unity's VideoPlayer
to read frames from a specified video file and converts each frame to an OpenCV Mat
object. This component automatically retrieves frames based on the video's playback rate, ensuring smooth frame updates and accurate timing.
To ensure compatibility within Unity, it is recommended to use the MP4 format for video files, as it is widely supported by the VideoPlayer
class.
This component is particularly useful for applications requiring frame-by-frame video processing in Unity, allowing seamless integration with OpenCV-based image processing routines while using Unity’s native video playback features.
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 current video frame in Mat
format. The helper class manages video file loading, playback control, and frame updates based on the video's playback rate.
|
protectedvirtual |
Initialize this instance by coroutine.
|
protectedvirtual |
|
protectedvirtual |
Cancel Init Coroutine.
|
protectedvirtual |
Cancel WaitForEndOfFrame Coroutine.
|
virtual |
Use this to check if the Mat has changed since the last frame. Since it would not make sense to do expensive video processing in each Update call, check this value before doing any processing.
true
, if the Mat has been updated false
otherwise.Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.
|
virtual |
Releases all resource used by the UnityVideoPlayer2MatHelper object.
Call Dispose when you are finished using the UnityVideoPlayer2MatHelper. The Dispose method leaves the UnityVideoPlayer2MatHelper in an unusable state. After calling Dispose, you must release all references to the UnityVideoPlayer2MatHelper so the garbage collector can reclaim the memory that the UnityVideoPlayer2MatHelper was occupying.
Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.
|
protectedvirtual |
|
protectedvirtual |
|
virtual |
Return the video base color format.
Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.
|
virtual |
Return the active video device name.
Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.
|
virtual |
Return the video framerate.
Implements OpenCVForUnity.UnityUtils.Helper.IVideoSource2MatHelper.
|
virtual |
Return the number of frames in the current video content.
Implements OpenCVForUnity.UnityUtils.Helper.IVideoSource2MatHelper.
|
virtual |
Return the video frame index.
Implements OpenCVForUnity.UnityUtils.Helper.IVideoSource2MatHelper.
|
virtual |
Return the relative position of the video file: 0=start of the film, 1=end of the film.
Implements OpenCVForUnity.UnityUtils.Helper.IVideoSource2MatHelper.
|
virtual |
Return the video 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 |
Return the VideoCapture instance.
|
virtual |
Return the video width.
Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.
|
virtual |
Initialize this instance.
autoPlay | If set to true play after completion of initialization. |
Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.
|
virtual |
Initialize this instance.
requestedVideoFilePath | Requested video file path. |
autoPlay | If set to true play after completion of initialization. |
|
virtual |
Indicate whether this instance has been initialized.
true
, if this instance has been initialized, false
otherwise.Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.
|
virtual |
Indicate whether the video is paused.
true
, if the video is paused, false
otherwise.Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.
|
virtual |
Indicate whether the video is currently playing.
true
, if the video is playing, false
otherwise.Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.
|
protectedvirtual |
|
protectedvirtual |
Raises the destroy event.
|
protectedvirtual |
|
virtual |
Pause the video.
Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.
|
virtual |
Start the video.
Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.
|
protectedvirtual |
|
protectedvirtual |
To release the resources.
|
virtual |
Set the video frame index.
index | The video frame index. |
Implements OpenCVForUnity.UnityUtils.Helper.IVideoSource2MatHelper.
|
virtual |
Set the relative position of the video file: 0=start of the film, 1=end of the film.
ratio | The relative position of the video file: 0=start of the film, 1=end of the film. |
Implements OpenCVForUnity.UnityUtils.Helper.IVideoSource2MatHelper.
|
virtual |
Stop the video.
Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
asyncGPUReadbackRequestBuffer
|
protected |
If set to true play after completion of initialization.
|
protected |
The base color format.
|
protected |
The base mat.
|
protected |
Whether the mat that can be obtained with the GetMat method has been updated in this frame. This flag is changed after waiting until WaitForEndOfFrame in the coroutine.
|
protected |
The frame index.
|
protected |
frameIndexBuffer
|
protected |
The frame mat.
|
protected |
The get file path coroutine.
|
protected |
Indicates whether this instance has been initialized.
|
protected |
The initialization coroutine.
|
protected |
Indicates whether this instance is waiting for initialization to complete.
|
protected |
texture2DBuffer.
|
protected |
The useAsyncGPUReadback.
|
protected |
The videoPlayer.
|
protected |
The waitForEndOfFrameCoroutine.
|
getset |
Indicate whether to play this video in a loop.
Implements OpenCVForUnity.UnityUtils.Helper.IVideoSource2MatHelper.
|
getset |
UnityEvent that is triggered when this instance is disposed.
Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.
|
getset |
UnityEvent that is triggered when this instance is error Occurred.
Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.
|
getset |
UnityEvent that is triggered when this instance is initialized.
Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.
|
getset |
Select the output color format.
Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.
|
getset |
Set the video file path, relative to the starting point of the "StreamingAssets" folder, or absolute path.
Implements OpenCVForUnity.UnityUtils.Helper.IVideoSource2MatHelper.
|
getset |
The number of frames before the initialization process times out.
Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.