-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeepface_recognition.py
More file actions
113 lines (85 loc) · 2.3 KB
/
Copy pathdeepface_recognition.py
File metadata and controls
113 lines (85 loc) · 2.3 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
from deepface import DeepFace
import cv2
import os
camera = cv2.VideoCapture(0)
print("Starting AI Face Recognition...")
while True:
ret, frame = camera.read()
if not ret:
break
try:
result = DeepFace.find(
img_path=frame,
db_path="faces",
model_name="ArcFace",
enforce_detection=True,
silent=True
)
# Debug: print the result
print(result)
if len(result) > 0 and len(result[0]) > 0:
if len(result) > 0 and len(result[0]) > 0:
best = result[0].iloc[0]
distance = best["distance"]
identity = best["identity"]
name = identity.split("/")[1]
if distance < 0.20:
cv2.putText(
frame,
name,
(40,50),
cv2.FONT_HERSHEY_SIMPLEX,
1,
(0,255,0),
2
)
print("Recognized:", name)
else:
cv2.putText(
frame,
"Unknown",
(40,50),
cv2.FONT_HERSHEY_SIMPLEX,
1,
(0,0,255),
2
)
else:
cv2.putText(
frame,
"Unknown",
(40,50),
cv2.FONT_HERSHEY_SIMPLEX,
1,
(0,0,255),
2
)
else:
cv2.putText(
frame,
"Unknown",
(40, 50),
cv2.FONT_HERSHEY_SIMPLEX,
1,
(0, 0, 255),
2
)
except Exception as e:
print("ERROR:", e)
cv2.putText(
frame,
"Unknown",
(40, 50),
cv2.FONT_HERSHEY_SIMPLEX,
1,
(0, 0, 255),
2
)
cv2.imshow(
"SentinelAI DeepFace",
frame
)
if cv2.waitKey(1) & 0xFF == ord("q"):
break
camera.release()
cv2.destroyAllWindows()