Skip to content

Commit 4420727

Browse files
committed
Getting encodings before face recognition
1 parent 60d8d15 commit 4420727

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

FaceDetect/facedetect.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class FaceDetect:
4444
'face-extraction': False,
4545
'print': True,
4646
'face-features': [],
47-
'known-faces': {'D1': 'path1', 'D2': 'path2'}
47+
'known-faces': {'D1': 'resources/person1.png', 'D2': 'resources/person2.png'}
4848
}
4949
ACCEPTED_VIDEO_FORMAT = ['avi', 'mp4', 'mov']
5050
ACCEPTED_IMAGE_FORMAT = ['jpeg', 'jpg', 'gif', 'png']
@@ -69,12 +69,16 @@ def __init__(self, settings=None):
6969
# Populating setting from input (overrides are possible)
7070
if settings:
7171
for setting in settings:
72-
setting = setting.lower()
7372

74-
# Sanitize if string, otherwise take as is
75-
val = settings[setting].lower().strip() if isinstance(settings[setting], str) else settings[setting]
73+
# Sanitize the key
74+
sanitized_setting = setting.lower()
7675

77-
self.settings[setting] = val
76+
# Get the value and sanitize if string, otherwise take as is
77+
val = settings.get(setting)
78+
val = val.lower().strip() if type(val) is str else val
79+
80+
# Set the settings to the sanitized keys and values
81+
self.settings[sanitized_setting] = val
7882

7983
####################################################
8084
# Public methods for face detection and recognition
@@ -244,12 +248,12 @@ def __detect(self):
244248
self.face_labels.append(label)
245249

246250
# Upon face detection
247-
if self.face_locations:
248251

249-
# Condense the face locations and labels into tuples
250-
self.detections = zip(self.face_locations, self.face_labels)
252+
# Condense the face locations and labels into tuples
253+
self.detections = zip(self.face_locations, self.face_labels) if self.face_locations else None
251254

252-
# Format onto tuples if there are self detections
255+
# Format onto tuples if there are self detections
256+
if self.detections:
253257
self.detections = [(detection[0], detection[1]) for detection in self.detections]
254258

255259
def __callback(self):
@@ -300,7 +304,8 @@ def __execute_setting(self):
300304

301305
def __recognize(self):
302306
""" Calls the face recognition """
303-
print('recognizing')
307+
308+
print('recognize')
304309
return self
305310

306311
####################################################

main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#
1919

2020

21-
facedetector = FaceDetect()
21+
facedetector = FaceDetect({'method': 'recognize'})
2222

2323
try:
2424
# When the start method is not given an image or video path, it starts the webcam

0 commit comments

Comments
 (0)