资源简介
利用OpenCV3.0,将多张图片合成一个视频。代码加可执行程序加样例图片。
图片合成视频OpenCV代码加执行程序加样例图片。
图片合成视频OpenCV代码加执行程序加样例图片。
代码片段和文件信息
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
using namespace cv;
string GetFilePosfix(const char* path);
void demoTest();
vector getImagePathes(string folderPath);
bool IsSupportPos(const std::string& posfixconst std::string& support);
wstring s2ws(const std::string& s);
void dfsFolder(string& folderPathvector& vecFilePathint& errFileCount);
struct Author
{
string name;
string studentID;
};
struct Paramsj
{
string imageFolder;
string videoName;
float showTime;
};
Paramsj getParams();
Author inputAuthorInfo();
int main(int argc char *argv[])
{
//get author info
Author au;
Paramsj para;
if (argc>1)
{
au.name=“Tom and Jerry“;
au.studentID = “123456789“;
para.imageFolder=argv[1];
para.videoName = argv[3];
para.showTime = atof(argv[2]);
}else{
au = inputAuthorInfo();
para = getParams();
}
vector imagePathes;
//get parameters;
//string imageFolder = “D:\\StudyFile\\2014\\CV\\test1\\Debug“;
//string videoName = “vi.avi“;
//float showTime=1.0;
float fps;
fps = 1/para.showTime;
// init video writer
Size videoSize = Size(1024 1024);
//VideoWriter::fourcc(‘P‘‘I‘‘M‘‘1‘)
//VideoWriter writer = VideoWriter(videoName VideoWriter::fourcc(‘P‘‘I‘‘M‘‘4‘) fps videoSize);
//VideoWriter writer = VideoWriter(videoName -1 fps videoSize);
VideoWriter writer = VideoWriter(para.videoName VideoWriter::fourcc(‘M‘‘J‘‘P‘‘G‘) fps videoSize);
// get image names;
imagePathes = getImagePathes(para.imageFolder);
Mat authorInfo = Mat::eye(1024 1024 CV_8UC3);
Point firstP(200256);
Point secondP(256512);
//“AuthroName: “+
//“StudentID: “+
string name = “AuthorName: “+au.name;
string id = “StudentID: “+au.studentID;
putText(authorInfo name firstP FONT_ITALIC 2 Scalar(255255255) 5);
putText(authorInfo id secondP FONT_ITALIC 2 Scalar(255255255) 5);
Mat blank;
blank = Mat::eye(1024 1024 CV_8UC3);
Mat image;
Mat im1;
//blank.create(10241024CV_8UC(15));
writer.write(blank);
writer.write(authorInfo);
writer.write(authorInfo);
vector::iterator it;
for (it=imagePathes.begin();it!=imagePathes.end();it++)
{
image = imread(*it);
resize(image im1 videoSize);
writer.write(im1);
}
writer.write(blank);
writer.release();
//system(“pause“);
return 0;
}
Author inputAuthorInfo()
{
Author au;
string name;
cout << “Please input author name(default\“Tom and Jerry\“): “;
getline(cinname);
if (name.length()>3)
{
au.name = name;
}else{
au.name = “Tom and Jerry“;
}
au.studentID = “123456789“;
return au;
}
Paramsj getParams()
{
string inString;
Paramsj para;
para.showTime = 1.0;
c
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2015-04-29 22:08 作业1_11321051_宋骏\
文件 47021 2008-01-18 04:30 作业1_11321051_宋骏\2008000010.jpg
文件 114777 2008-01-17 11:13 作业1_11321051_宋骏\2008_000001.jpg
文件 85537 2008-01-18 05:39 作业1_11321051_宋骏\2008_000004.jpg
文件 107807 2008-01-19 12:32 作业1_11321051_宋骏\2008_000005.jpg
文件 79397 2008-01-18 03:47 作业1_11321051_宋骏\2008_000006.jpg
文件 52538 2008-01-17 16:22 作业1_11321051_宋骏\2008_000011.jpg
文件 76708 2008-01-17 13:47 作业1_11321051_宋骏\2008_000012.jpg
文件 170910 2008-01-18 01:11 作业1_11321051_宋骏\2008_000013.jpg
文件 140054 2008-01-17 13:43 作业1_11321051_宋骏\2008_000014.jpg
文件 6168 2015-04-29 22:09 作业1_11321051_宋骏\main.cpp
文件 743248 2010-03-18 09:15 作业1_11321051_宋骏\msvcp100d.dll
文件 1498960 2010-03-18 09:15 作业1_11321051_宋骏\msvcr100d.dll
文件 10535057 2013-12-02 08:12 作业1_11321051_宋骏\opencv_ffmpeg300.dll
文件 27294208 2014-11-08 01:20 作业1_11321051_宋骏\opencv_world300.dll
文件 38912512 2014-11-08 01:26 作业1_11321051_宋骏\opencv_world300d.dll
文件 30720 2014-12-26 12:48 作业1_11321051_宋骏\run.exe
- 上一篇:docker源码分析完整版pdf
- 下一篇:Msc.Marc User Guide
评论
共有 条评论