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.WebCamTexture2MatHelper Class Reference

A helper component class for obtaining camera frames from WebCamTexture and converting them to OpenCV Mat format in real-time. More...

Public Member Functions

virtual bool DidUpdateThisFrame ()
 Indicate whether the video buffer of the frame has been updated.
 
virtual void Dispose ()
 Releases all resource used by the WebCamTexture2MatHelper object.
 
virtual Source2MatHelperColorFormat GetBaseColorFormat ()
 Return the video base color format.
 
virtual Color32[] GetBufferColors ()
 Get the buffer colors.
 
virtual Matrix4x4 GetCameraToWorldMatrix ()
 Return the camera to world matrix.
 
virtual string GetDeviceName ()
 Return the active camera device name.
 
virtual float GetFPS ()
 Return the active camera framerate.
 
virtual int GetHeight ()
 Return the active camera height.
 
virtual Mat GetMat ()
 Get the mat of the current frame.
 
virtual Matrix4x4 GetProjectionMatrix ()
 Return the projection matrix matrix.
 
virtual WebCamDevice GetWebCamDevice ()
 Return the active WebcamDevice.
 
virtual WebCamTexture GetWebCamTexture ()
 Return the active WebcamTexture.
 
virtual int GetWidth ()
 Return the active camera width.
 
virtual void Initialize (bool autoPlay=true)
 Initialize this instance.
 
virtual void Initialize (bool requestedIsFrontFacing, float requestedFPS=30f, bool rotate90Degree=false, bool autoPlay=true)
 Initialize this instance.
 
virtual void Initialize (int requestedWidth, int requestedHeight, bool autoPlay=true)
 Initialize this instance.
 
virtual void Initialize (string deviceName, int requestedWidth, int requestedHeight, bool requestedIsFrontFacing=false, float requestedFPS=30f, bool rotate90Degree=false, bool autoPlay=true)
 Initialize this instance.
 
virtual bool IsFrontFacing ()
 Indicate whether the active camera device is currently front facng.
 
virtual bool IsInitialized ()
 Indicate whether this instance has been initialized.
 
virtual bool IsPaused ()
 Indicate whether the camera is paused.
 
virtual bool IsPlaying ()
 Indicate whether the active camera is currently playing.
 
virtual void Pause ()
 Pause the active camera.
 
virtual void Play ()
 Start the active camera.
 
virtual void Stop ()
 Stop the active camera.
 
- Public Member Functions inherited from OpenCVForUnity.UnityUtils.Helper.ICameraSource2MatHelper
- Public Member Functions inherited from OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper

Protected Member Functions

virtual IEnumerator _Initialize ()
 Initialize this instance by coroutine.
 
virtual void CancelInitCoroutine ()
 Cancel Init Coroutine.
 
virtual void FlipMat (Mat mat, bool flipVertical, bool flipHorizontal)
 Flip the mat.
 
virtual IEnumerator hasUserAuthorizedCameraPermission ()
 Check camera permission state by coroutine.
 
virtual IEnumerator OnApplicationFocus (bool hasFocus)
 
virtual void OnDestroy ()
 Raises the destroy event.
 
virtual void OnValidate ()
 
virtual void ReleaseResources ()
 To release the resources.
 
virtual void Update ()
 

Protected Attributes

bool _flipHorizontal = false
 Set whether to flip horizontal.
 
bool _flipVertical = false
 Set whether to flip vertically.
 
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.
 
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.
 
bool _requestedIsFrontFacing = false
 Set whether to use the front facing camera.
 
int _requestedWidth = 640
 Set the width of camera.
 
bool _rotate90Degree = false
 Set whether to rotate camera frame 90 degrees. (clockwise)
 
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.
 
Color32[] colors
 The buffer colors.
 
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 isScreenSizeChangeWaiting = false
 
Mat rotatedFrameMat
 The rotated frame mat.
 
int screenHeight
 The height of the screen.
 
ScreenOrientation screenOrientation
 The orientation of the screen.
 
int screenWidth
 The width of the screen.
 
WebCamDevice webCamDevice
 The active WebcamDevice.
 
WebCamTexture webCamTexture
 The active WebcamTexture.
 

Properties

virtual bool flipHorizontal [get, set]
 
virtual bool flipVertical [get, set]
 
UnityEvent onDisposed [get, set]
 
Source2MatHelperErrorUnityEvent onErrorOccurred [get, set]
 
UnityEvent onInitialized [get, set]
 
virtual Source2MatHelperColorFormat outputColorFormat [get, set]
 
virtual string requestedDeviceName [get, set]
 
virtual float requestedFPS [get, set]
 
virtual int requestedHeight [get, set]
 
virtual bool requestedIsFrontFacing [get, set]
 
virtual int requestedWidth [get, set]
 
virtual bool rotate90Degree [get, set]
 
virtual int timeoutFrameCount [get, set]
 
- Properties inherited from OpenCVForUnity.UnityUtils.Helper.ICameraSource2MatHelper
- Properties inherited from OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper

Detailed Description

A helper component class for obtaining camera frames from WebCamTexture and converting them to OpenCV Mat format in real-time.

The WebCamTexture2MatHelper class captures video frames from a device's camera using WebCamTexture and converts each frame to an OpenCV Mat object every frame. This component handles camera orientation, rotation, and necessary transformations to ensure the Mat output aligns correctly with the device's display orientation.

This component is particularly useful for image processing tasks in Unity, such as computer vision applications, where real-time camera input in Mat format is required. It enables seamless integration of OpenCV-based image processing algorithms with Unity's camera input.

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 camera frame in Mat format. The helper class manages camera start/stop operations and frame updates internally.

Member Function Documentation

◆ _Initialize()

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

Initialize this instance by coroutine.

◆ CancelInitCoroutine()

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

Cancel Init Coroutine.

◆ DidUpdateThisFrame()

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

Releases all resource used by the WebCamTexture2MatHelper object.

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

Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.

◆ FlipMat()

virtual void OpenCVForUnity.UnityUtils.Helper.WebCamTexture2MatHelper.FlipMat ( Mat mat,
bool flipVertical,
bool flipHorizontal )
protectedvirtual

Flip the mat.

Parameters
matMat.

◆ GetBaseColorFormat()

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

Return the video base color format.

Returns
The video base color format.

Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.

◆ GetBufferColors()

virtual Color32[] OpenCVForUnity.UnityUtils.Helper.WebCamTexture2MatHelper.GetBufferColors ( )
virtual

Get the buffer colors.

Returns
The buffer colors.

◆ GetCameraToWorldMatrix()

virtual Matrix4x4 OpenCVForUnity.UnityUtils.Helper.WebCamTexture2MatHelper.GetCameraToWorldMatrix ( )
virtual

Return the camera to world matrix.

Returns
The camera to world matrix.

Implements OpenCVForUnity.UnityUtils.Helper.ICameraSource2MatHelper.

◆ GetDeviceName()

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

Return the active camera device name.

Returns
The active camera device name.

Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.

◆ GetFPS()

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

Return the active camera framerate.

Returns
The active camera framerate.

Implements OpenCVForUnity.UnityUtils.Helper.ICameraSource2MatHelper.

◆ GetHeight()

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

Return the active camera height.

Returns
The active camera height.

Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.

◆ GetMat()

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

◆ GetProjectionMatrix()

virtual Matrix4x4 OpenCVForUnity.UnityUtils.Helper.WebCamTexture2MatHelper.GetProjectionMatrix ( )
virtual

Return the projection matrix matrix.

Returns
The projection matrix.

Implements OpenCVForUnity.UnityUtils.Helper.ICameraSource2MatHelper.

◆ GetWebCamDevice()

virtual WebCamDevice OpenCVForUnity.UnityUtils.Helper.WebCamTexture2MatHelper.GetWebCamDevice ( )
virtual

Return the active WebcamDevice.

Returns
The active WebcamDevice.

◆ GetWebCamTexture()

virtual WebCamTexture OpenCVForUnity.UnityUtils.Helper.WebCamTexture2MatHelper.GetWebCamTexture ( )
virtual

Return the active WebcamTexture.

Returns
The active WebcamTexture.

◆ GetWidth()

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

Return the active camera width.

Returns
The active camera width.

Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.

◆ hasUserAuthorizedCameraPermission()

virtual IEnumerator OpenCVForUnity.UnityUtils.Helper.WebCamTexture2MatHelper.hasUserAuthorizedCameraPermission ( )
protectedvirtual

Check camera permission state by coroutine.

◆ Initialize() [1/4]

virtual void OpenCVForUnity.UnityUtils.Helper.WebCamTexture2MatHelper.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/4]

virtual void OpenCVForUnity.UnityUtils.Helper.WebCamTexture2MatHelper.Initialize ( bool requestedIsFrontFacing,
float requestedFPS = 30f,
bool rotate90Degree = false,
bool autoPlay = true )
virtual

Initialize this instance.

Parameters
requestedIsFrontFacingIf set to true requested to using the front camera.
requestedFPSRequested FPS.
rotate90DegreeIf set to true requested to rotate camera frame 90 degrees. (clockwise)
autoPlayIf set to true play after completion of initialization.

◆ Initialize() [3/4]

virtual void OpenCVForUnity.UnityUtils.Helper.WebCamTexture2MatHelper.Initialize ( int requestedWidth,
int requestedHeight,
bool autoPlay = true )
virtual

Initialize this instance.

Parameters
requestedWidthRequested width.
requestedHeightRequested height.
autoPlayIf set to true play after completion of initialization.

◆ Initialize() [4/4]

virtual void OpenCVForUnity.UnityUtils.Helper.WebCamTexture2MatHelper.Initialize ( string deviceName,
int requestedWidth,
int requestedHeight,
bool requestedIsFrontFacing = false,
float requestedFPS = 30f,
bool rotate90Degree = false,
bool autoPlay = true )
virtual

Initialize this instance.

Parameters
deviceNameDevice name.
requestedWidthRequested width.
requestedHeightRequested height.
requestedIsFrontFacingIf set to true requested to using the front camera.
requestedFPSRequested FPS.
rotate90DegreeIf set to true requested to rotate camera frame 90 degrees. (clockwise)
autoPlayIf set to true play after completion of initialization.

◆ IsFrontFacing()

virtual bool OpenCVForUnity.UnityUtils.Helper.WebCamTexture2MatHelper.IsFrontFacing ( )
virtual

Indicate whether the active camera device is currently front facng.

Returns
true, if the active camera device is front facng, false otherwise.

Implements OpenCVForUnity.UnityUtils.Helper.ICameraSource2MatHelper.

◆ IsInitialized()

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

Indicate whether the camera is paused.

Returns
true, if the active camera is paused, false otherwise.

Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.

◆ IsPlaying()

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

Indicate whether the active camera is currently playing.

Returns
true, if the active camera is playing, false otherwise.

Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.

◆ OnApplicationFocus()

virtual IEnumerator OpenCVForUnity.UnityUtils.Helper.WebCamTexture2MatHelper.OnApplicationFocus ( bool hasFocus)
protectedvirtual

◆ OnDestroy()

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

Raises the destroy event.

◆ OnValidate()

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

◆ Pause()

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

Pause the active camera.

Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.

◆ Play()

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

Start the active camera.

Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.

◆ ReleaseResources()

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

To release the resources.

◆ Stop()

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

Stop the active camera.

Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.

◆ Update()

virtual void OpenCVForUnity.UnityUtils.Helper.WebCamTexture2MatHelper.Update ( )
protectedvirtual

Member Data Documentation

◆ _flipHorizontal

bool OpenCVForUnity.UnityUtils.Helper.WebCamTexture2MatHelper._flipHorizontal = false
protected

Set whether to flip horizontal.

◆ _flipVertical

bool OpenCVForUnity.UnityUtils.Helper.WebCamTexture2MatHelper._flipVertical = false
protected

Set whether to flip vertically.

◆ _onDisposed

UnityEvent OpenCVForUnity.UnityUtils.Helper.WebCamTexture2MatHelper._onDisposed
protected

UnityEvent that is triggered when this instance is disposed.

◆ _onErrorOccurred

Source2MatHelperErrorUnityEvent OpenCVForUnity.UnityUtils.Helper.WebCamTexture2MatHelper._onErrorOccurred
protected

UnityEvent that is triggered when this instance is error Occurred.

◆ _onInitialized

UnityEvent OpenCVForUnity.UnityUtils.Helper.WebCamTexture2MatHelper._onInitialized
protected

UnityEvent that is triggered when this instance is initialized.

◆ _outputColorFormat

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

Select the output color format.

◆ _requestedDeviceName

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

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

◆ _requestedFPS

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

Set the frame rate of camera.

◆ _requestedHeight

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

Set the height of camera.

◆ _requestedIsFrontFacing

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

Set whether to use the front facing camera.

◆ _requestedWidth

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

Set the width of camera.

◆ _rotate90Degree

bool OpenCVForUnity.UnityUtils.Helper.WebCamTexture2MatHelper._rotate90Degree = false
protected

Set whether to rotate camera frame 90 degrees. (clockwise)

◆ _timeoutFrameCount

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

The number of frames before the initialization process times out.

◆ autoPlayAfterInitialize

bool OpenCVForUnity.UnityUtils.Helper.WebCamTexture2MatHelper.autoPlayAfterInitialize
protected

If set to true play after completion of initialization.

◆ baseColorFormat

Source2MatHelperColorFormat OpenCVForUnity.UnityUtils.Helper.WebCamTexture2MatHelper.baseColorFormat = Source2MatHelperColorFormat.RGBA
protected

The base color format.

◆ baseMat

Mat OpenCVForUnity.UnityUtils.Helper.WebCamTexture2MatHelper.baseMat
protected

The base mat.

◆ colors

Color32 [] OpenCVForUnity.UnityUtils.Helper.WebCamTexture2MatHelper.colors
protected

The buffer colors.

◆ frameMat

Mat OpenCVForUnity.UnityUtils.Helper.WebCamTexture2MatHelper.frameMat
protected

The frame mat.

◆ hasInitDone

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

Indicates whether this instance has been initialized.

◆ initCoroutine

IEnumerator OpenCVForUnity.UnityUtils.Helper.WebCamTexture2MatHelper.initCoroutine
protected

The initialization coroutine.

◆ isInitWaiting

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

Indicates whether this instance is waiting for initialization to complete.

◆ isScreenSizeChangeWaiting

bool OpenCVForUnity.UnityUtils.Helper.WebCamTexture2MatHelper.isScreenSizeChangeWaiting = false
protected

◆ rotatedFrameMat

Mat OpenCVForUnity.UnityUtils.Helper.WebCamTexture2MatHelper.rotatedFrameMat
protected

The rotated frame mat.

◆ screenHeight

int OpenCVForUnity.UnityUtils.Helper.WebCamTexture2MatHelper.screenHeight
protected

The height of the screen.

◆ screenOrientation

ScreenOrientation OpenCVForUnity.UnityUtils.Helper.WebCamTexture2MatHelper.screenOrientation
protected

The orientation of the screen.

◆ screenWidth

int OpenCVForUnity.UnityUtils.Helper.WebCamTexture2MatHelper.screenWidth
protected

The width of the screen.

◆ webCamDevice

WebCamDevice OpenCVForUnity.UnityUtils.Helper.WebCamTexture2MatHelper.webCamDevice
protected

The active WebcamDevice.

◆ webCamTexture

WebCamTexture OpenCVForUnity.UnityUtils.Helper.WebCamTexture2MatHelper.webCamTexture
protected

The active WebcamTexture.

Property Documentation

◆ flipHorizontal

virtual bool OpenCVForUnity.UnityUtils.Helper.WebCamTexture2MatHelper.flipHorizontal
getset

◆ flipVertical

virtual bool OpenCVForUnity.UnityUtils.Helper.WebCamTexture2MatHelper.flipVertical
getset

◆ onDisposed

UnityEvent OpenCVForUnity.UnityUtils.Helper.WebCamTexture2MatHelper.onDisposed
getset

◆ onErrorOccurred

Source2MatHelperErrorUnityEvent OpenCVForUnity.UnityUtils.Helper.WebCamTexture2MatHelper.onErrorOccurred
getset

◆ onInitialized

UnityEvent OpenCVForUnity.UnityUtils.Helper.WebCamTexture2MatHelper.onInitialized
getset

◆ outputColorFormat

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

◆ requestedDeviceName

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

◆ requestedFPS

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

◆ requestedHeight

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

◆ requestedIsFrontFacing

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

◆ requestedWidth

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

◆ rotate90Degree

virtual bool OpenCVForUnity.UnityUtils.Helper.WebCamTexture2MatHelper.rotate90Degree
getset

◆ timeoutFrameCount

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

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