gpt4 book ai didi

python - 在 Windows 主机上使用 python (cv2.VideoCapture) 在 docker 容器中打开网络摄像头

转载 作者:行者123 更新时间:2023-12-04 19:41:37 24 4
gpt4 key购买 nike

我在 Windows 主机上运行 docker 工具箱。我已经安装了opencv槽pip install opencv-contrib-python ,这很成功。现在,当我使用 docker exec -it centos /bin/bash 进入我的 CentOS Docker 容器时, 在我输入 python 之后和 import cv2在我的 python 解释器中。我尝试创建一个视频捕获对象 CapDev = cv2.VideoCapture(0) ,并返回错误 VIDEOIO ERROR: V4L: can't open camera by index 0 .当我尝试使用索引 -1 时,它说:VIDEOIO ERROR: V4L: can't find camera device是什么导致了这个问题?是因为windows主机不允许docker容器打开摄像头,还是其他原因?

最佳答案

What is causing this problem? Is it because of the windows host not allowing the docker container to open the camera, or is it something else?


有点。由于 Docker 使用容器,因此您正在运行的容器不包括笔记本电脑的网络摄像头。我进行了广泛搜索,但通过 Windows 上的 Docker 解决这个问题似乎并不容易。
如果您使用的是 linux,则只需添加 --device=/dev/video0:/dev/video0到您的 docker 命令。 Windows似乎使它更复杂!我找到了 this page这看起来很有帮助,但还没有解决我的问题,因为我无法切换到 Windows 容器。如果您能够切换到 Windows 容器,这可能是您的解决方案!

关于python - 在 Windows 主机上使用 python (cv2.VideoCapture) 在 docker 容器中打开网络摄像头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58900385/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com