【发布时间】:2016-03-15 20:21:55
【问题描述】:
我想列出所有使用 C++、OpenCV 2.4.11、Windows 8.1 和 Qt Creator 3.4.2 连接的网络摄像头(USB 网络摄像头和内部网络摄像头)。 对我来说,通过以下方式获取可访问网络摄像头的数量就足够了:
VideoCapture videoCapture(0); // Will access my internal laptop webcam.
VideoCapture videoCapture(1); // Will access the first connected usb webcam.
这是我的代码:
// Following procedure detects, how many webcams are accessible from 0 on upwards.
numberOfDevices = 0;
bool noError = true;
while (noError)
{
try
{
// Check if camera is available.
VideoCapture videoCapture(numberOfDevices); // Will crash if not available, hence try/catch.
// ...
}
catch (...)
{
noError = false;
}
// If above call worked, we have found another camera.
numberOfDevices++;
}
如果我激活了内部网络摄像头,try-block 中的代码将起作用。当我在硬件管理器中停用内部摄像头(并且没有其他摄像头连接到我的笔记本电脑)时调用失败,并显示以下错误消息(调试模式):
Exception Triggered --------------------------- The inferior stopped because it triggered an exception.<p>Stopped in thread 0 by: Exception at 0x7ff8533d9090, code: 0xc0000005: read access violation at: 0x0, flags=0x0 (first chance).
以及以下 2 个构建问题:
Exception at 0x7ff871af8b9c, code: 0xa1a01db1: , flags=0x0 (first chance) Exception at 0x7ff8533d9090, code: 0xc0000005: read access violation at: 0x0, flags=0x0 (first chance)
如何获取发生的错误?如您所见,try/catch 不起作用。
或者有没有一种方法可以让我访问 OpenCV 中所有可用的网络摄像头,而不会出现这种脏循环?
【问题讨论】:
-
我在 Windows 上没有观察到崩溃,在执行非常类似的操作时...
-
好的,这似乎取决于安装的设备驱动程序。在安装 GigE 相机之前,我只是尝试打开它们来测试不存在的设备没有问题...
-
有一个类似的线程link。评论者有不同的结果。 ://
-
我鼓励你使用 VideoInput 库(无论如何在内部被 openCV 使用):github.com/ofTheo/videoInput
标签: c++ opencv webcam video-capture