Sitemap
Ted James

Ted James

The world is my office, and every destination is my inspiration

Member-only story

‘can’t open camera by index’ using cv.videocapture(0)

2 min readMay 28, 2024

I get:

[ WARN:0@0.790] global /tmp/pip-wheel-5v2wouk5/opencv-contrib-python_f04c010cf0414c5a81144576b45aa287/opencv/modules/videoio/src/cap_v4l.cpp (889) open VIDEOIO(V4L2:/dev/video0): can’t open camera by index

when deploying a Docker container to Raspberry Pi 4B (Debian). Second line is where the warning comes from:

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)

The Docker container is deployed to the device by first building it in Visual Studio and thereafter pushing it to Azure Container Registry by:

docker build — rm -f “c:”my_path”\arm32v7.Dockerfile” -t “my_crname”.azurecr.io/cameracapture:0.2.11-arm32v7 “c:… ; if ($?) { docker push “my_crname”.azurecr.io/cameracapture:0.2.11-arm32v7 } if ($?) { docker build — rm -f “c:”my_path”\arm32v7.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 }

it is thereafter ‘deployed to a single device’ in Visual Studio through a configfile (deployment.json).

The Docker has permissions to access the camera module 3 integrated camera mounted on /dev/video0:

--

--

Ted James
Ted James

Written by Ted James

The world is my office, and every destination is my inspiration