-
Notifications
You must be signed in to change notification settings - Fork 323
Quickstart
Import FaceRecognitionDotNet into your .NET project. You can choice the following packages.
Deploy the following libraries from Intel MKL 2019 Initial Release
- libiomp5md.dll
- mkl_core.dll
- mkl_def.dll
- mkl_intel_thread.dll
Install cuDNN to CUDA directory.
- cudnn64_7.dll
sudo yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
sudo yum install libX11-devel openblas-devel
sudo apt-get install libx11-6 libopenblas-dev
- Please refer About X11 for Mac
Download the 4 model files from face_recognition_models Then, copy files to directory you want to deploy.
You may want to get 194 face landmark points or age/gender of human face. Train the dataset and deploy model files you trained to the above same directory. Then, you must rename model files like the following.
-
AgeTraining
- adience-age-network.dat
-
GenderTraining
- adience-gender-network.dat
-
HelenTraining
- helen-dataset.dat
The above training program and functions are experimental. Deployment step and model file names may be changed.
Create FaceRecognition instance. You must specify the model files directory path. Internal library of FaceRecognition can not handle the some non-alphanumeric character. Therefore, you should specify the encoding to have library understand path string.
FaceRecognition.InternalEncoding = System.Text.Encoding.GetEncoding("shift_jis");
string directory = "C:\models"
using (FaceRecognition fr = FaceRecognition.Create(directory))Load image files from file. Here, these files contain 1 human face. Certainly, picture can contain multiple faces!
using (Image imageA = FaceRecognition.LoadImageFile(imagePathA))
using (Image imageB = FaceRecognition.LoadImageFile(imagePathB))Detect faces from imageA and imageB. Actually, the library may detect multiple faces.
IEnumerable<Location> locationsA = fr.FaceLocations(imageA);
IEnumerable<Location> locationsB = fr.FaceLocations(imageB);Compute human face encoding to compare faces. You must dispose FaceEncoding objects after you are finished using.
IEnumerable<FaceEncoding> encodingA = FaceRecognition.FaceEncodings(imageA, locationsA.First());
IEnumerable<FaceEncoding> encodingB = FaceRecognition.FaceEncodings(imageB, locationsB.First());Compare FaceEncoding objects to know whether detected faces are same or not. tolerance is threshold. If distance of compared faces is lower than tolerance, faces are same. Otherwise not same.
const double tolerance = 0.6d;
bool match = FaceRecognition.CompareFace(encodingA.First(), encodingB.First(), tolerance);Build your .NET project and run program!!