Skip to content

Instantly share code, notes, and snippets.

@ojura
Created February 8, 2019 10:52
Show Gist options
  • Save ojura/2913c6bf9c0dc42345f31fd7c0b6b0f4 to your computer and use it in GitHub Desktop.
Save ojura/2913c6bf9c0dc42345f31fd7c0b6b0f4 to your computer and use it in GitHub Desktop.
import rosbag
import os
import sys
def remove_tf(inbag,outbag,frame_ids):
rospy.loginfo(' Processing input bagfile: %s', inbag)
rospy.loginfo(' Writing to output bagfile: %s', outbag)
rospy.loginfo(' Removing frame_ids: %s', ' '.join(frame_ids))
outbag = rosbag.Bag(outbag,'w')
for topic, msg, t in rosbag.Bag(inbag,'r').read_messages():
if topic == "/tf":
new_transforms = []
for transform in msg.transforms:
if transform.child_frame_id not in frame_ids:
new_transforms.append(transform)
msg.transforms = new_transforms
outbag.write(topic, msg, t)
rospy.loginfo('Closing output bagfile and exit...')
outbag.close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment