Face Detection and Recognition
DNN-based face detection and recognition using the FaceDetectorYN and FaceRecognizerSF classes.FaceDetectorYN
DNN-based face detector class. Model download link: Face Detection YuNetConstructor
Use the staticcreate() method to create an instance.
create (from file)
Path to the requested model file
Path to the config file for compatibility (not requested for ONNX models)
Size of the input image
Threshold to filter out bounding boxes of score less than the given value
Threshold to suppress bounding boxes that have IoU greater than the given value
Number of bounding boxes to preserve from top rank based on score before NMS
ID of the backend (DNN backend)
ID of the target device
create (from buffer)
Name of origin framework
Buffer with content of binary file with model weights
Buffer with content of text file containing network configuration
Methods
setInputSize
Sets the size for the network input.Size of the input image. This overwrites the input size used when creating the model.
Call this method when the size of the input image does not match the input size when creating the model.
getInputSize
Gets the current input size.setScoreThreshold
Sets the score threshold to filter out bounding boxes.Threshold for filtering out bounding boxes
getScoreThreshold
Gets the current score threshold.setNMSThreshold
Sets the Non-maximum-suppression threshold.Threshold for NMS operation to suppress bounding boxes that have IoU greater than the given value
getNMSThreshold
Gets the current NMS threshold.setTopK
Sets the number of bounding boxes preserved before NMS.Number of bounding boxes to preserve from top rank based on score
getTopK
Gets the current top K value.detect
Detects faces in the input image.Input image to detect faces in
Detection results stored in a 2D cv::Mat of shape [num_faces, 15]:
- 0-1: x, y of bbox top left corner
- 2-3: width, height of bbox
- 4-5: x, y of right eye
- 6-7: x, y of left eye
- 8-9: x, y of nose tip
- 10-11: x, y of right corner of mouth
- 12-13: x, y of left corner of mouth
- 14: face score
Example Usage
- C++
- Python
FaceRecognizerSF
DNN-based face recognizer class. Model download link: Face Recognition SFaceConstructor
Use the staticcreate() method to create an instance.
create (from file)
Path to the ONNX model used for face recognition
Path to the config file for compatibility (not requested for ONNX models)
ID of the backend
ID of the target device
create (from buffer)
Name of the framework (ONNX, etc.)
Buffer containing the binary model weights
Buffer containing the network configuration
Enums
DisType
Distance types for calculating distance between face features.Methods
alignCrop
Aligns detected face with the source input image and crops it.Input image
Detected face result from the input image (from FaceDetectorYN)
Output aligned and cropped face image
feature
Extracts face feature from aligned image.Input aligned face image
Output face feature vector
match
Calculates the distance between two face features.First input feature vector
Second input feature vector of the same size and type as face_feature1
Distance calculation method: FR_COSINE (cosine distance) or FR_NORM_L2 (L2 norm distance)
Example Usage
- C++
- Python
Complete Workflow Example
- C++
- Python
