takuya-takeuchi / FaceRecognitionDotNet

The world's simplest facial recognition api for .NET on Windows, MacOS and Linux
MIT License
1.27k stars 308 forks source link

Unable to manually manage FaceEncodings #14

Closed turowicz closed 5 years ago

turowicz commented 5 years ago

I store face encodings in a database in encrypted form. I need to be able to load them up without using any image files and use them in C#. So far I've been working with python and that feature is available there.

Unfortunately the constructor of FaceEncoding is private in https://github.com/takuya-takeuchi/FaceRecognitionDotNet/blob/master/src/FaceRecognitionDotNet/FaceEncoding.cs#L12

turowicz commented 5 years ago

Ideally it would be nice to be able to create a FaceEncoding from double[]

takuya-takeuchi commented 5 years ago

Please use serializer for FaceEncoding. I know it is easy to support creating FaceEncoding from double[].

However, if you creare it from array, you have to pass row and column value. It means you have to store array, row, column to disk.

turowicz commented 5 years ago

Could you show me how to create it using serializer? I've got it as OpenCvSharp Mat object.

The constructior needs to be public then.

turowicz commented 5 years ago

@takuya-takeuchi

turowicz commented 5 years ago

@takuya-takeuchi I've got all my face encodings persisted as double[] because this is what python dlib + face_recognition uses. Any idea how to make this work with your port?

turowicz commented 5 years ago

This is how I managed to convert double[] to FaceEncoding:

double[] identity = GetIdentity();
var identityEncoding = new FaceEncoding(new Matrix<double>(identity, identity.Length, 1));
Seth-Julien-de-Lampon commented 5 years ago

This is how I managed to convert double[] to FaceEncoding:

double[] identity = GetIdentity();
var identityEncoding = new FaceEncoding(new Matrix<double>(identity, identity.Length, 1));

This is exactly what I need, but FaceEncoding has a private constructor. How did you manage to work arround this?

takuya-takeuchi commented 5 years ago

TBH, I can not understand why some developer requires this function. Already, FaceEncoding has serializable attribute and it can save it as file. So generally we need not to import 'raw' binary data. Do you have reason which convince me? Perhaps, I guess you already had created face encoding data which are by application like OpenCV.

P.S. I could implement it as static method like FaceRecognition.LoadImage at best. Definitely, I do NOT change private to public.

Seth-Julien-de-Lampon commented 5 years ago

I did not see how i can save it as file. Do you have an example for me? Since that would be more than fine aswell!

takuya-takeuchi commented 5 years ago

Please check https://github.com/takuya-takeuchi/FaceRecognitionDotNet/blob/master/test/FaceRecognitionDotNet.Tests/FaceRecognitionTest.cs#L287

Seth-Julien-de-Lampon commented 5 years ago

That is amazing, thank you!

turowicz commented 5 years ago

@MitchVonk I pulled the code and changed the constructor myself in CI :D

takuya-takeuchi commented 5 years ago

latest version 1.2.3.10 support to create FaceEncoding from double array by using LoadFaceEncoding method. Please use it.