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

@@ -1,11 +1,13 @@
#!/usr/bin/env python

# Lock with mlock, unlock when face is detected

import subprocess
import threading

locker = subprocess.Popen([ "mlock" ])
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")

def waitfor(x, others):

+ 9
- 1
facematcher.py View File

@@ -1,4 +1,7 @@
#!/usr/bin/env python3

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

import cv2
import numpy as np
import face_recognition
@@ -28,7 +31,7 @@ def match(paths, cap, show):
if cv2.mean(frame)[0] < 30:
continue

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

@@ -114,6 +117,9 @@ sub_match.add_argument(
sub_match.add_argument(
"-s", "--show", default=False, action="store_true",
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(
"faces", type=str, nargs="+",
help="the source image file(s)")
@@ -129,6 +135,8 @@ sub_record.add_argument(
args = parser.parse_args()

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

+ 22
- 0
facewaiter.sh View File

@@ -0,0 +1,22 @@
#!/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