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).



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值