一般都是由於顯示速度太快。也就是你在顯示的時候未在後面加上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;
}