Closed utarn closed 5 years ago
You can refer https://github.com/takuya-takeuchi/FaceRecognitionDotNet/issues/40 He noted sample source code to load from OpenCVSharp.
Sorry takuya-takeuchi, I'm still not getting the reference. I got a cropped grayscale Mat from opencvsharp as I use haarcascade to do a rough detect. I also tried
var array = new byte[source.Height * source.Width];
source.GetArray(source.Width, source.Height, array);
var image = FaceRecognition.LoadImage(array, source.Height, source.Width, 1);
Last argument of LoadImage is not 1. It is stride. stride is width channels. So it is width 1 if grayscale.
Oh, sorry. You are correct. Last argument is element size.
But still I got ArrayOutOfRangException. So I tried
var array = new byte[source.Height * source.Width];
source.GetArray(source.Rows-1, source.Cols-1, array);
var image = FaceRecognition.LoadImage(array, source.Height, source.Width, 1);
var encodings = faceRecognition.FaceEncodings(image).ToArray();
But the encodings.Length is 0.
Could you check the following sample? I wrote sample project using OpenCVSharp. It may be helpful. https://github.com/takuya-takeuchi/FaceRecognitionDotNet/tree/develop/examples/OpenCVSharpSample
Thank you so much. It worked!
I got a Mat object from OpenCVSharp. How do I efficiently load the image to FaceRecognition.LoadImage or should I use DlibDotNet to load an image?
Thanks