-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathwebcam_test.py
41 lines (33 loc) · 1.26 KB
/
webcam_test.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
import os
from pathlib import Path
import cv2
from facetools import FaceDetection, IdentityVerification, LivenessDetection
from facetools.utils import visualize_results
root = Path(os.path.abspath(__file__)).parent.absolute()
data_folder = root / "data"
resNet_checkpoint_path = data_folder / "checkpoints" / "InceptionResnetV1_vggface2.onnx"
facebank_path = data_folder / "reynolds.csv"
deepPix_checkpoint_path = data_folder / "checkpoints" / "OULU_Protocol_2_model_0_0.onnx"
faceDetector = FaceDetection(max_num_faces=1)
identityChecker = IdentityVerification(
checkpoint_path=resNet_checkpoint_path.as_posix(),
facebank_path=facebank_path.as_posix(),
)
livenessDetector = LivenessDetection(checkpoint_path=deepPix_checkpoint_path.as_posix())
cap = cv2.VideoCapture(0)
while True:
ret, frame = cap.read()
if not ret:
break
canvas = frame.copy()
faces, boxes = faceDetector(frame)
for face_arr, box in zip(faces, boxes):
min_sim_score, mean_sim_score = identityChecker(face_arr)
liveness_score = livenessDetector(face_arr)
canvas = visualize_results(canvas, box, liveness_score, mean_sim_score)
cv2.imshow("face", canvas)
k = cv2.waitKey(1)
if k == ord("q"):
break
cv2.destroyAllWindows()
cap.release()