測(cè)試環(huán)境:
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()
運(yùn)行結(jié)果:
cloud(size) = 112586
set parameters文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-521999.html
bun0.pcd文件需要去這個(gè)地址下載:https://github.com/strawlab/python-pcl/blob/master/examples/official/Surface/bun0.pcd文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-521999.html
到了這里,關(guān)于[python][pcl]python-pcl案例之基于多項(xiàng)式重構(gòu)的平滑和正態(tài)估計(jì)重采樣的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!