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;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/258954.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Font Rending 的 Hint 机制对排版的影响

Font Rending 的 Hint 机制对排版的影响【转】 在设计一种 Font 时&#xff0c;设计者使用的是一个抽象的单位&#xff0c;叫做 EM&#xff0c;来源于大写 M 的宽度&#xff08;通常英文字体中大写 M 的宽度最大&#xff09;。EM 即不同于在屏幕显示时用的像素&#xff08;Pixe…

《SQL初学者指南(第2版)》——2.4 指定列

本节书摘来自异步社区出版社《SQL初学者指南&#xff08;第2版&#xff09;》一书中的第2章&#xff0c;第2.4节&#xff0c;作者&#xff1a;【美】Larry Rockoff&#xff0c;更多章节内容可以访问云栖社区“异步社区”公众号查看。 2.4 指定列 到目前为止&#xff0c;我们只…

python从文件中提取特定文本_使用Python从HTML文件中提取文本

我发现最好的一段代码用于提取文本&#xff0c;而不需要javascript或不需要的东西&#xff1a;import urllibfrom bs4 import BeautifulSoupurl "http://news.bbc.co.uk/2/hi/health/2284783.stm"html urllib.urlopen(url).read()soup BeautifulSoup(html)# kill …

mutable、volatile的使用

本文转载自http://blog.csdn.net/tht2009/article/details/6920511 (1)mutable 在C中&#xff0c;mutable是为了突破const的限制而设置的。被mutable修饰的变量&#xff0c;将永远处于可变的状态&#xff0c;即使在一个const函数中&#xff0c;甚至结构体变量或者类对象为const…

文本框点击后文字消失总结

1.文本框显示默认文字&#xff1a; <textarea>白鸽男孩</textarea> <textarea>白鸽男孩</textarea>    2.鼠标点击文本框&#xff0c;默认文字消失&#xff1a; <textarea οnfοcus”if(value’白鸽男孩’) {value’ ‘}”>白鸽男孩</text…

[裴礼文数学分析中的典型问题与方法习题参考解答]4.5.8

需要全部的解答, 请 http://www.cnblogs.com/zhangzujin/p/3527416.html 设 $f(x)$ 在 $[a,\infty)$ 上可微; 且 $x\to\infty$ 时, $f(x)$ 单调递增趋于 $\infty$, 则 $$\bex \int_a^\infty \sin f(x)\rd x,\quad \int_a^\infty \cos f(x)\rd x \eex$$ 都收敛. 证明: 由 $$\be…

《PowerShell V3——SQL Server 2012数据库自动化运维权威指南》——2.13 创建视图...

本节书摘来自异步社区出版社《PowerShell V3—SQL Server 2012数据库自动化运维权威指南》一书中的第2章&#xff0c;第2.13节&#xff0c;作者&#xff1a;【加拿大】Donabel Santos&#xff0c;更多章节内容可以访问云栖社区“异步社区”公众号查看。 2.13 创建视图 本方案展…

python刷抖音_用Python生成抖音字符视频!

抖音字符视频在去年火过一段时间。 反正我是始终忘不了那段极乐净土的音乐... 这一次自己也来实现一波&#xff0c;做一个字符视频出来。 主要用到的库有cv2&#xff0c;pillow库。 原视频如下&#xff0c;直接抖音下载的&#xff0c;妥妥的水印。 不过并不影响本次的操作。 / …

变长参数

转载自&#xff1a;http://blog.csdn.net/tht2009/article/details/7019635 变长参数 设计一个参数个数可变、参数类型不定的函数是可能的&#xff0c;最常见的例子是printf函数、scanf函数和高级语言的Format函数。在C/C中&#xff0c;为了通知编译器函数的参数个数和类型可变…

第十七章 我国农业科学技术

农村改革解说&#xff08;专著&#xff09;第十七章 第十七章 我国农业科学技术 1、为什么说科学技术是生产力&#xff1f; 我们说科学技术是生产力&#xff0c;是因为在构成生产力的两个主要因素中&#xff0c;都包含着科学技术在内。 A、生产力中人的因素是同一定的科学技术紧…

《淘宝网开店 拍摄 修图 设计 装修 实战150招》一一1.2 选购镜头时应注意的事项...

本节书摘来自异步社区出版社《淘宝网开店 拍摄 修图 设计 装修 实战150招》一书中的第1章&#xff0c;第1.2节&#xff0c;作者&#xff1a; 葛存山&#xff0c;更多章节内容可以访问云栖社区“异步社区”公众号查看。 1.2 选购镜头时应注意的事项 面对如此之多的镜头&#xf…

OpenCV中的神器Image Watch

Image Watch是在VS2012上使用的一款OpenCV工具&#xff0c;能够实时显示图像和矩阵Mat的内容&#xff0c;跟Matlab很像&#xff0c;方便程序调试&#xff0c;相当好用。跟VS2012配合使用&#xff0c;简直就是一款神器&#xff01;让我一下就爱上它了&#xff01; 下面介绍一些链…

python异步_Python通过Thread实现异步

当long函数耗时较长时&#xff0c;需要程序先向下执行&#xff0c;这就需要异步&#xff0c;改写代码如下&#xff1a; import _thread import time def long(cb): print (long execute) def fun(callback): time.sleep(5) result long end callback(result) _thread.start_ne…

SAM4E单片机之旅——13、LCD之ASF初步

在Atmel Studio 6中&#xff0c;集成了Atmel Software Framework&#xff08;ASF框架&#xff09;。通过它提供的库&#xff0c;可以很快速地完成新的项目。 这次的最终目标使用ASF在LCD上显示出文字“Hello World!”&#xff0c;现阶段目标是点亮LCD的背光&#xff0c;学习目标…

《HTML5与CSS3实战指南》——2.2 基本的HTML5模板

本节书摘来自异步社区《HTML5与CSS3实战指南》一书中的第2章&#xff0c;第2.2节,作者&#xff1a; 【美】Estelle Weyl , Louis Lazaris , Alexis Goldstein 更多章节内容可以访问云栖社区“异步社区”公众号查看。 2.2 基本的HTML5模板 在您学习HTML5和新技术时&#xff0c;您…

c# Message const

typeTMsg packed recordhwnd: HWND; //窗口句柄message: UINT;//消息常量标识符wParam: WPARAM ;// 32位消息的特定附加信息lParam: LPARAM ;// 32位消息的特定附加信息time: DWORD;//消息创建时的时间pt: TPoint; //消息创建时的鼠标位置end ; 消息中有什么&#xff1f;是否觉…

OpenCV坐标体系的初步认识

实验基础本次实验通过一个简短的例子&#xff0c;主要来说明下面4个问题&#xff1a; 1. 坐标体系中的零点坐标为图片的左上角&#xff0c;X轴为图像矩形的上面那条水平线&#xff1b;Y轴为图像矩形左边的那条垂直线。该坐标体系在诸如结构体Mat,Rect,Point中都是适用的。&…

python爬取知乎live_Python爬虫 - 简单抓取百度指数

前言有点忙&#xff0c;没空写东西&#xff0c;这是之前写的&#xff0c;加了些配图而已 这次要爬的网站是百度指数 正文 一、分析 打开网站(百度指数)&#xff0c;呈现出来是这样的 如果搜索的话就需要登陆了&#xff0c;如果没有什么特别频繁的请求的话&#xff0c;直接登陆复…

在Visual Studio上开发Node.js程序

在Visual Studio上开发Node.js程序 原文:在Visual Studio上开发Node.js程序【题外话】 最近准备用Node.js做些东西&#xff0c;于是找找看能否有Visual Studio上的插件以方便开发。结果还真找到了一个&#xff0c;来自微软的Node.js Tools for Visual Studio&#xff08;NTVS&a…

Oracle ASM 翻译系列第十一弹:高级知识 Offline or drop?

Offline or drop? 当一个ASM磁盘不可用时&#xff0c;ASM会把它从磁盘组里移除&#xff0c;对吗&#xff1f;要看情况&#xff0c;通常取决于ASM版本和磁盘组的冗余级别。因为一个external冗余的磁盘组会直接被dismount&#xff0c;所以主要关注normal和high冗余磁盘组的情况。…