Accessing a webcam using OpenCV (Python) in Docker?

I am trying to use Docker for one of our projects that uses OpenCV to handle webcam feeds (Python). But I can’t access the webcam in the docker, here is the code that I use to check access to the webcams:

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

And here is what I have 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

They all return False, what am I doing wrong?

+4
source share
1 answer

The Docker file in the specified link does not indicate how opencv was installed, can you provide the Docker file that you used? Or how did you install opencv?

VideoCapture (0) will not work if you install opencv via pip.

--device=/dev/video0:/dev/video0.

+2

Source: https://habr.com/ru/post/1680521/


All Articles