C++视频分解和图片合成视频代码

附上两个常用的代码,一个是视频分解,一个是图片集合成video。

1、视频分解代码

//将视频分解成一张张图片并保存
#include"opencv2/opencv.hpp"
using namespace cv;//如果不定义命名空间则图像采集这个功能是无效的
void main()
{
	VideoCapture cap("D:\\Photo and Video\\depth\\depthCorrect.mp4");
	Mat frame;
	char outfile[50];
	if(!cap.isOpened())//打开失败便退回
		return;
	int totallFrame=cap.get(CV_CAP_PROP_FRAME_COUNT);//获取视频总帧数
	for(int i=1;i<=totallFrame;i++)
	{
	   cap>>frame;//取帧
		if(frame.empty())
			break;
		sprintf(outfile,"D:\\Photo and Video\\depth1\\%d.png",i);//这行代码的作用就是提供一个标准化的名字
		imwrite(outfile,frame);//outfile之所以不加引号是因为outfile是一个已经被定义的字符串
		imshow("video",frame);
		waitKey(100);//每隔两秒显示1帧,数值越小播放越快,有种快进的感觉,后退也一样
	}
	  cap.release();
	  destroyAllWindows();
}

2、图片合成video,该代码没有优化,需要手动调节图片大小以及帧率

#include 
#include <

你可能感兴趣的:(图像处理)