博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PCL几种采样方法
阅读量:6994 次
发布时间:2019-06-27

本文共 3815 字,大约阅读时间需要 12 分钟。

(1)下采样  Downsampling

一般下采样是通过构造一个三维体素栅格,然后在每个体素内用体素内的所有点的重心近似显示体素中的其他点,这样体素内所有点就用一个重心点来表示,进行下采样的来达到滤波的效果,这样就大大的减少了数据量,特别是在配准,曲面重建等工作之前作为预处理,可以很好的提高程序的运行速度,

#include 
#include
intmain(int argc, char** argv){ // 创建点云对象 pcl::PointCloud
::Ptr cloud(new pcl::PointCloud
); pcl::PointCloud
::Ptr filteredCloud(new pcl::PointCloud
); // 读取PCD文件 if (pcl::io::loadPCDFile
(argv[1], *cloud) != 0) { return -1; } // 创建滤波对象 pcl::VoxelGrid
filter; filter.setInputCloud(cloud); // 设置体素栅格的大小为 1x1x1cm filter.setLeafSize(0.01f, 0.01f, 0.01f); filter.filter(*filteredCloud);}

实验结果(略)

(2)

均匀采样:这个类基本上是相同的,但它输出的点云索引是选择的关键点在计算描述子的常见方式。

#include 
#include
intmain(int argc, char** argv){
pcl::PointCloud
::Ptr cloud(new pcl::PointCloud
); pcl::PointCloud
::Ptr filteredCloud(new pcl::PointCloud
); if (pcl::io::loadPCDFile
(argv[1], *cloud) != 0) { return -1; } // Uniform sampling object. pcl::UniformSampling
filter; filter.setInputCloud(cloud); filter.setRadiusSearch(0.01f); // We need an additional object to store the indices of surviving points. pcl::PointCloud
keypointIndices; filter.compute(keypointIndices); pcl::copyPointCloud(*cloud, keypointIndices.points, *filteredCloud);}

(3)增采样 :增采样是一种表面重建方法,当你有比你想象的要少的点云数据时,增采样可以帮你恢复原有的表面(S),通过内插你目前拥有的点云数据,这是一个复杂的猜想假设的过程。所以构建的结果不会百分之一百准确,但有时它是一种可选择的方案。所以,在你的点云云进行下采样时,一定要保存一份原始数据!

#include 
#include
int main(int argc,char** argv){// 新建点云存储对象pcl::PointCloud
::Ptr cloud(new pcl::PointCloud
);pcl::PointCloud
::Ptr filteredCloud(new pcl::PointCloud
); // 读取文件 if (pcl::io::loadPCDFile
(argv[1], *cloud) != 0) { return -1; } // 滤波对象 pcl::MovingLeastSquares
filter; filter.setInputCloud(cloud); //建立搜索对象 pcl::search::KdTree
::Ptr kdtree; filter.setSearchMethod(kdtree); //设置搜索邻域的半径为3cm filter.setSearchRadius(0.03); // Upsampling 采样的方法有 DISTINCT_CLOUD, RANDOM_UNIFORM_DENSITY filter.setUpsamplingMethod(pcl::MovingLeastSquares
::SAMPLE_LOCAL_PLANE); // 采样的半径是 filter.setUpsamplingRadius(0.03); // 采样步数的大小 filter.setUpsamplingStepSize(0.02); filter.process(*filteredCloud);}

实验的结果

原始图像可视化:

 

(4)表面重建

深度传感器的测量是不准确的,和由此产生的点云也是存在的测量误差,比如离群点,孔等表面,可以用一个算法重建表面,遍历所有的点云和插值数据,试图重建原来的表面。比如增采样,PCL使用MLS算法和类。执行这一步是很重要的,因为由此产生的点云的法线将更准确。

#include 
#include
#include
#include
#include
intmain(int argc, char** argv){ pcl::PointCloud
::Ptr cloud(new pcl::PointCloud
); pcl::PointCloud
::Ptr smoothedCloud(new pcl::PointCloud
); if (pcl::io::loadPCDFile
(argv[1], *cloud) != 0) { return -1; } // Smoothing object (we choose what point types we want as input and output). pcl::MovingLeastSquares
filter; filter.setInputCloud(cloud); // Use all neighbors in a radius of 3cm. filter.setSearchRadius(0.03); // If true, the surface and normal are approximated using a polynomial estimation // (if false, only a tangent one). filter.setPolynomialFit(true); // We can tell the algorithm to also compute smoothed normals (optional). filter.setComputeNormals(true); // kd-tree object for performing searches. pcl::search::KdTree
::Ptr kdtree; filter.setSearchMethod(kdtree); filter.process(*smoothedCloud); boost::shared_ptr
viewer(new pcl::visualization::PCLVisualizer("smooth"));viewer->addPointCloud
(smoothedCloud,"smoothed");while(!viewer->wasStopped()) { viewer->spinOnce(100);boost::this_thread::sleep(boost::posix_time::microseconds(1000000)); }}

运行即可查看结果

                                                               原始图像(加了颜色)

                                             增采样平滑后(没有颜色信息)

 

微信公众号号可扫描二维码一起共同学习交流

转载地址:http://uzsvl.baihongyu.com/

你可能感兴趣的文章
我的友情链接
查看>>
vim显示行号、语法高亮、自动缩进的设置
查看>>
Apache Thrift入门2-Java代码实现例子
查看>>
关于浏览器全屏
查看>>
SQL语句操作数据表
查看>>
在eclipse中运行maven命令没有反应,console也不打印信息
查看>>
Kali Linux 2017.3发布了
查看>>
数据库镜像中证书过期的解决方案
查看>>
java并发实战读书笔记
查看>>
discuz使用之三——同步注册和同步登录
查看>>
C#相等比较器的使用
查看>>
以工作表的方式合并excel
查看>>
AIX 创建VG及文件系统
查看>>
Ansible自动化部署之ROLES
查看>>
golang 获取当前文件名和行号的方法
查看>>
hibernate.cfg.xml
查看>>
CentOS 7.5安装配置Tomcat详解(一)
查看>>
学习使用编码和解码
查看>>
Android系统进程Zygote启动过程的源代码分析(2)
查看>>
Oracle ASM故障数据恢复
查看>>