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
How to Set the 'Backend' in Matplotlib in Python
Set Chrome Browser Binary Through Chromedriver in Python
Splitting Out the Output of Ps Using Python
How to Sort a Dictionary by Value
How to Make Function Decorators and Chain Them Together
How Is Returning the Output of a Function Different from Printing It
How to Make a Python Script Standalone Executable to Run Without Any Dependency
Sorting List Based on Values from Another List
How to Make a Python Script Run Like a Service or Daemon in Linux
How to Update a Python Package
Force Another Program'S Standard Output to Be Unbuffered Using Python
What Does the "Yield" Keyword Do
How to Sort a Dictionary by Key
Difference Between Modes A, A+, W, W+, and R+ in Built-In Open Function