欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 科技 > 能源 > PCL-直通滤波

PCL-直通滤波

2025/2/24 1:01:37 来源:https://blog.csdn.net/qq_43049432/article/details/141780974  浏览:    关键词:PCL-直通滤波

本篇内容:

  • 讲解直通滤波的作用
  • 通过pcl实现直通滤波
    效果:
    在这里插入图片描述

1 主要原理

点云数据通常包含x、y、z三个维度的数据,用户指定维度、范围后,直通滤波过滤或保留该范围内的所有点云
假设我指定维度’y’,范围(0.0,0.1),运行直通滤波后,则过滤或保留y坐标为(0.0,0.1)范围内的所有点云

2 直通滤波主要流程

初始化直通滤波器:

pcl::PassThrough<PointType> pt_filter;

设置输入点云:

pt_filter.setInputCloud(cloud);

设置过滤维度:

pt_filter.setFilterFieldName("y");

设置过滤范围:

pt_filter.setFilterLimits(0.0, 0.1);

设置过滤或保留:

pt_filter.setNegative(true);	// 设置为true,表示保留在过滤范围外的点,为false,表示保留在过滤范围内的点

执行过滤:

pt_filter.filter(*cloud_filter);

3 完整代码

#include <string>
#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl/filters/passthrough.h>// 前置点云类型,方便以后更改
using PointType = pcl::PointXYZ;
using PointCloud = pcl::PointCloud<PointType>;
using PointCloud_Ptr = PointCloud::Ptr;int main(int argc, char **argv) {if (argc < 3) {std::cout<<"Usage: ./read_pcd <pcd_file_path> <pcd_save_path>\n";return -1;}std::string pcd_file_path(argv[1]);std::string pcd_save_path(argv[2]);// 声明变量,用于保存点云数据PointCloud_Ptr cloud(new PointCloud);PointCloud_Ptr cloud_filter(new PointCloud);// 读取pcd点云文件if (pcl::io::loadPCDFile<PointType>(pcd_file_path, *cloud) == -1) {std::cerr<<"check pcd path\n";return -1;}// 初始化过滤器pcl::PassThrough<PointType> pt_filter;// 设置输入点云pt_filter.setInputCloud(cloud);// 设置过滤维度pt_filter.setFilterFieldName("y");// 设置过滤范围pt_filter.setFilterLimits(0.0, 0.1);// 设置为true,表示保留在过滤范围外的点,为false,表示保留在过滤范围内的点pt_filter.setNegative(true);// 执行过滤pt_filter.filter(*cloud_filter);// 保存点云文件pcl::io::savePCDFileASCII(pcd_save_path, *cloud_filter);return 0;
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词