粗大メモ置き場

個人用,たまーに来訪者を意識する雑記メモ

ROS publish the camera info in C++ (PerceptIn Camera)

I'm now using PerceptIn camera to make ROS wrapper.

Publish camera image

See the sample code online_feature.cpp to check how to get image from perceptIn camera.

Publish Camera info

Initialization and put value

Use cameraInfo.h.
sensor_msgs/CameraInfo Documentation
First, include and add your value.

Part of an example is below:

//init 
sensor_msgs::CameraInfoPtr lcam(new sensor_msgs::CameraInfo());
// put value
lcam->height = 480;
lcam->width = 640;
lcam->distortion_model = "plumb_bob";
lcam->D = { -0.361976, 0.110510, 0.001014, 0.000505, 0.000000};
lcam->K = {438.783367, 0.000000, 305.593336, 0.000000, 437.302876, 243.738352, 0.000000, 0.000000, 1.000000};
lcam->R = {0.999978, 0.002789, -0.006046, -0.002816, 0.999986, -0.004401, 0.006034, 0.004417, 0.999972};
lcam->P = {393.653800, 0.000000, 322.797939, 0.000000, 0.000000, 393.653800, 241.090902, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000};

Of course, it is better to read a calibration file to fill these information.

Publishing

When you publish the data, you should synchronize the camera image and camera info (many ROS packages yield that).

Sample code is like below:

lcam->header.stamp = imageLeftMsg->header.stamp;
lcam->header.frame_id = imageLeftMsg->header.frame_id;

imageLeftMsg means image data is for data to be published.

When debugging

Be careful [rostopic echo] will not visualize your CameraInfo until the synchronized image is subscribed by another topic.
github.com