|
|
@@ -5,6 +5,9 @@ import threading |
|
|
|
import getpass |
|
|
|
import os |
|
|
|
import time |
|
|
|
import glob |
|
|
|
import cv2 |
|
|
|
import numpy as np |
|
|
|
|
|
|
|
class I3Locker: |
|
|
|
def run(self): |
|
|
@@ -28,25 +31,15 @@ class FaceLocker: |
|
|
|
self.waitingProc = None |
|
|
|
|
|
|
|
# Import here because it's sloow |
|
|
|
import numpy as np |
|
|
|
import face_recognition |
|
|
|
import cv2 |
|
|
|
|
|
|
|
# Read all face files |
|
|
|
faces = [] |
|
|
|
faceencs = [] |
|
|
|
path = f"./faces/{getpass.getuser()}" |
|
|
|
path = f"./faces/{getpass.getuser()}/*.npy" |
|
|
|
paths = [] |
|
|
|
for f in os.listdir(path): |
|
|
|
p = f"{path}/{f}" |
|
|
|
for p in glob.glob(path): |
|
|
|
print(f"reading {p}") |
|
|
|
face = face_recognition.load_image_file(p) |
|
|
|
faces.append(face) |
|
|
|
encs = face_recognition.face_encodings(face) |
|
|
|
if len(encs) == 0: |
|
|
|
print("Warning: "+path+" has no face!") |
|
|
|
continue |
|
|
|
faceencs.append(encs[0]) |
|
|
|
faceencs.append(np.load(p)) |
|
|
|
paths.append(p) |
|
|
|
|
|
|
|
# Wait here if we're on battery |
|
|
@@ -60,9 +53,6 @@ class FaceLocker: |
|
|
|
bat = True |
|
|
|
if bat: |
|
|
|
print("Waiting for enter before starting face recognition") |
|
|
|
# Blink IR blasters |
|
|
|
cap = cv2.VideoCapture(self.dev) |
|
|
|
cap.release() |
|
|
|
self.waitForKey(keyboard, key) |
|
|
|
|
|
|
|
# Match faces, blocks until a match is found or we're killed |
|
|
@@ -110,6 +100,7 @@ class FaceLocker: |
|
|
|
dist = dists[0] |
|
|
|
distidx = 0 |
|
|
|
for i, d in enumerate(dists): |
|
|
|
print(i, d) |
|
|
|
if d < dist: |
|
|
|
dist = d |
|
|
|
distidx = i |
|
|
@@ -123,6 +114,11 @@ class FaceLocker: |
|
|
|
self.waitingProc = subprocess.Popen( |
|
|
|
f"xinput test '{keyboard}' | grep --line-buffered 'key press {key}' | exit", |
|
|
|
shell=True) |
|
|
|
|
|
|
|
# Blink IR blasters |
|
|
|
cap = cv2.VideoCapture(self.dev) |
|
|
|
cap.release() |
|
|
|
|
|
|
|
self.waitingProc.wait() |
|
|
|
|
|
|
|
def kill(self): |