carmines / UnityPluginCollection

source code for Unity plugins for Desktop and UWP
MIT License
30 stars 7 forks source link

Want to get camera capture data in ByteArray format. #11

Closed EnoxSoftware closed 3 years ago

EnoxSoftware commented 3 years ago

Hello I was looking for an asset to access camera stream on Holorens. Thank you for publishing a great asset.

I want to perform image processing on the acquired camera image using OpenCV, but the processing that combines Graphics.Blit and texture2D.ReadPixels to obtain the ByteArray of the pixel data of ExternalTexture is very expensive. Could you please tell me if there is a way to get ByteArray (BGRA format) for each frame directly from the plugin at high speed?

carmines commented 3 years ago

You would be better served to use the already available FrameSource/Reader api from MediaCapture.Frames namespace. That api will provide you the frames in the output format you want. Have a look at the HolographicFaceTracking sample as an example. If you need it as a plugin, you can simplify Plugin.CaptureEngine to use that code instead.

carmines commented 3 years ago

https://github.com/microsoft/Windows-universal-samples/blob/master/Samples/HolographicFaceTracking/cpp/Content/VideoFrameProcessor.cpp

https://github.com/microsoft/Windows-universal-samples/blob/master/Samples/HolographicFaceTracking/cpp/Content/NV12VideoTexture.cpp