Converting a rosbag to pcd files and process them using pcl

asked 2019-08-21 14:22:03 -0500

Don gravatar image

Hi all, I have a rosbag file which has sensor_msgs/PointCloud2 format messages coming from a topic (velodyne registered lidar data). I converted the rosbag to set of pcd files using command "rosrun pcl_ros bag_to_pcd ". I want to read those pcd files as "pcl::PointCloud" so that I can uss PCL functions to process data. My file read function is as follows:

template typename pcl::PointCloud::Ptr ProcessPointClouds::loadPcd(std::string file) { typename pcl::PointCloud::Ptr cloud (new pcl::PointCloud); if (pcl::io::loadPCDFile (file, cloud) == -1) // load the file { PCL_ERROR ("Couldn't read file \n"); } std::cerr << "Loaded " << cloud->points.size () << " data points from "+file << std::endl; return cloud; }

However, I could not read it successfully and had error msgs such as "[pcl::PCDReader::readHeader] Invalid COUNT value specified.", "Failed to find match for field 'x','y','z','intensity'". When I check, my pcd file has following fields: FIELDS x_origin y_origin z_origin x y z reflectance amplitude ring _ time_sec _ time_nsec _ return_type _

My questions are:

1) Does the ros command "rosrun pcl_ros bag_to_pcd " convert sensor_msgs/PointCloud2 format to "pcl::PCLPointCloud2" format when it makes the pcd files from the rosbag, or do I need to implement some conversion?

2) Is there any way that I can convert the rosbag file to a pcl readable format directly?

Thank you and any help is highly appreciated!

edit retag flag offensive close merge delete