0
0
Fork 0
mirror of https://github.com/boltgolt/howdy.git synced 2024-09-19 09:51:19 +02:00
howdy/compair.py

51 lines
913 B
Python
Raw Normal View History

2018-01-05 01:59:44 +01:00
import face_recognition
import cv2
import sys
import os
2018-01-05 14:34:18 +01:00
import json
2018-01-05 01:59:44 +01:00
2018-01-05 02:41:56 +01:00
import config
2018-01-05 01:59:44 +01:00
def stop(status):
video_capture.release()
sys.exit(status)
try:
if not isinstance(sys.argv[1], str):
sys.exit(1)
except IndexError:
sys.exit(1)
user = sys.argv[1]
encodings = []
2018-01-05 14:34:18 +01:00
tries = 0
2018-01-05 01:59:44 +01:00
try:
2018-01-05 16:07:48 +01:00
encodings = json.load(open(os.path.dirname(__file__) + "/models/" + user + ".dat"))
2018-01-05 01:59:44 +01:00
except FileNotFoundError:
2018-01-05 02:41:56 +01:00
stop(10)
2018-01-05 01:59:44 +01:00
2018-01-05 14:34:18 +01:00
if len(encodings) < 3:
stop(1)
video_capture = cv2.VideoCapture(config.device_id)
2018-01-05 01:59:44 +01:00
while True:
# Grab a single frame of video
ret, frame = video_capture.read()
face_encodings = face_recognition.face_encodings(frame)
# Loop through each face in this frame of video
for face_encoding in face_encodings:
matches = face_recognition.face_distance(encodings, face_encoding)
for match in matches:
2018-01-05 02:41:56 +01:00
if match < config.certainty:
2018-01-05 01:59:44 +01:00
stop(0)
2018-01-05 02:41:56 +01:00
if tries > config.frame_count:
stop(11)
2018-01-05 01:59:44 +01:00
tries += 1