4 from sensor_msgs.msg
import CameraInfo
5 from sensor_msgs.msg
import Image
8 with open(yaml_fname,
"r") as file_handle: 9 calib_data = yaml.load(file_handle) 11 camera_info_msg = CameraInfo() 12 camera_info_msg.width = calib_data["image_width"]
13 camera_info_msg.height = calib_data[
"image_height"]
14 camera_info_msg.K = calib_data[
"camera_matrix"][
"data"]
15 camera_info_msg.D = calib_data[
"distortion_coefficients"][
"data"]
16 camera_info_msg.R = calib_data[
"rectification_matrix"][
"data"]
17 camera_info_msg.P = calib_data[
"projection_matrix"][
"data"]
18 camera_info_msg.distortion_model = calib_data[
"distortion_model"]
19 return camera_info_msg
23 global camera_info_msg
24 camera_info_msg.header = image.header
25 publisher.publish(camera_info_msg)
27 if __name__ ==
"__main__":
29 rospy.init_node(
"yaml_to_camera_info", anonymous=
True)
31 yaml_path = rospy.get_param(
'~yaml_path',
'')
33 print 'yaml_path parameter should be set to path of the calibration file!' 38 publisher = rospy.Publisher(
"camera_info", CameraInfo, queue_size=1)
39 rospy.Subscriber(
"image", Image, callback, queue_size=1)
def yaml_to_CameraInfo(yaml_fname)