Skip to content

Commit

Permalink
Merge pull request opencv#20935 from crywang:dnn_face
Browse files Browse the repository at this point in the history
Fix problems in tutorial and python sample of dnn_face.

* Update dnn_face.markdown

* Update face_match.py
  • Loading branch information
crywang authored Oct 27, 2021
1 parent 60f949e commit 244ba1a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions doc/tutorials/dnn/dnn_face/dnn_face.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

## Introduction

In this section, we introduce the DNN-based module for face detection and face recognition. Models can be obtained in [Models](#Models). The usage of `FaceDetectorYN` and `FaceRecognizer` are presented in [Usage](#Usage).
In this section, we introduce the DNN-based module for face detection and face recognition. Models can be obtained in [Models](#Models). The usage of `FaceDetectorYN` and `FaceRecognizerSF` are presented in [Usage](#Usage).

## Models

Expand Down Expand Up @@ -58,8 +58,8 @@ x1, y1, w, h, x_re, y_re, x_le, y_le, x_nt, y_nt, x_rcm, y_rcm, x_lcm, y_lcm
Following Face Detection, run codes below to extract face feature from facial image.
```cpp
// Initialize FaceRecognizer with model path (cv::String)
Ptr<FaceRecognizer> faceRecognizer = FaceRecognizer::create(model_path, "");
// Initialize FaceRecognizerSF with model path (cv::String)
Ptr<FaceRecognizerSF> faceRecognizer = FaceRecognizerSF::create(model_path, "");
// Aligning and cropping facial image through the first face of faces detected by dnn_face::DNNFaceDetector
Mat aligned_face;
Expand Down
10 changes: 5 additions & 5 deletions samples/dnn/face_match.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,20 @@
face2_align = recognizer.alignCrop(img2, face2[1][0])

# Extract features
face1_feature = recognizer.faceFeature(face1_align)
face2_feature = recognizer.faceFeature(face2_align)
face1_feature = recognizer.feature(face1_align)
face2_feature = recognizer.feature(face2_align)

# Calculate distance (0: cosine, 1: L2)
cosine_similarity_threshold = 0.363
cosine_score = recognizer.faceMatch(face1_feature, face2_feature, 0)
cosine_score = recognizer.match(face1_feature, face2_feature, 0)
msg = 'different identities'
if cosine_score >= cosine_similarity_threshold:
msg = 'the same identity'
print('They have {}. Cosine Similarity: {}, threshold: {} (higher value means higher similarity, max 1.0).'.format(msg, cosine_score, cosine_similarity_threshold))

l2_similarity_threshold = 1.128
l2_score = recognizer.faceMatch(face1_feature, face2_feature, 1)
l2_score = recognizer.match(face1_feature, face2_feature, 1)
msg = 'different identities'
if l2_score <= l2_similarity_threshold:
msg = 'the same identity'
print('They have {}. NormL2 Distance: {}, threshold: {} (lower value means higher similarity, min 0.0).'.format(msg, l2_score, l2_similarity_threshold))
print('They have {}. NormL2 Distance: {}, threshold: {} (lower value means higher similarity, min 0.0).'.format(msg, l2_score, l2_similarity_threshold))

0 comments on commit 244ba1a

Please sign in to comment.