我正在阅读《Learning OpenCV 3》一书并测试视频示例 2.3。我可以编辑、编译和运行它,但问题是它立即关闭了。
// DisplayPicture.cpp : Defines the entry point for the console application.
//
//#include "opencv2/opencv.hpp" // Include file for every supported OpenCV function
#include "opencv2\imgproc\imgproc.hpp"
#include "opencv2\highgui\highgui.hpp"
#include <opencv2/videoio.hpp>
#include <stdio.h>
#include <string.h>
using namespace cv;
using namespace std;
int main(int argc, char** argv) {
namedWindow("video3", WINDOW_AUTOSIZE);
VideoCapture cap;
cap.open( string(argv[1]));
int tell = 0;
Mat frame;
for (;;) {
cap >> frame;
//waitKey(30);
if (frame.empty())
{
break;
//end of film
}
imshow("video3", frame);
}
return 0;
}
我发现我的电脑处理数据的速度太快了。它无法足够快地读取下一帧。if (frame.empty())
变为 true 程序到达break
语句并结束。
通过waitkey
在查看图像帧之前添加 30 毫秒,视频程序运行良好。至少我可以看视频。由于此示例来自“圣经”,因此它应该可以工作,但不适用于我的计算机。
我正在运行带有nvidia gtx880m的MSI gt72 2PE计算机。不确定这是否重要。
我认为添加 awaitKey(30)
是不合适的,因此我正在寻求有关可以采取不同做法的建议。