Go to the documentation of this file.00001
00002 import roslib; roslib.load_manifest('rosbag')
00003 import rospy
00004 import rosbag
00005 import os
00006 import sys
00007
00008 def fix(infile, outfile):
00009 sys.stderr.write("Fixing {0} and writing to {1}".format(infile, outfile))
00010 with rosbag.Bag(infile, 'r') as bag:
00011 with rosbag.Bag(outfile, 'w') as outbag:
00012 UNMODIFIED_TOPICS = ['base_scan', 'camera/depth/camera_info',
00013 'camera/rgb/camera_info', 'camera/rgb/image_raw',
00014 'map', 'tf', 'tilt_scan_filtered']
00015 DEPTH_TOPIC = 'camera/depth/image_raw'
00016
00017
00018 i = 0
00019 for topic, msg, stamp in bag.read_messages(topics=UNMODIFIED_TOPICS,
00020 raw=True):
00021 outbag.write(topic, msg, t=stamp, raw=True)
00022 i += 1
00023 if i%10000==0:
00024 sys.stderr.write('.')
00025
00026
00027 for topic, msg, stamp in bag.read_messages(topics=[DEPTH_TOPIC],
00028 raw=False):
00029 assert msg.encoding=='16SC1' or msg.encoding=='',\
00030 "Received unexpected encoding {0}".\
00031 format(msg.encoding)
00032 msg.encoding = '16UC1'
00033 outbag.write(topic, msg, t=stamp, raw=False)
00034 i += 1
00035 if i%10000==0:
00036 sys.stderr.write('.')
00037 sys.stderr.write('\n')
00038
00039
00040
00041
00042 if __name__ == '__main__':
00043 if len(sys.argv) < 3:
00044 print "Usage: {0} OUTPATH INFILE1 ...".format(sys.argv[0])
00045 sys.exit(1)
00046 for f in sys.argv[2:]:
00047 outfile = os.path.join(sys.argv[1], os.path.basename(f))
00048 fix(f, outfile)