camera_info_parser.py
Go to the documentation of this file.
00001 #!/usr/bin/python
00002 """
00003 Copyright (c) 2012,
00004 Systems, Robotics and Vision Group
00005 University of the Balearican Islands
00006 All rights reserved.
00007 
00008 Redistribution and use in source and binary forms, with or without
00009 modification, are permitted provided that the following conditions are met:
00010     * Redistributions of source code must retain the above copyright
00011       notice, this list of conditions and the following disclaimer.
00012     * Redistributions in binary form must reproduce the above copyright
00013       notice, this list of conditions and the following disclaimer in the
00014       documentation and/or other materials provided with the distribution.
00015     * Neither the name of Systems, Robotics and Vision Group, University of
00016       the Balearican Islands nor the names of its contributors may be used to
00017       endorse or promote products derived from this software without specific
00018       prior written permission.
00019 
00020 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00021 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00022 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00023 DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
00024 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00025 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00026 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00027 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00028 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00029 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00030 """
00031 
00032 
00033 PKG = 'bag_tools' # this package name
00034 
00035 import roslib; roslib.load_manifest(PKG)
00036 import yaml
00037 import sensor_msgs.msg
00038 
00039 def parse_yaml(filename):
00040   stream = file(filename, 'r')
00041   calib_data = yaml.load(stream)
00042   cam_info = sensor_msgs.msg.CameraInfo()
00043   cam_info.width = calib_data['image_width']
00044   cam_info.height = calib_data['image_height']
00045   cam_info.header.frame_id = calib_data['camera_name']
00046   cam_info.K = calib_data['camera_matrix']['data']
00047   cam_info.D = calib_data['distortion_coefficients']['data']
00048   cam_info.R = calib_data['rectification_matrix']['data']
00049   cam_info.P = calib_data['projection_matrix']['data']
00050   cam_info.distortion_model = calib_data['distortion_model']
00051   return cam_info
00052 
00053 if __name__ == "__main__":
00054   rospy.init_node('camera_info_parser')
00055   import argparse
00056   parser = argparse.ArgumentParser(description='Parses camera info yaml files and returns them as sensor_msgs.msg.CameraInfo.')
00057   parser.add_argument('filename', help='input yaml file')
00058   args = parser.parse_args()
00059   try:
00060     info = parse_yaml(args.filename)
00061     rospy.loginfo('Read the following info from %s\n%s', args.filename, info)
00062   except Exception, e:
00063     import traceback
00064     traceback.print_exc()


bag_tools
Author(s): Stephan Wirth , Miquel Massot
autogenerated on Sat Jun 8 2019 20:10:13