app.py
Browse files
app.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import threading
|
2 |
+
import cv2
|
3 |
+
from deepface import DeepFace
|
4 |
+
|
5 |
+
cap = cv2.VideoCapture(0, cv2.CAP_DSHOW)
|
6 |
+
|
7 |
+
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
|
8 |
+
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)
|
9 |
+
|
10 |
+
counter = 8
|
11 |
+
|
12 |
+
face_match = False
|
13 |
+
reference_img = cv2.imread("reference.jpeg")
|
14 |
+
|
15 |
+
def check_face(frame):
|
16 |
+
global face_match
|
17 |
+
try:
|
18 |
+
if DeepFace.verify(frame, reference_img.copy())['verified']:
|
19 |
+
face_match = True
|
20 |
+
else:
|
21 |
+
face_match = False
|
22 |
+
except ValueError:
|
23 |
+
face_match = False
|
24 |
+
|
25 |
+
while True:
|
26 |
+
ret, frame = cap.read()
|
27 |
+
|
28 |
+
if ret:
|
29 |
+
if counter%30 ==0:
|
30 |
+
try:
|
31 |
+
threading.Thread(target=check_face, args = (frame.copy(),)).start()
|
32 |
+
except ValueError:
|
33 |
+
pass
|
34 |
+
counter += 1
|
35 |
+
|
36 |
+
if face_match:
|
37 |
+
cv2.putText(frame, "Face Match!", (20, 450), cv2.FONT_HERSHEY_SIMPLEX, 2, (0, 255, 0), 3)
|
38 |
+
else:
|
39 |
+
cv2.putText(frame, "Face Not Match!", (20, 450), cv2.FONT_HERSHEY_SIMPLEX, 2, (0, 0, 255), 3)
|
40 |
+
|
41 |
+
cv2.imshow("video", frame)
|
42 |
+
|
43 |
+
key = cv2.waitKey(1)
|
44 |
+
if key == ord('q'):
|
45 |
+
break
|
46 |
+
|
47 |
+
cv2.destroyAllWindows()
|