利用Mat数据结构打开摄像头

来源:互联网 发布:网络桥接器 编辑:程序博客网 时间:2024/05/29 17:48

利用Mat数据结构打开摄像头

     一个没上过C++的课程的编程盲,现在开始学openCV挑战还真是不小,一个简单的小问题就要很长时间才能解决。例如利用openCV的新数据结构打开摄像头,参考着别人做的运行时总是出现问题,无意中发现在debug下编译出错,在release下编译就可以了。把程序列出来,很简单,就是打开一个摄像头,然后显示出来。刚开始做,希望能帮助初学者吧

#include"opencv2/imgproc/imgproc.hpp"
#include"opencv2/highgui/highgui.hpp"


using namespace std;
using namespace cv;




int main()
{
Mat frame;
VideoCapture captRefrnc;
captRefrnc.open(1);
//cvWaitKey(10000);
int a=0;
namedWindow("result",CV_WINDOW_AUTOSIZE);
if(!captRefrnc.isOpened())


return 0;

while (true)
{
captRefrnc>>frame;


imshow("result",frame);
char c=cvWaitKey(33);
if(c==27)break;
}
return 0;


}

0 0