How to retrieve list from ros parameter server that is not comma-separated
I need to be able to read some parameters from my code, (ultimately into openCV matrices)
I can correctly read a parameter from the ros parameter server like this (with commas)
/cam_left_left_info_pub/projection_matrix/data
[1041.022827, 0.0, 938.549637, 0.0, 0.0, 1045.705078, 602.181309, 0.0, 0.0, 0.0, 1.0, 0.0]
/cam_left_left_info_pub/projection_matrix/rows
3
/cam_left_left_info_pub/projection_matrix/cols
4
using this code:
// 1D vector for temporarily holding matrix elements
std::vector<double> _data;
// matrix dimensions
int _rows, _cols;
// read from param server
nodehandle.getParam(param + std::string("/data"), _data);
nodehandle.getParam(param + std::string("/rows"), _rows);
nodehandle.getParam(param + std::string("/cols"), _cols);
// init matrix and copy
cv::Mat(_rows, _cols, CV_64F, _data.data()).copyTo(*cv_matrix);
// check if values were read correctly
std::cout << "my matrix: " << std::endl << cv_matrix << std::endl;
but this data (NO COMMAS) does not work, the data is read as seemingly random numbers.
/cam_left_left_info_pub/distortion_coefficients/data
[-0.034062 0.026819 0.000826 -0.002720 0.000000]
/cam_left_left_info_pub/distortion_coefficients/rows
1
/cam_left_left_info_pub/distortion_coefficients/cols
5
How Can I read data in the format: [0.1 0.2 0.3] from the rosparameter server into a std::vector?
* EDIT: Context of this problem *
I am writing a camera_info publisher The output of the ROS camera_calibration package
Is a YAML file. Here is a complete example:
image_width: 1920
image_height: 1200
camera_name: narrow_stereo
camera_matrix:
rows: 3
cols: 3
data: [1043.889715, 0.000000, 946.091722, 0.000000, 1045.536555, 601.201155, 0.000000, 0.000000, 1.000000]
distortion_model: plumb_bob
distortion_coefficients:
rows: 1
cols: 5
data: [-0.034062 0.026819 0.000826 -0.002720 0.000000]
rectification_matrix:
rows: 3
cols: 3
data: [1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000]
projection_matrix:
rows: 3
cols: 4
data: [1041.022827, 0.000000, 938.549637, 0.000000, 0.000000, 1045.705078, 602.181309, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000]
I publish these values in my launch file like this:
<rosparam file="$(find calibration_publisher)/cfg/$(arg cam_name).yaml" />
Linking the issue you posted on the ros-perception/image_pipeline tracker: ros-perception/image_pipeline#533.