ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

[转]PCL几种采样方法 - Bein

2021-10-28 10:00:18  阅读:212  来源: 互联网

标签:采样 include PCL Bein filter pcl PointCloud cloud


(1)下采样  Downsampling

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

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

实验结果(略)

(2)

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

这里的filter.compute 是错误的,但是我也没搞明白应该怎么写,有懂得还望能告知一声!

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

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

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

实验的结果

原始图像可视化:

 

(4)表面重建

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

#include <pcl/io/pcd_io.h>#include <pcl/surface/mls.h>#include <pcl/visualization/pcl_visualizer.h>#include <pcl/visualization/cloud_viewer.h>#include <boost/thread/thread.hpp>intmain(int argc, char** argv){        pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);        pcl::PointCloud<pcl::PointNormal>::Ptr smoothedCloud(new pcl::PointCloud<pcl::PointNormal>);    if (pcl::io::loadPCDFile<pcl::PointXYZ>(argv[1], *cloud) != 0)    {        return -1;    }    // Smoothing object (we choose what point types we want as input and output).    pcl::MovingLeastSquares<pcl::PointXYZ, pcl::PointNormal> 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<pcl::PointXYZ>::Ptr kdtree;    filter.setSearchMethod(kdtree);    filter.process(*smoothedCloud);  boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer(new pcl::visualization::PCLVisualizer("smooth"));viewer->addPointCloud<pcl::PointNormal>(smoothedCloud,"smoothed");while(!viewer->wasStopped())  { viewer->spinOnce(100);boost::this_thread::sleep(boost::posix_time::microseconds(1000000)); }}

运行即可查看结果

                                                               原始图像(加了颜色)

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

 

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


---------------------
作者:Being_young
来源:CNBLOGS
原文:https://www.cnblogs.com/li-yao7758258/p/6527969.html
版权声明:本文为作者原创文章,转载请附上博文链接!
内容解析By:CSDN,CNBLOG博客文章一键转载插件

标签:采样,include,PCL,Bein,filter,pcl,PointCloud,cloud
来源: https://www.cnblogs.com/excellentliu/p/15474181.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有