当前位置:网站首页>PCL之滤波
PCL之滤波
2022-07-02 07:00:00 【AICVer】
直通滤波
直通滤波保留指定范围内部的点。
#include <iostream>
#include <pcl/point_types.h>
#include <pcl/filters/passthrough.h>
int main(int argc, char **argv)
{
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered(new pcl::PointCloud<pcl::PointXYZ>);
// Fill in the cloud data
cloud->width = 5;
cloud->height = 1;
cloud->points.resize(cloud->width * cloud->height);
for (auto &point : *cloud) //填充点云
{
point.x = 1024 * rand() / (RAND_MAX + 1.0f);
point.y = 1024 * rand() / (RAND_MAX + 1.0f);
point.z = 1024 * rand() / (RAND_MAX + 1.0f);
}
cloud->points[0].z = 1;//为了测试边界条件
cloud->points[1].z = 0;
std::cerr << "Cloud before filtering: " << std::endl;
for (const auto &point : *cloud)
std::cerr << " " << point.x << " "
<< point.y << " "
<< point.z << std::endl;
// Create the filtering object
//设置滤波器对象
pcl::PassThrough<pcl::PointXYZ> pass;
pass.setInputCloud(cloud); //输入点云
pass.setFilterFieldName("z"); //滤波字段
//这里只保留 0.0 < z < 1.0的点云
pass.setFilterLimits(0.0, 1.0); //设置过滤字段的范围
//setFilterLimitsNegative默认设置为false。如果设置true,则表示setFilterLimits范围内的点滤掉
//pass.setFilterLimitsNegative (true);
pass.filter(*cloud_filtered); //执行过滤,并输出到cloud_filtered,但是输入的cloud不会变化
std::cerr << "Cloud before filtering:cloud " << std::endl;
for (const auto &point : *cloud)
std::cerr << " " << point.x << " "
<< point.y << " "
<< point.z << std::endl;
std::cerr << "Cloud after filtering: cloud_filtered" << std::endl;
for (const auto &point : *cloud_filtered)
std::cerr << " " << point.x << " "
<< point.y << " "
<< point.z << std::endl;
return (0);
}
体素滤波下采样
#include <iostream>
#include <pcl/filters/voxel_grid.h>//体素滤波器头文件
#include <pcl/io/pcd_io.h> //PCD 读写类相关的头文件
#include <pcl/point_types.h> //点类型相关定义
#include <pcl/visualization/cloud_viewer.h> //点云可视化相关定义 可视化支持头文件
#include <pcl/common/common.h> //common模块,common.h的函数有pcl::getMinMax3D
int main (int argc, char** argv)
{
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;
// 把路径改为自己存放文件的路径
reader.read ("D:\\pclcode\\filter\\voxel_grid\\source\\table_scene_lms400.pcd", *cloud); //读取文件夹里面的table_scene_lms400.pcd点云文件
//pcl::visualization::CloudViewer viewer("cloud viewer");//显示
//viewer.showCloud(cloud);//显示cloud
std::cerr << "PointCloud before filtering: " << cloud->width * cloud->height
<< " data points (" << pcl::getFieldsList(*cloud) << ").";//输出滤波前点的总个数
//system("pause");//暂停
// 创建滤波器对象
pcl::VoxelGrid<pcl::PointXYZ> sor;//创建滤波器对象
sor.setInputCloud (cloud);//设置输入点云
sor.setLeafSize (0.01f, 0.01f, 0.01f);//体素大小设置为10*10*10cm
sor.filter (*cloud_filtered);//执行滤波,保存过滤结果在cloud_filtered
std::cerr << "PointCloud after filtering: " << cloud_filtered->width * cloud_filtered->height
<< " data points (" << pcl::getFieldsList (*cloud_filtered) << ").";//输出滤波后的总个数
pcl::PCDWriter writer;//pcd写操作
writer.write ("2f.pcd", *cloud_filtered);//将滤波后的点云存储在build文件夹里,并命名为2f.pcd
//pcl::visualization::CloudViewer viewer("cloud viewer");//显示
//viewer.showCloud(cloud_filterd);//显示cloud
system("pause");//暂停
return (0);
}
//PointCloud before filtering : 460400 data points(x y z).
//PointCloud after filtering : 41049 data points(x y z).
//请按任意键继续. . .
边栏推荐
- [jetbrain rider] an exception occurred in the construction project: the imported project "d:\visualstudio2017\ide\msbuild\15.0\bin\roslyn\microsoft.csh" was not found
- Internet News: Tencent conference application market was officially launched; Soul went to Hong Kong to submit the listing application
- 01-spooldir
- Database dictionary Navicat automatic generation version
- Application of rxjs operator withlatestfrom in Spartacus UI of SAP e-commerce cloud
- Delivery mode design of Spartacus UI of SAP e-commerce cloud
- MYSQL环境配置
- Pytest learning --base
- Pywin32打开指定窗口
- 14. Code implementation of semaphore
猜你喜欢
随机推荐
lunix重新分配root 和 home 空间内存
flink 提交程序
【TS】1368- 秒懂 TypeScript 泛型工具类型!
LeetCode+ 76 - 80 暴搜专题
JS settimeout() and interview questions
Blender model import UE, collision settings
AttributeError: type object ‘Image‘ has no attribute ‘fromarray‘
[pit avoidance guide] pit encountered using ugui: the text component cannot indent the first line by two spaces
Beautiful and intelligent, Haval H6 supreme+ makes Yuanxiao travel safer
Pywin32打开指定窗口
网络通信学习
Merge ordered sequence
12.进程同步与信号量
【避坑指南】Unity3D项目接入腾讯Bugly工具时遇到的坑
《MySQL 8 DBA基础教程》简介
pytest--之测试报告allure配置
Mock Server基本使用方法
快速做出原型
14. Code implementation of semaphore
Postman -- use







![[Fantasy 4] the transformation from U3D to UE4](/img/bb/665eba3c8cd774c94fe14f169121da.png)

