Problems with VideoCapture on Windows

Hello,

I’m trying to port on Windows an application I wrote on Linux using Python(Qt5 and OpenCV).

The problem is that, when I try to open a webcam using cv2.VideoCapture(camera) where camera is obtained as follows:

self.available_cameras = QCameraInfo.availableCameras()
#The user select the camera from a QComboBox(shouldn't be important)
camera = self.available_cameras[combo_box_index].deviceName()

I get the following error:

[ERROR:0@14.725] global D:\a\opencv-python\opencv-python\opencv\modules\videoio\src\cap.cpp (166) cv::VideoCapture::open VIDEOIO(CV_IMAGES): raised OpenCV exception:

OpenCV(4.6.0) D:\a\opencv-python\opencv-python\opencv\modules\videoio\src\cap_images.cpp:253: error: (-5:Bad argument) CAP_IMAGES: can't find starting number (in the name of file): @device:pnp:\\?\usb#vid_045e&pid_076d&mi_00#7&315bdc05&0&0000#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\global in function 'cv::icvExtractPattern'

Anybody knows why?

cv::VideoCapture, for video devices, is supposed to get an index, not a “name”. if a “name” ever worked, some system-specific backend felt responsible and accepted that.

You can use Qt to read from your camera. you should. and if you need some sensible way to choose a camera, you must.

Yes, actually, on Linux, it worked. I was not aware of this issue. I’ll try to do as you suggested. Thanks for your help

CameraInfo::availableCameras() returns a list of available cameras and that list obviously has indices starting from zero, so a name is not a necessary representation. Of course that doesn’t mean those ids could be passed to VideoCapture…

or that OpenCV would assign indices the same way Qt did, or that OpenCV would see the same cameras that Qt does (various APIs)

Hello, I’m still struggling a bit with this problem(I have a related thread on the Qt forum too). The problem is that, it looks like that video capture with Qt is not supported on Windows. The question then is: is there any way to obtain a complete list of available devices(the device’s numbers, in particular) using OpenCV?

Qt may lack MSMF support but it can do directshow.

“viewfinder” is what you want.

https://doc.qt.io/qt-5/qtmultimedia-windows.html

if that really doesn’t suit you, I’m sure there are recipes for accessing MSMF/DShow directly.

you can’t use OpenCV for the level of flexibility that you require. OpenCV does not have a list of video devices.