使用tinyXML2 读写配置文件
来源:互联网 发布:post请求返回json数据 编辑:程序博客网 时间:2024/06/06 16:30
1. 前言
我们上次写了一段用来提取图片中交点信息的程序: http://blog.csdn.net/zhyh1435589631/article/details/53084795
但是, 我们发现代码中存在好多奇异值,非常的讨人厌, 我们就希望可以讲这部分变化的参数移动到配置文件中, 我们只需要让程序读取这个配置文件中的参数就可以了。
2. TinyXML2
2.1 TinyXML2 基本介绍
- TinyXML2 的官网地址: http://www.grinninglizard.com/tinyxml2docs/index.html
- github 地址: https://github.com/leethomason/tinyxml2
- 这是一个非常简单的用来读写xml 文件的一个C++开源工具
2.2 配置文件实例
参考文章: http://blog.csdn.net/k346k346/article/details/44258739
我们精选一下我们的配置文件
<config> <autoSet> <autoSetGray2BinaryLower>true</autoSetGray2BinaryLower> <CurrentMean>25</CurrentMean> </autoSet></config>
2.3 读取配置文件
绑定配置文件:
tinyxml2::XMLDocument doc;doc.LoadFile(filename.c_str());
读取配置文件信息
使用FirstChildElement 和 FirstChild 组合即可bool CXML::getAutoSetGray2BinaryLower(){ string data = doc.FirstChildElement("config") ->FirstChildElement("autoSet") ->FirstChildElement("autoSetGray2BinaryLower") ->FirstChild()->ToText()->Value(); return data == "true";}double CXML::getAutoSetCurrentMean(){ string data = doc.FirstChildElement("config") ->FirstChildElement("autoSet") ->FirstChildElement("CurrentMean") ->FirstChild()->ToText()->Value(); return stod(data);}
2.4 写配置文件
使用setText 写数据到相应节点中去
bool CXML::setAutoSetCurrentMean(double value){ tinyxml2::XMLElement * data = doc.FirstChildElement("config") ->FirstChildElement("autoSet") ->FirstChildElement("CurrentMean"); data->SetText(value); return true; }
3. 加入工程文件
项目工程地址: https://code.csdn.net/zhyh1435589631/picture_handle_tianwentai/tree/master
相应的配置文件 xml, 通过修改这个文件中的参数, 我们可以非常方便的控制图像处理过程的控制~~
<config> <loadImage> <show>false</show> </loadImage> <downSample> <downSampleFactor_x>0.1</downSampleFactor_x> <downSampleFactor_y>0.1</downSampleFactor_y> <show>false</show> </downSample> <autoSet> <autoSetGray2BinaryLower>true</autoSetGray2BinaryLower> <CurrentMean>25</CurrentMean> </autoSet> <DealWithImageRough> <show>false</show> <Gray2Binary> <lower>120</lower> <higher>255</higher> </Gray2Binary> <EdgeDetection> <canny_lower>50</canny_lower> <canny_higher>200</canny_higher> </EdgeDetection> <DetectLines> <rho>1</rho> <theta_splitNums>180</theta_splitNums> <threshold>80</threshold> <minLineLength>70</minLineLength> <maxLineGap>50</maxLineGap> </DetectLines> <RemoveDuplicateLines> <threshold>70</threshold> <angle_splitNum>24</angle_splitNum> </RemoveDuplicateLines> <CalcPoints> </CalcPoints> <RemoveDuplicatePoints> </RemoveDuplicatePoints> </DealWithImageRough> <DealWithImageROI> <ROI_size>300</ROI_size> <show>false</show> <Gray2Binary> <lower>100</lower> <higher>255</higher> </Gray2Binary> <EdgeDetection> <canny_lower>50</canny_lower> <canny_higher>200</canny_higher> </EdgeDetection> <DetectLines> <rho>1</rho> <theta_splitNums>180</theta_splitNums> <threshold>80</threshold> <minLineLength>200</minLineLength> <maxLineGap>50</maxLineGap> </DetectLines> <RemoveDuplicateLines> <threshold>70</threshold> <angle_splitNum>24</angle_splitNum> </RemoveDuplicateLines> <CalcPoints> </CalcPoints> <RemoveDuplicatePoints> </RemoveDuplicatePoints> </DealWithImageROI></config>
0 0
- 使用tinyXML2 读写配置文件
- c++使用xml简单读写 tinyxml2.cpp使用
- 使用WindowsAPI读写配置文件
- tinyxml2简单使用
- cocos2dx TinyXml2的使用
- 使用C++ tinyxml2库
- TinyXML2使用教程
- C++中使用TinyXML2
- TinyXML2开源库使用
- tinyxml2库的使用
- tinyxml2的使用
- TinyXML2
- tinyxml2读写XML文件的例程
- 使用ConfigurationManager类 读写配置文件
- 使用ConfigurationManager类 读写配置文件
- 使用C#读写ini配置文件
- 使用tinyxml2库解析xml
- C++使用TinyXml2解析Xml
- linux内核锁的几点理解
- Google投影坐标和WGS84坐标系的转换
- 《Linux设备驱动开发详解》读书笔记(1)
- iOS A/B Test 方案探索
- Boost.Asio学习之Allocation
- 使用tinyXML2 读写配置文件
- 深入理解C#:编程技巧总结(二)
- 二分图匹配模板
- 最常用的Eclipse快捷键
- 程序员面试金典: 9.9 递归和动态规划 9.9八皇后问题
- PAT甲级1001
- Ubantu 14.04 下连接mysql
- 基于TI-RTOS的CC2650DK开发(30)--- Swi官方示例
- 解析IntelliJ IDEA内部设计