-
Notifications
You must be signed in to change notification settings - Fork 1
/
detect_on_webcam.py
41 lines (35 loc) · 1021 Bytes
/
detect_on_webcam.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
#/usr/bin/python3
"""
Test RateMe on video stream
"""
import cv2
from rateme.utils import RateMe, CAM
import argparse
parser = argparse.ArgumentParser(description="Like/dislike detector")
parser.add_argument("-c", "--camera", dest="cam",
help="Webcam index (0 by default),\
there could be video stream address",
metavar="CAM_ID",
default=0,
type=int)
args = parser.parse_args()
# load net
net = RateMe()
# access to webcam
cap = CAM(args.cam)
while cap.video.isOpened():
# get new frame
frame = cap.next()
# get net predictions
label = net.predict(frame)
# plot detections on frame
tmp = frame.copy()
cv2.putText(tmp, "{}".format(str(label)),
(10, 30),
cv2.FONT_HERSHEY_SIMPLEX,
1, (255, 0, 0), 2)
# show frame series
cv2.imshow('FPS', tmp)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cv2.destroyAllWindows()