当前位置:网站首页>[PCL self study: filtering] introduction and use of various filters in PCL (continuously updated)
[PCL self study: filtering] introduction and use of various filters in PCL (continuously updated)
2022-07-03 04:30:00 【Stanford rabbit】
PCL_filter Catalogue of various filters in the module
- One 、 Pass through filter (PassThrough): Used for threshold filtering
- Two 、 Voxel filter (VoxelGrid filter): For down sampling
- 3、 ... and 、 Statistical outlier filter (StatisticalOutlierRemoval filter): For outliers filtering
- Four 、 Condition and radius filter (Conditional or RadiusOutlier ): For outliers filtering
One 、 Pass through filter (PassThrough): Used for threshold filtering
1、 Introduction to pass through filter
Pass through filter (PassThrough), As the name suggests, it is to use a certain threshold Direct filtration Drop the filter that does not meet the threshold . For example, there is a value range of 1 To 100 100000 numbers , The pass through filter is set to a threshold of <50, Then it is filtered by the through filter , All of these 100000 figures >=50 The number of will be discarded , Only keep all numbers that meet the threshold .
2、 Sample code
First , Create a file in the editor , such as pass .cpp, And put the following into it , See notes for code analysis .
#include <iostream>
#include <pcl/point_types.h>
#include <pcl/filters/passthrough.h>
int main ()
{
// Raw point cloud pointer
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
// Filtered point cloud pointer
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered (new pcl::PointCloud<pcl::PointXYZ>);
// Set the point cloud to unordered point cloud , common 5 A little bit
cloud->width = 5;
cloud->height = 1;
cloud->points.resize (cloud->width * cloud->height);
for (auto& point: *cloud) // Randomly generate point coordinates
{
point.x = 1024 * rand () / (RAND_MAX + 1.0f);
point.y = 1024 * rand () / (RAND_MAX + 1.0f);
point.z = 1024 * rand () / (RAND_MAX + 1.0f);
}
// Output the created point
std::cerr << "Cloud before filtering: " << std::endl;
for (const auto& point: *cloud)
std::cerr << " " << point.x << " "
<< point.y << " "
<< point.z << std::endl;
/* * The following code creates PassThrough Filter object , And set its parameters . * The filter field name is set to z coordinate , * The accepted interval value is set to (0.0;1.0). */
// Create filter object
pcl::PassThrough<pcl::PointXYZ> pass;
pass.setInputCloud (cloud); // Fill in data
pass.setFilterFieldName ("z"); // Set the dimension name to be filtered , Here for z Directional dimension
pass.setFilterLimits (580.0, 900); // Set the filtering threshold
//pass.setFilterLimitsNegative (true);
pass.filter (*cloud_filtered); // Start filtering
// Output the filtered point
std::cerr << "Cloud after filtering: " << std::endl;
for (const auto& point: *cloud_filtered)
std::cerr << " " << point.x << " "
<< point.y << " "
<< point.z << std::endl;
return (0);
}
Filtering effect : Green is the threshold within the threshold (580,900) The point of , Red is the filtered dot . When setFilterLimitsNegative The parameter is set to True when , Then choose ( Z<580 || Z >900 ) Point cloud in .
Two 、 Voxel filter (VoxelGrid filter): For down sampling
1、 Voxel filter introduction
Voxel filter (VoxelGrid filter), It is often used to reduce the number of point clouds , Point cloud sampling . It can be analogous to sampling under the image pyramid . seeing the name of a thing one thinks of its function , Divide the point cloud into voxels in three dimensions ( Spatial grid ), And use mathematical methods to replace the point cloud in each voxel with a point , Thus reducing the number of point clouds .
Official explanation :
Voxel descent : To be shown VoxelGrid Class creates a 3D Voxel grid ( Think of voxel mesh as a group of miniatures in space 3D The box ). then , In each voxel ( namely 3D box ) in , All appearing points will be approximated ( Down sampling ) To their centroid . This method is slower than approaching them with voxel centers , But it can more accurately represent the underlying surface .
2、 Sample code
First , Download datasets table_scene_lms400.pcd And save it somewhere on disk . I can't connect here for the time being github, Use others' renderings instead .
Paste the following code into the editor , And compile .
#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/filters/voxel_grid.h>
int
main ()
{
pcl::PCLPointCloud2::Ptr cloud (new pcl::PCLPointCloud2 ());
pcl::PCLPointCloud2::Ptr cloud_filtered (new pcl::PCLPointCloud2 ());
// Create a point cloud reader object
pcl::PCDReader reader;
// Will download pcd The file path replaces the following path
reader.read ("table_scene_lms400.pcd", *cloud);
std::cerr << "PointCloud before filtering: " << cloud->width * cloud->height
<< " data points (" << pcl::getFieldsList (*cloud) << ")." << std::endl;
// Create voxel filter objects
pcl::VoxelGrid<pcl::PCLPointCloud2> sor;
sor.setInputCloud (cloud);
//LeafSize Is a voxel grid leaf size parameter , Each element represents the voxel in XYZ Dimension in direction . The unit is m, here 0.01 Represents one centimeter .
sor.setLeafSize (0.01f, 0.01f, 0.01f);
sor.filter (*cloud_filtered);
std::cerr << "PointCloud after filtering: " << cloud_filtered->width * cloud_filtered->height
<< " data points (" << pcl::getFieldsList (*cloud_filtered) << ")." << std::endl;
// Create a point cloud writer to write the filtered point cloud pcd In file
pcl::PCDWriter writer;
writer.write ("table_scene_lms400_downsampled.pcd", *cloud_filtered,
Eigen::Vector4f::Zero (), Eigen::Quaternionf::Identity (), false);
return (0);
}
The filtering effect is as follows :
Before voxel filtering :
The effect of voxel filtering :
3、 ... and 、 Statistical outlier filter (StatisticalOutlierRemoval filter): For outliers filtering
1、 Introduction to statistical outlier filter
Statistical outlier filter (StatisticalOutlierRemoval filter) Often used in Delete outliers ( Noise and specks ), The filter uses statistical analysis techniques to remove noise measurements from point cloud data sets , For example, outliers .
1.1 background :
Laser scanning usually generates point cloud data sets with different point densities . Besides , Measurement errors can also lead to sparse outliers , Thus further undermining the results . This makes the local point cloud feature ( Such as changes in surface normals or curvature ) Our estimates become complicated , This results in an incorrect value , This may lead to the failure of point cloud registration . Some of these irregularities can be solved by statistical analysis of the neighborhood of each point , And trim those points that do not meet certain standards . The outlier removal method is based on the distribution of the distance from the calculated point to the adjacent point in the input data set . For each of these points , Calculate the average distance from it to all adjacent points . Through assumptions The distribution is a Gaussian distribution with mean and standard deviation , All points , Its mean distance is outside the interval defined by the mean and standard deviation of the global distance , Can be regarded as outliers , And prune from the data set .
The following picture shows the effect of outlier analysis and removal : On the left is the raw data set , On the right is the generated data set . The figure shows the average of a point before and after filtering k Neighbor distance .
2、 Sample code
It is still from github Download the following data set table_scene_lms400_inliers.pcd. Then paste the following code into the compiler .
#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/filters/statistical_outlier_removal.h>
int
main ()
{
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered (new pcl::PointCloud<pcl::PointXYZ>);
// Point cloud data
pcl::PCDReader reader;
// Will download pcd Replace the following path with the file path
reader.read<pcl::PointXYZ> ("table_scene_lms400.pcd", *cloud);
std::cerr << "Cloud before filtering: " << std::endl;
std::cerr << *cloud << std::endl;
// Create filter object sor
pcl::StatisticalOutlierRemoval<pcl::PointXYZ> sor;
/* Parameter setting : * The number of neighbors to be analyzed at each point is set to 50, The standard deviation multiplier is 1. * It means , All the distance to the query point is greater than 1 Points with standard deviations will be marked as outliers and deleted . * The output is calculated and stored in cloud_filtered in . */
sor.setInputCloud (cloud);// Fill in the point cloud
sor.setMeanK (50); // Set the average parameter K
sor.setStddevMulThresh (1.0);// Set up
sor.filter (*cloud_filtered);
std::cerr << "Cloud after filtering: " << std::endl;
std::cerr << *cloud_filtered << std::endl;
// Output the filtered point cloud as pcd Format file
pcl::PCDWriter writer;
writer.write<pcl::PointXYZ> ("table_scene_lms400_inliers.pcd", *cloud_filtered, false);
sor.setNegative (true); // Set to true, The condition will become that the distance to the query point is less than 1 Points with standard deviations will be marked as outliers and deleted , Leave those points that were filtered before .
sor.filter (*cloud_filtered);
writer.write<pcl::PointXYZ> ("table_scene_lms400_outliers.pcd", *cloud_filtered, false);
return (0);
}
Four 、 Condition and radius filter (Conditional or RadiusOutlier ): For outliers filtering
1、 Condition and radius filter introduction
[1] Conditional filter , seeing the name of a thing one thinks of its function , Is to give some conditional values to the filter , It can be one or more , Using conditional filter can filter out all points that do not meet the conditions , Commonly used for outlier filtering .
In the sample code , We use to add two comparisons to the condition : Greater than (GT) 0.0 And less than (LT) 0.8. Then use this condition to build a filter .
[2] Radius filter , seeing the name of a thing one thinks of its function , Given the specified radius , And the minimum number of points in the radius to filter , For example, meet the radius 0.8 Inside , The number of points is at least 2, That is, calculate the number of points within the radius of each point , Less than this number of points will be filtered , Commonly used for outlier filtering .
Let's look directly at the code :
The following figure can help us understand RadiusOutlierRemoval The role of filter objects . The user specified some neighborhood points , Each index must be within the specified radius parameter . for example , If you specify 1 Adjacent points , Then only the yellow dot will change from PointCloud Delete in . If you specify 2 Adjacent points , Then the yellow and green dots will change from PointCloud Delete in .
2、 Sample code
#include <iostream>
#include <pcl/point_types.h>
#include <pcl/filters/radius_outlier_removal.h>
#include <pcl/filters/conditional_removal.h>
int
main (int argc, char** argv)
{
if (argc != 2)
{
std::cerr << "please specify command line arg '-r' or '-c'" << std::endl;
exit(0);
}
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered (new pcl::PointCloud<pcl::PointXYZ>);
// Randomly generate some point cloud data
cloud->width = 5;
cloud->height = 1;
cloud->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);
}
// If the user enters -r Then use the radius filter to filter out the point cloud , Set filtering conditions : Search radius 0.8, Minimum points 2, After filtering, the point cloud is still organized ( Keep the order )
if (strcmp(argv[1], "-r") == 0){
pcl::RadiusOutlierRemoval<pcl::PointXYZ> outrem;
// Set filtering parameters
outrem.setInputCloud(cloud);
outrem.setRadiusSearch(0.8);
outrem.setMinNeighborsInRadius (2);
outrem.setKeepOrganized(true);
// Start filter
outrem.filter (*cloud_filtered);
}
// If the user enters an instruction -c, Then enable the conditional filter .
else if (strcmp(argv[1], "-c") == 0){
// Create conditional filter “ Conditions ”, Set the condition to two “ Compare ” filter ,“GT” It means greater than , In this case, it means z>0 The point of ;“LT” It means less than , In this case, it means z<0.8 The point of . Therefore, the filter retains (0<z<0.8) The point of .
pcl::ConditionAnd<pcl::PointXYZ>::Ptr range_cond (new
pcl::ConditionAnd<pcl::PointXYZ> ());
range_cond->addComparison (pcl::FieldComparison<pcl::PointXYZ>::ConstPtr (new
pcl::FieldComparison<pcl::PointXYZ> ("z", pcl::ComparisonOps::GT, 0.0)));
range_cond->addComparison (pcl::FieldComparison<pcl::PointXYZ>::ConstPtr (new
pcl::FieldComparison<pcl::PointXYZ> ("z", pcl::ComparisonOps::LT, 0.8)));
// Create a conditional filter , After filtering, the point cloud is still organized ( Keep the order )
pcl::ConditionalRemoval<pcl::PointXYZ> condrem;
condrem.setCondition (range_cond);
condrem.setInputCloud (cloud);
condrem.setKeepOrganized(true);
// Start filtering
condrem.filter (*cloud_filtered);
}
else{
std::cerr << "please specify command line arg '-r' or '-c'" << std::endl;
exit(0);
}
std::cerr << "Cloud before filtering: " << std::endl;
for (const auto& point: *cloud)
std::cerr << " " << point.x << " "
<< point.y << " "
<< point.z << std::endl;
// display pointcloud after filtering
std::cerr << "Cloud after filtering: " << std::endl;
for (const auto& point: *cloud_filtered)
std::cerr << " " << point.x << " "
<< point.y << " "
<< point.z << std::endl;
return (0);
}
summary :
This article introduces the pass through filter , Voxel filter , Statistical outlier filter , Concept and example code of radius filter and conditional filter . however PCL There are many filters not introduced in , For example, point cloud filtering inside arbitrary polygons CropHull( It is mostly used for writing point cloud post-processing software , For user interface interaction ). The introductions here are relatively simple , The detailed introduction and experimental results can be referred to The article of the elder generation . After learning all the contents in the later stage , Prepare to write a point cloud post-processing software yourself , Use QT+PCL Realize various point cloud post-processing functions , At that time, I will write a blog post about the compilation process , Coming soon .
【 About bloggers 】
Stanford rabbit , male , Master of mechanical engineering, Tianjin University . Since graduation, I have been engaged in optical three-dimensional imaging and point cloud processing . Because the three-dimensional processing library used in work is the internal library of the company , Not universally applicable , So I learned to open source by myself PCL Library and its related mathematical knowledge for use . I would like to share the self-study process with you .
Bloggers lack of talent and knowledge , Not yet able to guide , If you have any questions, please leave a message in the comments section for everyone to discuss .
If seniors have job opportunities, you are welcome to send a private letter .
边栏推荐
- Classes in TS
- [Chongqing Guangdong education] reference materials for design and a better life of Zhongyuan Institute of science and technology
- The time has come for the domestic PC system to complete the closed loop and replace the American software and hardware system
- Dismantle a 100000 yuan BYD "Yuan". Come and see what components are in it.
- [set theory] set operation (Union | intersection | disjoint | relative complement | symmetric difference | absolute complement | generalized union | generalized intersection | set operation priority)
- [software testing-6] & Test Management
- Function introduction of member points mall system
- AWS VPC
- Data Lake three swordsmen -- comparative analysis of delta, Hudi and iceberg
- [set theory] ordered pair (ordered pair | ordered triple | ordered n ancestor)
猜你喜欢
vulnhub HA: Natraj
[fxcg] market analysis today
JVM原理简介
Basic use of continuous integration server Jenkins
[NLP]—sparse neural network最新工作简述
I've been in software testing for 8 years and worked as a test leader for 3 years. I can also be a programmer if I'm not a professional
[pat (basic level) practice] - [simple simulation] 1063 calculate the spectral radius
540. Single element in ordered array
Some information about the developer environment in Chengdu
The programmer went to bed at 12 o'clock in the middle of the night, and the leader angrily scolded: go to bed so early, you are very good at keeping fit
随机推荐
因子选股-打分模型
JVM原理简介
2022 chemical automation control instrument examination summary and chemical automation control instrument certificate examination
What's wrong with SD card data damage? How to recover SD card data damage
Reptile exercise 02
Smart contract security audit company selection analysis and audit report resources download - domestic article
Fcpx template: sweet memory electronic photo album photo display animation beautiful memory
Ffmpeg tanscoding transcoding
Bugku CTF daily question baby_ flag. txt
Priv-app permission异常
[fairseq] error: typeerror:_ broadcast_ coalesced(): incompatible function arguments
Employee attendance management system based on SSM
跨境电商多商户系统怎么选
使用BENCHMARKSQL工具对KingbaseES预热数据时执行:select sys_prewarm(‘NDX_OORDER_2 ‘)报错
MC Layer Target
[set theory] set operation (Union | intersection | disjoint | relative complement | symmetric difference | absolute complement | generalized union | generalized intersection | set operation priority)
2022 registration examination for safety production management personnel of hazardous chemical production units and examination skills for safety production management personnel of hazardous chemical
Database management tool, querious direct download
Small program animation realizes the running lantern and animation object
[untitled] 2022 safety production supervisor examination question bank and simulated safety production supervisor examination questions