-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCamera.py
More file actions
38 lines (30 loc) · 910 Bytes
/
Camera.py
File metadata and controls
38 lines (30 loc) · 910 Bytes
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
import cv2
import sys
class Camera():
camera_index : int
video_cap : cv2.VideoCapture
cap_w : int
cap_h : int
def __init__(self, camera_index=0, cap_w=640, cap_h=480) -> None:
self.camera_index = camera_index,
self.video_cap = cv2.VideoCapture(0)
self.cap_w = cap_w
self.cap_h = cap_h
self.video_cap.set(3,cap_w)
self.video_cap.set(4,cap_h)
def capture_frame(self):
ret, frame = self.video_cap.read()
if ret:
return frame
else:
print('Failed to capture frame')
return None
def display_frame(self, frame) -> None:
if frame is not None:
cv2.imshow('Frame', frame)
if cv2.waitKey(1) == ord('q'):
print('Exiting...')
sys.exit(0)
else:
print('Camera frame is empty')
sys.exit(-1)