用最小二乘法对点云进行平滑处理

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/kdtree/kdtree_flann.h>
#include <pcl/surface/mls.h>

int main() {
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
pcl::io::loadPCDFile("bun000.pcd",*cloud);
pcl::search::KdTree<pcl::PointXYZ>::Ptr tree (new pcl::search::KdTree<pcl::PointXYZ>);
pcl::PointCloud<pcl::PointNormal> normals;

//实例化最小二乘对象mls
pcl::MovingLeastSquares<pcl::PointXYZ,pcl::PointNormal> mls;
mls.setComputeNormals(true);
//设定参数
mls.setInputCloud(cloud);
mls.setPolynomialFit(true);
mls.setSearchMethod(tree);
mls.setSearchRadius(0.03);
//重建计算
mls.process(normals);
pcl::io::savePCDFile("bun000.mls.pcd",normals);
return 0;
}

结果输出对比

感谢您的阅读。 🙏 关于转载请看这里