forked from jkjung-avt/tensorrt_demos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cam_test.py
42 lines (32 loc) · 1.02 KB
/
cam_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
42
import sys
from timeit import default_timer as timer
import cv2
sys.path.insert(1, "../..")
from trt_mtcnn import TrtMTCNNWrapper
from util.visuals import GraphicsRenderer, Camera
if __name__ == "__main__":
mtcnn = TrtMTCNNWrapper(
"mtcnn/det1.engine", "mtcnn/det2.engine", "mtcnn/det3.engine"
)
cap = Camera(threaded=False)
graphics = GraphicsRenderer()
try:
visuals = bool(int(sys.argv[1]))
except IndexError:
print("USAGE: python3 cam_test.py [visuals]")
sys.exit(1)
while True:
_, frame = cap.read()
start = timer()
result = mtcnn.detect_faces(frame)
elapsed = timer() - start
if result:
if visuals:
for person in result:
graphics.add_graphics(frame, person, True, "", elapsed)
print("FACE DETECTED!!")
print(f"{elapsed * 1000} ms")
if visuals:
cv2.imshow("cam test", frame)
if cv2.waitKey(1) & 0xFF == ord("q"):
break