Created
November 3, 2017 12:53
-
-
Save ojura/d4a15c1f44aca1ac5d0e58aa32cfa0ba to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import rospy | |
import rosbag | |
import os | |
import sys | |
import argparse | |
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.header.frame_id not in frame_ids and 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(); | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser( | |
description='removes all transforms from the /tf topic that contain one of the given frame_ids in the header as parent or child.') | |
parser.add_argument('-i', metavar='INPUT_BAGFILE', required=True, help='input bagfile') | |
parser.add_argument('-o', metavar='OUTPUT_BAGFILE', required=True, help='output bagfile') | |
parser.add_argument('-f', metavar='FRAME_ID', required=True, help='frame_id(s) of the transforms to remove from the /tf topic', nargs='+') | |
args = parser.parse_args() | |
try: | |
remove_tf(args.i,args.o,args.f) | |
except Exception, e: | |
import traceback | |
traceback.print_exc() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment