@@ -75,37 +75,45 @@ def verify(
75
75
as a string, numpy array (BGR), or base64 encoded images.
76
76
77
77
model_name (str): Model for face recognition. Options: VGG-Face, Facenet, Facenet512,
78
- OpenFace, DeepFace, DeepID, Dlib, ArcFace and SFace
78
+ OpenFace, DeepFace, DeepID, Dlib, ArcFace and SFace (default is VGG-Face).
79
79
80
80
detector_backend (string): face detector backend. Options: 'opencv', 'retinaface',
81
- 'mtcnn', 'ssd', 'dlib', 'mediapipe', 'yolov8'.
81
+ 'mtcnn', 'ssd', 'dlib', 'mediapipe', 'yolov8' (default is opencv)
82
82
83
83
distance_metric (string): Metric for measuring similarity. Options: 'cosine',
84
- 'euclidean', 'euclidean_l2'.
84
+ 'euclidean', 'euclidean_l2' (default is cosine) .
85
85
86
86
enforce_detection (boolean): If no face is detected in an image, raise an exception.
87
- Default is True. Set to False to avoid the exception for low-resolution images.
87
+ Set to False to avoid the exception for low-resolution images (default is True) .
88
88
89
89
align (bool): Flag to enable face alignment (default is True).
90
90
91
91
normalization (string): Normalize the input image before feeding it to the model.
92
- Default is base. Options: base, raw, Facenet, Facenet2018, VGGFace, VGGFace2, ArcFace
92
+ Options: base, raw, Facenet, Facenet2018, VGGFace, VGGFace2, ArcFace (default is base)
93
93
94
94
Returns:
95
95
result (dict): A dictionary containing verification results.
96
96
97
- {
98
- "verified": True
99
- , "distance": 0.2563
100
- , "max_threshold_to_verify": 0.40
101
- , "model": "VGG-Face"
102
- , "similarity_metric": "cosine"
103
- , 'facial_areas': {
104
- 'img1': {'x': 345, 'y': 211, 'w': 769, 'h': 769},
105
- 'img2': {'x': 318, 'y': 534, 'w': 779, 'h': 779}
106
- }
107
- , "time": 2
108
- }
97
+ - 'verified' (bool): Indicates whether the images represent the same person (True)
98
+ or different persons (False).
99
+
100
+ - 'distance' (float): The distance measure between the face vectors.
101
+ A lower distance indicates higher similarity.
102
+
103
+ - 'max_threshold_to_verify' (float): The maximum threshold used for verification.
104
+ If the distance is below this threshold, the images are considered a match.
105
+
106
+ - 'model' (str): The chosen face recognition model.
107
+
108
+ - 'similarity_metric' (str): The chosen similarity metric for measuring distances.
109
+
110
+ - 'facial_areas' (dict): Rectangular regions of interest for faces in both images.
111
+ - 'img1': {'x': int, 'y': int, 'w': int, 'h': int}
112
+ Region of interest for the first image.
113
+ - 'img2': {'x': int, 'y': int, 'w': int, 'h': int}
114
+ Region of interest for the second image.
115
+
116
+ - 'time' (float): Time taken for the verification process in seconds.
109
117
"""
110
118
111
119
return verification .verify (
@@ -140,53 +148,67 @@ def analyze(
140
148
You can exclude some of these attributes from the analysis if needed.
141
149
142
150
enforce_detection (boolean): If no face is detected in an image, raise an exception.
143
- Default is True. Set to False to avoid the exception for low-resolution images.
151
+ Set to False to avoid the exception for low-resolution images (default is True) .
144
152
145
153
detector_backend (string): face detector backend. Options: 'opencv', 'retinaface',
146
- 'mtcnn', 'ssd', 'dlib', 'mediapipe', 'yolov8'.
154
+ 'mtcnn', 'ssd', 'dlib', 'mediapipe', 'yolov8' (default is opencv) .
147
155
148
156
distance_metric (string): Metric for measuring similarity. Options: 'cosine',
149
- 'euclidean', 'euclidean_l2'.
157
+ 'euclidean', 'euclidean_l2' (default is cosine) .
150
158
151
- align (boolean): Perform alignment based on the eye positions.
159
+ align (boolean): Perform alignment based on the eye positions (default is True) .
152
160
153
- silent (boolean): Suppress or allow some log messages for a quieter analysis process.
161
+ silent (boolean): Suppress or allow some log messages for a quieter analysis process
162
+ (default is False).
154
163
155
164
Returns:
156
165
results (List[Dict[str, Any]]): A list of dictionaries, where each dictionary represents
157
- the analysis results for a detected face. Example:
158
-
159
- [
160
- {
161
- "region": {'x': 230, 'y': 120, 'w': 36, 'h': 45},
162
- "age": 28.66,
163
- 'face_confidence': 0.9993908405303955,
164
- "dominant_gender": "Woman",
165
- "gender": {
166
- 'Woman': 99.99407529830933,
167
- 'Man': 0.005928758764639497,
168
- }
169
- "dominant_emotion": "neutral",
170
- "emotion": {
171
- 'sad': 37.65260875225067,
172
- 'angry': 0.15512987738475204,
173
- 'surprise': 0.0022171278033056296,
174
- 'fear': 1.2489334680140018,
175
- 'happy': 4.609785228967667,
176
- 'disgust': 9.698561953541684e-07,
177
- 'neutral': 56.33133053779602
178
- }
179
- "dominant_race": "white",
180
- "race": {
181
- 'indian': 0.5480832420289516,
182
- 'asian': 0.7830780930817127,
183
- 'latino hispanic': 2.0677512511610985,
184
- 'black': 0.06337375962175429,
185
- 'middle eastern': 3.088453598320484,
186
- 'white': 93.44925880432129
187
- }
188
- }
189
- ]
166
+ the analysis results for a detected face.
167
+
168
+ Each dictionary in the list contains the following keys:
169
+
170
+ - 'region' (dict): Represents the rectangular region of the detected face in the image.
171
+ - 'x': x-coordinate of the top-left corner of the face.
172
+ - 'y': y-coordinate of the top-left corner of the face.
173
+ - 'w': Width of the detected face region.
174
+ - 'h': Height of the detected face region.
175
+
176
+ - 'age' (float): Estimated age of the detected face.
177
+
178
+ - 'face_confidence' (float): Confidence score for the detected face.
179
+ Indicates the reliability of the face detection.
180
+
181
+ - 'dominant_gender' (str): The dominant gender in the detected face.
182
+ Either "Man" or "Woman."
183
+
184
+ - 'gender' (dict): Confidence scores for each gender category.
185
+ - 'Man': Confidence score for the male gender.
186
+ - 'Woman': Confidence score for the female gender.
187
+
188
+ - 'dominant_emotion' (str): The dominant emotion in the detected face.
189
+ Possible values include "sad," "angry," "surprise," "fear," "happy,"
190
+ "disgust," and "neutral."
191
+
192
+ - 'emotion' (dict): Confidence scores for each emotion category.
193
+ - 'sad': Confidence score for sadness.
194
+ - 'angry': Confidence score for anger.
195
+ - 'surprise': Confidence score for surprise.
196
+ - 'fear': Confidence score for fear.
197
+ - 'happy': Confidence score for happiness.
198
+ - 'disgust': Confidence score for disgust.
199
+ - 'neutral': Confidence score for neutrality.
200
+
201
+ - 'dominant_race' (str): The dominant race in the detected face.
202
+ Possible values include "indian," "asian," "latino hispanic,"
203
+ "black," "middle eastern," and "white."
204
+
205
+ - 'race' (dict): Confidence scores for each race category.
206
+ - 'indian': Confidence score for Indian ethnicity.
207
+ - 'asian': Confidence score for Asian ethnicity.
208
+ - 'latino hispanic': Confidence score for Latino/Hispanic ethnicity.
209
+ - 'black': Confidence score for Black ethnicity.
210
+ - 'middle eastern': Confidence score for Middle Eastern ethnicity.
211
+ - 'white': Confidence score for White ethnicity.
190
212
"""
191
213
return demography .analyze (
192
214
img_path = img_path ,
0 commit comments