PCL點雲固定數量採樣

在某些情況下,我們採樣的時候可能需要固定數量的採樣,未必是要均勻的採樣。這個時候需要採用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的採樣數度很快,而且不需要再調整參數。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章