一般都是由于显示速度太快。也就是你在显示的时候未在后面加上waitKey(数值)。这个数值,当显示图片时候选取为0;当读取相机或者视频时候,选择为帧率,一般为20-30都行。
附送相机打开程序
#include <opencv2\opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
//摄像头捕捉视频
cv::namedWindow("Example7", cv::WINDOW_AUTOSIZE);
cv::VideoCapture cap;
cap.open(0);//0为相机编号,一个相机就选择0
if (!cap.isOpened())
{
cout << "couldn't open capture" << endl;
system("pause");
return -1;
}
cv::Mat frames;
while (1)
{
cap >> frames;
imshow("Example7", frames);
waitKey(20);
}
destroyAllWindows();
system("pause");
return 0;
}