Browse Source

facewaiter waits for enter

master
Martin Dørum 5 years ago
parent
commit
141c91a2ba
3 changed files with 34 additions and 2 deletions
  1. 3
    1
      facelock.py
  2. 9
    1
      facematcher.py
  3. 22
    0
      facewaiter.sh

+ 3
- 1
facelock.py View File

#!/usr/bin/env python #!/usr/bin/env python


# Lock with mlock, unlock when face is detected

import subprocess import subprocess
import threading import threading


locker = subprocess.Popen([ "mlock" ]) locker = subprocess.Popen([ "mlock" ])
print("locker "+str(locker.pid)+" spawned") print("locker "+str(locker.pid)+" spawned")
matcher = subprocess.Popen([ "sh", "-c", "./facematcher.py match -d 2 faces/$USER/*" ])
matcher = subprocess.Popen([ "./facewaiter.sh" ])
print("matcher "+str(matcher.pid)+" spawned") print("matcher "+str(matcher.pid)+" spawned")


def waitfor(x, others): def waitfor(x, others):

+ 9
- 1
facematcher.py View File

#!/usr/bin/env python3 #!/usr/bin/env python3

# Match camera against existing faces, or record a new face.

import cv2 import cv2
import numpy as np import numpy as np
import face_recognition import face_recognition
if cv2.mean(frame)[0] < 30: if cv2.mean(frame)[0] < 30:
continue continue


scale = 0.5
scale = 1
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)


sub_match.add_argument( sub_match.add_argument(
"-s", "--show", default=False, action="store_true", "-s", "--show", default=False, action="store_true",
help="show what the camera sees") help="show what the camera sees")
sub_match.add_argument(
"-w", "--wait", default=False, action="store_true",
help="wait for newline on stdin")
sub_match.add_argument( sub_match.add_argument(
"faces", type=str, nargs="+", "faces", type=str, nargs="+",
help="the source image file(s)") help="the source image file(s)")
args = parser.parse_args() args = parser.parse_args()


if args.command == "match": if args.command == "match":
if args.wait:
input("Waiting for newline...")
match(args.faces, cv2.VideoCapture(args.device), args.show) match(args.faces, cv2.VideoCapture(args.device), args.show)
elif args.command == "record": elif args.command == "record":
record(args.face, cv2.VideoCapture(args.device)) record(args.face, cv2.VideoCapture(args.device))

+ 22
- 0
facewaiter.sh View File

#!/bin/sh

keyboard="AT Translated Set 2 keyboard"

rm -f .testfifo
mkfifo .testfifo
xinput test "AT Translated Set 2 keyboard" \
| grep --line-buffered "key press 36" > .testfifo &
xpid=$!

rm -f .matchfifo
mkfifo .matchfifo
cat .matchfifo | ./facematcher.py match --device 2 --wait faces/$USER/* &

read <.testfifo
echo > .matchfifo

kill $xpid
wait

rm -f .testfifo
rm -f .matchfifo

Loading…
Cancel
Save