赞
踩
在测量较小的数据时会产生一些误差,这些误差所造成的不规则数据如果直接拿来曲面重建的话,会使得重建的曲面不光滑或者有漏洞,可以采用对数据重采样来解决这样问题,通过对周围的数据点进行高阶多项式插值来重建表面缺少的部分。
示例代码:
- #include <pcl/point_types.h>
- #include <pcl/io/pcd_io.h>
- #include <pcl/kdtree/kdtree_flann.h> //kd-tree搜索对象的类定义的头文件
- #include <pcl/surface/mls.h> //最小二乘法平滑处理类定义头文件
-
- int main(int argc, char** argv)
- {
- pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>());
- pcl::io::loadPCDFile("E://TY//camport3-master//cylinder.pcd", *cloud);
-
- // 创建 KD-Tree
- pcl::search::KdTree<pcl::PointXYZ>::Ptr tree(new pcl::search::KdTree<pcl::PointXYZ>);
-
- // Output has the PointNormal type in order to store the normals calculated by MLS
- pcl::PointCloud<pcl::PointNormal> mls_points;
-
- // 定义最小二乘实现的对象mls
- pcl::MovingLeastSquares<pcl::PointXYZ, pcl::PointNormal> mls;
-
- mls.setComputeNormals(true); //设置在最小二乘计算中需要进行法线估计
-
- // Set parameters
- mls.setInputCloud(cloud);
- mls.setPolynomialFit(true); //设置false,可以加速平滑
- mls.setSearchMethod(tree);
- mls.setSearchRadius(35.0); //单位m,设置用于拟合的K近邻半径
-
- // Reconstruct
- mls.process(mls_points); //输出
-
- // Save output
- pcl::io::savePCDFile("E://TY//camport3-master//bun0-mls2.pcd", mls_points);
- }
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
注:调整etSearchRadius(35.0)参数值,确定搜索半径,在此半径里进行表面映射和曲面拟合,半径越小拟合后曲面的失真度越小,反之可能出现过拟合的现象。
参考链接 PCL: Surface模块之Moving Least Squares(移动最小二乘法)_movingleastsquares_云初的博客-CSDN博客
总结:
点云数据模型构建处理流程:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。