指定点云中特定字段域的数字范围,保留或剔除操做php
http://pointclouds.org/documentation/tutorials/passthrough.php#passthroughios
#include <iostream> #include <pcl/point_types.h> #include <pcl/filters/passthrough.h> pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>); pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered (new pcl::PointCloud<pcl::PointXYZ>); // Create the filtering object pcl::PassThrough<pcl::PointXYZ> pass; pass.setInputCloud (cloud); //设置pcl::PointXYZ中字段域z pass.setFilterFieldName ("z"); pass.setFilterLimits (0.0, 1.0); //默认是false,表示保留z字段是0.0-1.0的点云数据 true:不保留 pass.setFilterLimitsNegative (true); pass.filter (*cloud_filtered);
使用三维立体方格进行方格的重心估计,每一个方格只保留一个点,所以使用的方格越大则剔除的点数越多。app
http://pointclouds.org/documentation/tutorials/voxel_grid.php#voxelgridui
#include <pcl/filters/voxel_grid.h> pcl::PCLPointCloud2::Ptr cloud (new pcl::PCLPointCloud2 ()); pcl::PCLPointCloud2::Ptr cloud_filtered (new pcl::PCLPointCloud2 ()); // Create the filtering object pcl::VoxelGrid<pcl::PCLPointCloud2> sor; sor.setInputCloud(cloud); //设置方格大小为1立方厘米 sor.setLeafSize(0.01f, 0.01f, 0.01f); sor.filter(*cloud_filtered);
对于一个点的邻域进行统计分析,并修剪掉那些不符合标准的点,该滤波基于邻近点的距离,在范围K个点中计算平均距离,将小于或大于该距离的点剔除或保留。spa
http://pointclouds.org/documentation/tutorials/statistical_outlier.php#statistical-outlier-removalcode
#include <pcl/filters/statistical_outlier_removal.h> // Create the filtering object pcl::StatisticalOutlierRemoval<pcl::PointXYZ> sor; sor.setInputCloud(cloud); //设置周边50个点进行统计 sor.setMeanK(50); //若是一个点的平均距离大于1.0则剔除 sor.setStddevMulThresh(1.0); sor.filter(*cloud_filtered); //保存在1.0范围内的点集 pcl::PLYWriter writer; writer.write<pcl::PointXYZ>("test_Static_inliners.ply", *cloud_filtered, false); //保存在1.0范围外的点集 sor.setNegative(true); sor.filter(*cloud_filtered); writer.write<pcl::PointXYZ>("test_Static_outliers.ply", *cloud_filtered, false);
将点云投影到一个平面上,下面程序中将点云投影到z=0即xoy平面。ci
http://pointclouds.org/documentation/tutorials/project_inliers.php#project-inliersrem
#include <pcl/ModelCoefficients.h> #include <pcl/filters/project_inliers.h> pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>); pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_projected (new pcl::PointCloud<pcl::PointXYZ>); // Create a set of planar coefficients with X=Y=0,Z=1 pcl::ModelCoefficients::Ptr coefficients (new pcl::ModelCoefficients ()); coefficients->values.resize (4); coefficients->values[0] = coefficients->values[1] = 0; coefficients->values[2] = 1.0; coefficients->values[3] = 0; // Create the filtering object pcl::ProjectInliers<pcl::PointXYZ> proj; proj.setModelType (pcl::SACMODEL_PLANE); proj.setInputCloud (cloud); proj.setModelCoefficients (coefficients); proj.filter (*cloud_projected);
条件滤波指定字段域上的取值范围,保留该取值范围内的数据。get
http://pointclouds.org/documentation/tutorials/remove_outliers.php#remove-outliersit
#include <pcl/filters/conditional_removal.h> pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>); pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered(new pcl::PointCloud<pcl::PointXYZ>); // build the condition 与条件 pcl::ConditionAnd<pcl::PointXYZ>::Ptr range_cond (new pcl::ConditionAnd<pcl::PointXYZ> ()); //增长一个z值>0.0 range_cond->addComparison (pcl::FieldComparison<pcl::PointXYZ>::ConstPtr (new pcl::FieldComparison<pcl::PointXYZ> ("z", pcl::ComparisonOps::GT, 0.0))); //增长一个z值<0.8 range_cond->addComparison (pcl::FieldComparison<pcl::PointXYZ>::ConstPtr (new pcl::FieldComparison<pcl::PointXYZ> ("z", pcl::ComparisonOps::LT, 0.8))); // build the filter pcl::ConditionalRemoval<pcl::PointXYZ> condrem; condrem.setCondition (range_cond); condrem.setInputCloud (cloud); condrem.setKeepOrganized(true); // apply filter condrem.filter (*cloud_filtered);
指定半径范围值和邻近点个数,若是在该半径的圆形内的点云个数小于指定的邻近点数则进行将该点删除。而删除的点云说明距离其它点云距离较远。
http://pointclouds.org/documentation/tutorials/remove_outliers.php#remove-outliers
#include <pcl/filters/radius_outlier_removal.h> pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>); pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered(new pcl::PointCloud<pcl::PointXYZ>); pcl::RadiusOutlierRemoval<pcl::PointXYZ> outrem; // build the filter outrem.setInputCloud(cloud); //设置搜索半径0.8 outrem.setRadiusSearch(0.8); //设置若是在0.8半径范围内的点云个数小于2个则删除该点 outrem.setMinNeighborsInRadius(2); // apply filter outrem.filter(*cloud_filtered);