A helper component class for efficiently obtaining camera frames from WebCamTexture and converting them to OpenCV Mat
format in real-time using AsyncGPUReadback
.
More...
|
override 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.
|
|
override void | Dispose () |
| Releases all resource used by the WebCamTexture2MatAsyncGPUHelper object.
|
|
override Mat | GetMat () |
| Get the mat of the current frame.
|
|
virtual float | GetMatUpdateFPS () |
| Return the frame rate at which the Mat is updated. (interval at which the DidUpdateThisFrame() method becomes true).
|
|
override void | Pause () |
| Pause the active camera.
|
|
override void | Play () |
| Start the active camera.
|
|
override void | Stop () |
| Stop the active camera.
|
|
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 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.
|
|
|
override IEnumerator | _Initialize () |
| Initialize this instance by coroutine.
|
|
virtual IEnumerator | _WaitForEndOfFrameCoroutine () |
|
virtual void | CallReadback () |
|
virtual void | CancelWaitForEndOfFrameCoroutine () |
| Cancel WaitForEndOfFrame Coroutine.
|
|
virtual void | OnCompleteReadback (AsyncGPUReadbackRequest request) |
|
override void | OnValidate () |
|
override void | ReleaseResources () |
| To release the resources.
|
|
override void | Update () |
|
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 float | requestedMatUpdateFPS [get, set] |
| Sets the frame rate at which the Mat is updated. (interval at which the DidUpdateThisFrame() method becomes true).
|
|
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.
|
|
A helper component class for efficiently obtaining camera frames from WebCamTexture and converting them to OpenCV Mat
format in real-time using AsyncGPUReadback
.
The WebCamTexture2MatAsyncGPUHelper
class captures video frames from a device's camera using WebCamTexture and utilizes AsyncGPUReadback
to efficiently transfer pixel data to the CPU. Each frame is then converted to an OpenCV Mat
object. This component handles camera orientation, rotation, and necessary transformations to ensure the Mat
output aligns correctly with the device's display orientation.
By leveraging AsyncGPUReadback
, this component reduces CPU load and enhances performance, making it particularly suitable for applications requiring real-time image processing with high frame rates. It enables seamless integration of OpenCV-based image processing algorithms with Unity's camera input while optimizing resource usage.
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, AsyncGPUReadback
requests, and frame updates internally.