检测拔出的捕获设备(OpenCV) [英] Detecting an unplugged capture device (OpenCV)

查看:85
本文介绍了检测拔出的捕获设备(OpenCV)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试检测摄像头是否已拔出.我的假设是对cvQueryFrame的调用将返回NULL,但是它将继续返回最后一个有效帧.

I'm attempting to detect if my capture camera gets unplugged. My assumption was that a call to cvQueryFrame would return NULL, however it continues to return the last valid frame.

有人知道如何使用OpenCV检测摄像机的插拔事件吗?这似乎太基本了……我想念什么?

Does anyone know of how to detect camera plug/unplug events with OpenCV? This seems so rudimentary...what am I missing?

推荐答案

不幸的是,没有API函数可以做到这一点.

There is no API function to do that, unfortunately.

但是,我的建议是您创建另一个线程,该线程仅调用cvCaptureFromCAM()并检查其结果(在循环内).如果摄像机断开连接,则应返回NULL.

However, my suggestion is that you create another thread that simply calls cvCaptureFromCAM() and check it's result (inside a loop). If the camera get's disconnected then it should return NULL.

我将粘贴一些代码只是为了说明我的想法:

I'll paste some code just to illustrate my idea:

// This code should be executed on another thread!
while (1)
{
  CvCapture* capture = NULL;
  capture = cvCaptureFromCAM(-1); // or whatever parameter you are already using
  if (!capture)
  {
    std::cout << "!!! Camera got disconnected !!!!" << std::endl;
    break;
  }

  // I'm not sure if releasing it will have any affect on the other thread
  cvReleaseCapture(&capture); 
}

这篇关于检测拔出的捕获设备(OpenCV)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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