【发布时间】:2021-07-02 07:05:51
【问题描述】:
我正在尝试从 Mac 上的外部网络摄像头读取 VideoCapture 并拍摄图像,但我无法显示图像。这是我正在使用的:
- Python:3.9.1
- opencv-contrib-python: 4.5.1.48
- MacOS Big Sur 11.2.3
- 外置网络摄像头:罗技 C905
我正在从命令行运行脚本,我很确定我提供了所有需要的权限。在我朋友的使用 Linux 的笔记本电脑上一切正常。当我使用 FaceTime 或 Photo Booth 时,我能够看到网络摄像头图像。
代码如下:
class Camera:
def __init__(self, camera_index: int):
self._camera_index = camera_index
self._capture = None
self._open_capture()
def take_world_image(self):
return self._get_camera_frame()
def _get_camera_frame(self):
print(self._capture.read)
opened_successfully, current_frame = self._capture.read()
if not opened_successfully:
raise InvalidCameraConfigException
return current_frame
def _open_capture(self):
self._capture = cv2.VideoCapture(self._camera_index)
def _close_capture(self):
self._capture.release()
if __name__ == "__main__":
camera = Camera(1)
while True:
image = camera.take_world_image()
cv2.imshow("image", image)
if cv2.waitKey(1) & 0xFF == ord("q"):
break
cv2.destroyAllWindows()
open_successfully 返回 True,但这是我得到的图像: image
感谢您的帮助!
【问题讨论】: