boost解析info文件
先给出info文件:
parameters
{MAX_STAGES 4MAX_DEPTH 3MAX_NUMTRESS 5MAX_NUMTHRESHS 500MAX_NUMFEATS 1000,1000,1000,500,500,500,400,400MAX_RATIO_RADIUS 0.3,0.2,0.2,0.15,0.12,0.10,0.08,0.06,0.06,0.05BAGGING_OVERLAP 0.4IS_FLIP true
}meanface
{MAX_ITERS 120MAX_ERRORS 0.000001SCALE_FACTOR 1.0SCALE_CONST 1.0WIDTH_DIV 1.95HEIGHT_DIV 1.60
}train
{FACE_DETECT_PATH haarcascade_frontalface_alt2.xml LANDMARK_TYPE LANDMARK_TYPE_68 dataset{0{DATA_PATH E:\\dataset\\lfpw\\trainset\\Path_Images.txt}1{DATA_PATH E:\\datasets\\afw\\Path_Images.txt}}
}
接下来我们给出使用boost如何解析上述文件:
params.h内容:
#ifndef PARAMS_H
#define PARAMS_H#include <string>
#include <vector>using sParams = struct sParams{int __max_numstage;int __max_depth;int* __max_numfeats = nullptr;int __max_numtrees;int __max_numthreshs;double __bagging_overlap;double* __max_raio_radius = nullptr;bool __isflip;//mean faceint __procrustes_iters;double __procrustes_errors;double __facebox_scale_factor;double __facebox_scale_const;double __facebox_width_div;double __facebox_height_div;std::string __landmark_type;std::vector<std::string> __images_path;
};#endif
具体的读取方法:
#include <boost/program_options.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/info_parser.hpp>
#include "params.h"
#include <iostream>namespace po = boost::program_options;
using boost::filesystem::path;
using boost::property_tree::ptree;void Init_Params(sParams *params)
{params->__max_numfeats = NULL;params->__max_raio_radius = NULL;
}int main(int argc, char *argv[])
{path configfile = "./train.info";ptree pt;sParams params;try {read_info(configfile.string(), pt);}catch (const boost::property_tree::ptree_error& e) {std::cout << std::string("Error reading the config file: ") + e.what() << std::endl;return -EXIT_FAILURE;}try{ptree parameters = pt.get_child("parameters");params.__max_numstage = parameters.get<int>("MAX_STAGES");params.__max_depth = parameters.get<int>("MAX_DEPTH");params.__max_numtrees = parameters.get<int>("MAX_NUMTRESS");params.__max_numthreshs = parameters.get<int>("MAX_NUMTHRESHS");params.__bagging_overlap = parameters.get<double>("BAGGING_OVERLAP");params.__isflip = parameters.get<bool>("IS_FLIP");std::string str_numfeats = parameters.get<std::string>("MAX_NUMFEATS");std::string str_ration = parameters.get<std::string>("MAX_RATIO_RADIUS");std::vector<std::string> split_numfeats;std::vector<std::string> split_ration;boost::split(split_numfeats, str_numfeats, boost::is_any_of(","));int num_numfeats = 0;for (int i = 0; i < split_numfeats.size(); i++){if (split_numfeats[i] != std::string(",")){num_numfeats++;}}params.__max_numfeats = new int[num_numfeats];int index = 0;for (int i = 0; i < split_numfeats.size(); i++){if (split_numfeats[i] != std::string(",")){params.__max_numfeats[index] = boost::lexical_cast<int>(split_numfeats[i]);index++;}}boost::split(split_ration, str_ration, boost::is_any_of(","));int num_ration = 0;for (int i = 0; i < split_ration.size(); i++){if (split_ration[i] != std::string(",")){num_ration++;}}params.__max_raio_radius = new double[num_ration];for (int i = 0, index = 0; i < split_ration.size(); i++){if (split_ration[i] != std::string(",")){params.__max_raio_radius[index] = boost::lexical_cast<double>(split_ration[i]);index++;}}//init mean faceptree meanface = pt.get_child("meanface");params.__procrustes_iters = meanface.get<int>("MAX_ITERS");params.__procrustes_errors = meanface.get<double>("MAX_ERRORS");params.__facebox_scale_factor = meanface.get<double>("SCALE_FACTOR");params.__facebox_scale_const = meanface.get<double>("SCALE_CONST");params.__facebox_width_div = meanface.get<double>("WIDTH_DIV");params.__facebox_height_div = meanface.get<double>("HEIGHT_DIV");//init trainptree train = pt.get_child("train");std::string facedetect_file = train.get<std::string>("FACE_DETECT_PATH");params.__landmark_type = train.get<std::string>("LANDMARK_TYPE");ptree dataset = train.get_child("dataset");for (auto it = dataset.begin(); it != dataset.end(); it++){std::string dataset_str = it->second.get<std::string>("DATA_PATH");params.__images_path.push_back(dataset_str);}}catch (const boost::property_tree::ptree_error& error){std::cout << std::string("Parsing config: ") + error.what() << std::endl;return -EXIT_FAILURE;}delete params.__max_numfeats;delete params.__max_raio_radius;return EXIT_SUCCESS;
}
boost解析info文件相关推荐
- boost解析xml文件
前面我们介绍了xml文件,今天我们试着用boost库来解析xml文件.我们将举两个例子来说明怎么使用. 来自boost官方的例子 先看xml文件的内容: <debug><filena ...
- C++学习之第八天-解析RSS文件
1.使用tinyXml2解析RSS文件,并生成一个网页库pagelib.dat. tinyXml2 -- https://github.com/leethomason/tinyxml2 rss ...
- 利用pstsdk进行解析pst文件
pstsdk下载地址:https://archive.codeplex.com/?p=pstsdk 下载后,我们只需要取出pstsdk目录,并自己进行dll封装,实现提取邮件内容.主题.收件人信息,把 ...
- C++解析json文件
文章目录 1 JSON文件简介[1] 1.1 JSON文件的语法规则 1.2 JSON值的类型 2 JSON文件解析 1 JSON文件简介[1] 一个项目在设计时会存在很多参数,比如data文件路径. ...
- python中利用lxml模块解析xml文件报错XMLSyntaxError: Opening and ending tag mismatch
今天在代码中第一次使用lxml解析xml文件时出错了, XMLSyntaxError: Opening and ending tag mismatch: keyEffectiveDate line 2 ...
- java代码使用http请求解压zip包并解析xml_Javascript 是如何解析 Excel 文件的?
最近要做一个导入导出 Excel 的功能,上一次做这个功能的时候,还是用的 Java Apache POI,这是一个用 Java 编写的免费开源的跨平台的 Java API,能够对 Microsoft ...
- java xml中的冒号_Java jdom解析xml文件带冒号的属性
Java jdom解析xml文件带冒号的属性 如果xml文件解析带了冒号的属性,一般都是要特别处理,这里是命名空间,N年前遇到过一次忘记记录,后来也忘了,这次再记录下. 解决了,记录下,分享给大家,百 ...
- 编程模板-R语言脚本写作:最简单的统计与绘图,包安装、命令行参数解析、文件读取、表格和矢量图输出
写在前面 个人认为:是否能熟悉使用Shell(项目流程搭建)+R(数据统计与可视化)+Perl/Python等(胶水语言,数据格式转换,软件间衔接)三门语言是一位合格生物信息工程师的标准. 之前分享过 ...
- java 解析 csv 文件
文章分类:JavaEye 一.貌似有bug,不行用 二.或 三. 的方法 Java代码 import java.io.BufferedReader; import java.io.FileInpu ...
最新文章
- basequickadapter详解_BaseRecyclerViewAdapter(持续更新!)
- python 去掉空格_如何从Python DataFrame中去除空格在这个例子中
- NOI提高级:排序算法
- Serverless 实战 —— 阿里云函数计算配合SpringBoot项目
- 【转】几个超炫的专业词汇
- Jedis操作reids集群
- 拉式工序不允许倒冲财务仓
- eval(转换html,js eval函数使用,js对象和字符串互转实例
- 面试中常见的问题总结
- 算法分析——算法的渐进效率分析 和 渐进符号大O、大Ω、大θ、小o、小ω
- matlab线性代数方程的解法,Matlab中线性代数方程组的求解.pdf
- ftp服务启动之后拖文件失败,返回code550的错误之一
- linux shm open,undefined reference to \'shm_open\'解决办法-j_cle-ChinaUnix博客
- 人工智能,落地为王!深圳人工智能企业百强榜超七成为应用层
- 新零售时代下,物流行业迎来新机遇
- 我与无人机的2020上半年
- 关于MIDI键盘的服务对接
- consul kv迁移
- uniapp设置的组件样式在H5和APP中生效,在微信小程序中不生效问题解决
- python 正整数因数分解_Python正整数分解质因数