UoA-eResearch / hololens_facial_recognition

A Unity hololens app to detect faces and display their attributes
MIT License
233 stars 53 forks source link

Softwarebitmap post to web api #13

Closed RawadBahsas closed 6 years ago

RawadBahsas commented 6 years ago

Hi, I am currently working on something similar to this project, where I have live feed from hololens camera and I use windows sdk to detect faces and draw rectangles around the faces in the 3d view. whenever I discover a face, I need to send its frame to an API to do face recognition the same way you do. what am facing is the byre array that am getting from the capture element is a Softwarebitmap, and my API is an ASP.NET web API. I receive the post request and I get the binary data, but I can't manage to convert it to a Bitmap to be used in my face recognition library. do you have any idea how to do so.?

neon-ninja commented 6 years ago

Hi,

Your question isn't really related to this project, so this issue tracker isn't really the best place for it. StackOverflow would be a better place to ask such a question, and you wouldn't be the first to ask it, for sure. You should be able to reconstruct the SoftwareBitmap on the receiving end, in your ASP.NET application (https://docs.microsoft.com/en-us/uwp/api/windows.graphics.imaging.softwarebitmap.copyfrombuffer#Windows_Graphics_Imaging_SoftwareBitmap_CopyFromBuffer_Windows_Storage_Streams_IBuffer_). You'll need to instantiate the bitmap with the appropriate pixel format, width and height first, then copy the binary into it. So the code would look something like

var bitmap = new SoftwareBitmap(BitmapPixelFormat.Nv12, width, height);
bitmap.CopyFromBuffer(bytes);