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

import time import time
import argparse import argparse


def match(paths, cap, show):
def match(paths, cap, show, delay):
faces = [] faces = []
faceencs = [] faceencs = []
for path in paths: for path in paths:


matching = False matching = False


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


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

scale = 1 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)
"-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( sub_match.add_argument(
"-w", "--wait", default=False, action="store_true",
"-w", "--waitfor", type=str, default=None,
help="wait for newline on stdin") 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( 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)
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": elif args.command == "record":
record(args.face, cv2.VideoCapture(args.device)) record(args.face, cv2.VideoCapture(args.device))

+ 25
- 2
facewaiter.sh View File

#!/bin/sh #!/bin/sh


echo "hello am facewaiter $$"

keyboard="AT Translated Set 2 keyboard" 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 rm -f .testfifo
mkfifo .testfifo mkfifo .testfifo


rm -f .matchfifo rm -f .matchfifo
mkfifo .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 read <.testfifo
echo > .matchfifo
echo start > .matchfifo


kill $xpid kill $xpid
wait wait

Loading…
Cancel
Save