图片与视频的转存,貌似只支持生成avi格式
#include<opencv2\core\core.hpp>
#include<opencv2\opencv.hpp>
#include<opencv2\imgproc\imgproc.hpp>
#include<opencv2\highgui\highgui.hpp>
#include<iostream>
using namespace cv;
using namespace std;
int main()
{
cout << "---------------Video_To_Image-----------------" << endl;
char image_name[20];
string s_image_name;
cv::VideoWriter writer;
int isColor = 1;//不知道是干啥用的
int frame_fps = 30; //每秒帧数
int frame_width = 1920; //视频大小格式(必须与图片大小一样)
int frame_height = 1080;
string video_name = "out1.avi"; //视频名称
writer = VideoWriter(video_name, CV_FOURCC('X', 'V', 'I', 'D'),frame_fps,Size(frame_width,frame_height),isColor);
// VideoWrite函数
cout << "frame_width is " << frame_width << endl;
cout << "frame_height is " << frame_height << endl;
cout << "frame_fps is " << frame_fps << endl;
// cv::namedWindow("image to video", CV_WINDOW_AUTOSIZE);
int num =1560;//输入的图片总张数
int i = 0;
Mat img,img1;
while (i<num)
{
sprintf(image_name, "F:\\haze1\\%d.jpg", i );
img = imread(image_name);//读入图片
// resize(img,img1,Size(1920,1080));
if (!img.data)//判断图片调入是否成功
{
cout << "Could not load image file...\n" << endl;
}
//写入
writer.write(img);
cout<<i<<endl<<endl;
i++;
}
}