摄像头连接和断开捕捉 [英] Camera connection and disconnection catch

查看:149
本文介绍了摄像头连接和断开捕捉的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有C ++ API的OpenCV,为了使我的项目更可靠,我需要某种照相机连接/断开连接处理. 我已经搜索了操作方法,但是我只能找到需要进行骇客入侵的答案.

Hey guys, I'm using OpenCV with the C++ API, and in order for my project to be more reliable I need a certain camera connection\disconnection handling. I have searched for how-to's, but I could only find answers that require an ugly hack in order to do so.

您能建议一种更清洁的方法吗?

Can you suggest a cleaner way to do it?

Thnx

推荐答案

检测相机连接/断开连接可能需要一些技巧.

Detecting camera connection/disconnection might require some tricks.

我建议您在应用程序运行时启动另一个线程来循环检查cvCreateCameraCapture()是否成功.

I suggest that you start another thread to check the success of cvCreateCameraCapture() in a loop, while your application is running.

类似以下内容:

while (run_detection_thread) // global variable controlled by the main thread
{
  CvCapture* capture = cvCreateCameraCapture(-1); //-1 or whatever number works for you
  if (camera) //camera is connected
  {
    sleep(1);
  }
  else
  {
    // camera was disconnected        
  }
}

这篇关于摄像头连接和断开捕捉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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