当前位置:网站首页>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。
边栏推荐
猜你喜欢

Toronto Research Chemicals盐酸乙环胺应用说明
![[免费专栏] Android安全之和平精英(FZ)APK逆向分析](/img/22/a5129a310eec5ee1bf6f1cf90d05de.png)
[免费专栏] Android安全之和平精英(FZ)APK逆向分析

Haven't tried line art videos this year??

C#/VB.NET:从PowerPoint文档中提取文本和图片

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

ebook download | "Business executives' IT strategy guide - why enterprises should implement DevOps"

全自动化机器学习建模!效果吊打初级炼丹师!

Abbkine TraKine Pro 活细胞微管染色试剂盒重要特色
![[免费专栏] Android安全之Root检测和绕过(浅析)](/img/04/4170dea9c367c406fe3f36cb9c6501.png)
[免费专栏] Android安全之Root检测和绕过(浅析)
![[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
随机推荐
Tims中国上市进入倒计时:年亏3.8亿 估值降至14亿美元
【kali-权限提升】(4.2.7)社会工程学工具包:权限维持创建后门、清除痕迹
有文章说明或者证明MYSQL 嵌套子查询不足之处吗?
小满nestjs(第五章 nestjs cli)
EsgynDB Troubleshooting - ERROR[2012] Server process tdm_arkesp could not becreated
渗透测试-对新型内存马webshell的研究
AttributeError: module 'click' has no attribute 'get_os_args'
韩国严厉监管元宇宙相关企业
php删除字符串的空格
WPF 实现带蒙版的 MessageBox 消息提示框
How to suppress alarm storms?
【Unity3D】2D动画
Flume (五) --------- 自定义 Interceptor、自定义 Source 与 自定义 Sink
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
2022深圳(软考中级)系统集成项目管理工程师报名
技术分享 | 接口自动化测试如何处理 Header cookie
C#/VB.NET:从PowerPoint文档中提取文本和图片
[免费专栏] Android安全之安卓APK浅析
OpenSSL SSL_read: Connection was reset, errno 10054
Swift -- 数组高阶函数