#include "stdafx.h"
#include <iostream>
#include <cv.h>
#include <highgui.h>
void main()
{
int num = 0;
double fps = 15;
CvSize size = cvSize(1280, 480);
//<span style = "white-space:pre"> < / span>//每秒钟的帧率
CvVideoWriter *writer = 0;
writer = cvCreateVideoWriter("out.mp4", CV_FOURCC('X', 'V', 'I', 'D'), fps, cvSize(1280,480));//创建视频文件
char Lcname[100];
char Dcname[100];
while (1)
{
sprintf(Lcname, "D:\\image\\L%d.pgm", num); //加载图片的文件夹,图片的名称编号是1开始1,2,3,4,5.。。。
sprintf(Dcname, "D:\\image\\disparity%d.pgm", num);
IplImage* Left= cvLoadImage(Lcname);
IplImage* Dis= cvLoadImage(Dcname);
/*if (Left.empty())
{
return;
}*/
IplImage* src_resize = cvCreateImage(size, IPL_DEPTH_8U,3); //创建视频文件格式大小的图片
cvSetImageROI(src_resize, cvRect(0, 0, 640, 480));
cvCopy(Left, src_resize);
cvResetImageROI(src_resize);
cvSetImageROI(src_resize, cvRect(640, 0, 640, 480));
cvCopy(Dis, src_resize);
cvResetImageROI(src_resize);
cvNamedWindow("Myavi");
cvShowImage("Myavi", src_resize);
cvWaitKey(300);
cvWriteFrame(writer, src_resize); //保存图片为视频流格式
num++; //循环读取数据
cvReleaseImage(&Left);
cvReleaseImage(&Dis);
cvReleaseImage(&src_resize);
}
cvDestroyWindow("Myavi");
}