版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/lxn9492878lbl/article/details/84970703
在某些情况下,我们采样的时候可能需要固定数量的采样,未必是要均匀的采样。这个时候需要采用RandomSample的类来实现。
#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/filters/random_sample.h>
int
main (int argc, char** argv)
{
pcl::PointCloud<pcl::PointXYZI>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZI>);
pcl::PointCloud<pcl::PointXYZI>::Ptr cloud_sample (new pcl::PointCloud<pcl::PointXYZI>);
if (pcl::io::loadPCDFile<pcl::PointXYZI> ("/home/............/Marketplace_2D_I_downsampled.pcd", *cloud) == -1) //* 读入PCD格式的文件,如果文件不存在,返回-1
{
PCL_ERROR ("Couldn't read file\n");
return (-1);
}
pcl::RandomSample<pcl::PointXYZI> rs;
rs.setInputCloud(cloud);
//设置输出点的数量
rs.setSample(100);
//下采样并输出到cloud_sample
rs.filter(*cloud_sample);
pcl::io::savePCDFileASCII ("/home/..........222.pcd", *cloud_sample);
return 0;
}
但是固定数量的采样可能会不均匀,但是如果要求不是很高,cloud_sample的采样数度很快,而且不需要再调整参数。