Browse Source

hey

master
Martin Dørum 5 years ago
parent
commit
e026ea7597
2 changed files with 19 additions and 12 deletions
  1. 17
    10
      facematcher.py
  2. 2
    2
      facewaiter.py

+ 17
- 10
facematcher.py View File

@@ -9,10 +9,11 @@ import os
import time
import argparse

def match(paths, cap, show, delay):
def match(paths, dev, show, delay, wait):
faces = []
faceencs = []
for path in paths:
print(f"reading {path}")
face = face_recognition.load_image_file(path)
faces.append(face)
encs = face_recognition.face_encodings(face)
@@ -24,6 +25,11 @@ def match(paths, cap, show, delay):
if len(faceencs) == 0:
print("Warning: No valid faces!")

if args.wait:
input("Waiting for newline...")
print("Got newline.");

cap = cv2.VideoCapture(dev)
matching = False

tacc = delay
@@ -50,6 +56,7 @@ def match(paths, cap, show, delay):
rgb_frame = cv2.cvtColor(frame, cv2.COLOR_GRAY2RGB)
small_rgb_frame = cv2.resize(rgb_frame, (0, 0), fx=scale, fy=scale)

print("hey")
framelocs = face_recognition.face_locations(small_rgb_frame)
frameencs = face_recognition.face_encodings(small_rgb_frame, framelocs)

@@ -58,10 +65,12 @@ def match(paths, cap, show, delay):
# See if the face is a match for the known face(s)
dists = face_recognition.face_distance(faceencs, frameenc)
dist = dists[0]
for d in dists:
distidx = 0
for i, d in enumerate(dists):
if d < dist:
dist = d
print("Distance: "+str(dist))
distidx = i
print(f"Distance: {dist} ({paths[distidx]})")

if show:
cv2.rectangle(
@@ -90,7 +99,7 @@ def match(paths, cap, show, delay):
else:
exit(1)

def record(path, cap):
def record(path, dev):
def draw_face_rec(name, frame):
rgb_frame = cv2.cvtColor(frame, cv2.COLOR_GRAY2RGB)
framelocs = face_recognition.face_locations(rgb_frame)
@@ -100,6 +109,8 @@ def record(path, cap):

cv2.imshow(name, rgb_frame)

cap = cv2.VideoCapture(dev)

avg = 128
while True:
ret, frame = cap.read()
@@ -156,10 +167,6 @@ sub_record.add_argument(
args = parser.parse_args()

if args.command == "match":
if args.wait:
input("Waiting for newline...")
print("Got newline.");

match(args.faces, cv2.VideoCapture(args.device), args.show, args.delay)
match(args.faces, args.device, args.show, args.delay, args.wait)
elif args.command == "record":
record(args.face, cv2.VideoCapture(args.device))
record(args.face, args.device)

+ 2
- 2
facewaiter.py View File

@@ -15,6 +15,7 @@ if battery is not None:
if s == "Discharging" or s == "Unknown":
bat = True

print("starting facematcher")
proc = subprocess.Popen(
f"./facematcher.py match --wait --delay 500 --device {device} {faces}/$USER/*",
stdin=subprocess.PIPE, shell=True)
@@ -22,8 +23,7 @@ proc = subprocess.Popen(
if bat:
print(f"On battery, so waiting for {key}")
subprocess.check_output(
f"xinput test '{keyboard}' | grep --line-buffered 'key press {key}' | " +
f"while read -r line; do exit; done",
f"xinput test '{keyboard}' | grep --line-buffered 'key press {key}' | exit",
shell=True)
print(f"Got {key}.")


Loading…
Cancel
Save