0

Rosanswers logo

I have a bag file that publishes camera/image_raw. I also have the calibration parameters of the corresponding camera in a separate YAML file. How can I publish cam_info messages using only the YAML file so that I can rectify the image_raw?


Originally posted by mohito on ROS Answers with karma: 21 on 2016-11-21

Post score: 2

2 Answers2

0

Rosanswers logo

This is the same as http://answers.ros.org/question/236976/how-to-publish-camera_info-manually/ though the comment there points to something that isn't quite what you want.

https://github.com/lucasw/vimjay/blob/master/scripts/dr_camera_info.py is an example of publishing a camera info defined by dynamic reconfigure- but if your yaml file is loaded into the node namespace (with rosparam load) and shares the same layout then when the dr server starts it will get the right camera parameters. That script only publishes the camera info once, it could be modified to easily to also subscribe to an image and then in the image callback it would republish the camera info with a timestamp copied from the image.

It really seems like this ought to already exist- if it were really done right there would be a node that also provided the set_camera_info service and then the yaml could be provided as a url, using camera_info_manager.


Originally posted by lucasw with karma: 8729 on 2016-11-21

This answer was ACCEPTED on the original site

Post score: 1

Lucas Walter
  • 3,337
  • 1
  • 14
  • 19
0

Rosanswers logo

Nice gist from @rossbar https://gist.github.com/rossbar/ebb282c3b73c41c1404123de6cea4771

# Load data from file
with open(yaml_fname, "r") as file_handle:
    calib_data = yaml.load(file_handle)
# Parse
camera_info_msg = CameraInfo()
camera_info_msg.width = calib_data["image_width"]
camera_info_msg.height = calib_data["image_height"]
camera_info_msg.K = calib_data["camera_matrix"]["data"]
camera_info_msg.D = calib_data["distortion_coefficients"]["data"]
camera_info_msg.R = calib_data["rectification_matrix"]["data"]
camera_info_msg.P = calib_data["projection_matrix"]["data"]
camera_info_msg.distortion_model = calib_data["distortion_model"]
return camera_info_msg

Originally posted by ckirksey with karma: 203 on 2017-08-29

This answer was NOT ACCEPTED on the original site

Post score: 2


Original comments

Comment by fjp on 2021-08-29:
Is this still the best method to create the CameraInfo messages from a yaml calibrationf file? Or is there an official ros package to do this?