Set value for distortion coefficient in CameraInfo
Hi,
I am currently working with 2 stereo cameras and I wish to publish their information
on ROS topics (sensor_msgs/Image
and sensor_msgs/CameraInfo
) for using the stereo_img_proc package.
I can publish my stereo camera images the sensor_msgs/Image but I am missing one component
for the other one, ie sensors_msgs::CameraInfo
message/object.
From the online documentation for CameraInfo.msg message, the distortion array D is declared as
float64[] D;
My current attempt does this -
sensor_msgs::CameraInfo caminfo;
cv::FileStorage fs; // using OpenCV to read YAML file
// read parameters as openCV cv::Mat and then fill array
cv::Mat D1;
fs["distortion_coefficients"] >> D1;
caminfo.D[0] = D1.at<double>(0,0);
caminfo.D[1] = D1.at<double>(0,1);
caminfo.D[2]= D1.at<double>(0,2);
caminfo.D[3] = D1.at<double>(0,3);
caminfo.D[4] =D1.at<double>(0,4);
However, this does not work and I get an error ( Segmentation Fault core dumped ) on running the node/executable. This is probably because I'm making assumptions on the distortion array length but in reality I'm not aware of where the length is defined , since it is not given even here,
My Question: Can someone please explain how to fill in the distortion matrix parameter for sensor_msgs::CameraInfo ?