PCL点云库滤波器模块学习笔记

一、直通滤波器

1.头文件:#include<pcl/filters/passthrough.h>

2.pcl::PassThrough<PoinT>类下的常用函数调用:

pcl::PassThrough<PointType> ptfilter (true);  // 此处true表示允许提取去除点的索引,false表示不允许提取,一般情况下不加括号这一部分
ptfilter.setInputCloud (cloud_in);            //输入点云对象
ptfilter.setFilterFieldName ("x");            //设置滤波器维度名称,根据PoinT点云类型中含有的维度,如XYZ intensity等
ptfilter.setFilterLimits (0.0, 1000.0);设置滤波维度数据的取值范围
ptfilter.filter (*indices_x);
// The indices_x array indexes all points of cloud_in that have x between 0.0 and 1000.0
indices_rem = ptfilter.getRemovedIndices ();
// The indices_rem array indexes all points of cloud_in that have x smaller than 0.0 or larger than 1000.0
// and also indexes all non-finite points of cloud_in
ptfilter.setIndices (indices_x);
ptfilter.setFilterFieldName ("z");
ptfilter.setFilterLimits (-10.0, 10.0);
ptfilter.setNegative (true);                  //此处如果设置为true,则返回的是取值范围外的点集;如果设置为false,则是返回取值范围内的点集,默认值为取值范围内的,false
ptfilter.filter (*indices_xz);
// The indices_xz array indexes all points of cloud_in that have x between 0.0 and 1000.0 and z larger than 10.0 or smaller than -10.0
ptfilter.setIndices (indices_xz);
ptfilter.setFilterFieldName ("intensity");
ptfilter.setFilterLimits (FLT_MIN, 0.5);
ptfilter.setNegative (false);
ptfilter.filter (*cloud_out);
// The resulting cloud_out contains all points of cloud_in that are finite and have:
// x between 0.0 and 1000.0, z larger than 10.0 or smaller than -10.0 and intensity smaller than 0.5.

3.适用场景:去除高于车载激光雷达的点集


二、VoxelGrid滤波器

1.头文件:#include <pcl/filters/voxel_grid.h>

2.pcl::VoxelGrid< PointT>类下的常用函数调用:

  pcl::VoxelGrid<pcl::PCLPointCloud2> sor;   //创建滤波对象,利用VoxelGrid类及类中的有关函数
  sor.setInputCloud (cloud);                 //设置需要过滤的点云给滤波对象
  sor.setLeafSize (0.01f, 0.01f, 0.01f);     //设置滤波时创建的体素体积为1cm的立方体
  sor.filter (*cloud_filtered);              //执行滤波处理,存储输出

3.适用场景:各种点云的降采样


三、StatisticalOutlierRemoval滤波器

1.头文件:#include <pcl/filters/statistical_outlier_removal.h>

2.pcl::StatisticalOutlierRemoval< PointT >类下的常用函数调用:

// 创建滤波器,对每个点分析的临近点的个数设置为8 ,并将标准差的倍数设置为1  这意味着如果一个点的距离超出了平均距离一个标准差以上,则该点被标记为离群点,并将它移除

pcl::StatisticalOutlierRemoval<PointType> sorfilter (true);  //创建滤波器对象,true允许提取去除的点 
sorfilter.setInputCloud (cloud_in);                          //输入待滤波点云
sorfilter.setMeanK (8);                                      //设置在进行统计时考虑查询点临近点数
sorfilter.setStddevMulThresh (1.0);                          //设置判断是否为离群点的阈值
sorfilter.filter (*cloud_out);                               //输出保存滤波后的点云
// The resulting cloud_out contains all points of cloud_in that have an average distance to their 8 nearest neighbors that is below the computed threshold
// Using a standard deviation(标准差) multiplier of 1.0 and assuming the average distances are normally distributed there is a 84.1% chance that a point will be an inlier
indices_rem = sorfilter.getRemovedIndices ();                //输出保存滤掉的点集
// The indices_rem array indexes all points of cloud_in that are outliers

3.适用场景:离群点去除通用


四、参数化模型滤波

1.头文件:

模型系数头文件:#include <pcl/ModelCoefficients.h> 

投影滤波类头文件:#include <pcl/filters/project_inliers.h>

2.pcl::ModelCoefficients类下的常用参数赋值(构建参数化模型):

//填充ModelCoefficients的值,使用ax+by+cz+d=0平面模型,其中 a=b=d=0,c=1 也就是X——Y平面

  pcl::ModelCoefficients::Ptr coefficients (new pcl::ModelCoefficients ());  
//定义模型系数对象,并填充对应的数据。此处注意模型系数对象为指针对象,要与new搭配使用,调用指针对象参数使用“->”
  coefficients->values.resize (4);   //四个模型系数,abcd,0123,从0开始排
  coefficients->values[0] = coefficients->values[1] = 0;
  coefficients->values[2] = 1.0;
  coefficients->values[3] = 0;

3.pcl::ProjectInliers<PointT>类下的常用函数调用(投影滤波):

// 创建ProjectInliers对象,使用ModelCoefficients作为投影对象的模型参数

  pcl::ProjectInliers<pcl::PointXYZ> proj;      //创建投影滤波对象
  proj.setModelType (pcl::SACMODEL_PLANE);      //设置对象对应的投影模型
  proj.setInputCloud (cloud);                   //设置输入点云
  proj.setModelCoefficients (coefficients);     //设置模型对应的系数
  proj.filter (*cloud_projected);               //投影结果存储cloud_projected

4.适用场景:???


五、ConditionalRemoval滤波器

1.头文件:#include <pcl/filters/conditional_removal.h> 

2.pcl::ConditionalRemoval< PointT >类下的常用参数赋值

        ConditionalRemoval滤波器必须为其提供一个滤波条件,滤波条件主要分为两种, ConditionAnd 和 ConditionOr,每个条件需要包括一个或多个对比或者其他条件,其中一个对比条件需要包括一个名称、对比操作和对比参数值。

        ConditionAnd,如果所有的对比或条件都为真,则结果为真;

        ConditionOr。如果任何一个对比条件为真,则结果为真。

pcl::ConditionAnd<PointT>::Ptr range_cond (new pcl::ConditionAnd<PointT> ());//建立条件(注意,为指针类型,格式直接复制,我也不知道什么意思)
range_cond->addComparison (pcl::FieldComparison<PointT>::Ptr (new pcl::FieldComparison<PointT>("z", pcl::ComparisonOps::LT, 2.0)));//添加比较算子利用pcl::ComparisonOps类中的LT,在z字段上小于2.0
range_cond->addComparison (pcl::FieldComparison<PointT>::Ptr (new pcl::FieldComparison<PointT>("z", pcl::ComparisonOps::GT, 0.0)));//添加比较算子利用pcl::ComparisonOps类中的GT,在z字段上大于0.0

pcl::ConditionalRemoval<PointT> range_filt;//创建滤波器对象
range_filt.setCondition (range_cond);      //输入滤波条件
range_filt.setInputCloud(cloud);           //输入原始点云
range_filt.setUserFilterValue(float val);  //设置去滤除点的值,默认为NAN
range_filt.setKeepOrganized (false);       //设置是否保留滤波后删除的点,true为保留滤除点,滤除点按照setUserFilterValue中的设置取值,false为删除滤除点

3.适用场景:去除高于车载激光雷达的点集


六、RadiusOutlierRemoval滤波器

1.头文件:#include <pcl/filters/radius_outlier_removal.h>

2.pcl::RadiusOutlierRemoval< PointT >类下的常用函数调用:

pcl::RadiusOutlierRemoval<PointType> rorfilter (true);  //创建滤波器对象,允许提取滤除点
rorfilter.setInputCloud (cloud_in);                     //输入原始点云
rorfilter.setRadiusSearch (0.1);                        //设置搜索半径,在半径0.1范围内寻找临近点
rorfilter.setMinNeighborsInRadius (5);                  //设置查询点的邻域点集数小于5的删除
rorfilter.setNegative (true);                           //输出滤波结果为范围内的点集
rorfilter.filter (*cloud_out);                          //输出滤波后的点云

// The resulting cloud_out contains all points of cloud_in that have 4 or less neighbors within the 0.1 search radius
indices_rem = rorfilter.getRemovedIndices ();           //提取滤除点
// The indices_rem array indexes all points of cloud_in that have 5 or more neighbors within the 0.1 search radius

3.适用场景:去除离群点


  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值