Ask Your Question
0

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
3

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 imagelucasw ( 2018-02-27 10:36:00 -0600 )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

2 followers

Stats

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

Seen: 412 times

Last updated: Feb 27 '18