0
votes

I am trying to segment the input point cloud using surface normal based region growing, following the tutorial here:http://pointclouds.org/documentation/tutorials/region_growing_segmentation.php. I have been able to achieve satisfactory results for my use case and I could also visualize the segments using pcl::PointCloud ::Ptr colored_cloud = reg.getColoredCloud ();

However, I am not able to find a way to extract a particular cluster that contains all points with normals oriented in a particular direction, for example, the cluster which has all the points with point normals along the z-axis. I assume that such an access to the cluster should be possible, please correct me if I am wrong. Also, any alternative methods to get the feature/s of the individual cluster would be very helpful. Thanks in advance.

1

1 Answers

0
votes

Take a look at these lines (from the tutorial you mention):

std::vector <pcl::PointIndices> clusters;
reg.extract (clusters);

Each "cluster" is repressented by pcl::PointIndices, which is just a wrapper for a vector<int> of indices in the input cloud.

Here is a simple example for calculating the mean normal for each cluster:

std::vector<Eigen::Vector3f> mean_normals(clusters.size(), Eigen::Vector3f({ 0.,0.,0. }));
for (auto cluster_idx = 0; cluster_idx < clusters.size(); cluster_idx++)
{
    for (auto point_idx: clusters[cluster_idx].indices)
    {
        mean_normals[cluster_idx] += normals->points[point_idx].getNormalVector3fMap();
    }
    mean_normals[cluster_idx].normalize();
}

You may also use pcl::PointIndices to create a new cloud for each cluster using pcl::ExtractIndices, as in this tutorial. Short example:

pcl::PointCloud<pcl::PointXYZ>::Ptr cluster_cloud(new pcl::PointCloud<pcl::PointXYZ>)
pcl::ExtractIndices<pcl::PointXYZ> extract;
extract.setInputCloud (cloud);
extract.setIndices (clusters[cluster_idx]);
extract.filter (*cluster_cloud);