2016-12-14 110 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

相關問題