PCL均匀采样滤波(uniform_sampling)

注意:和体素滤波区别在于,会有邻近搜索的一步,在计算出每个体素块的中心点之后,再搜索这个体素块中距离中心点最近的点云点作为特征点(这一步KD搜索会降低速度),注意取舍。

1.原理

将所有点云点三维体素化为一个一个的小的体素块,计算该体素块中所有点云点的质心点,然后获取点云中距离质心点最近的点作为该体素块的特征点;遍历所有体素块,得到最终的结果。

(1)三维点云化作一个一个的小体素块。

(2)计算每个体素块中所有点云点的质心点。

(3)获取点云中距离质心点最近的点作为该体素块的特征点

(4)遍历所有体素块,得到结果点云。

如何理解体素化:如下图,将整体点云体素化为多个小体素块,用一个个正方形的小块代表该范围内的点云。

2.使用场景

抽稀:相较于体素滤波,均匀采样滤波计算出的最终结果点云,不改变点云点的位置,保持其原始形态

3.注意事项

均匀采样滤波因为有质心点复原到体素块这一步,因此速度会比体素滤波更慢些。

4.关键函数

(1)设置体素块的边长大小;

setRadiusSearch()

5.代码

#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/keypoints/uniform_sampling.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <boost/thread/thread.hpp>

int main()
{
    /****************均匀采样********************/
    // 原始点云
    pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZRGB>);
    pcl::io::loadPCDFile("D:/code/csdn/data/bunny.pcd", *cloud);   // 加载原始点云数据
    // 结果点云
    pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_filtered(new pcl::PointCloud<pcl::PointXYZRGB>);

    // 均匀采样
    pcl::UniformSampling<pcl::PointXYZRGB> filter;
    filter.setInputCloud(cloud);
    filter.setRadiusSearch(0.003);                               // 体素块大小
    filter.filter(*cloud_filtered);

    /****************展示********************/
    boost::shared_ptr<pcl::visualization::PCLVisualizer> view_raw(new pcl::visualization::PCLVisualizer("raw"));
    view_raw->addPointCloud<pcl::PointXYZRGB>(cloud, "raw cloud");
    view_raw->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "raw cloud");

    boost::shared_ptr<pcl::visualization::PCLVisualizer> view_filtered(new pcl::visualization::PCLVisualizer("filter"));
    view_filtered->addPointCloud<pcl::PointXYZRGB>(cloud_filtered, "filtered cloud");
    view_filtered->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "filtered cloud");

    while (!view_raw->wasStopped())
    {
        view_raw->spinOnce(100);
        boost::this_thread::sleep(boost::posix_time::microseconds(100000));
    }
    while (!view_filtered->wasStopped())
    {
        view_filtered->spinOnce(100);
        boost::this_thread::sleep(boost::posix_time::microseconds(100000));
    }

    return 0;
}

6.结果展示

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值