前端之家收集整理的这篇文章主要介绍了
如何利用opencv创建图像列表,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
第一次写
博客,有写得不好的地方,请提出批评,谢谢!
@H_
301_2@最近在研究相机标定这个小课题,标定时需要将
图片打包成XML YML TXT格式,根据自己的理解总算是写好了这段可运行的
代码,不多说,贴出
代码
/*this creates a yaml or xml list of files */
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <string>
#include <iostream>
using std::string;
using std::endl;
using namespace cv;
int main()
{
string outputname = "D:\\Documents\\Visual Studio 2013\\Projects\\插件机视觉系统_MFC\\Result_data\\imagelist.yml"; //图片列表保存路径,可自己设置
char imagename[20];
Mat m = imread(outputname); //check if the output is an image - prevent overwrites!
if(!m.empty())
{
std::cerr << "fail! Please specify an output file,don't want to overwrite you images!" << endl;
return 1;
}
FileStorage fs(outputname,FileStorage::WRITE); //利用FileStorage类定义对象fs,以写入方式打开文件
fs << "images" << "["; // "[" 此中括号意思是:表示开始写入文本系列
for(int i = 1; i <= 26; i++) //有26张图片
{
sprintf(imagename,"%.2d.jpg",i); //将图片名称写进imagename字符串中
fs << imagename;
}
fs << "]"; //关闭文本
return 0;
}