如何利用opencv创建图像列表

本文介绍了一种使用OpenCV库生成相机标定所需的图片列表的方法,并提供了完整的C++代码实现,该方法能够将指定目录下的图片文件名打包成XML、YML或TXT格式。

第一次写博客,有写得不好的地方,请提出批评,谢谢!

最近在研究相机标定这个小课题,标定时需要将图片打包成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;
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值