Removing all /map frames from a rosbag

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Removing all /map frames from a rosbag

matlabbe
Administrator
This post was updated on .
Hi,

This post is for information purpose. When I do a rosbag with rtabmap running, sometimes I want to remove the frames /map -> /odom frames recorded in /tf so I can play the rosbag again with rtabmap or other mapping algorithms. The following Python example is able the remove all /map frames in a tfMessage containing many frames.

import rosbag
from tf.msg import tfMessage

with rosbag.Bag('output.bag', 'w') as outbag:
    for topic, msg, t in rosbag.Bag('input.bag').read_messages():
        if topic == "/tf" and msg.transforms:
            filteredTransforms = [];
            for m in msg.transforms:
                if m.header.frame_id != "map":
                    filteredTransforms.append(m)
                else:
                    print('map frame removed!')
            if len(filteredTransforms)>0:
                msg.transforms = filteredTransforms
                outbag.write(topic, msg, t)
        else:
            outbag.write(topic, msg, t)

cheers
Reply | Threaded
Open this post in threaded view
|

Re: Removing all /map frames from a rosbag

g.bartoli
Useful, thanks for the information!
~Guido