-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCapture.py
More file actions
55 lines (44 loc) · 1.3 KB
/
Capture.py
File metadata and controls
55 lines (44 loc) · 1.3 KB
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
48
49
50
51
52
53
54
55
import cv2
class Capture:
def __init__(self):
self.port = self.getPort()
if self.port > -1:
self.cam = cv2.VideoCapture(self.port)
else:
raise Exception('No camera input')
def getPort(self):
port = -1
for i in range(0,6):
testedPort = cv2.VideoCapture(i)
if testedPort.isOpened():
is_reading, img = testedPort.read()
if is_reading:
port = i
if port > -1:
break
return port
def captureImageArray(self):
result, image = self.cam.read()
if not result:
raise Exception('Image not captured')
return image
def captureImagePng(self):
result, image = self.cam.read()
cv2.imwrite('frame.png', image)
def previewVideo(self):
while(True):
result, image = self.cam.read()
cv2.imshow('preview (press q to quit)', image)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
self.destroy()
def destroy(self):
self.cam.release()
cv2.destroyAllWindows()
def capture_test():
capture = Capture()
capture.captureImagePng()
def video_test():
capture = Capture()
capture.previewVideo()
#capture_test()