def __init__(self, id=None, auto_init=False): if id is None: self.id = -1 else: self.id = id self.cap_config = CVCaptureConfig(self.id, type_='camera') self.cap = None self.props = None super(CVCameraCapture, self).__init__(auto_init=auto_init)
class CVCameraCapture(CameraCaptureBase): def __init__(self, id=None, auto_init=False): if id is None: self.id = -1 else: self.id = id self.cap_config = CVCaptureConfig(self.id, type_='camera') self.cap = None self.props = None super(CVCameraCapture, self).__init__(auto_init=auto_init) def _release_capture(self): if self.cap is not None: del self.cap if self.props is not None: del self.props def _init_capture(self): self.cap = self.cap_config.create_capture() def get_frame(self): cv.GrabFrame(self.cap) frame = cv.RetrieveFrame(self.cap) if frame: return frame else: return None def _set_dimensions(self, dimensions): cv.SetCaptureProperty(self.cap, cv.CV_CAP_PROP_FRAME_WIDTH, dimensions[0]) cv.SetCaptureProperty(self.cap, cv.CV_CAP_PROP_FRAME_HEIGHT, dimensions[1]) self._dimensions = dimensions @property def dimensions(self): if self._dimensions is None: self.props = CVCaptureProperties(self.cap) self._dimensions = (self.props.width, self.props.height) return self._dimensions