|
|
@@ -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)) |