Ask Your Question
2

Camera calibration parser in python [closed]

asked 2012-05-13 22:06:07 -0600

Stephan gravatar image

Does ROS contain any camera calibration parsers written in python? I would like to have an interface that accepts a (YAML) filename as input, reads the data and gives me a CameraInfo message.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Stephan
close date 2012-07-10 00:36:38

1 Answer

Sort by ยป oldest newest most voted
2

answered 2012-07-09 23:59:02 -0600

Stephan gravatar image

updated 2012-07-10 00:36:15 -0600

Finally I wrote one on my own. It turned out to be fairly simple.

#!/usr/bin/python
PKG = 'camera_calibration_parsers_python'
import roslib; roslib.load_manifest('PKG')
import yaml
import sensor_msgs.msg

def parse_yaml(filename):
  stream = file(filename, 'r')
  calib_data = yaml.load(stream)
  cam_info = sensor_msgs.msg.CameraInfo()
  cam_info.width = calib_data['image_width']
  cam_info.height = calib_data['image_height']
  cam_info.K = calib_data['camera_matrix']['data']
  cam_info.D = calib_data['distortion_coefficients']['data']
  cam_info.R = calib_data['rectification_matrix']['data']
  cam_info.P = calib_data['projection_matrix']['data']
  cam_info.distortion_model = calib_data['distortion_model']
  return cam_info

if __name__ == "__main__":
  import argparse
  parser = argparse.ArgumentParser(description='Parses camera info yaml files and returns them as sensor_msgs.msg.CameraInfo.')
  parser.add_argument('filename', help='input yaml file')
  args = parser.parse_args()
  try:
    info = parse_yaml(args.filename)
    print 'Read the following info from', args.filename, '\n', info
  except Exception, e:
    import traceback
    traceback.print_exc()
edit flag offensive delete link more

Question Tools

Stats

Asked: 2012-05-13 22:06:07 -0600

Seen: 1,063 times

Last updated: Jul 10 '12