Skip to content

Commit 28aa8ce

Browse files
committed
Fixes + Installer
- Fixes the anti-spoof being too much suspicious - Fixes authentication only *possible after end of face recogntion algorithm (daemon problem) - Add installer script and fixe typo in the makefile of the grosshack
1 parent 4f40456 commit 28aa8ce

File tree

7 files changed

+43
-519
lines changed

7 files changed

+43
-519
lines changed

daemon.py

100644100755
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def GetIdentifier(self, username, timeout = 3):
4949
self.commands_trigger[id] = []
5050
if self.checkthread is None: # Start recognition if device is available
5151
self.checkthread = Thread(target = self.RunRecognition, args = (id,))
52-
self.checkthread.run()
52+
self.checkthread.start()
5353
return id
5454

5555
def RunRecognition(self, recid):
@@ -64,16 +64,14 @@ def GetState(self, request_id):
6464
return self.states[request_id]
6565
elif self.checkthread is None:
6666
self.checkthread = Thread(target = self.RunRecognition, args = (request_id,))
67-
self.checkthread.run()
67+
self.checkthread.start()
6868
return "None" # if first conditions is not respected, there is no state
6969

7070
def ReleaseDevice(self,request_id):
71-
if self.checkthread is not None:
71+
if self.checkthread is not None and request_id in self.commands_trigger:
7272
self.commands_trigger[request_id].append(1) # send quit signal
7373
self.checkthread.join() # wait until the thread completely stop
7474
del self.states[request_id]
75-
76-
7775
try:
7876
# D-Bus
7977
loop = GLib.MainLoop()

facerec.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ def align_face_with_landmarks(face_bgr, orig_frame, bbox, output_size=(128, 128)
378378
landmarks = np.array([*landmarks[:2],mouth_center])[:2]
379379
# 5. Reference points (ArcFace), scaled to output_size
380380
ref_landmarks = get_scaled_ref_landmarks((128,128),zoom=1)[:2] # + (bbox[0],bbox[1])
381-
ref_landmarks_anti_spoof = get_scaled_ref_landmarks((128,128),zoom=1/anti_spoof_size_boost)[:2]
381+
ref_landmarks_anti_spoof = get_scaled_ref_landmarks((128,128),zoom=2/anti_spoof_size_boost)[:2]
382382

383383
# 6. Estimate affine transform
384384
tform, _ = cv2.estimateAffinePartial2D(landmarks, ref_landmarks, method=cv2.LMEDS)
@@ -483,9 +483,7 @@ def score(rec_embedding):
483483
if not ret:
484484
break
485485
frame = ensure_bgr(frame)
486-
487-
488-
if not image_quality_score(frame)>0.3:
486+
if not image_quality_score(frame)>0.2:
489487
failed_find_attempts[current_cap] += 1
490488
continue
491489
else:
@@ -506,7 +504,7 @@ def score(rec_embedding):
506504
for (xmin, ymin, xmax, ymax, conf, _) in boxes:
507505
# Crop the detected face from the original frame
508506
face_crop = frame[ymin:ymax, xmin:xmax]
509-
if not image_quality_score(face_crop) > 0.2:
507+
if not image_quality_score(face_crop) > 0.25:
510508
continue
511509
did_try=1
512510

@@ -518,7 +516,7 @@ def score(rec_embedding):
518516
anti_spoof_face = cv2.resize(anti_spoof_face,[80,80]).transpose(2, 0, 1)[np.newaxis, ...].astype(np.float32)
519517
anti_spoof_result = compiled_anti_spoof([anti_spoof_face])[compiled_anti_spoof.output(0)]
520518
label = np.argmax(anti_spoof_result)
521-
value = anti_spoof_result[0][label]/2
519+
value = anti_spoof_result[0][label]
522520

523521
if label != 1:
524522
spoof_attempts+=1
@@ -620,7 +618,7 @@ def add_face(cap_path=...,face_name=...,complete=False):
620618
rec_face = stretch_contrast(face_crop)
621619
rec_face , anti_spoof_face = align_face_with_landmarks(rec_face, frame, (xmin,ymin,xmax,ymax))
622620
#rec_face=gray_world_correction(rec_face)
623-
frame[ymin:ymax, xmin:xmax] = cv2.resize(rec_face,crop_dims)
621+
frame[ymin:ymax, xmin:xmax] = cv2.resize(anti_spoof_face,crop_dims)
624622
# 3. Run recognition on the face crop
625623
rec_input = rec_face.transpose(2, 0, 1)[np.newaxis, ...].astype(np.float32)
626624
rec_embedding = compiled_rec([rec_input])[compiled_rec.output(0)]

0 commit comments

Comments
 (0)