OpenCV VideoCapture is not functioning when deployed in Ubuntu server

Hi, I’m trying to open webcam using OpenCV after deploying the code in Ubuntu server. But am not able to open it and getting following error.

[ WARN:0] global /tmp/pip-req-build-rcdoave0/opencv/modules/videoio/src/cap_v4l.cpp (890) open VIDEOIO(V4L2:/dev/video1): can’t open camera by index

I tried to change parameters in cv2.VideoCapture(i) where i=[‘cv2.CAP_V4L2’,0,-1,1] but its not working.

Note: Its working fine with cv2.VideoCapture(0) in local laptop(windows 10) but its not working when deployed in server.

Please help me to resolve the issue.

welcome.

CAP_V4L (apiPreference) wants paths such as /dev/video0

CAP_FFMPEG also wants paths

on Windows, CAP_DSHOW and CAP_MSMF (dshow successor/evolution) open video devices by index

Hi, Thanks for the reply.
Inorder to open webcam in Ubuntu server without any paths, just wants to call by index,
what is the process that i need to follow?

try this. what does it say?

import cv2 as cv
camera_backends = cv.videoio_registry.getCameraBackends()
print(camera_backends)
print([
    cv.videoio_registry.getBackendName(apipref)
    for apipref in camera_backends
])

https://docs.opencv.org/master/de/db1/group__videoio__registry.html#gaf6e7163ade0d35b946c3ccccaf504e3e

Is this Ubuntu server on your local computer or external server?

Usually external servers don’t have webcams.
And external server also can’t access your local webcam.

1 Like