首页 > 代码库 > 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;
}
//
//#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;
}
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。