Skip to content

Quickstart

Takuya Takeuchi edited this page Mar 1, 2020 · 19 revisions

Import

Import FaceRecognitionDotNet into your .NET project. You can choice the following packages.

CPU

Intel CPU

GPU

Install dependencies

Windows

for MKL

Deploy the following libraries from Intel MKL 2019 Initial Release

  • libiomp5md.dll
  • mkl_core.dll
  • mkl_def.dll
  • mkl_intel_thread.dll

for CUDA

Install cuDNN to CUDA directory.

  • cudnn64_7.dll

Linux

RHEL/Fedora/CentOS

sudo yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
sudo yum install libX11-devel openblas-devel

Ubuntu/debian

sudo apt-get install libx11-6 libopenblas-dev

OSX

Install X11

Deploy model files

Download the 4 model files from face_recognition_models Then, copy files to directory you want to deploy.

💡 NOTE

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.

⚠️ WARNING

The above training program and functions are experimental. Deployment step and model file names may be changed.

Usage

1. Initialize

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))

2. Load Image

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))

3. Find Face

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);

4. Get Face Encoding

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());

5. Compare face

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 and Run

Build your .NET project and run program!!

Clone this wiki locally