Ask Your Question

Set value for distortion coefficient in CameraInfo

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

malharjajoo gravatar image

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


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] =<double>(0,0);
       caminfo.D[1] =<double>(0,1);
       caminfo.D[3] =<double>(0,3);

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

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

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



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 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



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

Seen: 636 times

Last updated: Feb 27 '18