gpt4 book ai didi

C++ OpenCV 2.4.11 : List all cameras

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:51:57 35 4
gpt4 key购买 nike

我想列出所有连接的网络摄像头(USB 网络摄像头和内部网络摄像头),使用 C++、OpenCV 2.4.11、Windows 8.1 和 Qt Creator 3.4.2。对我来说,通过以下方式获取可访问网络摄像头的数量就足够了:

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 中的代码就可以工作。当我在硬件管理器中停用内部摄像头(并且没有其他摄像头连接到我的笔记本电脑)并显示以下错误消息( Debug模式)时,调用失败:

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 中所有可用的网络摄像头?

最佳答案

目前 OpenCV(3.0.0 版本)中仍然没有任何与相机数量相关的功能 - 参见 corresponding ticket .

正确的相机处理似乎是 OpenCV 内部问题(例如,描述为 herehere)。它通常在物理禁用相机后出现在捕获代码中,而它仍在 OpenCV 中打开(当我们尝试读取已损坏的文件描述符时)。

通常您甚至可以实现自己的访问冲突处理程序(请查看 this thread ),但这确实是个肮脏的把戏。

关于C++ OpenCV 2.4.11 : List all cameras,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34197825/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com