Advertisement
ivbelkin

Untitled

Apr 17th, 2022
783
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.47 KB | None | 0 0
  1. import rospy
  2. import rosbag
  3. import argparse
  4. import os
  5.  
  6. from tqdm import tqdm
  7.  
  8.  
  9. def build_parser():
  10.     parser = argparse.ArgumentParser()
  11.     parser.add_argument('input', help='path to input .bag file')
  12.     parser.add_argument('output', help='path to output .bag file')
  13.     return parser
  14.  
  15.  
  16. def main(args):
  17.     inbag = rosbag.Bag(args.input)
  18.     # os.makedirs(os.path.dirname(args.output))
  19.  
  20.     with tqdm(total=inbag.get_message_count()) as pbar:
  21.         with rosbag.Bag(args.output, mode='w') as outbag:
  22.             for topic, msg, t in inbag.read_messages():
  23.                 pbar.update()
  24.  
  25.                 if topic == '/camera/camera_info':
  26.                     msg.header.frame_id = 'camera_left'
  27.                     outbag.write('/camera/color/camera_info', msg, t)
  28.                     outbag.write('/camera/depth/camera_info', msg, t)
  29.                 elif topic == '/camera/color/image_raw':
  30.                     msg.header.frame_id = 'camera_left'
  31.                     outbag.write('/camera/color/image_rect', msg, t)
  32.                 elif topic == '/camera/depth/image_raw':
  33.                     msg.header.frame_id = 'camera_left'
  34.                     outbag.write('/camera/depth/image_rect', msg, t)
  35.                 elif topic == '/tf':
  36.                     outbag.write(topic, msg, t)
  37.                 else:
  38.                     outbag.write(topic, msg, t)
  39.  
  40.  
  41. if __name__ == '__main__':
  42.     parser = build_parser()
  43.     args = parser.parse_args()
  44.     main(args)
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement