我已经编写了一个程序来使用 opencv
显示存储的视频文件。我附上了下面的代码。我在构建它时没有收到任何错误,但没有显示输出。
int main(int argc, char *argv[])
{
if (argc <= 1)
{
printf("Usage: %s video\n", argv[0]);
return -1;
}
VideoCapture capture(argv[1]);
namedWindow("display",cv::WINDOW_AUTOSIZE);
capture.set(cv::CAP_PROP_FRAME_WIDTH, 640);
capture.set(cv::CAP_PROP_FRAME_HEIGHT, 480);
if(!capture.isOpened())
{
printf("Failed to open the video\n");
return -1;
}
int i;
for(i=0;i<390;i++)
{
Mat frame;
capture >> frame; // get a new frame from camera
cout << "frame =" << endl << " " << frame << endl << endl;
imshow("display",frame);
}
}
我在末尾添加了 cout
行来检查框架是否获得任何值。所以 a 在矩阵中得到了一些值,但是视频窗口没有出现。
最佳答案
您必须在 imshow
之后使用 waitKey
添加一个非常小的延迟。
imshow("display",frame);
waitKey(10); //Wait 10 milliseconds before showing next frame.
关于c++ - 在 opencv : no error no output 中播放的视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21013869/