欧式聚类流程如下:
设置一个合适的聚类搜索半径Cluster-Tolerance很重要,如果半径过小,那么会分割出多个对象,如果设置太高会造成多个对应聚类到成一个,因此需要测试找到合适的搜索半径。
#include #include #include #include pcl::PointCloud::Ptr cloud_filtered (new pcl::PointCloud);// Creating the KdTree object for the search method of the extractionpcl::search::KdTree::Ptr tree (new pcl::search::KdTree); tree->setInputCloud (cloud_filtered);std::vector cluster_indices; pcl::EuclideanClusterExtraction ec; ec.setClusterTolerance (0.02); //设置近邻搜索的搜索半径2cmec.setMinClusterSize (100); //设置一个聚类需要的最少点数目ec.setMaxClusterSize (25000); //设置一个聚类需要的最大数目ec.setSearchMethod (tree); //设置点云的搜索方法ec.setInputCloud (cloud_filtered); ec.extract (cluster_indices); //从点云中提取聚类并保存到cluster_indices中//保存聚类后的点到磁盘int j = 0;for (std::vector::const_iterator it = cluster_indices.begin (); it != cluster_indices.end (); ++it) { pcl::PointCloud::Ptr cloud_cluster (new pcl::PointCloud); for (std::vector::const_iterator pit = it->indices.begin (); pit != it->indices.end (); ++pit) cloud_cluster->points.push_back (cloud_filtered->points[*pit]); //* cloud_cluster->width = cloud_cluster->points.size (); cloud_cluster->height = 1; cloud_cluster->is_dense = true; std::cout << "PointCloud representing the Cluster: " << cloud_cluster->points.size () << " data points." << std::endl; std::stringstream ss; ss << "cloud_cluster_" << j << ".pcd"; writer.write (ss.str (), *cloud_cluster, false); //* j++; }
人工智能 大数据 AI
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。