You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gesture_rec/camera/web_camera.py

21 lines
537 B
Python

import cv2
from camera.base_camera import Camera
class WebCamera(Camera):
def __init__(self, camera_id=0, mirror=False):
self.cap = cv2.VideoCapture(camera_id)
self.mirror = mirror
if not self.cap.isOpened():
raise RuntimeError("Cannot open web camera")
def get_frame(self):
ret, frame = self.cap.read()
if not ret:
return None
if self.mirror:
frame = cv2.flip(frame, 1)
return frame
def release(self):
self.cap.release()