-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb_cam.py
32 lines (26 loc) · 935 Bytes
/
web_cam.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
import cv2
class WebCam:
def __init__(self, width=640, height=480, fps=30):
""" Initialize the OpenCV camera manager. """
self.width = width
self.height = height
self.fps = fps
self.device = None
self.depth_enabled = False # for consistency
def start(self):
""" Open the camera. """
self.device = cv2.VideoCapture(0)
self.device.set(cv2.CAP_PROP_FRAME_WIDTH, self.width)
self.device.set(cv2.CAP_PROP_FRAME_HEIGHT, self.height)
self.device.set(cv2.CAP_PROP_FPS, self.fps)
def is_opened(self):
""" Check if the camera is opened. """
return self.device.isOpened()
def stop(self):
""" Close the camera. """
self.device.release()
self.device = None
def read_frame(self):
""" Read a frame from the camera. """
ret, frame = self.device.read()
return ret, frame