激光雷达点云处理:直通滤波、体素降采样、欧式聚类、boundingbox

       初接触ROS的小白一枚,借鉴PCL官方以及Adam大佬的内容,好不容易跑通了这一套处理点云的代码,在此做一下记录。

一、直通滤波:

PCL官方提供的代码使用通过过滤点云库 0.0 文档过滤点云云 (pcl.readthedocs.io)

以及借鉴的一篇CSDN文章(5条消息) PCL点云滤波:直通滤波PassThrough(简单卡阈值留点)和适用场景_手口一斤-CSDN博客

对z轴、y轴上的点云进行直通滤波:

void
cloud_cb (const sensor_msgs::PointCloud2ConstPtr& cloud_msg)
{
  // Container for original & filtered data
  pcl::PCLPointCloud2* cloud = new pcl::PCLPointCloud2;
  pcl::PCLPointCloud2ConstPtr cloudPtr(cloud);
  pcl::PCLPointCloud2* cloud_filtered = new pcl::PCLPointCloud2;
  pcl::PCLPointCloud2ConstPtr passPtr(cloud_filtered);

  // Convert to PCL data type
  pcl_conversions::toPCL(*cloud_msg, *cloud);

  // Perform the actual filtering
  pcl::PassThrough<pcl::PCLPointCloud2> pass;
    // build the filter
  pass.setInputCloud (cloudPtr);
  pass.setFilterFieldName ("y");
  pass.setFilterLimits (-5.0, 16.0);
    // apply filter
  pass.filter (*cloud_filtered);


 // Perform the actual filtering
  pcl::PassThrough<pcl::PCLPointCloud2> passz;
    // build the filter
  passz.setInputCloud (passPtr);
  passz.setFilterFieldName ("z");
  passz.setFilterLimits (-0.9, 20.0);
    // apply filter
  passz.filter (*cloud_filtered);


// Convert to ROS data type
  sensor_msgs::PointCloud2 cloud_pt;
  pcl_conversions::moveFromPCL(*cloud_filtered, cloud_pt);


  // Publish the data
  pub.publish (cloud_pt);
}

二、降采样

PCL官方提供的代码使用 VoxelGrid 过滤器对点云进行下采样 - 点云库 0.0 文档 (pcl.readthedocs.io)

void
cloud_cb (const sensor_msgs::PointCloud2ConstPtr& cloud_msg)
{
  // Container for original & filtered data
  pcl::PCLPointCloud2* cloud = new pcl::PCLPointCloud2;
  pcl::PCLPointCloud2ConstPtr cloudPtr(cloud);
  pcl::PCLPointCloud2 cloud_filtered;

  // Convert to PCL data type
  pcl_conversions::toPCL(*cloud_msg, *cloud);

  // Perform the actual filtering
    pcl::VoxelGrid<pcl::PCLPointCloud2> sor;
    // build the filter
    sor.setInputCloud (cloudPtr);
    sor.setLeafSize (0.5, 0.5, 0.5);
    // apply filter
    sor.filter (cloud_filtered);

  // Convert to ROS data type
  sensor_msgs::PointCloud2 cloud_vog;
  pcl_conversions::moveFromPCL(cloud_filtered, cloud_vog);

  // Publish the data
  pub.publish (cloud_vog);
}

三、欧式聚类和boundingbox

借鉴了Adam大佬的一篇博客(5条消息) 无人驾驶汽车系统入门(二十五)——基于欧几里德聚类的激光雷达点云分割及ROS实现_AdamShan的博客-CSDN博客

 四、总结

编写launch文件运行上述cpp文件的几个节点,最后出来的效果如上图。

 受实验环境影响,boundingbox的效果一般。

还需要继续努力呀!!


版权声明:本文为WWJ990729原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。