在Docker中使用OpenCV(Python)访问网络摄像头? [英] Access webcam using OpenCV (Python) in Docker?

查看:375
本文介绍了在Docker中使用OpenCV(Python)访问网络摄像头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Docker用于我们的使用OpenCV处理网络摄像头feed(Python)的项目之一.但是我似乎无法在docker中访问网络摄像头,这是我用来测试网络摄像头访问权限的代码:

I'm trying to use Docker for one of our projects which uses OpenCV to process webcam feed (Python). But I can't seem to get access to the webcam within docker, here's the code which I use to test webcam access:

python -c "import cv2;print(cv2.VideoCapture(0).isOpened())"

这是我到目前为止所尝试的,

And here's what I tried so far,

 docker run --device=/dev/video0 -it rec bash

 docker run --privileged --device=/dev/video0 -it rec bash

 sudo docker run --privileged --device=/dev/video0:/dev/video0 -it rec bash

所有这些都返回False,我在做什么错了?

All of these return False, what am I doing wrong?

推荐答案

您提供的链接中的Dockerfile没有指定opencv的安装方式,可以提供您使用的Dockerfile吗?还是您如何安装opencv?

The Dockerfile in the link you provided doesn't specify how opencv was installed, can you provide the Dockerfile you used? Or how you installed opencv?

如果通过pip安装opencv,VideoCapture(0)将无法工作.

VideoCapture(0) won't work if you install opencv via pip.

您正确使用了--device=/dev/video0:/dev/video0.

这篇关于在Docker中使用OpenCV(Python)访问网络摄像头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆