PCL:使用VoxelGrid filter对点云进行下采样

使用VoxelGrid filter对点云进行下采样,VoxelGrid可以堪称是个小的3D小方盒, 所有存在的点将以它们的质心近似(如,下采样)。这种方法比使用体素的中心近似慢,但它更准确地表示底层表面。

#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/filters/voxel_grid.h>

int
main (int argc, char** argv)
{
  pcl::PCLPointCloud2::Ptr cloud (new pcl::PCLPointCloud2 ());
  pcl::PCLPointCloud2::Ptr cloud_filtered (new pcl::PCLPointCloud2 ());

  // Fill in the cloud data
  pcl::PCDReader reader;
  // Replace the path below with the path where you saved your file
  reader.read ("table_scene_lms400.pcd", *cloud); // Remember to download the file first!

  std::cerr << "PointCloud before filtering: " << cloud->width * cloud->height 
       << " data points (" << pcl::getFieldsList (*cloud) << ").";

  // Create the filtering object
  pcl::VoxelGrid<pcl::PCLPointCloud2> sor;
  sor.setInputCloud (cloud);
  sor.setLeafSize (0.01f, 0.01f, 0.01f);
  sor.filter (*cloud_filtered);

  std::cerr << "PointCloud after filtering: " << cloud_filtered->width * cloud_filtered->height 
       << " data points (" << pcl::getFieldsList (*cloud_filtered) << ").";

  pcl::PCDWriter writer;
  writer.write ("table_scene_lms400_downsampled.pcd", *cloud_filtered, 
         Eigen::Vector4f::Zero (), Eigen::Quaternionf::Identity (), false);

  return (0);
}

这里就只写一次CMakeLists.txt,其他的使用PCL都是类似的

cmake_minimum_required(VERSION 2.8 FATAL_ERROR)

project(voxelgrid_filter)

//add PCL dependency
find_package(PCL 1.7 REQUIRED)

include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITION})


add_executable(voxelgrid_filter main.cpp)

target_link_libraries(voxelgrid_filter ${PCL_LIBRARIES})

install(TARGETS voxelgrid_filter RUNTIME DESTINATION bin)

这里写图片描述

看到点云的数量几乎变成原来的十分之一。。。。

这里写图片描述

可以看到橙色是原来采样之前的点是比较密集的,蓝色的是采样后的点,就变得相对来说更加稀疏了,如果继续修改LeafSize,还可以进行更加稀疏的采样,当过于稀疏会使得点云信息减少,对后续的操作不利。

这里写图片描述

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值