PCL uses RANSAC to fit segmentation plane by itself

Using PCL segmentation algorithm

 pcl::SACSegmentation<pcl::PointXYZ> seg;

, do not use the normal parameters, only get the segmentation patch according to the model parameters, which is far from the imagined patch,

 1  pcl::ModelCoefficients::Ptr coefficients (new pcl::ModelCoefficients ());
 2   pcl::PointIndices::Ptr inliers (new pcl::PointIndices ());
 3   // Create split objects
 4   pcl::SACSegmentation<pcl::PointXYZ> seg;
 5   // Optional
 6   seg.setOptimizeCoefficients (true);
 7   // Mandatory
 8   seg.setModelType (pcl::SACMODEL_PLANE);
 9   seg.setMethodType (pcl::SAC_RANSAC);
10   seg.setMaxIterations (1000);
11   seg.setDistanceThreshold (0.05);

After that, I use RANSAC fitting method to segment the patches

 1     std::vector<int> inliers;    //A vector that stores the index of points in a set of local points
 2     
 3     //Conduct RANSAC Plane fitting
 4     pcl::SampleConsensusModelPlane<PointT>::Ptr    model_p(new pcl::SampleConsensusModelPlane<PointT>(cloud));        //Objects for flat models
 5     pcl::RandomSampleConsensus<PointT> ransacP(model_p);
 6     ransacP.setDistanceThreshold(.1);        //Distance from plane is less than 0.1 As a local point
 7     ransacP.computeModel();                    //Perform random parameter estimation
 8     ransacP.getInliers(inliers);                //Store the estimated interior points
 9     pcl::copyPointCloud<PointT>(*cloud, inliers, *cloud_in);    //Copy all local points of the estimation model to cloud_in in
10     pcl::io::savePCDFile("./data/seg_RAN/RANSAC_building_1.pcd", *cloud_in);

Get:

After that, I want to iterate the patch fitting and segment it. I have problems in the index

So I came up with a more stupid way:

 

1 for (int i = 0; i < cloud->points.size(); i++)
2     {
3         std::vector<int>::iterator iter = find(inliers.begin(), inliers.end(), i);
4         if (iter == inliers.end())
5         {
6             cloud_out->points.push_back(cloud->points.at(i));
7         }
8     }

 

It's equivalent to writing a segmentation method.

Problems encountered in the process include:

Index of point cloud, write of ordered point cloud and unordered point cloud, uninstantiation of intelligent pointer

It is still unclear how to use indexes in PCL. For example: pointindexes, extractindexes, etc

If there is a small understanding of the partners want to inform, mutual help, common progress!

2019-04-12  19:04:34

Tags: C++ PCL less

Posted on Fri, 29 Nov 2019 16:31:16 -0500 by Joopy