我想打开一个* .avi文件并读取它的帧。但它没有用。我认为这是因为myopencv不支持这种avi文件。我能做些什么来使它有能力?
VideoCapture capture("part.avi");
if(!capture.isOpened()){
cout<<"failed to read the *.avi"<<endl;
return -1;
}
double rate = capture.get(CV_CAP_PROP_FPS);
Size videoSize(capture.get(CV_CAP_PROP_FRAME_WIDTH),
capture.get(CV_CAP_PROP_FRAME_HEIGHT));
long nFrame=static_cast<long>(capture.get(CV_CAP_PROP_FRAME_COUNT));
cout<<"FPS:"<<rate<<endl;
cout<<"width:"<<videoSize.width<<" height:"<<videoSize.height<<" number of frames:"<<nFrame<<endl;
Mat frame;
namedWindow("display");
long frameToStart = 500;
capture.set(CV_CAP_PROP_POS_FRAMES,frameToStart);
capture>>frame;
if(frame.empty()) return -1;
结果:
FPS:23.0769
宽度:1280高度:720帧数:42202
程序以退出代码结束:255
答案 0 :(得分:0)
我强烈建议您先阅读opencv documentation。这不是opencv的问题,而是你的代码。 视频由连续帧组成,您应该放置
capture>>frame;
if(frame.empty()) return -1;
在这样的循环中:
while(1){
capture>>frame;
if(frame.empty()) return -1;
imshow("display", frame); //don't forget to show
}