C++ 如何使用 opencv 获取网络摄像头设备列表?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9276350/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 12:35:20  来源:igfitidea点击:

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

c++windowsopencv

提问by Phil Hannent

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

我正在使用带有视频输入的 OpenCV2.2。我想升级到 OpenCV2.3.1,其中 videoInput 显然已合并到 OpenCV2.3 中。

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

我的问题是似乎没有 listdevices() 函数来返回所有可用的视频源。

Does anybody know the new equivalent?

有人知道新的等价物吗?

回答by Appleman1234

As you said videoinput has been merged in OpenCV since 2.3rc.

正如您所说,自 2.3rc 以来,视频输入已合并到 OpenCV 中。

Looking at the relevant sourcevideoinput 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_VIDEOINPUTand also requires it be a WIN32 build, see here).

按照 OpenCV 更改日志的规定,查看相关的视频输入似乎在 highgui 中。尽管您的 OpenCV 是否在启用它的情况下构建是 Cmake 中的一个可配置选项(该选项是WITH_VIDEOINPUT并且也要求它是 WIN32 构建,请参见此处)。

OpenCV calls listdevices internally as VI.listDevices()in the implementation of CvCaptureCAM_DShow::openand the videoInput Class is a protected member of CvCaptureCAM_DShow.

OpenCVVI.listDevices()在内部调用 listdevicesCvCaptureCAM_DShow::open和 videoInput 类是 CvCaptureCAM_DShow 的受保护成员。

You can get access listdevices function using

您可以使用访问列表设备功能

 CvCapture* capture = cvCaptureFromCAM( CV_CAP_DSHOW );
 capture->VI.listDevices();

回答by mevatron

See thisStackOverflow 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 requestagainst version 2.2 a while back.

请参阅StackOverflow 答案。OpenCV 目前不支持它,因为它是跨平台的,并且相机枚举是非常特定于平台的(例如,v4l2 枚举与 DirectShow 不同)。但是,不久前有人提交了针对 2.2 版的增强请求

回答by dagilpe

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.

我编写了一个允许使用 DirectShow 接口和枚举器枚举所有设备的类。虽然它仅适用于 Windows,但它允许您获取“友好设备名称”列表和您需要创建的 ID,例如 VideoCapture 对象。

The code is here:

代码在这里:

https://github.com/studiosi/OpenCVDeviceEnumerator

https://github.com/studiosi/OpenCVDeviceEnumerator