9/17/2014

opencv, simple source code Video frames to jpeg files (VideoCapture, imwrite)

simple source code.

read avi file and save jpeg files.

set video file name and save directory property in your setting.

#include < opencv2\opencv.hpp>
#include < stdio.h>


#ifdef _DEBUG        
#pragma comment(lib, "opencv_core249d.lib")
#pragma comment(lib, "opencv_imgproc249d.lib")   
#pragma comment(lib, "opencv_highgui249d.lib")
#else
#pragma comment(lib, "opencv_core249.lib")
#pragma comment(lib, "opencv_imgproc249.lib")
#pragma comment(lib, "opencv_highgui249.lib")
#endif  

using namespace std;
using namespace cv;

void main()
{
 VideoCapture stream1("./bigBugs1.avi");  //file name

 if (!stream1.isOpened()) { //check if video file has been initialised   
  cout << "cannot open the file";   
 }   
 //window name
 namedWindow("Origin");   

 //string 
 char str[256];
 int frameCount=0;
 //unconditional loop   
 while (true) {   
  Mat Frame;   
  if( stream1.read(Frame) == 0) //get one frame form video   
   break;
  imshow("Origin", Frame);   

  sprintf_s(str,".\\frames1\\%d_frames.jpg", frameCount++);
  imwrite(str,Frame);
  
  

  if (waitKey(30) >= 0)   
   break;   
 }   

 destroyAllWindows();   


}

..


No comments:

Post a Comment