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.
Loading...
Searching...
No Matches
OpenCVForUnity.UnityUtils.Helper.MultiSource2MatHelper Class Reference

A versatile helper component class for obtaining frames as OpenCV Mat objects from multiple sources, allowing dynamic switching between different ISource2MatHelper classes. More...

Public Types

enum  MultiSource2MatHelperClassName : int {
  WebCamTexture2MatHelper = 0 ,
  VideoCapture2MatHelper ,
  UnityVideoPlayer2MatHelper ,
  Image2MatHelper ,
  AsyncGPUReadback2MatHelper ,
  WebCamTexture2MatAsyncGPUHelper ,
  CustomSource2MatHelper
}
 

Public Member Functions

virtual bool DidUpdateThisFrame ()
 Indicate whether the source buffer of the frame has been updated.
 
virtual void Dispose ()
 
virtual Source2MatHelperColorFormat GetBaseColorFormat ()
 Return the source base color format.
 
virtual MultiSource2MatHelperClassName GetCurrentSource2MatHelperClassName ()
 
virtual string GetDeviceName ()
 Return the source device name.
 
virtual int GetHeight ()
 Return the source height.
 
virtual Mat GetMat ()
 Get the mat of the current frame.
 
virtual int GetWidth ()
 Return the source width.
 
virtual void Initialize (bool autoPlay=true)
 Initialize this instance.
 
virtual bool IsInitialized ()
 Indicate whether this instance has been initialized.
 
virtual bool IsPaused ()
 Indicate whether the device is paused.
 
virtual bool IsPlaying ()
 Indicate whether the source device is currently playing.
 
virtual void Pause ()
 Pause the source device.
 
virtual void Play ()
 Start the source device.
 
virtual void Stop ()
 Stop the source device.
 
- Public Member Functions inherited from OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper

Protected Types

enum  MultiSource2MatHelperClassInterfaces : int {
  None = 0 ,
  Camera = 1 << 0 ,
  Video = 1 << 1 ,
  Image = 1 << 2 ,
  Texture = 1 << 3 ,
  Custom = 1 << 4 ,
  MatUpdateFPS = 1 << 5
}
 

Protected Member Functions

virtual MultiSource2MatHelperClassInterfaces ClassNameToClassInterfaces (MultiSource2MatHelperClassName className)
 
virtual void OnValidate ()
 

Protected Attributes

MultiSource2MatHelperClassInterfaces _currentSource2MatHelperClassInterfaces = MultiSource2MatHelperClassInterfaces.Camera
 
MultiSource2MatHelperClassName _currentSource2MatHelperClassName = MultiSource2MatHelperClassName.WebCamTexture2MatHelper
 
Component _customClassComponent = null
 
bool _loop = true
 
UnityEvent _onDisposed
 
Source2MatHelperErrorUnityEvent _onErrorOccurred
 
UnityEvent _onInitialized
 
Source2MatHelperColorFormat _outputColorFormat = Source2MatHelperColorFormat.RGBA
 
bool _repeat = true
 
string _requestedDeviceName = null
 
float _requestedFPS = 30f
 
int _requestedHeight = 480
 
string _requestedImageFilePath = string.Empty
 
bool _requestedIsFrontFacing = false
 
float _requestedMatUpdateFPS = 30f
 
MultiSource2MatHelperClassName _requestedSource2MatHelperClassName = MultiSource2MatHelperClassName.WebCamTexture2MatHelper
 
string _requestedVideoFilePath = string.Empty
 
int _requestedWidth = 640
 
ISource2MatHelper _source2MatHelper
 
Texture _sourceTexture
 
int _timeoutFrameCount = 1500
 
bool autoPlayAfterInitialize
 If set to true play after completion of initialization.
 

Properties

virtual Component customClassComponent [get, set]
 Set the custom class <ISource2MatHelper> component.
 
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 bool repeat [get, set]
 Indicate whether to play this image in a repeat.
 
virtual string requestedDeviceName [get, set]
 Set the name of the camera device to use. (or device index number)
 
virtual float requestedFPS [get, set]
 Set the frame rate of camera.
 
virtual int requestedHeight [get, set]
 Set the height of camera.
 
virtual string requestedImageFilePath [get, set]
 Set the image file path, relative to the starting point of the "StreamingAssets" folder, or absolute path.
 
virtual bool requestedIsFrontFacing [get, set]
 Set whether to use the front facing camera.
 
virtual float requestedMatUpdateFPS [get, set]
 Set the frame rate of camera.
 
MultiSource2MatHelperClassName requestedSource2MatHelperClassName [get, set]
 Select the source to mat helper class name. If CustomSource2MatHelper is selected, only the UnityEvent inspector is overridden for the custom helper class component.
 
virtual string requestedVideoFilePath [get, set]
 Set the video file path, relative to the starting point of the "StreamingAssets" folder, or absolute path.
 
virtual int requestedWidth [get, set]
 Set the width of camera.
 
ISource2MatHelper source2MatHelper [get]
 
virtual Texture sourceTexture [get, set]
 Set the source texture.
 
virtual int timeoutFrameCount [get, set]
 The number of frames before the initialization process times out.
 
- Properties inherited from OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper

Detailed Description

A versatile helper component class for obtaining frames as OpenCV Mat objects from multiple sources, allowing dynamic switching between different ISource2MatHelper classes.

The MultiSource2MatHelper class integrates various ISource2MatHelper implementations, such as WebCamTexture2MatHelper, VideoCapture2MatHelper, UnityVideoPlayer2MatHelper, and Image2MatHelper, providing a unified interface for accessing frames as Mat objects. Through settings in the Inspector or during runtime, users can select or switch between these helper classes to obtain frames from different sources, such as webcams, video files, images, or textures.

This component is particularly useful for applications requiring flexible frame input sources, making it easy to integrate various media types into OpenCV-based processing workflows within Unity.

Attach this component to a GameObject and select the desired source in the Inspector. Use GetMat() to retrieve the current frame as a Mat object. The helper class manages source initialization, switching, and frame updates as needed.

Member Enumeration Documentation

◆ MultiSource2MatHelperClassInterfaces

Enumerator
None 
Camera 
Video 
Image 
Texture 
Custom 
MatUpdateFPS 

◆ MultiSource2MatHelperClassName

Enumerator
WebCamTexture2MatHelper 
VideoCapture2MatHelper 
UnityVideoPlayer2MatHelper 
Image2MatHelper 
AsyncGPUReadback2MatHelper 
WebCamTexture2MatAsyncGPUHelper 
CustomSource2MatHelper 

Member Function Documentation

◆ ClassNameToClassInterfaces()

virtual MultiSource2MatHelperClassInterfaces OpenCVForUnity.UnityUtils.Helper.MultiSource2MatHelper.ClassNameToClassInterfaces ( MultiSource2MatHelperClassName className)
protectedvirtual

◆ DidUpdateThisFrame()

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

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

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

Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.

◆ Dispose()

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

◆ GetBaseColorFormat()

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

Return the source base color format.

Returns
The source base color format.

Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.

◆ GetCurrentSource2MatHelperClassName()

virtual MultiSource2MatHelperClassName OpenCVForUnity.UnityUtils.Helper.MultiSource2MatHelper.GetCurrentSource2MatHelperClassName ( )
virtual

◆ GetDeviceName()

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

Return the source device name.

Returns
The source device name.

Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.

◆ GetHeight()

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

Return the source height.

Returns
The source height.

Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.

◆ GetMat()

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

◆ GetWidth()

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

Return the source width.

Returns
The source width.

Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.

◆ Initialize()

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

Initialize this instance.

Parameters
autoPlayIf set to true play after completion of initialization.

Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.

◆ IsInitialized()

virtual bool OpenCVForUnity.UnityUtils.Helper.MultiSource2MatHelper.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.MultiSource2MatHelper.IsPaused ( )
virtual

Indicate whether the device is paused.

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

Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.

◆ IsPlaying()

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

Indicate whether the source device is currently playing.

Returns
true, if the source device is playing, false otherwise.

Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.

◆ OnValidate()

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

◆ Pause()

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

Pause the source device.

Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.

◆ Play()

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

Start the source device.

Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.

◆ Stop()

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

Stop the source device.

Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.

Member Data Documentation

◆ _currentSource2MatHelperClassInterfaces

MultiSource2MatHelperClassInterfaces OpenCVForUnity.UnityUtils.Helper.MultiSource2MatHelper._currentSource2MatHelperClassInterfaces = MultiSource2MatHelperClassInterfaces.Camera
protected

◆ _currentSource2MatHelperClassName

MultiSource2MatHelperClassName OpenCVForUnity.UnityUtils.Helper.MultiSource2MatHelper._currentSource2MatHelperClassName = MultiSource2MatHelperClassName.WebCamTexture2MatHelper
protected

◆ _customClassComponent

Component OpenCVForUnity.UnityUtils.Helper.MultiSource2MatHelper._customClassComponent = null
protected

◆ _loop

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

◆ _onDisposed

UnityEvent OpenCVForUnity.UnityUtils.Helper.MultiSource2MatHelper._onDisposed
protected

◆ _onErrorOccurred

Source2MatHelperErrorUnityEvent OpenCVForUnity.UnityUtils.Helper.MultiSource2MatHelper._onErrorOccurred
protected

◆ _onInitialized

UnityEvent OpenCVForUnity.UnityUtils.Helper.MultiSource2MatHelper._onInitialized
protected

◆ _outputColorFormat

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

◆ _repeat

bool OpenCVForUnity.UnityUtils.Helper.MultiSource2MatHelper._repeat = true
protected

◆ _requestedDeviceName

string OpenCVForUnity.UnityUtils.Helper.MultiSource2MatHelper._requestedDeviceName = null
protected

◆ _requestedFPS

float OpenCVForUnity.UnityUtils.Helper.MultiSource2MatHelper._requestedFPS = 30f
protected

◆ _requestedHeight

int OpenCVForUnity.UnityUtils.Helper.MultiSource2MatHelper._requestedHeight = 480
protected

◆ _requestedImageFilePath

string OpenCVForUnity.UnityUtils.Helper.MultiSource2MatHelper._requestedImageFilePath = string.Empty
protected

◆ _requestedIsFrontFacing

bool OpenCVForUnity.UnityUtils.Helper.MultiSource2MatHelper._requestedIsFrontFacing = false
protected

◆ _requestedMatUpdateFPS

float OpenCVForUnity.UnityUtils.Helper.MultiSource2MatHelper._requestedMatUpdateFPS = 30f
protected

◆ _requestedSource2MatHelperClassName

MultiSource2MatHelperClassName OpenCVForUnity.UnityUtils.Helper.MultiSource2MatHelper._requestedSource2MatHelperClassName = MultiSource2MatHelperClassName.WebCamTexture2MatHelper
protected

◆ _requestedVideoFilePath

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

◆ _requestedWidth

int OpenCVForUnity.UnityUtils.Helper.MultiSource2MatHelper._requestedWidth = 640
protected

◆ _source2MatHelper

ISource2MatHelper OpenCVForUnity.UnityUtils.Helper.MultiSource2MatHelper._source2MatHelper
protected

◆ _sourceTexture

Texture OpenCVForUnity.UnityUtils.Helper.MultiSource2MatHelper._sourceTexture
protected

◆ _timeoutFrameCount

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

◆ autoPlayAfterInitialize

bool OpenCVForUnity.UnityUtils.Helper.MultiSource2MatHelper.autoPlayAfterInitialize
protected

If set to true play after completion of initialization.

Property Documentation

◆ customClassComponent

virtual Component OpenCVForUnity.UnityUtils.Helper.MultiSource2MatHelper.customClassComponent
getset

Set the custom class <ISource2MatHelper> component.

◆ loop

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

Indicate whether to play this video in a loop.

◆ onDisposed

UnityEvent OpenCVForUnity.UnityUtils.Helper.MultiSource2MatHelper.onDisposed
getset

UnityEvent that is triggered when this instance is disposed.

Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.

◆ onErrorOccurred

Source2MatHelperErrorUnityEvent OpenCVForUnity.UnityUtils.Helper.MultiSource2MatHelper.onErrorOccurred
getset

UnityEvent that is triggered when this instance is error Occurred.

Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.

◆ onInitialized

UnityEvent OpenCVForUnity.UnityUtils.Helper.MultiSource2MatHelper.onInitialized
getset

UnityEvent that is triggered when this instance is initialized.

Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.

◆ outputColorFormat

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

Select the output color format.

Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.

◆ repeat

virtual bool OpenCVForUnity.UnityUtils.Helper.MultiSource2MatHelper.repeat
getset

Indicate whether to play this image in a repeat.

◆ requestedDeviceName

virtual string OpenCVForUnity.UnityUtils.Helper.MultiSource2MatHelper.requestedDeviceName
getset

Set the name of the camera device to use. (or device index number)

◆ requestedFPS

virtual float OpenCVForUnity.UnityUtils.Helper.MultiSource2MatHelper.requestedFPS
getset

Set the frame rate of camera.

◆ requestedHeight

virtual int OpenCVForUnity.UnityUtils.Helper.MultiSource2MatHelper.requestedHeight
getset

Set the height of camera.

◆ requestedImageFilePath

virtual string OpenCVForUnity.UnityUtils.Helper.MultiSource2MatHelper.requestedImageFilePath
getset

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

◆ requestedIsFrontFacing

virtual bool OpenCVForUnity.UnityUtils.Helper.MultiSource2MatHelper.requestedIsFrontFacing
getset

Set whether to use the front facing camera.

◆ requestedMatUpdateFPS

virtual float OpenCVForUnity.UnityUtils.Helper.MultiSource2MatHelper.requestedMatUpdateFPS
getset

Set the frame rate of camera.

◆ requestedSource2MatHelperClassName

MultiSource2MatHelperClassName OpenCVForUnity.UnityUtils.Helper.MultiSource2MatHelper.requestedSource2MatHelperClassName
getset

Select the source to mat helper class name. If CustomSource2MatHelper is selected, only the UnityEvent inspector is overridden for the custom helper class component.

◆ requestedVideoFilePath

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

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

◆ requestedWidth

virtual int OpenCVForUnity.UnityUtils.Helper.MultiSource2MatHelper.requestedWidth
getset

Set the width of camera.

◆ source2MatHelper

ISource2MatHelper OpenCVForUnity.UnityUtils.Helper.MultiSource2MatHelper.source2MatHelper
get

◆ sourceTexture

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

Set the source texture.

◆ timeoutFrameCount

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

The number of frames before the initialization process times out.

Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.


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