当前位置:网站首页>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。
边栏推荐
- ebook下载 | 《 企业高管IT战略指南——企业为何要落地DevOps》
- IS31FL3737B general 12 x 12 LED drive 40 QFN I2C 42 ma
- competed中访问ref为undefined
- 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
- Openharmony Lightweight System Experiment--GPIO Lighting
- IS31FL3737B 通用12×12 LED驱动器 I2C 42mA 40QFN
- 这年头还不来尝试线稿图视频??
- 大健康产业商业供应链管理系统数字化提升产业链运作效率推动供应链标准化建设
- shell之变量详解,让你秒懂!
- ClickHouse一种高性能分布式join查询模型(Colocate Join)
猜你喜欢

Abbkine TraKine Pro 活细胞微管染色试剂盒重要特色

嵌入式开发:使用FILL提高代码完整性

真香|持一建证书央企可破格录取

数据分散情况的统计图-盒须图

三星旗舰优惠千八,苹果优惠过千,国产旗舰只降五百打发叫花子

【kali-密码攻击】(5.1.1)密码在线破解:Hydra(图形界面)

【IoT毕设】STM32与机智云自助开发平台的宠物智能喂养系统
![[免费专栏] Android安全之Android Fragment注入](/img/bf/244e7095ce010bfea799d02395b419.png)
[免费专栏] Android安全之Android Fragment注入

mysql 重复数据 分组 多条最新的记录
![[Free column] Xposed plug-in development for Android security [from scratch] tutorial](/img/7b/a036ac664c7e27ed7d87e7ee18c05d.png)
[Free column] Xposed plug-in development for Android security [from scratch] tutorial
随机推荐
如何从800万数据中快速捞出自己想要的数据?
2022深圳(软考高级)信息系统项目管理师认证报名
三星旗舰优惠千八,苹果优惠过千,国产旗舰只降五百打发叫花子
Oracle 字段自增
移动端,PC端,微信等常用平台和浏览器判断
laravel之phpunit单元测试
基于Web的疫情隔离区订餐系统
Paper sharing: "FED BN" uses the LOCAL BATCH NORMALIZATION method to solve the Non-iid problem
[免费专栏] Android安全之Android Fragment注入
axi4c
Flume (五) --------- 自定义 Interceptor、自定义 Source 与 自定义 Sink
[免费专栏] Android安全之安卓APK浅析
Toronto Research Chemicals加米霉素-d4说明书
【分享】入驻集简云开发者平台,如何使用Session Auth配置授权?
Mysql table structure change scheme comparison and analysis
超多AI开发者等你来玩转,一起燃动昇腾AI创享日南京站!
php安装make出现“collect2:error:ldreturned1exitstatus
2022.08.05_每日一题
Start cleaning up the long-term divers in the electronic chart development group again
安装多版本php(php5.6,php7.2)