当前位置:网站首页>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).
//请按任意键继续. . .
边栏推荐
- Webui automated learning
- 2021-10-04
- JS reduce accumulator
- js promise.all
- The nanny level tutorial of flutter environment configuration makes the doctor green to the end
- Internet News: Tencent conference application market was officially launched; Soul went to Hong Kong to submit the listing application
- pytest框架实现前后置
- Sus system availability scale
- Aiphacode is not a substitute for programmers, but a tool for developers
- KS009基于SSH实现宠物管理系统
猜你喜欢
随机推荐
合并有序数列
Pywin32 opens the specified window
记录 AttributeError: ‘NoneType‘ object has no attribute ‘nextcall‘
MySQL -- time zone / connector / driver type
Pytest learning --base
JS settimeout() and interview questions
Flink calculates topn hot list in real time
Introduction and Principle notes of UE4 material
AttributeError: type object ‘Image‘ has no attribute ‘fromarray‘
Aiphacode is not a substitute for programmers, but a tool for developers
Shutter - canvas custom graph
【Lua】常见知识点汇总(包含常见面试考点)
STM32 and motor development (upper system)
Session cookies and tokens
【MySQL】连接MySQL时出现异常:Connection must be valid and open
Webui automated learning
《实习报告》Skywalking分布式链路追踪?
2021-10-04
2.hacking-lab脚本关[详细writeup]
shell编程01_Shell基础