1.统计滤波,去除离群点
#include <pcl\filters\\statistical_outlier_removal.h> #include <iostream> #include <pcl\io\pcd_io.h> #include <pcl\point_types.h> #include <pcl\visualization\cloud_viewer.h> int main() { pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>); if (pcl::io::loadPCDFile<pcl::PointXYZ>("F:\\BaiduNetdiskDownload\\pcl\\desk.pcd", *cloud) == -1) { PCL_ERROR("Couldn't read file rabbit.pcd\n"); return(-1); } std::cout << "Loaded:" << cloud->width*cloud->height << "data points from test_pcd.pcd with the following fields:" << std::endl; /*for (size_t i = 0; i < cloud->points.size(); ++i) { std::cout << " " << cloud->points[i].x << " " << cloud->points[i].y << " " << cloud->points[i].z << " " << std::endl; }*/ // 统计滤波 // 创建滤波器,对每个点分析的临近点的个数设置为50 ,并将标准差的倍数设置为1 这意味着如果一 // 个点的距离超出了平均距离一个标准差以上,则该点被标记为离群点,并将它移除 pcl::StatisticalOutlierRemoval<pcl::PointXYZ> sor; // 创建滤波器对象 sor.setInputCloud(cloud); // 设置待滤波的点云 sor.setMeanK(50); // 设置在进行统计时考虑查询点临近点数 sor.setStddevMulThresh(1); // 设置判断是否为离群点的阀值 sor.filter(*cloud); // 过滤 // 存储 pcl::io::savePCDFileBinary("desk-sor.pcd", *cloud); // 显示 pcl::visualization::CloudViewer viewer("cloud viewer"); viewer.showCloud(cloud); while (!viewer.wasStopped()) { } system("pause"); return 0; }View Code