Browse Source

store encodings and not jpegs

master
Martin Dørum 1 year ago
parent
commit
cd1e9c02cf
2 changed files with 20 additions and 18 deletions
  1. 12
    16
      lock.py
  2. 8
    2
      record.py

+ 12
- 16
lock.py View File

@@ -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):

+ 8
- 2
record.py View File

@@ -14,6 +14,10 @@ def record(path, dev):
cv2.rectangle(rgb_frame, (left, top), (right, bottom), (0, 0, 255), 2)

cv2.imshow(name, rgb_frame)
if len(frameencs) == 0:
return None
else:
return [ frameencs[0] ]

cap = cv2.VideoCapture(dev)

@@ -33,11 +37,13 @@ def record(path, dev):
elif key == ord('\r'):
cv2.imshow("frame", frame)
cv2.waitKey(1)
draw_face_rec("frame", frame)
encs = draw_face_rec("frame", frame)
if encs == None:
continue
while True:
key = cv2.waitKey(0) & 0xFF
if key == ord('\r'):
cv2.imwrite(path, frame)
np.save(path, encs[0])
return
elif key == 27: # esc
break

Loading…
Cancel
Save