用区域生长方法进行平面分割

        pcl::PointCloud<pcl::PointXYZ>::Ptr cloudOriVox(new pcl::PointCloud<pcl::PointXYZ>);
		pcl::copyPointCloud(*cloudOri, *cloudOriVox);  //Ori的写到Vox里了

		pcl::search::Search<pcl::PointXYZ>::Ptr tree = boost::shared_ptr<pcl::search::Search<pcl::PointXYZ>>(new pcl::search::KdTree<pcl::PointXYZ>);//
		pcl::PointCloud<pcl::Normal>::Ptr normals(new pcl::PointCloud<pcl::Normal>);
		pcl::NormalEstimation<pcl::PointXYZ,pcl::Normal>normal_estimator;
		normal_estimator.setSearchMethod(tree);
		normal_estimator.setInputCloud(cloudOriVox);
		normal_estimator.setKSearch(50);
		normal_estimator.compute(*normals); //计算法线

		pcl::RegionGrowing<pcl::PointXYZ,pcl::Normal>reg; //建立区域增长的对象
		reg.setMinClusterSize(50); //平面包含的最少点数,小于这个数的平面会忽略不计
		reg.setMaxClusterSize(1000000); //包含的最大点数
		reg.setSearchMethod(tree); //设置搜索方法,使用kd树的方法,直接用(默认方法)
		reg.setNumberOfNeighbours(30); //设置搜索的邻域点数(看周围多少个点决定这是一个平面),数量太大可能会有点歪,数量太小
		reg.setInputCloud(cloudOriVox);  //输入要检测的点云
		reg.setInputNormals(normals);  //输入点云的法线
		reg.setSmoothnessThreshold(3.0 / 180.0*M_PI);  //设置判断的阈值(两个法线在多个夹角内还可以当做是共面的)
		reg.setCurvatureThreshold(1.0);  //弯曲的阈值,决定了比当前考察的点和平均的法线角度(具体看blog)

		std::vector<pcl::PointIndices>clusters;  //结果放到一个簇里,会自动把每个平面分成一个vector
		reg.extract(clusters);

		pcl::PointCloud<pcl::PointXYZRGB>::Ptr colored_cloudOriVox = reg.getColoredCloud();  //把检测到的每个平面涂上不同颜色
		pcl::visualization::CloudViewer viewer6("Cluster OriVox");
		viewer6.showCloud(colored_cloudOriVox);
		while (!viewer6.wasStopped())
		{

		}

pcl的几种点云分割的方法,上面是通过Region Growing,检测法线,几种点云分割方法见[添加链接描述]
https://blog.csdn.net/lizhengze1117/article/details/89034332
对于物体之间的转折处法线和曲率变化小的,算法比较难分割物体。如果点云有噪音,那就是灾难级的表现。而且算法对调参要求高,鲁棒性和普适性低。
适合分割四四方方的东西

代码解释参考
https://blog.csdn.net/liukunrs/article/details/80482788?utm_medium=distribute.pc_relevant.none-task-blog-baidujs-1
https://blog.csdn.net/u011021773/article/details/78941196

你可能感兴趣的:(用区域生长方法进行平面分割)