PCL --- downsample

记录一下

使用VoxelGrid的filter进行下采样

#include 
#include 
#include 

#include 



int main()
{
  //use PCDReader load PCD file
  pcl::PCDReader reader;
  pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZRGB>);
  reader.read ("../Data/0000_cloud.pcd",*cloud);
  std::cout<<"PointCloud has: "<< cloud->points.size()<<" data ponts."<<std::endl;

  
  // Create the filtering object: downsample the dataset using a leaf size of 1cm
  pcl::VoxelGrid<pcl::PointXYZRGB> vg;
  pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_filtered (new pcl::PointCloud<pcl::PointXYZRGB>);
  vg.setInputCloud (cloud);
  vg.setLeafSize (0.0025f, 0.0025f, 0.00255f);//change leaf size into 0.5cm
  vg.filter (*cloud_filtered);
  std::cout << "PointCloud after filtering has: " << cloud_filtered->points.size ()  << " data points." << std::endl; //

  pcl::visualization::CloudViewer viewer("cloud filtered viewer");
  viewer.showCloud (cloud_filtered);
  while(!viewer.wasStopped())
  {
  }
  
return (0);
}

setLeafSzie= 0.0025

setLeafSzie= 0.005PCL --- downsample_第1张图片

setLeafSzie= 0.05
PCL --- downsample_第2张图片
关于此下采样的原理,待总结。。。
VoxelGrid 官方说明
The VoxelGrid class creates a 3D voxel grid (think about a voxel grid as a set of tiny 3D boxes in space) over the input point cloud data. Then, in each voxel (i.e., 3D box), all the points present will be approximated (i.e., downsampled) with their centroid. This approach is a bit slower than approximating them with the center of the voxel, but it represents the underlying surface more accurately.

你可能感兴趣的:(PCL,基础知识)