opencv 之图片序列生成视频

我找了许多做人体目标跟踪的dataset,但是大部分是图像序列,我把它做成了视频,方便操作。使用的OpenCV 2.4.9实现。

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include<fstream>
#include<string>
using namespace cv;
using namespace std;
void main()
{
	string filename;
	ifstream inf("walking2.txt");
	VideoWriter writer("walking2.avi", CV_FOURCC('M', 'J', 'P', 'G'), 25.0, Size(384, 288));
	Mat frame;
	while (!inf.eof())
	{
		inf>>filename;
		filename="F:\\OpenCVproject\\data\\benchmark cvpr2013\\Walking2\\img\\"+filename;
	    frame=imread(filename);
		
		imshow("video", frame);
		writer << frame;
		if (cvWaitKey(20) == 27)
		{
			break;
		}
	}
}
函数原型:C++:   VideoWriter:: VideoWriter ( const string&  filename , int  fourcc , double  fps , Size  frameSize , bool  isColor =true )
Parameters:
  • filename – Name of the output video file.
  • fourcc – 4-character code of codec used to compress the frames. For example, CV_FOURCC('P','I','M','1') is a MPEG-1 codec, CV_FOURCC('M','J','P','G') is a motion-jpeg codec etc. List of codes can be obtained at Video Codecs by FOURCCpage.
  • fps – Framerate of the created video stream.
  • frameSize – Size of the video frames.
  • isColor – If it is not zero, the encoder will expect and encode color frames, otherwise it will work with grayscale frames (the flag is currently supported on Windows only).



你可能感兴趣的:(视频,opencv)