激光点云处理--聚类(Clustering)

Posted xuhongfei0021

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了激光点云处理--聚类(Clustering)相关的知识,希望对你有一定的参考价值。

问题:已经分割出地面,如何在剩余的点云中对不同的障碍物点云进行聚类?

技术图片

 

 

方法: 欧式聚类(Euclidean Clustering)

步骤:

技术图片

 

注:上流程中,使用KD-Tree来加速寻找nearest point

聚类结果(添加 bounding box):

技术图片

 

 

 

 代码:

//enviroment.cpp

    //cluster
    std::vector<pcl::PointCloud<pcl::PointXYZ>::Ptr> my_cluster_vector;
    my_cluster_vector=my_processor->Clustering(seg_cloud_pair.second,1,3,30);
    std::vector<Color> Colors = {Color(255,0,0),Color(0,255,0),Color(0,0,255)};
    int clusterid = 0;
    for(pcl::PointCloud<pcl::PointXYZ>::Ptr cluster: my_cluster_vector){
        std::cout<<"size of cluster"+std::to_string(clusterid)<<":";
        my_processor->numPoints(cluster);
        renderPointCloud(viewer, cluster, "obcluster"+std::to_string(clusterid), Colors[clusterid % Colors.size()]);

        Box box = my_processor->BoundingBox(cluster);
        renderBox(viewer,box,clusterid,Color(0,20,20));
        clusterid++;
    }
//ProcressPointClouds.cpp

template<typename PointT>
std::vector<typename pcl::PointCloud<PointT>::Ptr> ProcessPointClouds<PointT>::Clustering(typename pcl::PointCloud<PointT>::Ptr cloud, float clusterTolerance, int minSize, int maxSize)
{

    // Time clustering process
    auto startTime = std::chrono::steady_clock::now();

    std::vector<typename pcl::PointCloud<PointT>::Ptr> clusters;

    // TODO:: Fill in the function to perform euclidean clustering to group detected obstacles
    typename  pcl::search::KdTree<PointT>::Ptr tree (new pcl::search::KdTree<PointT>);
    tree->setInputCloud (cloud);
    std::vector<pcl::PointIndices> cluster_indices;
    pcl::EuclideanClusterExtraction<PointT> ec;
    ec.setClusterTolerance (clusterTolerance); // 2cm
    ec.setMinClusterSize (minSize);
    ec.setMaxClusterSize (maxSize);
    ec.setSearchMethod (tree);
    ec.setInputCloud (cloud);
    ec.extract (cluster_indices);
    for(auto x:cluster_indices)
    {
        typename pcl::PointCloud<PointT>::Ptr cloud_temp(new pcl::PointCloud<PointT>);
        for(auto p:x.indices)
        {
            cloud_temp->points.push_back(cloud->points[p]);
        }
        clusters.push_back(cloud_temp);
    }

    auto endTime = std::chrono::steady_clock::now();
    auto elapsedTime = std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime);
    std::cout << "clustering took " << elapsedTime.count() << " milliseconds and found " << clusters.size() << " clusters" << std::endl;

    return clusters;
}

 

 

 

以上是关于激光点云处理--聚类(Clustering)的主要内容,如果未能解决你的问题,请参考以下文章

Python+vtk 实现激光点云数据可视化学习(2021.7.12)

自动驾驶激光点云 3D 目标检测 PointPillar 论文简述

自动驾驶激光点云 3D 目标检测 PointPillar 论文简述

激光slam学习笔记2--激光点云数据结构特点可视化查看

基于全景图像与激光点云配准的彩色点云生成算法(2014年文章)

自动驾驶激光点云 3D 目标检测 VoxelNet 论文简述