Skip to content
Advertisement

Access webcam using OpenCV (Python) in 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

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

Advertisement

Answer

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?

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

You’re using --device=/dev/video0:/dev/video0 correctly.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement