-
Notifications
You must be signed in to change notification settings - Fork 0
/
webcam.py
47 lines (34 loc) · 1.01 KB
/
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
42
43
44
45
46
47
# -*- coding: utf-8 -*-
from __future__ import print_function
import cv2
from predict import predict, draw_face_info, show_image
import time
def run():
times = []
cv2.namedWindow("Webcam")
capture = cv2.VideoCapture(0)
if not capture.isOpened():
return
while True:
# calculate time
start_time = time.time()
rval, frame = capture.read()
if not rval:
break
image = frame
gray_image = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
for face_info in predict(gray_image):
draw_face_info(image, face_info)
cv2.imshow("Webcam", image)
end_time = time.time()
times.append(end_time-start_time)
key = cv2.waitKey(1)
if key == 27 or key == ord('q'): # exit on ESC or Q
break
cv2.destroyWindow("Webcam")
capture.release()
return times
if __name__ == '__main__':
times = run()
for time in times:
print(time)