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 camera frames from WebCamTexture and converting them to OpenCV Mat
format in real-time.
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 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 Mat | FlipAndRotateMat (Mat frameMat, Mat rotatedFrameMat, bool flipVertical, bool flipHorizontal, bool isFrontFacing, int videoRotationAngle, ScreenOrientation screenOrientation, bool isScreenOrientationCorrect, bool isVidevideoRotationAngleCorrect) |
virtual void | FlipMat (Mat mat, bool flipVertical, bool flipHorizontal, bool isFrontFacing, int videoRotationAngle) |
Flip Mat. | |
virtual IEnumerator | hasUserAuthorizedCameraPermission () |
Check camera permission state by coroutine. | |
virtual bool | IsScreenOrientationCorrect () |
Is ScreenOrientation the correct value? | |
virtual bool | IsVideoRotationAngleCorrect () |
Is VideoRotationAngle the correct value? | |
virtual bool | NeedsRotatedFrameMat (bool isScreenOrientationCorrect) |
Determines whether the RotatedFrameMat is needed. | |
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 |
bool | _flipVertical = false |
UnityEvent | _onDisposed |
Source2MatHelperErrorUnityEvent | _onErrorOccurred |
UnityEvent | _onInitialized |
Source2MatHelperColorFormat | _outputColorFormat = Source2MatHelperColorFormat.RGBA |
string | _requestedDeviceName = null |
float | _requestedFPS = 30f |
int | _requestedHeight = 480 |
bool | _requestedIsFrontFacing = false |
int | _requestedWidth = 640 |
bool | _rotate90Degree = false |
int | _timeoutFrameCount = 1500 |
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 | isScreenOrientationCorrect |
Is ScreenOrientation the correct value? | |
bool | isScreenSizeChangeWaiting = false |
isScreenSizeChangeWaiting | |
bool | isVideoRotationAngleCorrect |
Is VideoRotationAngle the correct value? | |
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] |
Set whether to flip horizontal. | |
virtual bool | flipVertical [get, set] |
Set whether to flip vertically. | |
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 | 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 bool | requestedIsFrontFacing [get, set] |
Set whether to use the front facing camera. | |
virtual int | requestedWidth [get, set] |
Set the width of camera. | |
virtual bool | rotate90Degree [get, set] |
Set whether to rotate camera frame 90 degrees. (clockwise) | |
virtual int | timeoutFrameCount [get, set] |
The number of frames before the initialization process times out. | |
Properties inherited from OpenCVForUnity.UnityUtils.Helper.ICameraSource2MatHelper | |
Properties inherited from OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper |
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.
|
protectedvirtual |
Initialize this instance by coroutine.
Reimplemented in OpenCVForUnity.UnityUtils.Helper.WebCamTexture2MatAsyncGPUHelper.
|
protectedvirtual |
Cancel Init 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.
Reimplemented in OpenCVForUnity.UnityUtils.Helper.WebCamTexture2MatAsyncGPUHelper.
|
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.
Reimplemented in OpenCVForUnity.UnityUtils.Helper.WebCamTexture2MatAsyncGPUHelper.
|
protectedvirtual |
|
protectedvirtual |
Flip Mat.
mat | |
flipVertical | |
flipHorizontal | |
isFrontFacing | |
videoRotationAngle |
|
virtual |
Return the video base color format.
Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.
|
virtual |
Get the buffer colors.
|
virtual |
Return the camera to world matrix.
Implements OpenCVForUnity.UnityUtils.Helper.ICameraSource2MatHelper.
|
virtual |
Return the active camera device name.
Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.
|
virtual |
Return the active camera framerate.
Implements OpenCVForUnity.UnityUtils.Helper.ICameraSource2MatHelper.
|
virtual |
Return the active camera 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.
Reimplemented in OpenCVForUnity.UnityUtils.Helper.WebCamTexture2MatAsyncGPUHelper.
|
virtual |
Return the projection matrix matrix.
Implements OpenCVForUnity.UnityUtils.Helper.ICameraSource2MatHelper.
|
virtual |
Return the active WebcamDevice.
|
virtual |
Return the active WebcamTexture.
|
virtual |
Return the active camera width.
Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.
|
protectedvirtual |
Check camera permission state by coroutine.
|
virtual |
Initialize this instance.
autoPlay | If set to true play after completion of initialization. |
Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.
|
virtual |
Initialize this instance.
requestedIsFrontFacing | If set to true requested to using the front camera. |
requestedFPS | Requested FPS. |
rotate90Degree | If set to true requested to rotate camera frame 90 degrees. (clockwise) |
autoPlay | If set to true play after completion of initialization. |
|
virtual |
Initialize this instance.
requestedWidth | Requested width. |
requestedHeight | Requested height. |
autoPlay | If set to true play after completion of initialization. |
|
virtual |
Initialize this instance.
deviceName | Device name. |
requestedWidth | Requested width. |
requestedHeight | Requested height. |
requestedIsFrontFacing | If set to true requested to using the front camera. |
requestedFPS | Requested FPS. |
rotate90Degree | If set to true requested to rotate camera frame 90 degrees. (clockwise) |
autoPlay | If set to true play after completion of initialization. |
|
virtual |
Indicate whether the active camera device is currently front facng.
true
, if the active camera device is front facng, false
otherwise.Implements OpenCVForUnity.UnityUtils.Helper.ICameraSource2MatHelper.
|
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 camera is paused.
true
, if the active camera is paused, false
otherwise.Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.
|
virtual |
Indicate whether the active camera is currently playing.
true
, if the active camera is playing, false
otherwise.Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.
|
protectedvirtual |
Is ScreenOrientation the correct value?
|
protectedvirtual |
Is VideoRotationAngle the correct value?
|
protectedvirtual |
Determines whether the RotatedFrameMat is needed.
|
protectedvirtual |
|
protectedvirtual |
Raises the destroy event.
|
protectedvirtual |
Reimplemented in OpenCVForUnity.UnityUtils.Helper.WebCamTexture2MatAsyncGPUHelper.
|
virtual |
Pause the active camera.
Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.
Reimplemented in OpenCVForUnity.UnityUtils.Helper.WebCamTexture2MatAsyncGPUHelper.
|
virtual |
Start the active camera.
Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.
Reimplemented in OpenCVForUnity.UnityUtils.Helper.WebCamTexture2MatAsyncGPUHelper.
|
protectedvirtual |
To release the resources.
Reimplemented in OpenCVForUnity.UnityUtils.Helper.WebCamTexture2MatAsyncGPUHelper.
|
virtual |
Stop the active camera.
Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.
Reimplemented in OpenCVForUnity.UnityUtils.Helper.WebCamTexture2MatAsyncGPUHelper.
|
protectedvirtual |
Reimplemented in OpenCVForUnity.UnityUtils.Helper.WebCamTexture2MatAsyncGPUHelper.
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
If set to true play after completion of initialization.
|
protected |
The base color format.
|
protected |
The base mat.
|
protected |
The buffer colors.
|
protected |
The frame mat.
|
protected |
Indicates whether this instance has been initialized.
|
protected |
The initialization coroutine.
|
protected |
Indicates whether this instance is waiting for initialization to complete.
|
protected |
Is ScreenOrientation the correct value?
|
protected |
isScreenSizeChangeWaiting
|
protected |
Is VideoRotationAngle the correct value?
|
protected |
The rotated frame mat.
|
protected |
The height of the screen.
|
protected |
The orientation of the screen.
|
protected |
The width of the screen.
|
protected |
The active WebcamDevice.
|
protected |
The active WebcamTexture.
|
getset |
Set whether to flip horizontal.
|
getset |
Set whether to flip vertically.
|
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 name of the camera device to use. (or device index number)
Implements OpenCVForUnity.UnityUtils.Helper.ICameraSource2MatHelper.
|
getset |
Set the frame rate of camera.
Implements OpenCVForUnity.UnityUtils.Helper.ICameraSource2MatHelper.
|
getset |
Set the height of camera.
Implements OpenCVForUnity.UnityUtils.Helper.ICameraSource2MatHelper.
|
getset |
Set whether to use the front facing camera.
Implements OpenCVForUnity.UnityUtils.Helper.ICameraSource2MatHelper.
|
getset |
Set the width of camera.
Implements OpenCVForUnity.UnityUtils.Helper.ICameraSource2MatHelper.
|
getset |
Set whether to rotate camera frame 90 degrees. (clockwise)
|
getset |
The number of frames before the initialization process times out.
Implements OpenCVForUnity.UnityUtils.Helper.ISource2MatHelper.