open camera

#include "stdafx.h"
#include "Opencvhead.h"
#include <iostream>
using namespace std;
using namespace cv;

int _tmain(int argc, _TCHAR* argv[])
{
   VideoCapture cap(0);
   if(!cap.isOpened())
   {
	   cout<<"Can't open the video cam"<<endl;
	   return -1;
   }

   namedWindow("MyVideo",CV_WINDOW_AUTOSIZE);
   Mat frame;
	char ch;

	while(true)
	{
		cap >> frame;
		if(frame.empty())
			break;

		imshow("MyVideo", frame); //show the frame in "MyVideo" window

		ch = waitKey(30);
		if( ch == 27)
			break;
	}

	return 0;
}

猜你喜欢

转载自blog.csdn.net/zxl2712028/article/details/80262218