|
|
@@ -9,10 +9,11 @@ import os |
|
|
|
import time |
|
|
|
import argparse |
|
|
|
|
|
|
|
def match(paths, cap, show, delay): |
|
|
|
def match(paths, dev, show, delay, wait): |
|
|
|
faces = [] |
|
|
|
faceencs = [] |
|
|
|
for path in paths: |
|
|
|
print(f"reading {path}") |
|
|
|
face = face_recognition.load_image_file(path) |
|
|
|
faces.append(face) |
|
|
|
encs = face_recognition.face_encodings(face) |
|
|
@@ -24,6 +25,11 @@ def match(paths, cap, show, delay): |
|
|
|
if len(faceencs) == 0: |
|
|
|
print("Warning: No valid faces!") |
|
|
|
|
|
|
|
if args.wait: |
|
|
|
input("Waiting for newline...") |
|
|
|
print("Got newline."); |
|
|
|
|
|
|
|
cap = cv2.VideoCapture(dev) |
|
|
|
matching = False |
|
|
|
|
|
|
|
tacc = delay |
|
|
@@ -50,6 +56,7 @@ def match(paths, cap, show, delay): |
|
|
|
rgb_frame = cv2.cvtColor(frame, cv2.COLOR_GRAY2RGB) |
|
|
|
small_rgb_frame = cv2.resize(rgb_frame, (0, 0), fx=scale, fy=scale) |
|
|
|
|
|
|
|
print("hey") |
|
|
|
framelocs = face_recognition.face_locations(small_rgb_frame) |
|
|
|
frameencs = face_recognition.face_encodings(small_rgb_frame, framelocs) |
|
|
|
|
|
|
@@ -58,10 +65,12 @@ def match(paths, cap, show, delay): |
|
|
|
# See if the face is a match for the known face(s) |
|
|
|
dists = face_recognition.face_distance(faceencs, frameenc) |
|
|
|
dist = dists[0] |
|
|
|
for d in dists: |
|
|
|
distidx = 0 |
|
|
|
for i, d in enumerate(dists): |
|
|
|
if d < dist: |
|
|
|
dist = d |
|
|
|
print("Distance: "+str(dist)) |
|
|
|
distidx = i |
|
|
|
print(f"Distance: {dist} ({paths[distidx]})") |
|
|
|
|
|
|
|
if show: |
|
|
|
cv2.rectangle( |
|
|
@@ -90,7 +99,7 @@ def match(paths, cap, show, delay): |
|
|
|
else: |
|
|
|
exit(1) |
|
|
|
|
|
|
|
def record(path, cap): |
|
|
|
def record(path, dev): |
|
|
|
def draw_face_rec(name, frame): |
|
|
|
rgb_frame = cv2.cvtColor(frame, cv2.COLOR_GRAY2RGB) |
|
|
|
framelocs = face_recognition.face_locations(rgb_frame) |
|
|
@@ -100,6 +109,8 @@ def record(path, cap): |
|
|
|
|
|
|
|
cv2.imshow(name, rgb_frame) |
|
|
|
|
|
|
|
cap = cv2.VideoCapture(dev) |
|
|
|
|
|
|
|
avg = 128 |
|
|
|
while True: |
|
|
|
ret, frame = cap.read() |
|
|
@@ -156,10 +167,6 @@ sub_record.add_argument( |
|
|
|
args = parser.parse_args() |
|
|
|
|
|
|
|
if args.command == "match": |
|
|
|
if args.wait: |
|
|
|
input("Waiting for newline...") |
|
|
|
print("Got newline."); |
|
|
|
|
|
|
|
match(args.faces, cv2.VideoCapture(args.device), args.show, args.delay) |
|
|
|
match(args.faces, args.device, args.show, args.delay, args.wait) |
|
|
|
elif args.command == "record": |
|
|
|
record(args.face, cv2.VideoCapture(args.device)) |
|
|
|
record(args.face, args.device) |