Browse Source

store encodings and not jpegs

master
Martin Dørum 5 years 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

import getpass import getpass
import os import os
import time import time
import glob
import cv2
import numpy as np


class I3Locker: class I3Locker:
def run(self): def run(self):
self.waitingProc = None self.waitingProc = None


# Import here because it's sloow # Import here because it's sloow
import numpy as np
import face_recognition import face_recognition
import cv2


# Read all face files # Read all face files
faces = []
faceencs = [] faceencs = []
path = f"./faces/{getpass.getuser()}"
path = f"./faces/{getpass.getuser()}/*.npy"
paths = [] paths = []
for f in os.listdir(path):
p = f"{path}/{f}"
for p in glob.glob(path):
print(f"reading {p}") 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) paths.append(p)


# Wait here if we're on battery # Wait here if we're on battery
bat = True bat = True
if bat: if bat:
print("Waiting for enter before starting face recognition") print("Waiting for enter before starting face recognition")
# Blink IR blasters
cap = cv2.VideoCapture(self.dev)
cap.release()
self.waitForKey(keyboard, key) self.waitForKey(keyboard, key)


# Match faces, blocks until a match is found or we're killed # Match faces, blocks until a match is found or we're killed
dist = dists[0] dist = dists[0]
distidx = 0 distidx = 0
for i, d in enumerate(dists): for i, d in enumerate(dists):
print(i, d)
if d < dist: if d < dist:
dist = d dist = d
distidx = i distidx = i
self.waitingProc = subprocess.Popen( self.waitingProc = subprocess.Popen(
f"xinput test '{keyboard}' | grep --line-buffered 'key press {key}' | exit", f"xinput test '{keyboard}' | grep --line-buffered 'key press {key}' | exit",
shell=True) shell=True)

# Blink IR blasters
cap = cv2.VideoCapture(self.dev)
cap.release()

self.waitingProc.wait() self.waitingProc.wait()


def kill(self): def kill(self):

+ 8
- 2
record.py View File

cv2.rectangle(rgb_frame, (left, top), (right, bottom), (0, 0, 255), 2) cv2.rectangle(rgb_frame, (left, top), (right, bottom), (0, 0, 255), 2)


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


cap = cv2.VideoCapture(dev) cap = cv2.VideoCapture(dev)


elif key == ord('\r'): elif key == ord('\r'):
cv2.imshow("frame", frame) cv2.imshow("frame", frame)
cv2.waitKey(1) cv2.waitKey(1)
draw_face_rec("frame", frame)
encs = draw_face_rec("frame", frame)
if encs == None:
continue
while True: while True:
key = cv2.waitKey(0) & 0xFF key = cv2.waitKey(0) & 0xFF
if key == ord('\r'): if key == ord('\r'):
cv2.imwrite(path, frame)
np.save(path, encs[0])
return return
elif key == 27: # esc elif key == 27: # esc
break break

Loading…
Cancel
Save