-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdetection.py
87 lines (73 loc) · 2.61 KB
/
detection.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import face_recognition
import cv2
import numpy as np
import time
import pickle
import sys
def exi(name):
a = open('/lib/security/third_eye/test.txt', 'w')
a.write(name)
a.close()
fpsLimit = 1 # throttle limit
startTime = time.time()
video_capture = cv2.VideoCapture(0)
# "known" folder consist preprocessed encodings and names
with open( "/lib/security/third_eye/known/known_encodings.txt", "rb") as fp:
known_face_encodings = pickle.load(fp)
with open("/lib/security/third_eye/known/known_names.txt", "rb") as fp:
known_face_names = pickle.load(fp)
face_locations = []
face_encodings = []
face_names = []
count = 0
running = True
while running:
# Grab a single frame of video
try:
nowTime = time.time()
if (int(nowTime - startTime)) > fpsLimit:
ret, frame = video_capture.read()
count = count + 1
print(count)
if count > 3:
print('video timeout has been reached')
video_capture.release()
cv2.destroyAllWindows()
exi("unknown")
sys.exit()
continue
small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25)
rgb_small_frame = small_frame[:, :, ::-1]
face_locations = face_recognition.face_locations(
rgb_small_frame)
face_encodings = face_recognition.face_encodings(
rgb_small_frame, face_locations)
for face_encoding in face_encodings:
matches = face_recognition.compare_faces(
known_face_encodings, face_encoding)
if True in matches:
print("got a true value")
first_match_index = matches.index(True)
name = known_face_names[first_match_index]
# If found then exit
video_capture.release()
cv2.destroyAllWindows()
print("name of the person", name)
exi(name) # person detected
running=False
break
else:
video_capture.release()
cv2.destroyAllWindows()
exi("guest")
running=False
break
startTime = time.time()
#cv2.imshow('Video', frame)
except:
if count > 3:
video_capture.release()
cv2.destroyAllWindows()
print("Terminate!")
exi("unknown") # person not detected
running=False