指定點雲中特定字段域的數字範圍,保留或剔除操做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);