ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
2

rosbag info C++ API

asked 2012-02-28 22:10:21 -0600

Enrique gravatar image

updated 2014-01-28 17:11:31 -0600

ngrennan gravatar image

Is there any way to recover the number of messages of a given topic from a .bag file using the C++ API?

I know the Python API does, which is used in rosbag info <bag> (I think, by means of the _get_yaml_info Bag class method), but I'd like to know whether we have the same feature in the C++ API or not?

Thanks!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
4

answered 2012-02-28 23:08:47 -0600

Lorenz gravatar image

updated 2012-02-29 03:07:50 -0600

Did you try the rosbag::View::size method? As I understand it, it should return the number of messages. Maybe std::distance(view.begin(), view.end()) could also work, but not sure about that.

edit flag offensive delete link more

Comments

I mean to obtain the number of messages without reading them, like rosbag info does (as I mention in my question). Currently, I read all messages using C++ API, and I convert them to some ASCII files I need, but only at the end I know the number of messages, and I need it at the very beginning.

Enrique gravatar image Enrique  ( 2012-02-29 02:54:08 -0600 )edit

Sorry. My fault. I updated my answer.

Lorenz gravatar image Lorenz  ( 2012-02-29 03:08:05 -0600 )edit

rosbag::View::size() works! It uses std::distance in its implementation, btw. Thanks a lot!

Enrique gravatar image Enrique  ( 2012-02-29 05:02:40 -0600 )edit

@Enrique Hi. I met almost the same question or need to get the number of messages in a rosbag. I used the function view.size() but it showed the size_cache (uint32) and it was 68435, not the value of the messages number. How could I make it works? Thank you

YancenBOB gravatar image YancenBOB  ( 2019-08-14 03:52:12 -0600 )edit

Question Tools

Stats

Asked: 2012-02-28 22:10:21 -0600

Seen: 1,789 times

Last updated: Feb 29 '12