Robotics StackExchange | Archived questions

Having problem converting sensor_msgs:: Pointcloud2 to pcl

Hello my friend,

I am trying to put point clouds gathered from Gazebo into PCL. The data format gathered from Block Laser is sensormsgs::PointCloud, and I have managed to convert it to sensormsgs::PointCloud2, but having problem convert it further into PCL Point cloud. My code is:

void scanCallback(const sensor_msgs::PointCloud scan)
{ 
    pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
    sensor_msgs::PointCloud2 cloud2;
    sensor_msgs::convertPointCloudToPointCloud2(scan, cloud2); //point_cloud - msg::pt2
     pcl::fromPCLPointCloud2(cloud2,cloud);

} 

where the last line complains an error which:

 error: no matching function for call to ‘fromPCLPointCloud2(sensor_msgs::PointCloud2&, pcl::PointCloud<pcl::PointXYZ>::Ptr&)

I have been struggling on this for quite a while, hopefully someone could very kindly point out the problem, cheers!

Asked by yuri_chen1995 on 2019-06-13 22:00:58 UTC

Comments

Is this from a tutorial or documentation? If so, can you please post a link to it? It seems like it may be old (I don't know though, I don't have experience with PCL). Have you seen this post?

Asked by jayess on 2019-06-14 00:24:04 UTC

Otherwise, there's this tutorial too

Asked by jayess on 2019-06-14 00:28:27 UTC

pcl::fromPCLPointCloud2(cloud2,cloud);

If you want to go from sensor_msgs/PointCloud2 to a PCL Pointcloud (ie: native type), then I believe you'd use:

pcl_conversions::toPCL(..)

Asked by gvdhoorn on 2019-06-14 02:04:41 UTC

Answers