Listing Available Devices in Python-Opencv

Listing available devices in python-opencv

This is a general problem of the OpenCV, as you can see below. It seems that only the builtin, or the first USB cam (only if you do not have a buildin cam) works in OpenCV:

How to use a camera with OpenCV

Cannot access usb webcam through OpenCV, Cygwin

OpenCV capture from USB not iSight (OSX)

Currently, there is no way to extract the number of cameras, as listed in this feature request:

https://code.ros.org/trac/opencv/ticket/935

List available cameras OpenCV/Python

The answer is negative. OpenCV doesn't have a method for listing the available video capture devices on your system. If you look at the code you see how currently OpenCV handles invalid device indices that don't exist. For instance for MacOS here is the code:

if ( cameraNum < 0 || devices.count <= NSUInteger(cameraNum) ) {
fprintf(stderr, "OpenCV: out device of bound (0-%ld): %d\n", devices.count-1, cameraNum);
[localpool drain];
return 0;
}

You see devices.count returns the number of available devices but OpenCV doesn't have a method to return that to the user.

The relevant code for Windows is here:

if ((unsigned)m_deviceID >= m_devices.Get()->Size)
{
OutputDebugStringA("Video::initGrabber - no video device found\n");
return false;
}

Again there is no function for returning m_devices.Get()->Size to the user. The Linux code is a bit more complex.

If you're building OpenCV from code you could add a function that returns the number of available devices. Or even better submit a pull request to OpenCV with your patch.



Related Topics



Leave a reply



Submit