【发布时间】:2018-01-27 21:44:04
【问题描述】:
我已经写了这些代码:
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
using namespace std;
int main()
{
cv::namedWindow( "Example 2-3", cv::WINDOW_AUTOSIZE );
cv::VideoCapture cap;
cap.open("/Testing/test.avi");
if(cap.isOpened()==0)
{
cout<<"The video file cannot be opened."<<endl;
return -1;
}
cv::Mat frame;
cap >> frame;
std::cout<<frame.empty()<<std::endl; // I have a problem here: Why the result is 1?
for(;;)
{
cap >> frame;
if( frame.empty() ) break; // Ran out of film
cv::imshow( "Example 2-3", frame );
if( (char)cv::waitKey(33) >= 0 ) break;
}
return 0;
}
我正在尝试逐帧显示视频,当我通过cap.open打开视频时,它是成功打开的,但是当程序执行代码std::cout<<frame.empty()<<std::endl;时,它应该是0,因为视频成功打开,所以frame不应该是空的,但是结果是1,表示frame是空的,所以视频不能显示,为什么?你有什么解决办法吗?
【问题讨论】: