使用 cv.videocapture(0)“无法通过索引打开相机”

问题描述 投票:0回答:1

我得到:

[ WARN:[email protected]] global /tmp/pip-wheel-5v2wouk5/opencv-contrib-python_f04c010cf0414c5a81144576b45aa287/opencv/modules/videoio/src/cap_v4l.cpp (889) 打开 VIDEOIO(V4L2:/dev/video0): 可以不按索引打开相机

将 Docker 容器部署到 Raspberry Pi 4B (Debian) 时。第二行是警告的来源:

def __init__(self, path, queueSize=3):
    self.stream = cv2.VideoCapture(path) #<--- here the warning pops up. path == 0 here.
    print("path: ", path)
    print("self.stream of cv2.VideoCapture(path) ", self.stream)

    self.stopped = False
    self.Q = Queue(maxsize=queueSize)

首先在 Visual Studio 中构建 Docker 容器,然后通过以下方式将其推送到 Azure 容器注册表,从而将其部署到设备:

docker build --rm -f "c:"my_path" rm32v7.Dockerfile" -t "my_crname".azurecr.io/cameracapture:0.2.11-arm32v7 "c:... ; if ($?) { docker推送“my_crname”.azurecr.io/cameracapture:0.2.11-arm32v7 } if ($?) { docker build --rm -f“c:”my_path“rm32v7.Dockerfile”-t“my_crname”.azurecr.io /imageclassifierservice:0.2.17-arm32v7 "c:"my_path"" } if ($?) { docker Push "my_crname".azurecr.io/imageclassifierservice:0.2.17-arm32v7 }

此后,它通过配置文件 (deployment.json) 在 Visual Studio 中“部署到单个设备”。

Docker有权限访问安装在/dev/video0上的摄像头模块3集成摄像头:

sudo nano /etc/udev/rules.d/99-camera.rules
SUBSYSTEM=="vchiq",MODE="0666"

我尝试在

cv2.VideoCapture(path)
中将0更改为-1和1。我重新连接了相机,重新启动并更新了 Raspberry Pi。我尝试通过
sudo raspi-config
启用/禁用旧版相机。
sudo ls/dev grep | video
显示
video0

如何解决这个问题?

python docker raspberry-pi camera azure-iot-edge
1个回答
0
投票

我设法通过将代码调整为

使其工作

cap = cv2.VideoCapture(index, cv2.CAP_V4L)

我已经在 stackoverflow.com/questions/66440070/… 上看到了这个解决方案,但在研究了这个函数之后,我认为这仅适用于基于 Windows 的设备,但显然它也适用于基于 Linux 的设备。

© www.soinside.com 2019 - 2024. All rights reserved.