[点云分割] 使用 ModelOutlierRemoving 过滤点云

使用已知系数的几何模型,例如平面或球体,对一个点云进行滤波操作。

cpp 复制代码
#include <iostream>
#include <pcl/point_types.h>
#include <pcl/filters/model_outlier_removal.h>

int main ()
{
    pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
    pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_sphere_filtered (new pcl::PointCloud<pcl::PointXYZ>);

    // 1. Generate cloud data
    std::size_t noise_size = 5;
    std::size_t sphere_data_size = 10;
    cloud->width = noise_size + sphere_data_size;
    cloud->height = 1;
    cloud->points.resize (cloud->width * cloud->height);

    // 1.1 Add noise
    for (std::size_t i = 0; i < noise_size; ++i)
    {
        (*cloud)[i].x = 1024 * rand () / (RAND_MAX + 1.0f);
        (*cloud)[i].y = 1024 * rand () / (RAND_MAX + 1.0f);
        (*cloud)[i].z = 1024 * rand () / (RAND_MAX + 1.0f);
     }

    // 1.2 Add sphere:
    double rand_x1 = 1;
    double rand_x2 = 1;
    for (std::size_t i = noise_size; i < (noise_size + sphere_data_size); ++i)
    {
        // See: http://mathworld.wolfram.com/SpherePointPicking.html
        while (pow (rand_x1, 2) + pow (rand_x2, 2) >= 1)
            {
            rand_x1 = (rand () % 100) / (50.0f) - 1;
            rand_x2 = (rand () % 100) / (50.0f) - 1;
            }
        double pre_calc = sqrt (1 - pow (rand_x1, 2) - pow (rand_x2, 2));
        (*cloud)[i].x = 2 * rand_x1 * pre_calc;
        (*cloud)[i].y = 2 * rand_x2 * pre_calc;
        (*cloud)[i].z = 1 - 2 * (pow (rand_x1, 2) + pow (rand_x2, 2));
        rand_x1 = 1;
        rand_x2 = 1;
        }

        std::cerr << "Cloud before filtering: " << std::endl;
    for (const auto& point: *cloud)
        std::cout << "    " << point.x << " " << point.y << " " << point.z << std::endl;

    // 2. filter sphere:
    // 2.1 generate model:
    // modelparameter for this sphere:
    // position.x: 0, position.y: 0, position.z:0, radius: 1
    pcl::ModelCoefficients sphere_coeff;
    sphere_coeff.values.resize (4);
    sphere_coeff.values[0] = 0;
    sphere_coeff.values[1] = 0;
    sphere_coeff.values[2] = 0;
    sphere_coeff.values[3] = 1;

    pcl::ModelOutlierRemoval<pcl::PointXYZ> sphere_filter;
    sphere_filter.setModelCoefficients (sphere_coeff);
    sphere_filter.setThreshold (0.05);
    sphere_filter.setModelType (pcl::SACMODEL_SPHERE);
    sphere_filter.setInputCloud (cloud);
    sphere_filter.filter (*cloud_sphere_filtered);

    std::cerr << "Sphere after filtering: " << std::endl;
    for (const auto& point: *cloud_sphere_filtered)
    std::cout << "    " << point.x << " " << point.y << " " << point.z << std::endl;

    return (0);
}
相关推荐
这张生成的图像能检测吗1 天前
(论文速读)IPFP:把图像特征反投影到 3D,用单分支完成多模态训练
人工智能·计算机视觉·点云·多模态融合·3d技术·三维感知·2d相机
feasibility.2 天前
一个生成接口统一计算机视觉:SenseNova-Vision 硬核解剖
人工智能·深度学习·目标检测·计算机视觉·图像分割·点云·cv
这张生成的图像能检测吗4 天前
(论文速读)Cylinder3D:面向室外 LiDAR 分割的柱面划分与非对称 3D 卷积
计算机视觉·点云·3d视觉·三维感知
这张生成的图像能检测吗4 天前
(论文速读)SphereFormer:用径向窗口解决 LiDAR 远距离稀疏点的信息断连
计算机视觉·点云·3d技术·三维感知
丶玉面小蛟龙2 个月前
DGCNN网络学习
学习·点云·dgcnn
bryant_meng2 个月前
【Point Cloud】Point Cloud Fundamentals(1)
计算机视觉·点云·点云配准·点云分割·点云检测·点云特征提取
Robot_Nav2 个月前
ROG-Map 技术解析:面向大场景高分辨率激光雷达运动规划的机器人中心占据栅格地图
点云·rog-map·占据栅格地图
沙振宇5 个月前
【Web】使用Vue3+PlayCanvas开发3D游戏(十二)渲染PCD点云可视化模型
3d·vue3·点云·pcd
给算法爸爸上香6 个月前
web网页显示点云
前端·3d·web·点云