-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvideocamera.py
44 lines (30 loc) · 871 Bytes
/
videocamera.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
"""
:/helper class
"""
import cv2
class VideoCamera(object):
def __init__(self):
self.video = cv2.VideoCapture(0)
def __del__(self):
self.video.release()
def get_frame(self, in_grayscale=False):
_, frame = self.video.read()
if in_grayscale:
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
return frame
def show_frame(self, seconds, in_grayscale=False):
_, frame = self.video.read()
if in_grayscale:
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.imshow('SnapShot', frame)
key_pressed = cv2.waitKey(seconds * 1000)
return key_pressed & 0xFF
'''
if __name__ == '__main__':
VC = VideoCamera()
while True:
KEY = VC.show_frame(1, True)
if KEY == 27:
break
VC.show_frame(1)
'''