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 cloud
shadowfilters.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 shadowfilters
shadowfilters.setNormals(cloud_normals);
//sets threshold
double shadowThreshold = 0.1;
shadowfilters.setThreshold(shadowThreshold);
//filters
pcl::PointCloud<pcl::PointXYZI>::Ptr outCloud(new pcl::PointCloud<pcl::PointXYZI>());
shadowfilters.filter(*outCloud);
cout << outCloud->points.size() << endl;
return outCloud;
}
耗时较高,怎么降低?
查看源码,分析耗时主要集中在计算法向量,检索了一下,可以加速的包含:
换pcl::kdtree->nanoflann还有openmmp
这篇文章测试openmmp没有作用:
【点云处理】点云法向量估计及其加速(2)_openex::pointnormal::ptr normal_cloud;_昌山小屋的博客-CSDN博客
【点云处理】点云法向量估计及其加速(5)_nanoflann_昌山小屋的博客-CSDN博客
GitHub - erikbern/ann-benchmarks: Benchmarks of approximate nearest neighbor libraries in Python
http://docs.ros.org/en/hydro/api/libnabo/html/index.html
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_filtered
return cloud_filtered;
}