Loo*_*mis 6 c++ webcam opencv video-capture
我想使用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.
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
// 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++;
}
Run Code Online (Sandbox Code Playgroud)
如果我激活了内部网络摄像头,则尝试块中的代码将起作用。当我在硬件管理器中停用内置摄像机(并且笔记本电脑未连接其他摄像机)时,调用失败,并显示以下错误消息(调试模式):
Run Code Online (Sandbox Code Playgroud)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).
和以下两个构建问题:
Run Code Online (Sandbox Code Playgroud)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中访问所有可用的网络摄像头而又不会出现这种麻烦的循环?
| 归档时间: |
|
| 查看次数: |
18135 次 |
| 最近记录: |