pcl 滤波
pcl::ShadowPoints
去除边缘不连续点云
#include <pcl/filters/shadowpoints.h>
#include <pcl/features/normal_3d.h>pcl::PointCloud<pcl::PointXYZI>::Ptr ShadowsCloudFilter(pcl::PointCloud<pcl::PointXYZI>::Ptr cloud)
{pcl::ShadowPoints<pcl::PointXYZI, pcl::Normal> shadowfilters(true);//sets the source point cloudshadowfilters.setInputCloud(cloud->makeShared());pcl::NormalEstimation<pcl::PointXYZI, pcl::Normal> ne;ne.setInputCloud(cloud->makeShared());pcl::search::KdTree<pcl::PointXYZI>::Ptr tree(new pcl::search::KdTree<pcl::PointXYZI>());ne.setSearchMethod(tree);pcl::PointCloud<pcl::Normal>::Ptr cloud_normals(new pcl::PointCloud<pcl::Normal>);double normalsThreshold = 100;ne.setRadiusSearch(normalsThreshold);ne.compute(*cloud_normals);//sets normals into shadowfiltersshadowfilters.setNormals(cloud_normals);//sets thresholddouble shadowThreshold = 0.1;shadowfilters.setThreshold(shadowThreshold);//filterspcl::PointCloud<pcl::PointXYZI>::Ptr outCloud(new pcl::PointCloud<pcl::PointXYZI>());shadowfilters.filter(*outCloud);cout << outCloud->points.size() << endl;return outCloud;
}
pcl::StatisticalOutlierRemoval
统计滤波: 去除小部分杂点,留下大部分点
#include <pcl/filters/statistical_outlier_removal.h>pcl::PointCloud<pcl::PointXYZI>::Ptr FilterCloud(pcl::PointCloud<pcl::PointXYZI>::Ptr cloud)
{pcl::PointCloud<pcl::PointXYZI>::Ptr cloud_filtered(new pcl::PointCloud<pcl::PointXYZI>);cout << "->正在进行统计滤波..." << endl;pcl::StatisticalOutlierRemoval<pcl::PointXYZI> sor; //创建滤波器对象sor.setInputCloud(cloud); //设置待滤波点云sor.setMeanK(50); //设置查询点近邻点的个数sor.setStddevMulThresh(0.1); //设置标准差乘数,来计算是否为离群点的阈值//sor.setNegative(true); //默认false,保存内点;true,保存滤掉的离群点sor.filter(*cloud_filtered); //执行滤波,保存滤波结果于cloud_filteredreturn cloud_filtered;
}