Cluster

Euclidean Cluster Extraction

Extract indices from a PointCloud

pcl::ModelCoefficients::Ptr coefficients (new pcl::ModelCoefficients());

pcl::PointIndices::Ptr inliers (new pcl::PointIndices ());

// Create the segmentation object pcl::SACSegmentation seg;

// Optional seg.setOptimizeCoefficients (true);

// Mandatory seg.setModelType (pcl::SACMODEL_PLANE); seg.setMethodType (pcl::SAC_RANSAC); seg.setMaxIterations (1000); seg.setDistanceThreshold (0.01);

// Create the filtering object pcl::ExtractIndices extract;

int i = 0, nr_points = (int) cloud_filtered->points.size (); // While 30% of the original cloud is still there while (cloud_filtered->points.size () > 0.3 nr_points) { // Segment the largest planar component from the remaining cloud seg.setInputCloud (cloud_filtered); seg.segment (inliers, *coefficients); if (inliers->indices.size () == 0) { std::cerr << "Could not estimate a planar model for the given dataset." << std::endl; break; }

// Extract the inliers extract.setInputCloud (cloud_filtered); extract.setIndices (inliers); extract.setNegative (false); extract.filter (*cloud_p);

std::cerr << "PointCloud representing the planar component: " << cloud_p->width * cloud_p->height << " data points." << std::endl;

std::stringstream ss; ss << "tablescene_lms400_plane" << i << ".pcd"; writer.write (ss.str (), *cloud_p, false);

// Create the filtering object extract.setNegative (true); extract.filter (*cloud_f); cloud_filtered.swap (cloud_f); i++; }

```

results matching ""

    No results matching ""