当前位置:网站首页>PCL学习之滤波Filtering
PCL学习之滤波Filtering
2022-08-09 18:53:00 【风轻云淡_Cauchy】
PCL学习之滤波Filtering
- 1. Filtering a PointCloud using a PassThrough filter--简单区间滤波方法
- 2. Downsampling a PointCloud using a VoxelGrid filter--体素网格
- 3. Removing outliers using a StatisticalOutlierRemoval filter
- 4. Projecting points using a parametric model
- 5. Extracting indices from a PointCloud
- 6. Removing outliers using a Conditional or RadiusOutlier removal
1. Filtering a PointCloud using a PassThrough filter–简单区间滤波方法
a simple filtering along a specified dimension – that is, cut off values that are either inside or outside a given user range. [a, b]之间的留下,之外的被滤掉,简单的滤波。
// Create the filtering object
pcl::PassThrough<pcl::PointXYZ> pass;
pass.setInputCloud (cloud);
pass.setFilterFieldName ("z");
pass.setFilterLimits (0.0, 1.0);
//pass.setFilterLimitsNegative (true);
pass.filter (*cloud_filtered);
2. Downsampling a PointCloud using a VoxelGrid filter–体素网格
downsample – that is, reduce the number of points – a point cloud dataset, using a voxelized grid approach. 体素化网格方法。
1)VoxelGrid 类在输入点云数据上创建一个 3D 体素网格(将体素网格想象为空间中的一组微小的 3D 框)。
2)在每个体素(即 3D 框)中,所有存在的点都将以其质心近似(即下采样)。
// Create the filtering object
pcl::VoxelGrid<pcl::PCLPointCloud2> sor;
sor.setInputCloud (cloud);
sor.setLeafSize (0.01f, 0.01f, 0.01f);
sor.filter (*cloud_filtered);
2.1 示例结果
原始:
以0.01立方体降采样的结果:
以0.02立方体降采样结果:
3. Removing outliers using a StatisticalOutlierRemoval filter
remove noisy measurements, e.g. outliers, from a point cloud dataset using statistical analysis techniques.
- 场景:激光扫描通常会生成不同点密度的点云数据集。
- 缺点:一般会产生稀疏异常值。
- 结果:使局部点云特征(例如表面法线或曲率变化)的估计复杂化,从而导致错误的值,进而可能导致点云配准失败。
- 解决方法:稀疏异常值去除基于输入数据集中点到邻居距离分布的计算;即,对于每个点,计算从它到所有邻居的平均距离。通过假设结果分布是具有均值和标准差的高斯分布,所有平均距离在由全局距离均值和标准差定义的区间之外的点都可以被视为异常值并从数据集中进行修剪。
// Create the filtering object
pcl::StatisticalOutlierRemoval<pcl::PointXYZ> sor;
sor.setInputCloud (cloud);
sor.setMeanK (50);
sor.setStddevMulThresh (1.0);
sor.filter (*cloud_filtered);
// sor.setNegative(true) // to obtain the outliers,as follows:3.1 outliers 结果
3.1 示例结果
原始数据:
inliers结果:
outliers结果:
4. Projecting points using a parametric model
project points onto a parametric model (e.g., plane, sphere, etc). The parametric model is given through a set of coefficients – in the case of a plane, through its equation: ax + by + cz + d = 0. 投影到一个平面上
// Create a set of planar coefficients with X=Y=0,Z=1
pcl::ModelCoefficients::Ptr coefficients (new pcl::ModelCoefficients ());
coefficients->values.resize (4);
coefficients->values[0] = coefficients->values[1] = 0;
coefficients->values[2] = 1.0;
36coefficients->values[3] = 0;
// Create the filtering object
pcl::ProjectInliers<pcl::PointXYZ> proj;
proj.setModelType (pcl::SACMODEL_PLANE);
proj.setInputCloud (cloud);
proj.setModelCoefficients (coefficients);
proj.filter (*cloud_projected);
结果:
red (x), green (y), and blue (z);red as the points before projection and green as the points after projection。
5. Extracting indices from a PointCloud
use an ExtractIndices filter to extract a subset of points from a point cloud based on the indices output by a segmentation algorithm。
- 这块儿有点儿不明白,后面有机会再深入学习
代码先粘到这儿:
#include <iostream>
#include <pcl/ModelCoefficients.h>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/sample_consensus/method_types.h>
#include <pcl/sample_consensus/model_types.h>
#include <pcl/segmentation/sac_segmentation.h>
#include <pcl/filters/voxel_grid.h>
#include <pcl/filters/extract_indices.h>
int main()
{
pcl::PCLPointCloud2::Ptr cloud_blob (new pcl::PCLPointCloud2), cloud_filtered_blob (new pcl::PCLPointCloud2);
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered (new pcl::PointCloud<pcl::PointXYZ>), cloud_p (new pcl::PointCloud<pcl::PointXYZ>), cloud_f (new pcl::PointCloud<pcl::PointXYZ>);
// Fill in the cloud data
pcl::PCDReader reader;
reader.read ("table_scene_lms400.pcd", *cloud_blob);
std::cerr << "PointCloud before filtering: " << cloud_blob->width * cloud_blob->height << " data points." << std::endl;
// Create the filtering object: downsample the dataset using a leaf size of 1cm
pcl::VoxelGrid<pcl::PCLPointCloud2> sor;
sor.setInputCloud (cloud_blob);
sor.setLeafSize (0.01f, 0.01f, 0.01f);
sor.filter (*cloud_filtered_blob);
// Convert to the templated PointCloud
pcl::fromPCLPointCloud2 (*cloud_filtered_blob, *cloud_filtered);
std::cerr << "PointCloud after filtering: " << cloud_filtered->width * cloud_filtered->height << " data points." << std::endl;
// Write the downsampled version to disk
pcl::PCDWriter writer;
writer.write<pcl::PointXYZ> ("table_scene_lms400_downsampled.pcd", *cloud_filtered, false);
pcl::ModelCoefficients::Ptr coefficients (new pcl::ModelCoefficients ());
pcl::PointIndices::Ptr inliers (new pcl::PointIndices ());
// Create the segmentation object
pcl::SACSegmentation<pcl::PointXYZ> seg;
// Optional
seg.setOptimizeCoefficients (true);
// Mandatory
seg.setModelType (pcl::SACMODEL_PLANE);
seg.setMethodType (pcl::SAC_RANSAC);
seg.setMaxIterations (1000);
seg.setDistanceThreshold (0.01);
// Create the filtering object
pcl::ExtractIndices<pcl::PointXYZ> extract;
int i = 0, nr_points = (int) cloud_filtered->size ();
// While 30% of the original cloud is still there
while (cloud_filtered->size () > 0.3 * nr_points)
{
// Segment the largest planar component from the remaining cloud
seg.setInputCloud (cloud_filtered);
seg.segment (*inliers, *coefficients);
if (inliers->indices.size () == 0)
{
std::cerr << "Could not estimate a planar model for the given dataset." << std::endl;
break;
}
// Extract the inliers
extract.setInputCloud (cloud_filtered);
extract.setIndices (inliers);
extract.setNegative (false);
extract.filter (*cloud_p);
std::cerr << "PointCloud representing the planar component: " << cloud_p->width * cloud_p->height << " data points." << std::endl;
std::stringstream ss;
ss << "table_scene_lms400_plane_" << i << ".pcd";
writer.write<pcl::PointXYZ> (ss.str (), *cloud_p, false);
// Create the filtering object
extract.setNegative (true);
extract.filter (*cloud_f);
cloud_filtered.swap (cloud_f);
i++;
}
return (0);
}
5.1 示例结果
先通过体素网格降采样,减少点云,为后面的Extract indices工作节省运算量。
Extract indices结果:
6. Removing outliers using a Conditional or RadiusOutlier removal
ConditionalRemoval filter which removes all indices in the given input cloud that do not satisfy one or more given conditions;
RadiusOutlierRemoval filter which removes all indices in its input cloud that don’t have at least some number of neighbors within a certain range。
边栏推荐
- 基于CC2530 E18-MS1-PCB Zigbee DIY作品
- Bi Sheng Compiler Optimization: Lazy Code Motion
- Laravel DB批量更新的方法
- leetcode 503.下一个更大元素II 单调栈
- win10配置CenterNet环境
- 环境:Flink版本:1.15.1jar包:flink-sql-connector-oracle
- EsgynDB Troubleshooting - ERROR[2012] Server process tdm_arkesp could not becreated
- 以技术创新加速国家“碳中和”建设进程,华为云创新中心助力欣冠精密实现云智控“气”
- AWS CodePipeLine deploys ECS across accounts
- 渗透测试-对新型内存马webshell的研究
猜你喜欢
[] free column Android dynamic debugging GDB APP of safety
pytest框架之mark标记功能详细介绍
全自动化机器学习建模!效果吊打初级炼丹师!
加工制造业智慧采购系统解决方案:助力企业实现全流程采购一体化协同
【kali-权限提升】(4.2.7)社会工程学工具包:权限维持创建后门、清除痕迹
新出现的去中心化科学能够为科学领域带来什么?
渗透测试——CFS三层靶机内网渗透实操
《痞子衡嵌入式半月刊》 第 60 期
Fully automated machine learning modeling!The effect hangs the primary alchemist!
小满nestjs(第四章 前置知识装饰器-实现一个GET请求)
随机推荐
Haven't tried line art videos this year??
Openharmony Lightweight System Experiment--GPIO Lighting
日期及时间处理包 Carbon 在 Laravel 中的简单使用[通俗易懂]
MFC tutorial
Swift--多条件排序
源码编译安装与yum和rpm软件安装详解
axi4c
技术分享 | 接口自动化测试如何处理 Header cookie
How to suppress alarm storms?
IS31FL3737B 通用12×12 LED驱动器 I2C 42mA 40QFN
韩国严厉监管元宇宙相关企业
Environment: Flink version: 1.15.1 jar package: flink-sql-connector-oracle
明明加了唯一索引,为什么还是产生重复数据?
看完这波 Android 面试题;助你斩获心中 offer
Samsung's flagship discount is 1,800, Apple's discount is over 1,000, and the domestic flagship is only reduced by 500 to send beggars
小满nestjs(第五章 nestjs cli)
[免费专栏] Android安全之数据存储与数据安全【大集合】
Transformer如何用于3D视觉?阿联酋MBZUAI最新《3D视觉Transformers处理》综述,涵盖100+种方法
钢材行业供应链协同管理系统提升企业上下游密切度,精细化企业内部管理
Why is the data of maxcompute garbled when imported into mysql?The table of mysql is the encoding of udf8mb4