OpenCV for Unity  2.6.2
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.
Public Member Functions | Protected Member Functions | Protected Attributes | Properties | List of all members
OpenCVForUnity.UnityUtils.Helper.VideoCapture2MatHelper Class Reference

VideoCapture 2 mat helper. v 1.0.0 More...

Inheritance diagram for OpenCVForUnity.UnityUtils.Helper.VideoCapture2MatHelper:
OpenCVForUnity.UnityUtils.Helper.IVideoSource2MatHelper OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper

Public Member Functions

virtual void Initialize (bool autoPlay=true)
 Initialize this instance. More...
 
virtual void Initialize (string requestedVideoFilePath, bool autoPlay=true)
 Initialize this instance. More...
 
virtual bool IsInitialized ()
 Indicate whether this instance has been initialized. More...
 
virtual void Play ()
 Start the video. More...
 
virtual void Pause ()
 Pause the video. More...
 
virtual void Stop ()
 Stop the video. More...
 
virtual bool IsPlaying ()
 Indicate whether the video is currently playing. More...
 
virtual bool IsPaused ()
 Indicate whether the video is paused. More...
 
virtual string GetDeviceName ()
 Return the active video device name. More...
 
virtual int GetWidth ()
 Return the video width. More...
 
virtual int GetHeight ()
 Return the video height. More...
 
virtual float GetFPS ()
 Return the video framerate. More...
 
virtual float GetFramePosRatio ()
 Return the relative position of the video file: 0=start of the film, 1=end of the film. More...
 
virtual void SetFramePosRatio (float ratio)
 Set the relative position of the video file: 0=start of the film, 1=end of the film. More...
 
virtual int GetFrameIndex ()
 Return the video frame index. More...
 
virtual void SetFrameIndex (int index)
 Set the video frame index. More...
 
virtual int GetFrameCount ()
 Return the number of frames in the current video content. More...
 
virtual Source2MatHelperColorFormat GetBaseColorFormat ()
 Return the video base color format. More...
 
virtual VideoCapture GetVideoCapture ()
 Return the VideoCapture instance. More...
 
virtual bool DidUpdateThisFrame ()
 Indicate whether the video buffer of the frame has been updated. More...
 
virtual Mat GetMat ()
 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). More...
 
virtual void Dispose ()
 Releases all resource used by the VideoCaptrueToMatHelper object. More...
 

Protected Member Functions

virtual void OnValidate ()
 
virtual void LateUpdate ()
 
virtual void ReadFrame ()
 
virtual void OnDestroy ()
 Raises the destroy event. More...
 
virtual IEnumerator _Initialize ()
 Initialize this instance by coroutine. More...
 
virtual void StartWaitFrameTimeThread ()
 
virtual void StopWaitFrameTimeThread ()
 
virtual void WaitFrameTimeThreadWorker ()
 
virtual void CancelInitCoroutine ()
 Cancel Init Coroutine. More...
 
virtual void ReleaseResources ()
 To release the resources. More...
 

Protected Attributes

string _requestedVideoFilePath = string.Empty
 Set the video file path, relative to the starting point of the "StreamingAssets" folder, or absolute path. More...
 
int _apiPreference = Videoio.CAP_ANY
 Set the apiPreference. VideoCapture API backends identifier. (Advanced Option) See ReadMe.pdf for setup instructions for using CAP_FFMPEG on Windows platforms. More...
 
Source2MatHelperColorFormat _outputColorFormat = Source2MatHelperColorFormat.BGR
 Select the output color format. More...
 
int _timeoutFrameCount = 1500
 The number of frames before the initialization process times out. More...
 
bool _loop = true
 Indicate whether to play this video in a loop. More...
 
UnityEvent _onInitialized
 UnityEvent that is triggered when this instance is initialized. More...
 
UnityEvent _onDisposed
 UnityEvent that is triggered when this instance is disposed. More...
 
Source2MatHelperErrorUnityEvent _onErrorOccurred
 UnityEvent that is triggered when this instance is error Occurred. More...
 
System.Object videoCaptureLockObject = new System.Object()
 
VideoCapture _videoCapture
 
System.Object sync = new System.Object()
 
bool _isReading = false
 
bool _isPlaying = false
 
bool _didUpdateThisFrame = false
 
bool _didUpdateImageBufferInCurrentFrame = false
 
Mat frameMat
 The frame mat. More...
 
Mat baseMat
 The base mat. More...
 
System.Object imageBufferMatLockObject = new System.Object()
 The image buffer mat. More...
 
Mat _imageBufferMat
 
Source2MatHelperColorFormat baseColorFormat = Source2MatHelperColorFormat.BGR
 The base color format. More...
 
bool isInitWaiting = false
 Indicates whether this instance is waiting for initialization to complete. More...
 
bool hasInitDone = false
 Indicates whether this instance has been initialized. More...
 
IEnumerator initCoroutine
 The initialization coroutine. More...
 
IEnumerator getFilePathCoroutine
 The get file path coroutine. More...
 
bool _isThreadRunning = false
 
bool _shouldStopThread = false
 
bool autoPlayAfterInitialize
 If set to true play after completion of initialization. More...
 

Properties

virtual string requestedVideoFilePath [get, set]
 
virtual int apiPreference [get, set]
 
virtual Source2MatHelperColorFormat outputColorFormat [get, set]
 
virtual int timeoutFrameCount [get, set]
 
virtual bool loop [get, set]
 
UnityEvent onInitialized [get, set]
 
UnityEvent onDisposed [get, set]
 
Source2MatHelperErrorUnityEvent onErrorOccurred [get, set]
 
VideoCapture videoCapture [get, set]
 
virtual bool isReading [get, set]
 
virtual bool isPlaying [get, set]
 
virtual bool didUpdateThisFrame [get, set]
 
virtual bool didUpdateImageBufferInCurrentFrame [get, set]
 
Mat imageBufferMat [get, set]
 
virtual bool isThreadRunning [get, set]
 
virtual bool shouldStopThread [get, set]
 
- Properties inherited from OpenCVForUnity.UnityUtils.Helper.IVideoSource2MatHelper
string requestedVideoFilePath [get, set]
 
bool loop [get, set]
 
- Properties inherited from OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper
Source2MatHelperColorFormat outputColorFormat [get, set]
 
int timeoutFrameCount [get, set]
 
UnityEvent onInitialized [get, set]
 
UnityEvent onDisposed [get, set]
 
Source2MatHelperErrorUnityEvent onErrorOccurred [get, set]
 

Detailed Description

VideoCapture 2 mat helper. v 1.0.0

By setting outputColorFormat to BGR, processing that does not include extra color conversion is performed.

Member Function Documentation

◆ _Initialize()

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

Initialize this instance by coroutine.

◆ CancelInitCoroutine()

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

Cancel Init Coroutine.

◆ DidUpdateThisFrame()

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

Indicate whether the video buffer of the frame has been updated.

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

Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.

◆ Dispose()

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

Releases all resource used by the VideoCaptrueToMatHelper object.

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

Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.

◆ GetBaseColorFormat()

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

Return the video base color format.

Returns
The video base color format.

Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.

◆ GetDeviceName()

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

Return the active video device name.

Returns
The active video device name.

Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.

◆ GetFPS()

virtual float OpenCVForUnity.UnityUtils.Helper.VideoCapture2MatHelper.GetFPS ( )
virtual

Return the video framerate.

Returns
The video framerate.

Implements OpenCVForUnity.UnityUtils.Helper.IVideoSource2MatHelper.

◆ GetFrameCount()

virtual int OpenCVForUnity.UnityUtils.Helper.VideoCapture2MatHelper.GetFrameCount ( )
virtual

Return the number of frames in the current video content.

Returns
The number of frames in the current video content.

Implements OpenCVForUnity.UnityUtils.Helper.IVideoSource2MatHelper.

◆ GetFrameIndex()

virtual int OpenCVForUnity.UnityUtils.Helper.VideoCapture2MatHelper.GetFrameIndex ( )
virtual

Return the video frame index.

Returns
The video frame index.

Implements OpenCVForUnity.UnityUtils.Helper.IVideoSource2MatHelper.

◆ GetFramePosRatio()

virtual float OpenCVForUnity.UnityUtils.Helper.VideoCapture2MatHelper.GetFramePosRatio ( )
virtual

Return the relative position of the video file: 0=start of the film, 1=end of the film.

Returns
The relative position of the video file: 0=start of the film, 1=end of the film.

Implements OpenCVForUnity.UnityUtils.Helper.IVideoSource2MatHelper.

◆ GetHeight()

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

Return the video height.

Returns
The video height.

Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.

◆ GetMat()

virtual Mat OpenCVForUnity.UnityUtils.Helper.VideoCapture2MatHelper.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).

Returns
The mat of the current frame.

Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.

◆ GetVideoCapture()

virtual VideoCapture OpenCVForUnity.UnityUtils.Helper.VideoCapture2MatHelper.GetVideoCapture ( )
virtual

Return the VideoCapture instance.

Returns
The VideoCapture instance.

◆ GetWidth()

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

Return the video width.

Returns
The video width.

Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.

◆ Initialize() [1/2]

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

Initialize 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.VideoCapture2MatHelper.Initialize ( string  requestedVideoFilePath,
bool  autoPlay = true 
)
virtual

Initialize this instance.

Parameters
requestedVideoFilePathRequested video file path.
autoPlayIf set to true play after completion of initialization.

◆ IsInitialized()

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

Indicate 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.VideoCapture2MatHelper.IsPaused ( )
virtual

Indicate whether the video is paused.

Returns
true, if the video is paused, false otherwise.

Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.

◆ IsPlaying()

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

Indicate whether the video is currently playing.

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

Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.

◆ LateUpdate()

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

◆ OnDestroy()

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

Raises the destroy event.

◆ OnValidate()

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

◆ Pause()

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

◆ Play()

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

◆ ReadFrame()

virtual void OpenCVForUnity.UnityUtils.Helper.VideoCapture2MatHelper.ReadFrame ( )
protectedvirtual

◆ ReleaseResources()

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

To release the resources.

◆ SetFrameIndex()

virtual void OpenCVForUnity.UnityUtils.Helper.VideoCapture2MatHelper.SetFrameIndex ( int  index)
virtual

Set the video frame index.

Parameters
indexThe video frame index.

Implements OpenCVForUnity.UnityUtils.Helper.IVideoSource2MatHelper.

◆ SetFramePosRatio()

virtual void OpenCVForUnity.UnityUtils.Helper.VideoCapture2MatHelper.SetFramePosRatio ( float  ratio)
virtual

Set the relative position of the video file: 0=start of the film, 1=end of the film.

Parameters
ratioThe relative position of the video file: 0=start of the film, 1=end of the film.

Implements OpenCVForUnity.UnityUtils.Helper.IVideoSource2MatHelper.

◆ StartWaitFrameTimeThread()

virtual void OpenCVForUnity.UnityUtils.Helper.VideoCapture2MatHelper.StartWaitFrameTimeThread ( )
protectedvirtual

◆ Stop()

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

◆ StopWaitFrameTimeThread()

virtual void OpenCVForUnity.UnityUtils.Helper.VideoCapture2MatHelper.StopWaitFrameTimeThread ( )
protectedvirtual

◆ WaitFrameTimeThreadWorker()

virtual void OpenCVForUnity.UnityUtils.Helper.VideoCapture2MatHelper.WaitFrameTimeThreadWorker ( )
protectedvirtual

Member Data Documentation

◆ _apiPreference

int OpenCVForUnity.UnityUtils.Helper.VideoCapture2MatHelper._apiPreference = Videoio.CAP_ANY
protected

Set the apiPreference. VideoCapture API backends identifier. (Advanced Option) See ReadMe.pdf for setup instructions for using CAP_FFMPEG on Windows platforms.

◆ _didUpdateImageBufferInCurrentFrame

bool OpenCVForUnity.UnityUtils.Helper.VideoCapture2MatHelper._didUpdateImageBufferInCurrentFrame = false
protected

◆ _didUpdateThisFrame

bool OpenCVForUnity.UnityUtils.Helper.VideoCapture2MatHelper._didUpdateThisFrame = false
protected

◆ _imageBufferMat

Mat OpenCVForUnity.UnityUtils.Helper.VideoCapture2MatHelper._imageBufferMat
protected

◆ _isPlaying

bool OpenCVForUnity.UnityUtils.Helper.VideoCapture2MatHelper._isPlaying = false
protected

◆ _isReading

bool OpenCVForUnity.UnityUtils.Helper.VideoCapture2MatHelper._isReading = false
protected

◆ _isThreadRunning

bool OpenCVForUnity.UnityUtils.Helper.VideoCapture2MatHelper._isThreadRunning = false
protected

◆ _loop

bool OpenCVForUnity.UnityUtils.Helper.VideoCapture2MatHelper._loop = true
protected

Indicate whether to play this video in a loop.

◆ _onDisposed

UnityEvent OpenCVForUnity.UnityUtils.Helper.VideoCapture2MatHelper._onDisposed
protected

UnityEvent that is triggered when this instance is disposed.

◆ _onErrorOccurred

Source2MatHelperErrorUnityEvent OpenCVForUnity.UnityUtils.Helper.VideoCapture2MatHelper._onErrorOccurred
protected

UnityEvent that is triggered when this instance is error Occurred.

◆ _onInitialized

UnityEvent OpenCVForUnity.UnityUtils.Helper.VideoCapture2MatHelper._onInitialized
protected

UnityEvent that is triggered when this instance is initialized.

◆ _outputColorFormat

Source2MatHelperColorFormat OpenCVForUnity.UnityUtils.Helper.VideoCapture2MatHelper._outputColorFormat = Source2MatHelperColorFormat.BGR
protected

Select the output color format.

◆ _requestedVideoFilePath

string OpenCVForUnity.UnityUtils.Helper.VideoCapture2MatHelper._requestedVideoFilePath = string.Empty
protected

Set the video file path, relative to the starting point of the "StreamingAssets" folder, or absolute path.

◆ _shouldStopThread

bool OpenCVForUnity.UnityUtils.Helper.VideoCapture2MatHelper._shouldStopThread = false
protected

◆ _timeoutFrameCount

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

The number of frames before the initialization process times out.

◆ _videoCapture

VideoCapture OpenCVForUnity.UnityUtils.Helper.VideoCapture2MatHelper._videoCapture
protected

◆ autoPlayAfterInitialize

bool OpenCVForUnity.UnityUtils.Helper.VideoCapture2MatHelper.autoPlayAfterInitialize
protected

If set to true play after completion of initialization.

◆ baseColorFormat

Source2MatHelperColorFormat OpenCVForUnity.UnityUtils.Helper.VideoCapture2MatHelper.baseColorFormat = Source2MatHelperColorFormat.BGR
protected

The base color format.

◆ baseMat

Mat OpenCVForUnity.UnityUtils.Helper.VideoCapture2MatHelper.baseMat
protected

The base mat.

◆ frameMat

Mat OpenCVForUnity.UnityUtils.Helper.VideoCapture2MatHelper.frameMat
protected

The frame mat.

◆ getFilePathCoroutine

IEnumerator OpenCVForUnity.UnityUtils.Helper.VideoCapture2MatHelper.getFilePathCoroutine
protected

The get file path coroutine.

◆ hasInitDone

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

Indicates whether this instance has been initialized.

◆ imageBufferMatLockObject

System.Object OpenCVForUnity.UnityUtils.Helper.VideoCapture2MatHelper.imageBufferMatLockObject = new System.Object()
protected

The image buffer mat.

◆ initCoroutine

IEnumerator OpenCVForUnity.UnityUtils.Helper.VideoCapture2MatHelper.initCoroutine
protected

The initialization coroutine.

◆ isInitWaiting

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

Indicates whether this instance is waiting for initialization to complete.

◆ sync

System.Object OpenCVForUnity.UnityUtils.Helper.VideoCapture2MatHelper.sync = new System.Object()
protected

◆ videoCaptureLockObject

System.Object OpenCVForUnity.UnityUtils.Helper.VideoCapture2MatHelper.videoCaptureLockObject = new System.Object()
protected

Property Documentation

◆ apiPreference

virtual int OpenCVForUnity.UnityUtils.Helper.VideoCapture2MatHelper.apiPreference
getset

◆ didUpdateImageBufferInCurrentFrame

virtual bool OpenCVForUnity.UnityUtils.Helper.VideoCapture2MatHelper.didUpdateImageBufferInCurrentFrame
getsetprotected

◆ didUpdateThisFrame

virtual bool OpenCVForUnity.UnityUtils.Helper.VideoCapture2MatHelper.didUpdateThisFrame
getsetprotected

◆ imageBufferMat

Mat OpenCVForUnity.UnityUtils.Helper.VideoCapture2MatHelper.imageBufferMat
getsetprotected

◆ isPlaying

virtual bool OpenCVForUnity.UnityUtils.Helper.VideoCapture2MatHelper.isPlaying
getsetprotected

◆ isReading

virtual bool OpenCVForUnity.UnityUtils.Helper.VideoCapture2MatHelper.isReading
getsetprotected

◆ isThreadRunning

virtual bool OpenCVForUnity.UnityUtils.Helper.VideoCapture2MatHelper.isThreadRunning
getsetprotected

◆ loop

virtual bool OpenCVForUnity.UnityUtils.Helper.VideoCapture2MatHelper.loop
getset

◆ onDisposed

UnityEvent OpenCVForUnity.UnityUtils.Helper.VideoCapture2MatHelper.onDisposed
getset

◆ onErrorOccurred

Source2MatHelperErrorUnityEvent OpenCVForUnity.UnityUtils.Helper.VideoCapture2MatHelper.onErrorOccurred
getset

◆ onInitialized

UnityEvent OpenCVForUnity.UnityUtils.Helper.VideoCapture2MatHelper.onInitialized
getset

◆ outputColorFormat

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

◆ requestedVideoFilePath

virtual string OpenCVForUnity.UnityUtils.Helper.VideoCapture2MatHelper.requestedVideoFilePath
getset

◆ shouldStopThread

virtual bool OpenCVForUnity.UnityUtils.Helper.VideoCapture2MatHelper.shouldStopThread
getsetprotected

◆ timeoutFrameCount

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

◆ videoCapture

VideoCapture OpenCVForUnity.UnityUtils.Helper.VideoCapture2MatHelper.videoCapture
getsetprotected

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