Deep Learning Based Face Recognition
Using deep learning based face recognition, you can perceive and understand faces within your application. This document is a guide on how to register a new face, unregister a face that is registered with a given label, and recognize a given face.
Prerequisites
To enable your application for using the deep learning based face recognition functionality, create DeepLearningFaceRecognizer instance:
C#
Copy
var deepLearningFaceRecognizer = new DeepLearningFaceRecognizer();
Register a new face
To register a new face image with a given label, follow these steps:
-
Prepare an input source to register. In this example, we use ImageUtil APIs to get the image buffer:
C#CopyMediaVisionSource inputSource = null; using (JpegDecoder jpegDecoder = new JpegDecoder()) { jpegDecoder.SetColorSpace(ColorSpace.Rgb888); var frame = (await jpegDecoder.DecodeAsync("path")).FirstOrDefault(); inputSource = new MediaVisionSource(frame.Buffer, (uint)frame.Size.Width, (uint)frame.Size.Height, ColorSpace.Rgb888); }
Note
The input source for
DeepLearningFaceRecognizer
should be RGB data. -
Now we can register a new face. This is a process where the face recognition framework trains and generates an internal model file with the given face data and its label. You could repeat this step to train the internal model file with more faces. For best accuracy, we recommend training at least three images per face:
C#CopydeepLearningFaceRecognizer.RegisterFace(inputSource, "FaceName1"); inputSource.Dispose();
You can unregister the face from
DeepLearningFaceRecognizer
internal model:C#CopydeepLearningFaceRecognizer.UnregisterFace("FaceName1");
Recognize face
To recognize a given face image, follow these steps:
-
Prepare a target image source. In this example, we use ImageUtil APIs to get the image buffer:
C#CopyMediaVisionSource targetSource = null; using (JpegDecoder jpegDecoder = new JpegDecoder()) { jpegDecoder.SetColorSpace(ColorSpace.Rgb888); var frame = (await jpegDecoder.DecodeAsync("path")).FirstOrDefault(); targetSource = new MediaVisionSource(frame.Buffer, (uint)frame.Size.Width, (uint)frame.Size.Height, ColorSpace.Rgb888); }
-
Recognize a given face image:
C#Copyvar result = deepLearningFaceRecognizer.Recognize(targetSource); // The result have Label property for recognized face. Log.Info("Vision", result.Label); targetSource.Dispose();
Related information
- Dependencies
- Tizen 7.0 and Higher