使用体素滤波器对点云进行下采样

使用体素画网格方法实现下采样,即减少点的数量从而减少点云数据,并同时保存点云的形状特征。下采样对提高配准,曲面重建,形状识别等算法速度很实用。
PCL实现的VoxeGrid类通过输入的点云数据创建一个三维体素网格,使用每个体素内所有点的重心来近似展示体素中的其他点,通过这样的操作,体素内的所有点都用一个重心点最终表示,对于体素处理后得到的过滤后的点云,这样方法比用体素重心逼近的方法更慢,但是对于采样点对应曲面的表示更为准确。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include <pcl/point_types.h>
#include <pcl/io/pcd_io.h>
#include <pcl/filters/voxel_grid.h>
int main(int argc,char ** argv){
pcl::PCLPointCloud2::Ptr cloud(new pcl::PCLPointCloud2());
pcl::PCLPointCloud2::Ptr cloud_fitered(new pcl::PCLPointCloud2);

pcl::PCDReader reader;

reader.read("table_400.pcd",*cloud);
std::cout<<"PointCloud before filtering: "<<cloud->width*cloud->height
<<" data points ("<<pcl::getFieldsList(*cloud)<<").";
/**********************************************************
创建一个叶大小为1cm的pcl::VoxelGrid滤波器
**********************************************************/
pcl::VoxelGrid<pcl::PCLPointCloud2> sor;//实例化一个体素处理对象
sor.setInputCloud(cloud);//设定输入点云
sor.setLeafSize(0.01f,0.01f,0.01f);//设定体素立方体大小
sor.filter(*cloud_fitered);//输出
std::cout<<"PointCloud before filtering: "<<cloud_fitered->width*cloud_fitered->height
<<" data points ("<<pcl::getFieldsList(*cloud_fitered)<<").";
pcl::PCDWriter writer;
writer.write("table_400_res.pcd",*cloud_fitered,Eigen::Vector4f::Zero(),Eigen::Quaternionf::Identity(), false);
return 0;

}

降采样前后点数比较

降采样前后点云的比较

感谢您的阅读。 🙏 关于转载请看这里