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.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  MultiSource2MatHelperClassCategory : int {
  Camera = 0 ,
  Video ,
  Image ,
  Texture ,
  Custom
}
 
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 Member Functions

virtual MultiSource2MatHelperClassCategory ClassNameToClassCategory (MultiSource2MatHelperClassName className)
 
virtual void OnValidate ()
 

Protected Attributes

MultiSource2MatHelperClassCategory _currentSource2MatHelperClassCategory = MultiSource2MatHelperClassCategory.Camera
 
MultiSource2MatHelperClassName _currentSource2MatHelperClassName = MultiSource2MatHelperClassName.WebCamTexture2MatHelper
 
Component _customClassComponent = null
 Set the custom class <ISource2MatHelper> component.
 
bool _loop = true
 Indicate whether to play this video in a loop.
 
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.
 
bool _repeat = true
 Indicate whether to play this image in a repeat.
 
string _requestedDeviceName = null
 Set the name of the camera device to use. (or device index number)
 
float _requestedFPS = 30f
 Set the frame rate of camera.
 
int _requestedHeight = 480
 Set the height of camera.
 
string _requestedImageFilePath = string.Empty
 Set the image file path, relative to the starting point of the "StreamingAssets" folder, or absolute path.
 
bool _requestedIsFrontFacing = false
 Set whether to use the front facing camera.
 
MultiSource2MatHelperClassName _requestedSource2MatHelperClassName = MultiSource2MatHelperClassName.WebCamTexture2MatHelper
 Select the source to mat helper class name. If CustomSource2MatHelper is selected, only the UnityEvent inspector is overridden for the custom helper class component.
 
string _requestedVideoFilePath = string.Empty
 Set the video file path, relative to the starting point of the "StreamingAssets" folder, or absolute path.
 
int _requestedWidth = 640
 Set the width of camera.
 
ISource2MatHelper _source2MatHelper
 
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.
 

Properties

virtual Component customClassComponent [get, set]
 
virtual bool loop [get, set]
 
UnityEvent onDisposed [get, set]
 
Source2MatHelperErrorUnityEvent onErrorOccurred [get, set]
 
UnityEvent onInitialized [get, set]
 
virtual Source2MatHelperColorFormat outputColorFormat [get, set]
 
virtual bool repeat [get, set]
 
virtual string requestedDeviceName [get, set]
 
virtual float requestedFPS [get, set]
 
virtual int requestedHeight [get, set]
 
virtual string requestedImageFilePath [get, set]
 
virtual bool requestedIsFrontFacing [get, set]
 
MultiSource2MatHelperClassName requestedSource2MatHelperClassName [get, set]
 
virtual string requestedVideoFilePath [get, set]
 
virtual int requestedWidth [get, set]
 
ISource2MatHelper source2MatHelper [get]
 
virtual Texture sourceTexture [get, set]
 
virtual int timeoutFrameCount [get, set]
 
- 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

◆ MultiSource2MatHelperClassCategory

Enumerator
Camera 
Video 
Image 
Texture 
Custom 

◆ MultiSource2MatHelperClassName

Enumerator
WebCamTexture2MatHelper 
VideoCapture2MatHelper 
UnityVideoPlayer2MatHelper 
Image2MatHelper 
AsyncGPUReadback2MatHelper 
WebCamTexture2MatAsyncGPUHelper 
CustomSource2MatHelper 

Member Function Documentation

◆ ClassNameToClassCategory()

virtual MultiSource2MatHelperClassCategory OpenCVForUnity.UnityUtils.Helper.MultiSource2MatHelper.ClassNameToClassCategory ( 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

◆ _currentSource2MatHelperClassCategory

MultiSource2MatHelperClassCategory OpenCVForUnity.UnityUtils.Helper.MultiSource2MatHelper._currentSource2MatHelperClassCategory = MultiSource2MatHelperClassCategory.Camera
protected

◆ _currentSource2MatHelperClassName

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

◆ _customClassComponent

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

Set the custom class <ISource2MatHelper> component.

◆ _loop

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

Indicate whether to play this video in a loop.

◆ _onDisposed

UnityEvent OpenCVForUnity.UnityUtils.Helper.MultiSource2MatHelper._onDisposed
protected

UnityEvent that is triggered when this instance is disposed.

◆ _onErrorOccurred

Source2MatHelperErrorUnityEvent OpenCVForUnity.UnityUtils.Helper.MultiSource2MatHelper._onErrorOccurred
protected

UnityEvent that is triggered when this instance is error Occurred.

◆ _onInitialized

UnityEvent OpenCVForUnity.UnityUtils.Helper.MultiSource2MatHelper._onInitialized
protected

UnityEvent that is triggered when this instance is initialized.

◆ _outputColorFormat

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

Select the output color format.

◆ _repeat

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

Indicate whether to play this image in a repeat.

◆ _requestedDeviceName

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

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

◆ _requestedFPS

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

Set the frame rate of camera.

◆ _requestedHeight

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

Set the height of camera.

◆ _requestedImageFilePath

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

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

◆ _requestedIsFrontFacing

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

Set whether to use the front facing camera.

◆ _requestedSource2MatHelperClassName

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

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

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

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

◆ _requestedWidth

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

Set the width of camera.

◆ _source2MatHelper

ISource2MatHelper OpenCVForUnity.UnityUtils.Helper.MultiSource2MatHelper._source2MatHelper
protected

◆ _sourceTexture

Texture OpenCVForUnity.UnityUtils.Helper.MultiSource2MatHelper._sourceTexture
protected

Set the source texture.

◆ _timeoutFrameCount

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

The number of frames before the initialization process times out.

◆ 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

◆ loop

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

◆ onDisposed

UnityEvent OpenCVForUnity.UnityUtils.Helper.MultiSource2MatHelper.onDisposed
getset

◆ onErrorOccurred

Source2MatHelperErrorUnityEvent OpenCVForUnity.UnityUtils.Helper.MultiSource2MatHelper.onErrorOccurred
getset

◆ onInitialized

UnityEvent OpenCVForUnity.UnityUtils.Helper.MultiSource2MatHelper.onInitialized
getset

◆ outputColorFormat

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

◆ repeat

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

◆ requestedDeviceName

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

◆ requestedFPS

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

◆ requestedHeight

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

◆ requestedImageFilePath

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

◆ requestedIsFrontFacing

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

◆ requestedSource2MatHelperClassName

MultiSource2MatHelperClassName OpenCVForUnity.UnityUtils.Helper.MultiSource2MatHelper.requestedSource2MatHelperClassName
getset

◆ requestedVideoFilePath

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

◆ requestedWidth

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

◆ source2MatHelper

ISource2MatHelper OpenCVForUnity.UnityUtils.Helper.MultiSource2MatHelper.source2MatHelper
get

◆ sourceTexture

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

◆ timeoutFrameCount

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

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