How can I convert a PhotoCaptureFrame byte data into SoftwareBitmap?
I am using Hololens. My goal is to use the FaceDetector from Windows.Media.FaceAnalysis to detect faces in a picture captured from the hololens camera. The FaceDetector expects a SoftwareBitmap input, and the PhotoCaptureFrame from Unity gives a byte list of image data in IMFMediaBuffer format. I have tried:
var buffer = new List<byte>();
photoCaptureFrame.CopyRawImageDataIntoBuffer(buffer);
var stream = new MemoryStream(buffer.ToArray()).AsRandomAccessStream();
var decoder = await BitmapDecoder.CreateAsync(stream);
The using
clauses are excluded for readability. The program crashes at the last line of code, and the reason for the crash is because await
receives nothing from the async Task. This hints that the data in buffer is not in the format that BitmapDecoder understands, which makes sense, because it is only a byte list of color value, without width and height information (correct me on this). Whereas BitmapDecoder expects a stream from an image file.
Please let me know how I can connect the output from PhotoCapture into SoftwareBitmap.
Hi. I have occured the same problem with you. I want to convert the List generated by the method "copyRawImageIntoBuffer" into VideoFrame type. I know SoftwareBitmap can be transformed into VideoFrame. So ,I am confusing about how to convert List into SoftwareBitmap. Have you ever solved this problem? Could you offer me some code or advice? Thank you very much!
Your answer
Follow this Question
Related Questions
How can i use my laptop camera in unity ? 0 Answers
How do I Add a Simple Blur Effect to the Camera? 0 Answers
tooltip in screen space camera 0 Answers
Cinemachine settings reset after relaunching project. 0 Answers
Retain Position and Scale Values of Render Texture Canvas Elements to another Canvas 0 Answers