我试图从我的mac电脑上的外部网络摄像头读取和图像从VideoCapture,但我不能显示的图像。我用的是:
我正在命令行中运行脚本,并且我非常肯定我给出了所需的所有权限。在我朋友使用Linux的笔记本电脑上,一切都很顺利。当我使用FaceTime或Photo时,我能够看到摄像头图像。
下面是代码:
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,但这是我得到的图像:图像
谢谢你的帮助!
发布于 2021-04-06 13:56:17
如果您的代码适用于主摄像头和linux,那么问题在于Mac权限,而不是python。
不要在iDE上运行脚本,而是将其打开到包含.py文件的文件夹中,并运行它。
https://stackoverflow.com/questions/66969636
复制相似问题