码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2020-03-18 15:28:30      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:OLE   size   分割   arc   near   ISE   RoCE   inf   处理   

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

技术图片

 

 

方法: 欧式聚类(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;
}

 

 

 

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

标签:OLE   size   分割   arc   near   ISE   RoCE   inf   处理   

原文地址:https://www.cnblogs.com/xuhongfei0021/p/12517246.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!