How to count cameras in OpenCV 2.3?(如何计算 OpenCV 2.3 中的摄像头?)
问题描述
我想获取可用摄像机的数量.
I want to get the number of available cameras.
我试着像这样计算摄像机:
I tried to count cameras like this:
for(int device = 0; device<10; device++)
{
VideoCapture cap(device);
if (!cap.isOpened())
return device;
}
如果我连接了相机,它永远不会打开失败.所以我尝试预览不同的设备,但我总是得到我相机的图像.
If I have a camera connected, it never failed to open. So I tried to preview different devices but I get always the image of my camera.
如果我连接第二个摄像头,设备 0 是摄像头 1,设备 1-10 是摄像头 2.
If I connect a second camera, device 0 is camera 1 and device 1-10 are camera 2.
我认为 DirectShow 设备有问题.
I think there is a problem with DirectShow devices.
如何解决这个问题?或者是否有像 OpenCV1 cvcamGetCamerasCount()
中的函数?
How to solve this problem? Or is there a function like in OpenCV1 cvcamGetCamerasCount()
?
我使用的是 Windows 7 和 USB 摄像头.
I am using Windows 7 and USB cameras.
推荐答案
OpenCV 仍然没有 API 来枚举摄像头或获取可用设备的数量.有关详细信息,请参阅 OpenCV 错误跟踪器上的这张票.
OpenCV still has no API to enumerate the cameras or get the number of available devices. See this ticket on OpenCV bug tracker for details.
对于大于连接的设备数量的设备编号,VideoCapture 的行为未定义,并且取决于用于与您的相机通信的 API.请参阅 OpenCV2.3 (C++,QtGui),关于 OpenCV 中使用的 API 列表初始化一些特定的 USB 设备和设置的问题.
Behavior of VideoCapture is undefined for device numbers greater then number of devices connected and depends from API used to communicate with your camera. See OpenCV 2.3 (C++,QtGui), Problem Initializing some specific USB Devices and Setups for the list of APIs used in OpenCV.
这篇关于如何计算 OpenCV 2.3 中的摄像头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何计算 OpenCV 2.3 中的摄像头?


基础教程推荐
- CString 到 char* 2021-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01