yaml_to_camera_info.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 import rospy
3 import yaml
4 from sensor_msgs.msg import CameraInfo
5 from sensor_msgs.msg import Image
6 
7 def yaml_to_CameraInfo(yaml_fname):
8  with open(yaml_fname, "r") as file_handle:
9  calib_data = yaml.load(file_handle)
10 
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
20 
21 def callback(image):
22  global publisher
23  global camera_info_msg
24  camera_info_msg.header = image.header
25  publisher.publish(camera_info_msg)
26 
27 if __name__ == "__main__":
28 
29  rospy.init_node("yaml_to_camera_info", anonymous=True)
30 
31  yaml_path = rospy.get_param('~yaml_path', '')
32  if not yaml_path:
33  print 'yaml_path parameter should be set to path of the calibration file!'
34  sys.exit(1)
35 
36  camera_info_msg = yaml_to_CameraInfo(yaml_path)
37 
38  publisher = rospy.Publisher("camera_info", CameraInfo, queue_size=1)
39  rospy.Subscriber("image", Image, callback, queue_size=1)
40  rospy.spin()
def yaml_to_CameraInfo(yaml_fname)


rtabmap_ros
Author(s): Mathieu Labbe
autogenerated on Fri Jun 7 2019 21:55:04