Spaces:
Running
Running
File size: 712 Bytes
15fb2ce | 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 | import cv2 as cv
class Camera:
def __init__(self):
self.camera = cv.VideoCapture(0)
if not self.camera.isOpened():
raise ValueError("Unable to open the camera!")
# IMPORTANT: convert to int
self.width = int(self.camera.get(cv.CAP_PROP_FRAME_WIDTH))
self.height = int(self.camera.get(cv.CAP_PROP_FRAME_HEIGHT))
def __del__(self):
if self.camera.isOpened():
self.camera.release()
def get_frame(self):
if self.camera.isOpened():
ret, frame = self.camera.read()
if ret:
frame = cv.cvtColor(frame, cv.COLOR_BGR2RGB)
return ret, frame
return False, None
|