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

Convert sensor_msgs::PointCloud2ConstPtr to pcl::PointCloud<pcl::PointXYZ>

asked 2020-06-02 21:04:18 -0500

czr gravatar image

I am trying to apply a segmentation model to a point cloud. The models on PCL expect a pcl::PointCloud<pcl::PointXYZ>, I have tried to converting the messages by using the functions suggested in other threads but it wont compile:

int segment_obstacles(const sensor_msgs::PointCloud2ConstPtr& input) 
{   
    pcl::PointCloud<pcl::PointXYZ> cloud (new pcl::PointCloud<pcl::PointXYZ>()); 

    // pcl::fromPCLPointCloud2(*input, *cloud);
    pcl::fromROSMsg(*input, *cloud);

I tried both functions. What would be the right way to convert the message point cloud?

edit retag flag offensive close merge delete

Comments

I use the same algorithm you are using.

The only difference i see is when you declare a pcl::pointcloud (I have it declared as a pointer). so, your third line should be :

pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>());

Actually for me makes sense due to the fact that "new" if i am not wrong is used for pointers.

Hope it helps!

Solrac3589 gravatar image Solrac3589  ( 2020-06-03 01:00:41 -0500 )edit

Thank you very much, that solved the compilation error.

czr gravatar image czr  ( 2020-06-03 18:03:47 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-06-03 14:27:14 -0500

rosberrypi gravatar image

updated 2020-06-03 14:34:32 -0500

This is how I use it. I am directly publishing and subscribing pcl::PointCloud types instead of sensor_msgs but if you create the new variable in the callback function as sensor_msgs it would work the same way.

void cloudCallback(const pcl::PointCloud<pcl::PointXYZ>::ConstPtr& msg)
{
    // Read incoming cloud
    pcl::PointCloud<pcl::PointXYZ>::Ptr filtered_cloud (new pcl::PointCloud<pcl::PointXYZ>);
    *filtered_cloud = *msg;
}
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2020-06-02 21:04:18 -0500

Seen: 1,665 times

Last updated: Jun 03 '20