PCL点云滤波:体素网格法VoxelGrid和适用场景

目录

PCL体素网格法VoxelGrid使用方法和点云效果显示

体素网格法VoxelGrid原理说明

适用场景和使用心得


PCL体素网格法VoxelGrid使用方法和点云效果显示

资源下载链接和参考教程在文章最后;

程序中实现最基本的滤波功能和对一个点云多次滤波的实现;

参数0.01f是1cm,调整后可以看效果;

/*20201213 by 手口一斤*/
#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/filters/voxel_grid.h>
#include <pcl/visualization/cloud_viewer.h>

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

    pcl::PCDReader reader;
    reader.read("table_scene_lms400.pcd", *cloud); 

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

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

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

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


    pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_show(new pcl::PointCloud<pcl::PointXYZ>);
    pcl::fromPCLPointCloud2(*cloud, *cloud_show);
    pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered_show(new pcl::PointCloud<pcl::PointXYZ>);
    pcl::fromPCLPointCloud2(*cloud_filtered, *cloud_filtered_show);

    pcl::visualization::CloudViewer viewer("Cloud Viewer");
    viewer.showCloud(cloud_filtered_show,"cloud filtered");
    //viewer.showCloud(cloud_show, "cloud");
    while (!viewer.wasStopped())
    {
        //viewer.spin(100);
    }

    return (0);
}

运行结果:

体素网格法VoxelGrid原理说明

VoxelGrid类在输入点云数据上创建一个三维体素网格(将体素网格看作空间中一组微小的三维长方体)。然后,在每个体素(即,3D框)中,所有存在的点都将用它们的质心近似。这种方法比用体素的中心近似它们慢一些,但它获得结果表示更精确;

适用场景和使用心得

密集点云下采样,并能保持原有的点云形状;

密度不同的点云下采样,均衡点云数据的分布密度;

下采样效率高,适合大规模点云;

作为配准、重建、形状识别、法向量求取等算法的预处理步骤。

参考和资源下载:https://pcl.readthedocs.io/projects/tutorials/en/latest/voxel_grid.html#voxelgrid

  • 2
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值