检测拔出的捕获设备(OpenCV)

编程入门 行业动态 更新时间:2024-10-25 02:27:14
本文介绍了检测拔出的捕获设备(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)

本文发布于:2023-11-05 04:06:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1559851.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:设备   OpenCV

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!