Skip to content

Instantly share code, notes, and snippets.

@ayrton04
Last active March 21, 2022 11:18
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save ayrton04/662964298a82211a7e28 to your computer and use it in GitHub Desktop.
Save ayrton04/662964298a82211a7e28 to your computer and use it in GitHub Desktop.
ROS rosbag filter command for filtering out specific tf transforms from your bag files
rosbag filter original.bag filtered.bag "topic != '/tf' or ((len(m.transforms) > 0 and m.transforms[0].header.frame_id != 'odom') and (len(m.transforms) <= 1 or (len(m.transforms) > 1 and m.transforms[1].header.frame_id != 'odom')) and (len(m.transforms) <= 2 or (len(m.transforms) > 2 and m.transforms[2].header.frame_id != 'odom')) and (len(m.transforms) <= 3 or (len(m.transforms) > 3 and m.transforms[3].header.frame_id != 'odom')) and (len(m.transforms) <= 4 or (len(m.transforms) > 4 and m.transforms[4].header.frame_id != 'odom')))"
@ayrton04
Copy link
Author

Note that if you have > 5 transforms in any one /tf message, you'll need to add some conditions for those. This script is only filtering tf transforms with a frame_id of "odom," but customizing it for your needs should be pretty straightforward. It could be rolled into a shell script, but you'll want to have some means of specifying parent and/or child frames.

@mbudris
Copy link

mbudris commented Dec 6, 2018

Three years later copy/paste is not working, at least for me. Had to use '/tf' instead of 'tf'.

Might save someone half of a day, since the link is in googles top answers.

And thanks Tom, of course.

@ayrton04
Copy link
Author

Two years later and I finally read this comment. Fixed the gist. :)

@hashim19
Copy link

6 years later, worked like a charm. :)

@RoboEvangelist
Copy link

RoboEvangelist commented Mar 18, 2022

How do we filter list of topics?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment