当前点云分割方法主要分为:①聚类分割;②基于随机采样一致性(RANSAC)的分割;
基于欧式聚类的点云分割
pcl::PointIndices::Ptr indices(new pcl::PointIndices);
//创建欧式聚类对象
pcl::EuclideanClusterExtraction<pcl::PointXYZ> ec;
//参数配置
ec.setClusterTolerance(0.02);
ec.setMinClusterSize(100);
ec.setMaxClustersize(5000);
ec.setSearchMethod(tree);
ec.setInputCloud(cloud0);
//提取聚类对象
ec.extract(indices);
基于随机采样一致性的平面分割
//创建分割模型对象
pcl::ModelCoefficients::Ptr coefficients(new pcl::ModelCoefficients);
pcl::PointIndices::Ptr inliers(new pcl::PointIndices);
pcl::SACSegmentation<pcl::PointXYZ> seg;
//配置模型参数
seg.setModelType(pcl::SACMODEL_PLANE);
seg.setMethodType(pcl::SAC_RANSAC);
seg.setDistanceThreshold(0.01);
seg.setInputCloud(cloud0);
//执行分割
seg.segment(*inliers,*coefficients);
//创建提取对象
pcl::ExtractIndices<pcl::PointXYZ> extract;
//提取平面点云
extract.setInputCloud(cloud0);
extract.setIndices(inliers);
extract.setNegative(false);
extract.filter(cloud_plane);
基于区域生长的分割
//创建区域生长分割对象
pcl::RegionGrowing<pcl::PointXYZ,pcl::Normal> reg;
//模型参数设置
reg.setMinClusterSize(100);
reg.setMaxClusterSize(5000);
reg.setSearchMethod(tree);
reg.setIndices(indices);
reg.setInputNormals(normals);
reg.setSmoothnessThreshold(SmoothnessThreshold/180.0*M_PI);
reg.setCurvatureThreshold(CurvatureThreshold);
//分割
std::vector<pcl::PointIndices> clusters;
reg.extract(clusters);
还有基于点云颜色的分割、基于最小图割的分割、基于超体素的分割等