Writing camera information (sensor_msgs::CameraInfo) to YAML file

asked 2017-11-05 22:30:47 -0600

ravijoshi gravatar image

I have camera information in the form of sensor_msgs::CameraInfo. I want to write it to YAML file, so that camera_info_manager.loadCameraInfo("PATH_TO_YAML") can be used directly. Below is the code snippet:

sensor_msgs::CameraInfo camera_info;
camera_info.height = 1080;
camera_info.width = 1920;
camera_info.distortion_model = "plumb_bob";
camera_info.D = {0.0, 0.0, 0.0, 0.0, 0.0};
camera_info.K = {1081.3720703125, 0.0, 959.5, 0.0, 1081.3720703125, 539.5, 0.0, 0.0, 1.0};
camera_info.R = {1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0};
camera_info.P = {1081.3720703125, 0.0, 959.5, 0.0, 0.0, 1081.3720703125, 539.5, 0.0, 0.0, 0.0, 1.0, 0.0};
camera_info.binning_x = 0;
camera_info.binning_y = 0;
camera_info.roi.x_offset = 0;
camera_info.roi.y_offset = 0;
camera_info.roi.height = 0;
camera_info.roi.width = 0;
camera_info.roi.do_rectify = false;

I want to save the above calibration values to YAML so that I can use following code:

camera_info_manager::CameraInfoManager camera_info_manager(nh, "rgb");
camera_info_manager.loadCameraInfo("CALIB_YAML");

I am using ROS CPP in ROS Indigo on Ubuntu 14.04 LTS PC.

edit retag flag offensive close merge delete