opencv 退出摄像头if (getWindowProperty("Video", WND_PROP_AUTOSIZE) != 1) break;
引发异常
#include <iostream>
#include <string>
#include <sstream>
#pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" )
using namespace std;
// OpenCV includes
#include "opencv2/highgui.hpp"
#include <opencv2/opencv.hpp>
using namespace cv;
int main(int argc,char** argv)
{
//视频采集对象;
VideoCapture cap;
//打开默认相机
cap.open(0);
if (!cap.isOpened())
return -1;
while (true)
{
Mat frame;
cap >> frame;
if (frame.empty())
return 0;
// 视频窗口
namedWindow("Video", WINDOW_AUTOSIZE);
// 显示
imshow("Video", frame);
// 空格暂停
int keyS = waitKey(30);
if (keyS == 32)
waitKey(0);
// 退出
if (getWindowProperty("Video", WND_PROP_AUTOSIZE) != 1)
break;
}
cap.release();
destroyAllWindows();
return 0;
}
设置项目使用多字节字符集