Go to the documentation of this file.00001
00002
00003
00004 import sys
00005 import yaml
00006 import roslib
00007 roslib.load_manifest("ps4eye");
00008 from sensor_msgs.msg import CameraInfo
00009 import rospy
00010 import rospkg
00011
00012 class CameraInfoPublisher:
00013
00014 def callback(self, data):
00015 left_cam_info_org = data
00016 right_cam_info_org = data
00017 self.left_cam_info.header = left_cam_info_org.header
00018 self.right_cam_info.header = left_cam_info_org.header
00019 publisher.publish()
00020
00021 def __init__(self, camera_name):
00022 self.left_cam_info_org = 0
00023 self.right_cam_info_org = 0
00024
00025
00026 left_file_name = rospy.get_param('~left_file_name', rospack.get_path('ps4eye')+'/camera_info/left.yaml')
00027 right_file_name = rospy.get_param('~right_file_name', rospack.get_path('ps4eye')+'/camera_info/right.yaml')
00028 self.left_cam_info = parse_yaml(left_file_name)
00029 self.right_cam_info = parse_yaml(right_file_name)
00030 left_topic = "/" + camera_name + "/left/camera_info"
00031 right_topic = "/" + camera_name + "/right/camera_info"
00032
00033 rospy.Subscriber("/null/left/camera_info", CameraInfo, self.callback)
00034 rospy.Subscriber("/null/right/camera_info", CameraInfo, self.callback)
00035
00036 self.left_pub = rospy.Publisher(left_topic,CameraInfo)
00037 self.right_pub = rospy.Publisher(right_topic,CameraInfo)
00038
00039 def publish(self):
00040 '''
00041 now = rospy.Time.now()
00042 self.left_cam_info.header.stamp = now
00043 self.right_cam_info.header.stamp = now
00044 '''
00045 self.left_pub.publish(self.left_cam_info)
00046 self.right_pub.publish(self.right_cam_info)
00047
00048 def parse_yaml(filename):
00049 stream = file(filename, 'r')
00050 calib_data = yaml.load(stream)
00051 cam_info = CameraInfo()
00052 cam_info.width = calib_data['image_width']
00053 cam_info.height = calib_data['image_height']
00054 cam_info.K = calib_data['camera_matrix']['data']
00055 cam_info.D = calib_data['distortion_coefficients']['data']
00056 cam_info.R = calib_data['rectification_matrix']['data']
00057 cam_info.P = calib_data['projection_matrix']['data']
00058 cam_info.distortion_model = calib_data['distortion_model']
00059 cam_info.binning_x = calib_data['binning_x']
00060 cam_info.binning_y = calib_data['binning_y']
00061 cam_info.roi.x_offset = calib_data['roi']['x_offset']
00062 cam_info.roi.y_offset = calib_data['roi']['y_offset']
00063 cam_info.roi.height = calib_data['roi']['height']
00064 cam_info.roi.width = calib_data['roi']['width']
00065 cam_info.roi.do_rectify = calib_data['roi']['do_rectify']
00066
00067 return cam_info
00068
00069 if __name__ == '__main__':
00070 argv = rospy.myargv(sys.argv)
00071 rospy.init_node("camera_info_publisher")
00072 rospack = rospkg.RosPack()
00073 publisher = CameraInfoPublisher('stereo')
00074
00075 while not rospy.is_shutdown():
00076 rospy.sleep(rospy.Duration(.1))