ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

PCL:PassThrough ❤️ 直通滤波

2021-09-05 15:05:53  阅读:258  来源: 互联网

标签:pcl viewer PassThrough v1 PCL 点云 filtered cloud 通滤波


文章目录

1 原理

针对点云某一维度,去掉指定范围内(或外)的点。

2 代码实现

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

using namespace std;

int main()
{
	//----------------------------------------- 加载点云 ----------------------------------------
	pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);	//待滤波点云
	if (pcl::io::loadPCDFile("desk.pcd", *cloud) < 0)
	{
		PCL_ERROR("点云文件不存在!\n");
		system("pause");
		return -1;
	}
	cout << "->加载点云个数:" << cloud->points.size() << endl;
	//==========================================================================================

	//----------------------------------------- 直通滤波 ----------------------------------------
	cout << "->正在进行直通滤波..." << endl;
	pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered(new pcl::PointCloud<pcl::PointXYZ>);	//滤波后点云
	pcl::PassThrough<pcl::PointXYZ> pt;	// 创建滤波器对象
	pt.setInputCloud(cloud);			//设置输入点云
	pt.setFilterFieldName("x");			//设置滤波所需字段z
	pt.setFilterLimits(-0.1, 1);		//设置Z字段过滤范围
	pt.setFilterLimitsNegative(true);	//默认false,保留范围内的点云;true,保存范围外的点云
	pt.filter(*cloud_filtered);			//执行滤波,并将滤波后点云保存到cloud_filtered中
	//==========================================================================================

	//-------------------------------------- 可视化(可选) -------------------------------------
	pcl::visualization::PCLVisualizer::Ptr viewer(new pcl::visualization::PCLVisualizer("滤波前后对比"));

	/*-----原始点云-----*/
	int v1(0);
	viewer->createViewPort(0.0, 0.0, 0.5, 1.0, v1); //设置第一个视口在X轴、Y轴的最小值、最大值,取值在0-1之间
	viewer->setBackgroundColor(0, 0, 0, v1); //设置背景颜色,0-1,默认黑色(0,0,0)
	viewer->addText("befor_filtered", 10, 10, "v1_text", v1);
	viewer->addPointCloud<pcl::PointXYZ>(cloud, "befor_filtered_cloud", v1);
	viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 2, "befor_filtered_cloud", v1);
	viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_COLOR, 1, 0, 0, "befor_filtered_cloud", v1);

	/*-----滤波后点云-----*/
	int v2(0);
	viewer->createViewPort(0.5, 0.0, 1.0, 1.0, v2);
	viewer->setBackgroundColor(0.3, 0.3, 0.3, v2);
	viewer->addText("after_filtered", 10, 10, "v2_text", v2);
	viewer->addPointCloud<pcl::PointXYZ>(cloud_filtered, "after_filtered_cloud", v2);
	viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 2, "after_filtered_cloud", v2);
	viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_COLOR, 0, 1, 0, "after_filtered_cloud", v2);

	while (!viewer->wasStopped())
	{
		viewer->spinOnce(100);
		boost::this_thread::sleep(boost::posix_time::microseconds(100000));
	}
	//==========================================================================================

	return 0;
}

3 结果展示

在这里插入图片描述


相关链接:

PCL点云数据处理基础❤️❤️❤️目录

标签:pcl,viewer,PassThrough,v1,PCL,点云,filtered,cloud,通滤波
来源: https://blog.csdn.net/weixin_46098577/article/details/120115064

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有