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