简体   繁体   中英

How do I get a list of webcam devices using opencv?

I am using OpenCV2.2 with videoInput. I want to upgrade to OpenCV2.3.1 where videoInput has apparently been merged into OpenCV2.3.

My problem is that there doesn't appear to be a listdevices() function to return all the video sources available.

Does anybody know the new equivalent?

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 (eg, 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:

https://github.com/studiosi/OpenCVDeviceEnumerator

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM