Browse Source

yay

master
Martin Dørum 2 years ago
parent
commit
4738e3104c
2 changed files with 22 additions and 27 deletions
  1. 14
    13
      facematcher.py
  2. 8
    14
      facewaiter.sh

+ 14
- 13
facematcher.py View File

@@ -26,11 +26,14 @@ def match(paths, cap, show, delay):

matching = False

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

# delay
@@ -97,9 +100,12 @@ def record(path, cap):

cv2.imshow(name, rgb_frame)

avg = 128
while True:
ret, frame = cap.read()
if cv2.mean(frame)[0] < 30:
mean = cv2.mean(frame)[0]
avg = (avg + mean) / 2
if mean < avg:
continue

cv2.imshow("frame", frame)
@@ -130,7 +136,7 @@ sub_match.add_argument(
"-s", "--show", default=False, action="store_true",
help="show what the camera sees")
sub_match.add_argument(
"-w", "--waitfor", type=str, default=None,
"-w", "--wait", type=str, default=None,
help="wait for newline on stdin")
sub_match.add_argument(
"-t", "--delay", type=int, default=0,
@@ -150,14 +156,9 @@ sub_record.add_argument(
args = parser.parse_args()

if args.command == "match":
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+"'.")
if args.wait:
input("Waiting for newline...")
print("Got newline.");

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

+ 8
- 14
facewaiter.sh View File

@@ -1,21 +1,10 @@
#!/bin/sh

echo "hello am facewaiter $$"
#!/bin/bash

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
@@ -32,11 +21,16 @@ xpid=$!

rm -f .matchfifo
mkfifo .matchfifo
./facematcher.py match --delay 500 --device 2 --waitfor start $faces/$USER/* <.matchfifo &

matcher() {
cat .matchfifo | ./facematcher.py match --delay 500 --device 2 --wait $faces/$USER/*
}
matcher &
matchpid=$!
trap "kill $matchpid" SIGINT SIGTERM

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

kill $xpid
wait

Loading…
Cancel
Save