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

import time import time
import argparse import argparse


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


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

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


tacc = delay tacc = delay
rgb_frame = cv2.cvtColor(frame, cv2.COLOR_GRAY2RGB) rgb_frame = cv2.cvtColor(frame, cv2.COLOR_GRAY2RGB)
small_rgb_frame = cv2.resize(rgb_frame, (0, 0), fx=scale, fy=scale) small_rgb_frame = cv2.resize(rgb_frame, (0, 0), fx=scale, fy=scale)


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


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


if show: if show:
cv2.rectangle( cv2.rectangle(
else: else:
exit(1) exit(1)


def record(path, cap):
def record(path, dev):
def draw_face_rec(name, frame): def draw_face_rec(name, frame):
rgb_frame = cv2.cvtColor(frame, cv2.COLOR_GRAY2RGB) rgb_frame = cv2.cvtColor(frame, cv2.COLOR_GRAY2RGB)
framelocs = face_recognition.face_locations(rgb_frame) framelocs = face_recognition.face_locations(rgb_frame)


cv2.imshow(name, rgb_frame) cv2.imshow(name, rgb_frame)


cap = cv2.VideoCapture(dev)

avg = 128 avg = 128
while True: while True:
ret, frame = cap.read() ret, frame = cap.read()
args = parser.parse_args() args = parser.parse_args()


if args.command == "match": 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": elif args.command == "record":
record(args.face, cv2.VideoCapture(args.device))
record(args.face, args.device)

+ 2
- 2
facewaiter.py View File

if s == "Discharging" or s == "Unknown": if s == "Discharging" or s == "Unknown":
bat = True bat = True


print("starting facematcher")
proc = subprocess.Popen( proc = subprocess.Popen(
f"./facematcher.py match --wait --delay 500 --device {device} {faces}/$USER/*", f"./facematcher.py match --wait --delay 500 --device {device} {faces}/$USER/*",
stdin=subprocess.PIPE, shell=True) stdin=subprocess.PIPE, shell=True)
if bat: if bat:
print(f"On battery, so waiting for {key}") print(f"On battery, so waiting for {key}")
subprocess.check_output( 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) shell=True)
print(f"Got {key}.") print(f"Got {key}.")



Loading…
Cancel
Save