激光扫描通常会生成不同点密度的点云数据集。此外,测量误差会导致稀疏异常值,从而进一步破坏结果。这会使局部点云特征(例如表面法线或曲率变化)的估计复杂化,从而导致错误的值,进而可能导致点云配准失败。其中一些不规则性可以通过对每个点的邻域进行统计分析并修剪不符合特定标准的那些来解决。我们的稀疏异常值去除基于输入数据集中点到邻居距离分布的计算。对于每个点,我们计算从它到所有邻居的平均距离。通过假设结果分布是具有均值和标准偏差的高斯分布。
首先,下载数据集table_scene_lms400.pcd
一、StatisticalOutlierRemoval
创建startistical_remove.cpp文件
源码:
1#include <iostream>
2#include <pcl/io/pcd_io.h>
3#include <pcl/point_types.h>
4#include <pcl/filters/statistical_outlier_removal.h>
5
6int
7main ()
8{
9 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
10 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered (new pcl::PointCloud<pcl::PointXYZ>);
11
12 // Fill in the cloud data
13 pcl::PCDReader reader;
14 // Replace the path below with the path where you saved your file
15 reader.read<pcl::PointXYZ> ("table_scene_lms400.pcd", *cloud);
16
17 std::cerr << "Cloud before filtering: " << std::endl;
18 std::cerr << *cloud << std::endl;
19
20 // Create the filtering object
21 pcl::StatisticalOutlierRemoval<pcl::PointXYZ> sor;
22 sor.setInputCloud (cloud);
23 sor.setMeanK (50);
24 sor.setStddevMulThresh (1.0);
25 sor.filter (*cloud_filtered);
26
27 std::cerr << "Cloud after filtering: " << std::endl;
28 std::cerr << *cloud_filtered << std::endl;
29
30 pcl::PCDWriter writer;
31 writer.write<pcl::PointXYZ> ("table_scene_lms400_inliers.pcd", *cloud_filtered, false);
32
33 sor.setNegative (true);
34 sor.filter (*cloud_filtered);
35 writer.write<pcl::PointXYZ> ("table_scene_lms400_outliers.pcd", *cloud_filtered, false);
36
37 return (0);
38}
说明:
1、所需要的头文件,创建点云对象
1#include <iostream>
2#include <pcl/io/pcd_io.h>
3#include <pcl/point_types.h>
4#include <pcl/filters/statistical_outlier_removal.h>
5
6int
7main ()
8{
9 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
10 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered (new pcl::PointCloud<pcl::PointXYZ>);
2、 读取点云信息
// Fill in the cloud data
pcl::PCDReader reader;
// Replace the path below with the path where you saved your file
reader.read<pcl::PointXYZ> ("table_scene_lms400.pcd", *c