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

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

Public Member Functions

virtual VideoCapture GetVideoCapture ()
 Return the VideoCapture instanse.
 
- Public Member Functions inherited from OpenCVForUnity.UnityUtils.Helper.WebCamTexture2MatHelper
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

Additional Inherited Members

- Protected Member Functions inherited from OpenCVForUnity.UnityUtils.Helper.WebCamTexture2MatHelper
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 inherited from OpenCVForUnity.UnityUtils.Helper.WebCamTexture2MatHelper
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 inherited from OpenCVForUnity.UnityUtils.Helper.WebCamTexture2MatHelper
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 OpenCV's VideoCapture and converting them to OpenCV Mat format in real-time.

The VideoCaptureCameraInput2MatHelper class captures video frames from a device's camera using OpenCV's VideoCapture 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 VideoCapture's camera input.

Note: Use the WebCamDevice.isFrontFacing and WebCamTexture.videoRotationAngle properties to flip the camera input image in VideoCaptue to the correct orientation. Note: This class is experimental and will not work properly on many platforms. Currently, it falls back to WebCamTexture2MatHelper for all but Windows and MacOS platforms. Note: By setting outputColorFormat to BGR, 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

◆ GetVideoCapture()

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

Return the VideoCapture instanse.

Returns
The VideoCapture instanse.

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