首先在launc**件中進行配置:
可以看到,此處定義了兩個string型別的引數:config_file\vins_folder
然後在相應的cpp裡,按照模板定義乙個讀取引數的程式。
template t readparam(ros::nodehandle &n, std::string name)
else
return ans;
}
最後在函式裡呼叫就行了:
std::string config_file;
config_file = readparam(n, "config_file");
cv::filestorage fssettings(config_file, cv::filestorage::read);
if(!fssettings.isopened())
用法:
fssettings["image_topic"] >> image_topic;
fssettings["imu_topic"] >> imu_topic;
max_cnt = fssettings["max_cnt"];
min_dist = fssettings["min_dist"];
row = fssettings["image_height"];
col = fssettings["image_width"];
freq = fssettings["freq"];
f_threshold = fssettings["f_threshold"];
show_track = fssettings["show_track"];
equalize = fssettings["equalize"];
fisheye = fssettings["fisheye"];
最後別忘了:
fssettings.release();
其餘的注意事項參考部落格已經說了。 SpringBoot如何讀取配置檔案引數並全域性使用
前言 讀取配置檔案引數的方法 value 註解。但是 value不能為static變數賦值,而且很多時候我們需要將引數放在乙個地方統一管理,而不是每個類都賦值一次。正文 注意 一定要給類加上 component 註解 application.xml test app id 12345 app sec...
讀取配置檔案
類載入器 1 直接用class.forname 類的路徑名 class.forname com.hsf.classloader.classloader 2 用classloder 類載入器 inputstream in classloader.getsystemresourceasstream aa...
Python讀取配置檔案和外部引數
配置檔案db.json this is a json document.title json example database server 192.10.92.10 ports 5000 5001 5002 connection max 5000 enabled true bool型別 redis...