简体   繁体   中英

Provide parameters to OpenCV C++ program in ROS from external file

I want to write a program using OpenCV C++ interface in ROS . I want to provide parameters used by the program from external file(not sure which format will be apt).

Say, I use the threshold function in the program, instead of changing the threshold value each time in the program,make and then run , I want the program to fetch the threshold value from a file so that if I wish to change any value, I could do it in the external file .

I want this because I think it will be helpful to a third-person who can just change the various parameters in the file and observe the result rather than opening the program, change values,make and run ( Sometimes the third person may not be a programmer and just wishes to see the results, in that case he would not know the technicalities of where to change parameters in the program )

Is there any way to do this in ROS ?? Any method for just a C++ program requiring several parameters could also be suggested.

well, if it's just simple params:

#include <fstream>

// write:
int param1 = 17;
float param2=2.5f;
ofstream o("params.txt");
o << param1 << endl;
o << param2 << endl;

// read:
int param1;
float param2;
ifstream i("params.txt");
i >> param1;
i >> param2;

similar idea, bit more advanced, for opencv stuff, use the FileStorage, it's a key-value store:

Mat face_labels;
Mat face_features;

cv::FileStorage fs("face.yml",cv::FileStorage::WRITE);
fs << "L" << face_labels;
fs << "F" << face_features;

cv::FileStorage sf("face.yml",cv::FileStorage::READ);
sf["L"] >> face_labels;
sf["F"] >> face_features;

You can do this via ROS parameters. See the roscpp params tutorial and the more detailed roscpp params overview . You probably want to go ahead and use the NodeHandle::param(...) form as it makes it easy to specify defaults.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM