How to extract timestamp from a bag file ?

asked 2015-05-06 20:21:47 -0600

lilouch gravatar image

updated 2015-05-07 21:44:23 -0600


I checked on the API c++ but I wasn't able to do what I want. Actually, I would like to write a little program which take an input a bag file and then obtain the the timestamp of each frame as an output. All the timestamp are stored in the /camera_topic.

So far what I did is the following:

 rosbag::Bag bag;"mybag.bag", rosbag::bagmode::Read);

rosbag::View view(bag, rosbag::TopicQuery("/camera_info"));

foreach(rosbag::MessageInstance const m, view)
    std_msgs::String::ConstPtr s = m.instantiate<std_msgs::String>();
    if (s != NULL)
        ASSERT_EQ(s->data, std::string("foo"));

    std_msgs::Int32::ConstPtr i = m.instantiate<std_msgs::Int32>();
    if (i != NULL)
        ASSERT_EQ(i->data, 42);


Is anyone can help me ? Maybe there is another easy way to do that stuff (bash ?) but It would be great using c++.


edit retag flag offensive close merge delete