Lidar系列文章

传感器融合是将多个传感器采集的数据进行融合处理,以更好感知周围环境;这里首先介绍激光雷达的相关内容,包括激光雷达基本介绍(本节内容),激光点云数据处理方法(点云数据显示,点云分割,点云聚类,障碍物识别实例)等。

系列文章目录

1. 激光雷达基本介绍
2. 激光点云数据显示
3. 基于RANSAC的激光点云分割
4. 点云分割入门级实例学习
5. 激光点云目标物聚类
6. 基于PCL实现欧式聚类提取
7. 激光雷达障碍物识别


文章目录

  • Lidar系列文章
  • 基于PCL实现欧式聚类提取

基于PCL实现欧式聚类提取

本节我们将介绍如何用PCL EuclideanClusterExtraction类采用欧氏聚类对三维点云组成的场景进行分割。
原始点云如下:

#include <pcl/ModelCoefficients.h>
#include <pcl/point_types.h>
#include <pcl/io/pcd_io.h>
#include <pcl/filters/extract_indices.h>
#include <pcl/filters/voxel_grid.h>
#include <pcl/features/normal_3d.h>
#include <pcl/kdtree/kdtree.h>
#include <pcl/sample_consensus/method_types.h>
#include <pcl/sample_consensus/model_types.h>
#include <pcl/segmentation/sac_segmentation.h>
#include <pcl/segmentation/extract_clusters.h>int
main (int argc, char** argv)
{// Read in the cloud data 读入点云数据pcl::PCDReader reader;pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>), cloud_f (new pcl::PointCloud<pcl::PointXYZ>);reader.read ("../table_scene_lms400.pcd", *cloud);std::cout << "PointCloud before filtering has: " << cloud->points.size () << " data points." << std::endl; //*// Create the filtering object: downsample the dataset using a leaf size of 1cm 降采样pcl::VoxelGrid<pcl::PointXYZ> vg;pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered (new pcl::PointCloud<pcl::PointXYZ>);vg.setInputCloud (cloud);vg.setLeafSize (0.01f, 0.01f, 0.01f);vg.filter (*cloud_filtered);std::cout << "PointCloud after filtering has: " << cloud_filtered->points.size ()  << " data points." << std::endl; //*// Create the segmentation object for the planar model and set all the parameters SANSAC点云分割pcl::SACSegmentation<pcl::PointXYZ> seg;pcl::PointIndices::Ptr inliers (new pcl::PointIndices);pcl::ModelCoefficients::Ptr coefficients (new pcl::ModelCoefficients);pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_plane (new pcl::PointCloud<pcl::PointXYZ> ());pcl::PCDWriter writer;seg.setOptimizeCoefficients (true);seg.setModelType (pcl::SACMODEL_PLANE);seg.setMethodType (pcl::SAC_RANSAC);seg.setMaxIterations (100);seg.setDistanceThreshold (0.02);int i=0, nr_points = (int) cloud_filtered->points.size ();while (cloud_filtered->points.size () > 0.3 * nr_points){// Segment the largest planar component from the remaining cloudseg.setInputCloud (cloud_filtered);seg.segment (*inliers, *coefficients);if (inliers->indices.size () == 0){std::cout << "Could not estimate a planar model for the given dataset." << std::endl;break;}// Extract the planar inliers from the input cloud 提取平面点云pcl::ExtractIndices<pcl::PointXYZ> extract;extract.setInputCloud (cloud_filtered);extract.setIndices (inliers);extract.setNegative (false);// Write the planar inliers to diskextract.filter (*cloud_plane);std::cout << "PointCloud representing the planar component: " << cloud_plane->points.size () << " data points." << std::endl;// Remove the planar inliers, extract the rest 移去平面局内点,提取剩余点云extract.setNegative (true);extract.filter (*cloud_f);cloud_filtered = cloud_f;}// Creating the KdTree object for the search method of the extraction 点云提取//为提取点云时使用的搜索对象利用输入点云cloud_filtered创建Kd树对象treepcl::search::KdTree<pcl::PointXYZ>::Ptr tree (new pcl::search::KdTree<pcl::PointXYZ>);  tree->setInputCloud (cloud_filtered);//创建点云索引向量,用于存储实际的点云信息//创建一个点云索引向量cluster_indices,用于存储检测到的点云聚类的点云索引信息,如cluster_indices[0]包含点云中第一个聚类中的点集的所有索引。std::vector<pcl::PointIndices> cluster_indices;pcl::EuclideanClusterExtraction<pcl::PointXYZ> ec;  //创建一个点云类型为PointXYZ的欧氏聚类对象//设置提取的参数和变量ec.setClusterTolerance (0.02); // 设置近邻搜索的搜索半径为2cmec.setMinClusterSize (100);  //设置一个聚类所需要的最小点数目为100ec.setMaxClusterSize (25000);  //设置一个聚类需要的最大点数目为25000ec.setSearchMethod (tree);  //设置点云的搜索机制ec.setInputCloud (cloud_filtered);ec.extract (cluster_indices);  //从点云中提取聚类,并将点云索引保存在cluster_indices中//迭代访问点云索引cluster_indices,直到分割出所有聚类int j = 0;for (std::vector<pcl::PointIndices>::const_iterator it = cluster_indices.begin (); it != cluster_indices.end (); ++it){//创建新的点云数据集,将所有当前聚类写入到点云数据集中pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_cluster (new pcl::PointCloud<pcl::PointXYZ>);for (std::vector<int>::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<pcl::PointXYZ> (ss.str (), *cloud_cluster, false); //*j++;}return (0);
}
./cluster_extraction PointCloud before filtering has: 460400 data points.
PointCloud after filtering has: 41049 data points.
PointCloud representing the planar component: 20536 data points.
PointCloud representing the planar component: 12442 data points.
PointCloud representing the Cluster: 4857 data points.
PointCloud representing the Cluster: 1386 data points.
PointCloud representing the Cluster: 321 data points.
PointCloud representing the Cluster: 291 data points.
PointCloud representing the Cluster: 123 data points.

分割结果如下:


资源链接:点云分割入门级实例学习

参考:
《点云库PCL从入门到精通》第十二章入门级实例解析。

基于PCL实现欧式聚类提取相关推荐

  1. PCL 快速欧式聚类(FEC)

    文章目录 一.简介 二.实现代码 三.实现效果 参考资料 一.简介 应一位同学的要求,出一版PCL的快速欧式聚类(FEC),该方法的具体原理可以参阅之前的博客:CloudCompare&PCL ...

  2. 点云PCL学习笔记-分割segmentation-RANSAC随机采样一致性算法欧式聚类提取

    随机采样一致性算法RANSAC 程序实例参考网址: https://pcl.readthedocs.io/projects/tutorials/en/latest/random_sample_cons ...

  3. 【点云处理技术之PCL】点云分割算法1——平面模型分割、圆柱模型分割和欧式聚类提取(含欧式聚类原理)

    文章目录 1. 平面分割 2. 圆柱分割 3. 欧式聚类分割 1. 平面分割 下列中,先随机创建了z=1.0的随机点,然后改变其中3个点的z值.最后,使用SACMODEL_PLANE平面模型对它进行拟 ...

  4. 基于python的K-means聚类提取图片主色

    基于python+opencv的彩色图片主色提取--利用K-means聚类算法 一.K-means聚类算法 1.K-means算法原理 2. K-means聚类算法流程 3.sklearn库中skle ...

  5. 基于欧式聚类的车载路面点云扫描线提取

    文章目录 1 扫描线示意图 2 基于欧式聚类的车载路面点云扫描线提取 3 实验结果分析 1 扫描线示意图 车载激光扫描系统主要的扫描方式为线形扫描[方莉娜,等:车载激光扫描数据的结构化道路自动提取方法 ...

  6. PCL点云库学习笔记 点云的欧式聚类

    欧式聚类详解(点云数据处理) 欧式聚类是一种基于欧氏距离度量的聚类算法.基于KD-Tree的近邻查询算法是加速欧式聚类算法的重要预处理方法. KD-Tree最近邻搜索 Kd-树是K-dimension ...

  7. 【点云处理】基于欧式聚类的点云分割

    对于范围较广的点云来说,一开始先使用基于模型的点云分割方法将类似于平面这样的点云块提出来,然后在对留下的小部分点云进行像欧式聚类这样的后续分割处理. 原始点云: 代码,对代码的理解都注释上了,以便于以 ...

  8. pcl聚类----欧式聚类分割方法

    欧式聚类分割方法 欧式聚类是一种基于欧氏距离度量的聚类算法 流程如下: 对于欧式聚类来说,距离判断准则为前文提到的欧氏距离.对于空间某点P,通过KD-Tree近邻搜索算法找到k个离p点最近的点,这些点 ...

  9. PCL点云库学习笔记(3):点云的欧式聚类

    初学者笔记: 点云欧式聚类算法流程 (1)点云读入: (2)体素化下采样(方便处理): (3)去离散点: (4)RANSAC算法检测平面,并剔除平面点云: (5)欧式聚类: (6)结果的输出和可视化: ...

最新文章

  1. numpy 数组 保留小数点后两位小数
  2. php与mysql字符集,php与mysql字符集编码问题
  3. python 优先队列_Python中heapq与优先队列【详细】
  4. oracle11g迁移到12cpdb,12c跨平台完成PDB的备份迁移
  5. 【收藏】电气设计相关计算公式大全(附举例)
  6. .NET for Apache Spark 1.0 版本发布
  7. DynamoRIO工作原理
  8. 自由响应和强迫响应和零输入零状态_零偏移有源低通滤波器,第1部分
  9. 游戏开发之extern “C“、内存申请及匿名函数(lambda)(C++基础)
  10. 数据结构——>数组模拟环形队列
  11. Camtasia怎么添加文字效果
  12. 注册谷歌账号,提示“此电话号码无法用于进行验证”
  13. 安卓APP应用启动流程详解
  14. 自己整理的申论知识体系梳理分享
  15. 有关于fprintf()函数的用法
  16. 爬取QQ空间说说日志、好友个人信息并进行加密
  17. ★三个和尚与机构臃肿的故事
  18. 【U8】凭证上修改使用自定义项科目的辅助信息
  19. 使用 SAP UI5 Smart Chart 控件轻松绘制十数种不同类型的专业图表试读版
  20. iis7无法写入配置文件,更换进入方式解决

热门文章

  1. 前大灯是近光灯还是远光灯_大快人心!仙游交警启动监控抓拍滥用远光灯车辆!...
  2. java有趣的平方数_JAVA小程序之独特的完全平方数问题
  3. mac怎么查node版本_py2neo基本操作(v4版本,亲测有效)
  4. Linux系统NFS什么意思,挂载NFS到底是什么概念
  5. python如何统计累计每日的人数‘’_Python数据分析2019陕西高考(理工)成绩及填报志愿...
  6. hysys动态模拟教程_Steam特别好评!新游《模拟消防英豪》现已上市
  7. LCT模板(无讲解)
  8. STM32F407之常识
  9. Jquery全选单选功能
  10. 使用 WorkflowIdentity 和版本控制