Ask Your Question

Publishing CameraInfo messages from YAML file

asked 2016-11-21 10:00:11 -0500

mohito gravatar image

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?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2016-11-21 18:25:41 -0500

lucasw gravatar image

This is the same as though the comment there points to something that isn't quite what you want. 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.

edit flag offensive delete link more

answered 2017-08-29 17:16:27 -0500

ckirksey gravatar image

Nice gist from @rossbar

# 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
edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

1 follower


Asked: 2016-11-21 10:00:11 -0500

Seen: 3,005 times

Last updated: Aug 29 '17