#include "stdafx.h"
#include<opencv2\highgui\highgui.hpp>
#include <opencv\cv.h>
#include <opencv2\opencv.hpp>
using namespace cv;
int main()
{
VideoCapture cap;
cap.open(0); //打开摄像头
if (!cap.isOpened())
return -1;
Mat frame;
while (1)
{
cap >> frame;//等价于cap.read(frame);
if (frame.empty())
break;
imshow("video", frame);
if (waitKey(20)>0)//按下任意键退出摄像头 因电脑环境而异,有的电脑可能会出现一闪而过的情况
break;
}
cap.release();
destroyAllWindows();//关闭所有窗口
return 0;
}