ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org |
![]() | 1 | initial version |
I found a workaround that works for me. Still, I wish there was a decrement function to step through the messages.
#include <rosbag/bag.h>
#include <rosbag/view.h>
#include <rosbag/query.h>
...
// Open rosbag file
rosbag::Bag input_bag;
input_bag.open(input_bag_path.c_str(), rosbag::bagmode::Read);
// Setup View
std::vector<std::string> topics;
topics.push_back(image_topic_name);
rosbag::View view(input_bag, rosbag::TopicQuery(topics));
// Make a vector with instances of the View::iterator class pointing to each message
std::vector<rosbag::View::iterator> iters;
for(rosbag::View::iterator iter = view.begin(); iter != view.end(); ++iter)
{
rosbag::View::iterator new_iter(iter);
iters.push_back( new_iter );
}
// Reverse iterate through the message pointers
for(std::vector<rosbag::View::iterator>::reverse_iterator r_iter = iters.rbegin(); r_iter != iters.rend(); ++r_iter)
{
sensor_msgs::Image::ConstPtr image_msg = (*(*r_iter)).instantiate<sensor_msgs::Image>();
...
}