Browse Source

fix things

master
Martin Dørum 5 years ago
parent
commit
cf1f72d0e8
2 changed files with 52 additions and 7 deletions
  1. 27
    5
      facematcher.py
  2. 25
    2
      facewaiter.sh

+ 27
- 5
facematcher.py View File

@@ -9,7 +9,7 @@ import os
import time
import argparse

def match(paths, cap, show):
def match(paths, cap, show, delay):
faces = []
faceencs = []
for path in paths:
@@ -26,11 +26,23 @@ def match(paths, cap, show):

matching = False

tacc = 0
then = time.time() * 1000
while not matching:
ret, frame = cap.read()
if cv2.mean(frame)[0] < 30:
continue

# delay
now = time.time() * 1000
if tacc < delay:
tacc += now - then
then = now
continue
else:
tacc = 0
then = now

scale = 1
rgb_frame = cv2.cvtColor(frame, cv2.COLOR_GRAY2RGB)
small_rgb_frame = cv2.resize(rgb_frame, (0, 0), fx=scale, fy=scale)
@@ -118,8 +130,11 @@ 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",
"-w", "--waitfor", type=str, default=None,
help="wait for newline on stdin")
sub_match.add_argument(
"-t", "--delay", type=int, default=0,
help="wait n milliseconds between each frame")
sub_match.add_argument(
"faces", type=str, nargs="+",
help="the source image file(s)")
@@ -135,8 +150,15 @@ 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)
print(args)
if args.waitfor is not None:
s = input("Waiting for '"+args.waitfor+"'...")
if s != args.waitfor:
print("Exiting because stdin was '"+s+"' and expected '"+args.waitfor+"'.")
exit(1)
else:
print("Got '"+s+"'.")

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

+ 25
- 2
facewaiter.sh View File

@@ -1,6 +1,28 @@
#!/bin/sh

echo "hello am facewaiter $$"

keyboard="AT Translated Set 2 keyboard"
battery="/sys/class/power_supply/BAT0"
device=2
faces="faces"

matchpid=
cleanup() {
if [ -n "$matchpid" ]; then
kill "$matchpid"
fi
exit 1
}
trap cleanup SIGTERM

if [ -n "$battery" ]; then
st="$(cat "$battery/status")"
if [ "$st" != "Discharging" ] && [ "$st" != "Unknown" ]; then
./facematcher.py match --delay 500 --device "$device" $faces/$USER/*
exit $?
fi
fi

rm -f .testfifo
mkfifo .testfifo
@@ -10,10 +32,11 @@ xpid=$!

rm -f .matchfifo
mkfifo .matchfifo
cat .matchfifo | ./facematcher.py match --device 2 --wait faces/$USER/* &
./facematcher.py match --delay 500 --device 2 --waitfor start $faces/$USER/* <.matchfifo &
matchpid=$!

read <.testfifo
echo > .matchfifo
echo start > .matchfifo

kill $xpid
wait

Loading…
Cancel
Save