当前位置:网站首页>Filtering of PCL
Filtering of PCL
2022-07-02 10:56:00 【AICVer】
Pass through filtering
Pass through filtering preserves points within a specified range .
#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) // Fill the 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;// To test the boundary conditions
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
// Set the filter object
pcl::PassThrough<pcl::PointXYZ> pass;
pass.setInputCloud(cloud); // Enter the point cloud
pass.setFilterFieldName("z"); // Filter field
// It's only reserved here 0.0 < z < 1.0 Point cloud of
pass.setFilterLimits(0.0, 1.0); // Set the range of filter fields
//setFilterLimitsNegative The default setting is false. If you set true, said setFilterLimits Filter out the points in the range
//pass.setFilterLimitsNegative (true);
pass.filter(*cloud_filtered); // filtering , And output to the cloud_filtered, But the input cloud No change
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);
}
Sampling under voxel filtering
#include <iostream>
#include <pcl/filters/voxel_grid.h>// Voxel filter header file
#include <pcl/io/pcd_io.h> //PCD Read and write class related header files
#include <pcl/point_types.h> // Point type related definitions
#include <pcl/visualization/cloud_viewer.h> // Point cloud visualization related definitions Visual support header file
#include <pcl/common/common.h> //common modular ,common.h The functions of are 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>());
// Fill in point cloud data
pcl::PCDReader reader;
// Change the path to the path where you store your files
reader.read ("D:\\pclcode\\filter\\voxel_grid\\source\\table_scene_lms400.pcd", *cloud); // Read the folder table_scene_lms400.pcd Point cloud file
//pcl::visualization::CloudViewer viewer("cloud viewer");// Show
//viewer.showCloud(cloud);// Show cloud
std::cerr << "PointCloud before filtering: " << cloud->width * cloud->height
<< " data points (" << pcl::getFieldsList(*cloud) << ").";// Output the total number of points before filtering
//system("pause");// Pause
// Create filter object
pcl::VoxelGrid<pcl::PointXYZ> sor;// Create filter object
sor.setInputCloud (cloud);// Set the input point cloud
sor.setLeafSize (0.01f, 0.01f, 0.01f);// The voxel size is set to 10*10*10cm
sor.filter (*cloud_filtered);// Perform filtering , Save the filter results in cloud_filtered
std::cerr << "PointCloud after filtering: " << cloud_filtered->width * cloud_filtered->height
<< " data points (" << pcl::getFieldsList (*cloud_filtered) << ").";// Output the total number of filtered
pcl::PCDWriter writer;//pcd Write operations
writer.write ("2f.pcd", *cloud_filtered);// Store the filtered point cloud in build Folder , And named it 2f.pcd
//pcl::visualization::CloudViewer viewer("cloud viewer");// Show
//viewer.showCloud(cloud_filterd);// Show cloud
system("pause");// Pause
return (0);
}
//PointCloud before filtering : 460400 data points(x y z).
//PointCloud after filtering : 41049 data points(x y z).
// Please press any key to continue . . .
边栏推荐
猜你喜欢
HDU1236 排名(结构体排序)
JSP webshell free -- the basis of JSP
Easyexcel, a concise, fast and memory saving excel processing tool
axis设备的rtsp setup头中的url不能带参
4. Random variables
从MediaRecord录像中读取H264参数
使用Windbg静态分析dump文件(实战经验总结)
互联网快讯:腾讯会议应用市场正式上线;Soul赴港递交上市申请书
[SUCTF2018]followme
Use WinDbg to statically analyze dump files (summary of practical experience)
随机推荐
JS settimeout() and interview questions
Solution of mysql8 forgetting password file in Windows Environment
HDU1234 开门人和关门人(水题)
Flink submitter
UVM factory mechanism
Hdu1236 ranking (structure Sorting)
"Matching" is true love, a new attitude for young people to make friends
[SUCTF2018]followme
大华设备播放过程中设置播放速度
Redis set password
使用华为性能管理服务,按需配置采样率
Lunix reallocates root and home space memory
AppGallery Connect场景化开发实战—图片存储分享
P1055 [noip2008 popularization group] ISBN number
如何用list组件实现tabbar标题栏
Disassembling Meitu SaaS: driving the plane to change the engine
Pywin32打开指定窗口
SUS系统可用性量表
AttributeError: type object ‘Image‘ has no attribute ‘fromarray‘
618再次霸榜的秘密何在?耐克最新财报给出答案