如何计算 OpenCV 2.3 中的摄像头? [英] How to count cameras in OpenCV 2.3?

查看:35
本文介绍了如何计算 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 中的摄像头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆