pcl-filter-passthrough

本文通过一个具体的示例介绍了如何使用PCL (Point Cloud Library) 的passthrough滤波器进行点云数据处理。首先加载了一个点云数据文件,然后通过设置Z轴的滤波范围来保留或过滤特定高度的数据,并展示了滤波前后的效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

之前已经写过一篇讲pcl安装在Windows的博客,现在开始跟着官网的例子学习pcl。

pcl(point cloud library)是一个点云库,包括filter、feature等内容,现在开始从filter的第一个例子passthrough开始。

#include <iostream>	
#include <pcl\point_types.h>
#include <pcl\filters\passthrough.h>
#include <pcl/io/pcd_io.h>
#include <pcl/visualization/cloud_viewer.h>

int main()
{
	pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
	pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered(new pcl::PointCloud<pcl::PointXYZ>);
	pcl::PCDReader reader;//读
	
	pcl::visualization::CloudViewer viewer("cloud viewer");//显示
	reader.read<pcl::PointXYZ>("table_scene_lms400.pcd", *cloud);//加载pcd文件
	viewer.showCloud(cloud);//显示cloud
	system("pause");//暂停
	
	/************************************************************************************
	创建直通滤波器的对象,设立参数,滤波字段名被设置为Z轴方向,可接受的范围为(0.0,1.0)
	即将点云中所有点的Z轴坐标不在该范围内的点过滤掉或保留,这里是过滤掉,由函数setFilterLimitsNegative设定
	***********************************************************************************/
	// 设置滤波器对象
	pcl::PassThrough<pcl::PointXYZ> pass;
	pass.setInputCloud(cloud);
	pass.setFilterFieldName("z");
	pass.setFilterLimits(-1.2, 0);//保留或过滤z轴方向-1.2到0
	//pass.setFilterLimitsNegative(true);//设置过滤器限制负//设置保留范围内false
	pass.filter(*cloud_filtered);
	std::cout << "after" << std::endl;

	viewer.showCloud(cloud_filtered);
	system("pause");

	pass.setFilterLimitsNegative(true);//设置过滤掉范围内true
	pass.filter(*cloud_filtered);
	viewer.showCloud(cloud_filtered);
	system("pause");

	return 0;	
}

这是过滤以前的文件

这是保留z范围内的图片

这是过滤掉z范围内的图片

程序代码可从我的资源中下载:http://download.youkuaiyun.com/detail/zpp13hao1/9821119


### PCL 库中 PassThrough 滤波器的使用 PassThrough 滤波器用于执行简单的裁剪操作,可以基于特定维度(如 X、Y 或 Z 坐标)过滤点云数据。这有助于移除不需要的数据区域。 #### 使用方法 要应用 PassThrough 滤波器,需创建 `pcl::PassThrough` 对象并设置参数: ```cpp #include <pcl/filters/passthrough.h> // 创建 PassThrough 滤波器对象 pcl::PassThrough<pcl::PointXYZ> pass; pass.setInputCloud(cloud); pass.setFilterFieldName("z"); // 设置过滤字段名称 pass.setFilterLimits(0.0, 1.0); // 设置上下限范围 bool limit_negative = false; // 是否取反,默认为false pass.setNegative(limit_negative); // 执行滤波处理 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered(new pcl::PointCloud<pcl::PointXYZ>); pass.filter(*cloud_filtered); ``` 此代码片段展示了如何配置和运行 PassThrough 滤波器[^2]。 - `setInputCloud()` 方法指定输入点云。 - `setFilterFieldName()` 定义要过滤的坐标轴或特征名。 - `setFilterLimits()` 设定允许通过的最小最大值区间。 - `setNegative()` 控制是否反转筛选逻辑;当设为 true 时,会保留超出设定区间的点。 #### 参数说明 | 参数 | 描述 | | --- | --- | | Filter Field Name | 要过滤的属性名称,通常是 "x", "y", 或 "z". | | Filter Limits | 过滤条件的数值边界,即允许存在的最小值和最大值。| | Negative Flag | 如果启用,则只保留不符合上述界限内的点。| 这种类型的滤波非常适合清理扫描仪获取到的大规模三维数据集,在实际项目中有广泛应用价值.
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值