[python][pcl]python-pcl案例之基于多项式重构的平滑和正态估计重采样

该代码示例演示了如何在Python中利用PCL库(版本1.12.1)对点云数据进行移动最小二乘(MLS)平滑处理并估计法向量。首先加载bun0.pcd文件,然后创建KD-Tree以便搜索,接着设置MLS参数如搜索半径,并执行处理。最后,保存处理后的点云数据到bun0-mls.pcd文件。
摘要由CSDN通过智能技术生成

测试环境:

pcl==1.12.1

python-pcl==0.3.1

python==3.7

代码:

# -*- coding: utf-8 -*-
# Smoothing and normal estimation based on polynomial reconstruction
# http://pointclouds.org/documentation/tutorials/resampling.php#moving-least-squares

import numpy as np
import pcl
import random


def main():
    # // Load input file into a PointCloud<T> with an appropriate type
    # pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ> ());
    # // Load bun0.pcd -- should be available with the PCL archive in test
    # pcl::io::loadPCDFile ("bun0.pcd", *cloud);
    cloud = pcl.load('bun0.pcd')
    print('cloud(size) = ' + str(cloud.size))

    # // Create a KD-Tree
    # pcl::search::KdTree<pcl::PointXYZ>::Ptr tree (new pcl::search::KdTree<pcl::PointXYZ>);
    tree = cloud.make_kdtree()
    # tree = cloud.make_kdtree_flann()
    # blankCloud = pcl.PointCloud()
    # tree = blankCloud.make_kdtree()

    # // Output has the PointNormal type in order to store the normals calculated by MLS
    # pcl::PointCloud<pcl::PointNormal> mls_points;
    # mls_points = pcl.PointCloudNormal()
    # // Init object (second point type is for the normals, even if unused)
    # pcl::MovingLeastSquares<pcl::PointXYZ, pcl::PointNormal> mls;
    # mls.setComputeNormals (true);
    #
    # // Set parameters
    # mls.setInputCloud (cloud);
    # mls.setPolynomialFit (true);
    # mls.setSearchMethod (tree);
    # mls.setSearchRadius (0.03);
    #
    # // Reconstruct
    # mls.process (mls_points);
    mls = cloud.make_moving_least_squares()
    # print('make_moving_least_squares')
    mls.set_Compute_Normals(True)
    mls.set_polynomial_fit(True)
    mls.set_Search_Method(tree)
    mls.set_search_radius(0.03)
    print('set parameters')
    mls_points = mls.process()

    # Save output
    # pcl::io::savePCDFile ("bun0-mls.pcd", mls_points);
    pcl.save_PointNormal(mls_points, 'bun0-mls.pcd')


if __name__ == "__main__":
    # import cProfile
    # cProfile.run('main()', sort='time')
    main()

运行结果:

cloud(size) = 112586
set parameters

bun0.pcd文件需要去这个地址下载:https://github.com/strawlab/python-pcl/blob/master/examples/official/Surface/bun0.pcd

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

码农张三疯

你的打赏是我写文章最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值