首页 > 代码库 > Opencv将图片转化成视频

Opencv将图片转化成视频

// VideoWriter.cpp : 定义控制台应用程序的入口点。
//
//#include "stdafx.h"
#include "cv.h"
#include "highgui.h"
#include "iostream"
using namespace std;


int main(int argc, char* argv[])
{
double fps = 29;//视频压缩帧率
CvSize size = cvSize(352, 288);//图片序列中每张图片的宽高
CvVideoWriter* writer = cvCreateVideoWriter("D:\\my.avi", -1,fps, size);
  int n;
char str[200];
for (int i=1; i<360; i++)
{
n=i/10;
memset(str, ‘\0‘, 200*sizeof(char));
//sprintf(str, "c:/result/%d.jpg", i);
//sprintf(str, "c:/result/%d.jpg", i);
if(n==0)
sprintf(str,"D:\\my\\img\\000%d.jpg",i);
if(n>=1&&n<=9)
sprintf(str,"D:\\my\\img\\00%d.jpg",i);
if(n>=10&&n<=99)
sprintf(str,"D:\\my\\img\\0%d.jpg",i);
if(n>=100&&n<=999)
sprintf(str,"D:\\my\\img\\%d.jpg",i);
IplImage* colorIn = cvLoadImage(str);


int flag = cvWriteFrame(writer, colorIn); 
cout<<flag<<endl;


cvReleaseImage(&colorIn);
}
cvReleaseVideoWriter(&writer);


system("pause");
return 0;
}