boost解析info文件
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                boost解析info文件
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.                        
                                先給出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}} }接下來(lái)我們給出使用boost如何解析上述文件: 
 params.h內(nèi)容:
具體的讀取方法:
#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; }總結(jié)
以上是生活随笔為你收集整理的boost解析info文件的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
 
                            
                        - 上一篇: 【C语言进阶深度学习记录】二十五 指针
- 下一篇: Web页面引入思源黑体
