Rosanswers logo

Hi all,

I am working on processing some data stored in a bag file. I am perfectly comfortable reading data and messages from bag files using python's rosbag module. I am not sure if this is a silly or naive question, but my searching thus far has not led very far. Here's the situation:

I have my tf messages stored in a bag file. The tf values for different frames do not change over time (rigid system). I know the names and transforms for the frames since this is stored in the bag data. What I would like to do is get the same functionality from lookupTransform() without needing to publish my transforms and listen form them to get the calculations performed by this function. It would be excellent to achieve this python, since this is language that my processing code is using. Essentially, I'm trying to perform the following in python without needing to actually perform the lookup by the frame id string.

StampedTransform& transform    
tf::StampedTransform from_geometry_messages1, from_geometry_messages2;
transform.setData( temp2 * temp1);
transform.stamp_ = temp2.stamp_;
transform.frame_id_ = target_frame;
transform.child_frame_id_ = source_frame;

Instead I would simply like to perform the calculation portions of the lookupTransform code in python.


Originally posted by jlef on ROS Answers with karma: 21 on 2014-07-08

Post score: 2


1 Answer 1


Rosanswers logo

You can feed a python transformer manually with messages. This is what I used in some post processing code:

tf_t = tf.Transformer(True, rospy.Duration(3600.0))
bag = rosbag.Bag(bag_file)
for topic, msg, t in bag.read_messages(topics=['/tf']):
    for msg_tf in msg.transforms:

You can now use the tf.Transformer as if it was filled from topics, i.e. call lookupTransform, etc.

Originally posted by dornhege with karma: 31395 on 2014-07-08

This answer was ACCEPTED on the original site

Post score: 4

Original comments

Comment by RachitB11 on 2018-07-11:
Excellent answer. Really helped.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.