ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

Set value for distortion coefficient in CameraInfo

asked 2018-02-27 00:50:20 -0600

malharjajoo gravatar image

updated 2018-02-27 00:50:55 -0600

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 ?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
4

answered 2018-02-27 05:31:25 -0600

NEngelhard gravatar image

If you look in sensor_msgs/CameraInfo.h, you find the declaration of D:

   typedef std::vector<double, typename ContainerAllocator::template rebind<double>::other >  _D_type;
  _D_type D;

It's a vector, so you will have to to a caminfo.D.push_back(...). (or resize the vector before writing into it).

edit flag offensive delete link more

Comments

1

The D1 mat also ought to be checked for size, if for some reason it isn't five columns then there will also be a segfault.

lucasw gravatar image lucasw  ( 2018-02-27 10:36:00 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2018-02-27 00:50:20 -0600

Seen: 1,186 times

Last updated: Feb 27 '18