Extract single messages from rosbag [closed]

asked 2013-11-07 00:38:43 -0500

Silv gravatar image

updated 2013-11-07 04:18:04 -0500


I have a point cloud contains two topics. I want to get the messages of the two topics on request from the Rosbag.

According to the motto: Give me the message number 10,15,20 and not more

If I use the BOOST_FOREACH function as explained in the ROS tutorials, I get all the messages from the Rosbag. But I need them individually.

Hence the question, is it possible to iterate over a Rosbag and to store only selected messages?

Currently I save all messages in a vector, but for large Rosbags that leads to memory problems.

std::vector<std::string> topics;  
rosbag::View view(input_bag, rosbag::TopicQuery(topics));   

std::vector<pcl17::PointCloud<pcl17::PointXYZRGB>::Ptr> pc_msg_vector; 

BOOST_FOREACH(rosbag::MessageInstance const m, view)
    pcl17::PointCloud<pcl17::PointXYZRGB>::Ptr temp_pc(new pcl17::PointCloud<pcl17::PointXYZRGB>);
    sensor_msgs::PointCloud2::ConstPtr pc_msg_ptr = m.instantiate<sensor_msgs::PointCloud2>();

    if (pc_msg_ptr != NULL)
        pcl17::fromROSMsg(*pc_msg_ptr, *temp_pcl);                            
        pc_msg_vector.push_back( temp_pcl );


edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by tfoote
close date 2015-11-19 20:08:22.335266