How do I get a list of webcam devices using opencv?
As you said videoinput has been merged in OpenCV since 2.3rc.
Looking at the relevant source videoinput appears to be in highgui as the OpenCV changelog specifies. Though whether your OpenCV is built with it enabled is a configurable option in Cmake (The option is WITH_VIDEOINPUT
and also requires it be a WIN32 build, see here).
OpenCV calls listdevices internally as VI.listDevices()
in the implementation of CvCaptureCAM_DShow::open
and the videoInput Class is a protected member of CvCaptureCAM_DShow.
You can get access listdevices function using
CvCapture* capture = cvCaptureFromCAM( CV_CAP_DSHOW ); capture->VI.listDevices();
See this StackOverflow answer. It is currently not supported by OpenCV because it is cross platform, and camera enumeration is very platform specific (e.g., v4l2 enumerates differently than DirectShow). But, someone submitted an enhancement request against version 2.2 a while back.
I coded a class that allows to enumerate all the devices by using the DirectShow interface and enumerators. While it will only work on Windows, it will allow you to obtain a list of "friendly device names" and the ids that you need to create, for example a VideoCapture object.
The code is here: