加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

如何利用opencv创建图像列表

发布时间:2020-12-16 02:08:52 所属栏目:百科 来源:网络整理
导读:第一次写博客,有写得不好的地方,请提出批评,谢谢! 最近在研究相机标定这个小课题,标定时需要将图片打包成XML YML TXT格式,根据自己的理解总算是写好了这段可运行的代码,不多说,贴出代码 /*this creates a yaml or xml list of files */ #include "op
第一次写博客,有写得不好的地方,请提出批评,谢谢! 
 

最近在研究相机标定这个小课题,标定时需要将图片打包成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:DocumentsVisual Studio 2013Projects插件机视觉系统_MFCResult_dataimagelist.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;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读