输入:inputcloud(ptr)
输入:min_size(int) 最小点云数
输入:max_size(int) 最大点云数
输入:distance_thr(float) 聚簇距离阈值
输出:点云簇的ptr( vector<ptr> )
过程:先聚簇,再对每个簇进行点云提取
与halcon3d里面的算子 connection_object_model_3d是一样的
//根据距离对点云聚簇,并返回聚簇后的点云的ptr的集合vector
template<class point5>
vector<class pcl::PointCloud<point5>::Ptr> connection_cloud(class pcl::PointCloud<point5>::Ptr input_cloud, float distace_thr = 0.001, int min_size = 3000, int max_size = 999999999)
{
vector<pcl::PointCloud<point5>::Ptr> cloud_ptr_vector;
vector<pcl::PointIndices> cluster_indices;
pcl::EuclideanClusterExtraction<point5> euc_clu;
euc_clu.setInputCloud(input_cloud);
class pcl::search::KdTree < point5 >::Ptr tree(new pcl::search::KdTree < point5 >);
euc_clu.setSearchMethod(tree);
euc_clu.setClusterTolerance(distace_thr);//距离阈值
euc_clu.setMinClusterSize(min_size); //最小簇的点云数
euc_clu.setMaxClusterSize(max_size); //最大簇的点云数
euc_clu.extract(cluster_indices);
for (auto& indice : cluster_indices)
{
class pcl::PointCloud<point5>::Ptr cluster_p(new pcl::PointCloud<point5>);
pcl::ExtractIndices<point5> extract_index;
extract_index.setInputCloud(input_cloud);
pcl::PointIndices::Ptr index_ptr(new pcl::PointIndices);
*index_ptr = indice;
extract_index.setIndices(index_ptr);
extract_index.filter(*cluster_p);
cloud_ptr_vector.push_back(cluster_p);
}
return cloud_ptr_vector;
}