2016-12-14 128 views
0

我试图将视频文件的帧数保存到.txt文件中。例如将帧号(0)保存到最后一帧。我可以显示视频文件的总帧数。将总视频文件的帧数保存到.txt文件中

#include "opencv2/opencv.hpp" 
#include <fstream> 


using namespace cv; 
using namespace std; 

int main(int argc, char** argv) 
{ 

// Open video file 
VideoCapture video("2.avi"); 

double fps = video.get(CV_CAP_PROP_FPS); 
double nframes = video.get(CAP_PROP_FRAME_COUNT); 

cout << "Frames per second using video.get(CV_CAP_PROP_FPS) : " << fps << endl; 
cout << "Frames count : " << nframes << endl; 
ofstream myfile; 
myfile.open ("example.txt"); 

for (int i=0;i<nframes;i++) 

{ 


myfile<< "Frame Number= "<<";"<< i<< endl; 

}  
myfile.close(); 
video.release(); 
return 0; 

} 

回答

2

的帧数是

double nframes = video.get(CAP_PROP_FRAME_COUNT); 

FPS是每秒的帧数,并告诉你一个球员应该多快的速度显示视频,你可以计算时间,如果你知道第一帧的时间。

要将数据写入你应该寻找写在C++的文件,你会发现帮助解答像Simple file write function in C++

+0

感谢@Micka一个文件,我想帧被保存像(0,1,2 ,....)。这是我的主要问题。 – tofi

+1

所以你想知道“当前帧数”?这也是一个财产。或者你只是数数自己。 – Micka

+0

例如,如果我有一个500帧的视频,我想保存从0开始的帧数到4999 – tofi

相关问题