【点云重采样Resampling】Python-pcl 基于多项式平滑点云及法线估计的曲面重建

1. 点云重采样

基于多项式平滑点云及法线估计的曲面重建以实现重采样,可以使得点云数据更规整一些,没之前那么杂乱。

  • set_Compute_Normals(True) 可以通过在最小二乘法中进行法线估计,提高重采样准确度;
  • set_polynomial_fit(True) 可以通过不需要多项式拟合来加快平滑速度,设置为True则在整个算法运行时采用多项式拟合来提高精度;

2. 效果如下:

重建前:

正面:
在这里插入图片描述侧面:
在这里插入图片描述
重建后:

正面:
在这里插入图片描述
侧面:
在这里插入图片描述
可以看到重采样后点云的形状清晰了许多。

3. 源码

# -*- coding: utf-8 -*-
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
#  <基于多项式平滑点云及法线估计的曲面重建
   重采样,使得数据更规整一些,没之前那么杂乱>
   Smoothing and normal estimation based on polynomial reconstruction
   http://pointclouds.org/documentation/tutorials/resampling.php#moving-least-squares
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
import pcl

def main():
    # 加载点云
    cloud = pcl.load('D:/tests/examples/official/Surface/bun0.pcd')
    print('cloud(size) = ' + str(cloud.size))

    # 构建kd树
    tree = cloud.make_kdtree()
    # 重建
    mls = cloud.make_moving_least_squares()
    print('make_moving_least_squares')
    mls.set_Compute_Normals(True)  # 设置在最小二乘计算中需要进行法线估计
    mls.set_polynomial_fit(True)  # 可以通过不需要多项式拟合来加快平滑速度,设置为true时则在整个算法运行时采用多项式拟合来提高精度
    mls.set_Search_Method(tree)
    mls.set_search_radius(0.03)
    print('set parameters')
    mls_points = mls.process()

    print('mls_points(size) = ' + str(mls_points.size))

    # 存储重采样结果
    pcl.save_PointNormal(mls_points,
                         'D:/tests/examples/official/Surface/bun0-mls-nonormas.pcd')


if __name__ == "__main__":
    main()

参考:

猜你喜欢

转载自blog.csdn.net/qq_40985985/article/details/108446933