---
title: "PCL 移动最小二乘法：点云平滑与法线估计"
author: "Perrin Yong"
author_profile: https://www.pystone.net/profile/
published_by: "Perrin Yong"
canonical: https://www.pystone.net/notes/pcl-mls-surface-reconstruction/
type: note
content_role: unspecified
visibility: public
id_stability: rename-stable
source_path: "10-计算机、信息技术与工程/08-图形学与三维重构/PCL移动最小二乘法表面重建（转载）.md"
content_hash: 6a7d7f5ea4634c1d4aeb84f42da73e9b19b09e12cbb49324fc3a8c930ff4d098
knowledge_version: 224c990773de.5fa8af6e39fa
site_commit: 224c990773de166d23a886306577dd90379529ce
notes_commit: 5fa8af6e39fa3891d1b9b4832bfa6c4e0ecaaf0a
---
# PCL 移动最小二乘法：点云平滑与法线估计

> **note · 来源与许可**
> 旧稿是 2014 年 CSDN 文章转载，导出内容未保留明确转载许可，故原转载已移入私有来源归档。本文是依据 PCL 官方教程重新编写的独立摘要；示例接口以 PCL 当前文档为准。PCL 项目使用 BSD 许可证。

## MLS 解决什么问题

移动最小二乘法（Moving Least Squares, MLS）在每个采样点的局部邻域拟合平滑曲面，并把点投影到局部曲面上。它常用于：

- 降低扫描噪声造成的局部起伏；
- 对点云重采样；
- 同时估计平滑后的法线；
- 为后续三角化提供更一致的点和法线。

MLS 输出的核心仍是点云（可包含法线），不会仅凭这一步生成三角网格。

## 基本流程

```cpp
#include <pcl/point_types.h>
#include <pcl/search/kdtree.h>
#include <pcl/surface/mls.h>

using InputPoint = pcl::PointXYZ;
using OutputPoint = pcl::PointNormal;

pcl::PointCloud<InputPoint>::Ptr input(new pcl::PointCloud<InputPoint>);
pcl::PointCloud<OutputPoint> output;

pcl::search::KdTree<InputPoint>::Ptr tree(
    new pcl::search::KdTree<InputPoint>);

pcl::MovingLeastSquares<InputPoint, OutputPoint> mls;
mls.setInputCloud(input);
mls.setSearchMethod(tree);
mls.setSearchRadius(0.03);  // 应按点间距与几何尺度调参
mls.setComputeNormals(true);
mls.process(output);
```

具体接口会随 PCL 版本变化，编译时应核对当前头文件和官方示例。

## 参数与边界

- **搜索半径**过小：邻域点不足，拟合不稳定或出现空洞。
- **搜索半径**过大：跨越尖锐边缘或薄壁两侧，细节被抹平。
- **多项式阶数**越高不等于越准确，噪声、采样密度和计算成本都会影响结果。
- 离群点会扭曲局部拟合，通常先进行统计或半径离群点过滤。
- 点云密度变化剧烈、存在大孔洞或薄结构时，应分区调参并与原始数据对照。

## 验证方式

1. 记录点间距分布，以它为搜索半径的尺度依据。
2. 在平面、曲面、尖锐边缘和稀疏区域分别抽样可视化。
3. 比较点到原始数据/参考表面的距离，而不只看“更光滑”。
4. 检查法线方向一致性及后续网格的孔洞、自交和错误连接。

## 参考资料

- [PCL 官方教程：Smoothing and normal estimation based on polynomial reconstruction](https://pointclouds.org/documentation/tutorials/resampling.html)
- [PCL BSD License](https://github.com/PointCloudLibrary/pcl/blob/master/LICENSE.txt)
