37 import roslib; roslib.load_manifest(
'pr2_calibration_launch')
38 import sensor_msgs.msg
39 import sensor_msgs.srv
50 print(
"Usage: ./baseline_updater camera:=[camera_namespace] [calibration_bagfile] [system_filename] [config_camera_name]")
51 print(
" camera_namespace: Ros name to prepend onto the call to set_calibration")
52 print(
" config_filename: yaml file that stores the baseline shift")
53 print(
" config_camera_name: Name of the camera in the configuration file. Tells script which baseline shift to use")
56 rospy.init_node(
'baseline_updater', anonymous=
True)
64 bag_filename = argv[1]
65 system_filename = argv[2]
66 config_cam_name = argv[3]
68 cam_info = get_cam_info(bag_filename, config_cam_name)
70 print(
"Could not find a camera of the name [%s]" % config_cam_name)
73 print(
"Original Projection Matrix:")
75 print(
" %s" %
" ".join([
"% 12.5f" % p
for p
in cam_info.P[k*4:k*4+4]]))
76 original_baseline = cam_info.P[3]
79 system_dict = yaml.load(open(system_filename))
80 cam_dict = system_dict[
'sensors'][
'rectified_cams']
81 target_cam_dict = cam_dict[config_cam_name]
82 baseline_shift = target_cam_dict[
'baseline_shift']
84 print(
"Baseline Shift:")
85 print(
" % 12.5f" % baseline_shift)
88 updated_baseline = original_baseline + baseline_shift
91 updated_P = list(cam_info.P)
92 updated_P[3] = updated_baseline
93 cam_info.P = updated_P
95 print(
"Updated Projection Matrix:")
97 print(
" %s" %
" ".join([
"% 12.5f" % p
for p
in cam_info.P[k*4:k*4+4]]))
100 cam_name = rospy.resolve_name(
"camera")
101 set_cal_service_name = cam_name +
"/set_camera_info" 103 print(
"Waiting for service [%s] to be available" % set_cal_service_name)
104 rospy.wait_for_service(set_cal_service_name)
105 print(
"Writing camera info to camera memory...")
106 set_cal_srv = rospy.ServiceProxy(set_cal_service_name, sensor_msgs.srv.SetCameraInfo)
107 resp = set_cal_srv(cam_info)
109 print(
"Done writing to camera")
111 print(
"**************** ERROR WRITING TO CAMERA. PLEASE RETRY ***********************")
114 if __name__ ==
"__main__":