Point Cloud Traditional Filtering Algorithm


This paper introduces the principles of various filtering algorithms and gives related implementation methods.


split function filter

Segmentation function filtering is a commonly used point cloud processing method, which can divide point cloud data into different parts so that each part can be processed independently.

pass filter

Passthrough filter (PassthroughFilter) is a commonly used point cloud filtering method. Its main purpose is to limit the data range of point cloud data in a certain dimension to a specified interval, so as to remove unnecessary point cloud data. Straight-through filtering can be used to remove useless point cloud data such as outliers, noise, and background in point cloud data, thereby improving the quality and accuracy of point cloud data.

The basic idea of ​​straight-through filtering is to limit the point cloud data in a certain dimension, and only keep the point cloud data in the specified interval. The specific operation steps are as follows:

  1. Select the dimension that needs to be restricted, such as the x dimension.
  2. Specify a range, for example, only keep point cloud data where x is between [0,1].
  3. Delete the point cloud data whose x is not between [0,1] in the point cloud data.

Straight-through filtering can be implemented through various point cloud processing libraries or software, such as PCL (Point Cloud Library). In PCL, you can use the pcl::PassThrough class to implement pass-through filtering. The specific code is as follows:

	pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
	pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered(new pcl::PointCloud<pcl::PointXYZ>);
	// 加载点云数据
	pcl::io::loadPCDFile<pcl::PointXYZ>("cloud.pcd", *cloud);
	// 创建直通滤波器
	pcl::PassThrough<pcl::PointXYZ> pass;
	pass.setInputCloud(cloud);
	pass.setFilterFieldName("x");
	pass.setFilterLimits(0.0, 1.0);
	// 执行直通滤波
	pass.filter(*cloud_filtered);
	// 保存滤波后的点云数据
	pcl::io::savePCDFile<pcl::PointXYZ>("cloud_filtered.pcd", *cloud_filtered);

The above code implements the straight-through filtering operation that limits the point cloud data to the range [0,1] in the x dimension, and saves the filtered point cloud data to a file. In practical applications, different dimensions can be restricted according to needs, so as to obtain more accurate point cloud data.

conditional filter

Conditional Filter (Conditional Filter) is a condition-based point cloud filtering method, which can filter out point cloud data that meets the conditions according to a given condition, thereby removing unnecessary point cloud data, which is a bit like a piecewise function. When point If the cloud is within a certain range, it will be kept, and if it is not, it will be discarded. A pass-through filter is a simpler conditional filter that is more like a tool without a filter kernel.

The basic idea of ​​conditional filtering is to filter out point cloud data that meets the conditions by setting conditions. Commonly used conditions include distance conditions, normal vector conditions, RGB color conditions, etc. The specific operation steps are as follows:

  1. Create condition objects, such as pcl::ConditionAndpcl::PointXYZRGB objects.
  2. Set conditions, such as setting distance conditions, point cloud data with distances less than 20 meet the conditions.
  3. Create filter objects such as pcl::ConditionalRemovalpcl::PointXYZRGB objects.
  4. Add a condition object to the filter.
  5. Perform conditional filtering.

Conditional filtering can be implemented through various point cloud processing libraries or software, such as PCL (Point Cloud Library). In PCL, you can use the pcl::ConditionalRemoval class to implement conditional filtering. The specific code is as follows:

pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZRGB>);
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_filtered(new pcl::PointCloud<pcl::PointXYZRGB>);
// 加载点云数据
pcl::io::loadPCDFile<pcl::PointXYZRGB>("cloud.pcd", *cloud);
// 创建条件对象
pcl::ConditionAnd<pcl::PointXYZRGB>::Ptr condition(new pcl::ConditionAnd<pcl::PointXYZRGB>());
condition->addComparison(pcl::TfQuadraticXYZComparison<pcl::PointXYZRGB>::ConstPtr(new pcl::TfQuadraticXYZComparison<pcl::PointXYZRGB>(pcl::ComparisonOps::LT, Eigen::Vector3f(0.0, 0.0, 0.0), 20.0)));
// 创建条件滤波器
pcl::ConditionalRemoval<pcl::PointXYZRGB> filter;
filter.setInputCloud(cloud);
filter.setCondition(condition);
filter.setKeepOrganized(true);
// 执行条件滤波
filter.filter(*cloud_filtered);
// 保存滤波后的点云数据
pcl::io::savePCDFile<pcl::PointXYZRGB>("cloud_filtered.pcd", *cloud_filtered);

The above code realizes the conditional filtering operation according to the distance condition (the distance is less than 20), and saves the filtered point cloud data to a file. In practical applications, different conditions can be set according to needs, so as to obtain more accurate point cloud data.

extract index filter

Extract Index Filter (Extract Indices Filter) is a commonly used point cloud filtering method. Its main purpose is to extract point cloud data within the specified index range to remove unnecessary point cloud data.

The basic idea of ​​extraction index filtering is to extract point cloud data that meets the conditions by specifying the index range. The specific operation steps are as follows:

  1. Create an index object containing the point cloud data to be extracted, such as pcl::PointIndices object.
  2. Add the index of the point cloud data to be extracted to the index object.
  3. Create filter objects such as pcl::ExtractIndicespcl::PointXYZRGB objects.
  4. Add an index object to the filter.
  5. Perform extraction index filtering.

Extraction index filtering can be realized by various point cloud processing libraries or software, such as PCL (Point Cloud Library). In PCL, you can use the pcl::ExtractIndices class to implement extraction index filtering. The specific code is as follows:

pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZRGB>);
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_filtered(new pcl::PointCloud<pcl::PointXYZRGB>);
// 加载点云数据
pcl::io::loadPCDFile<pcl::PointXYZRGB>("cloud.pcd", *cloud);
// 创建索引对象
pcl::PointIndices::Ptr indices(new pcl::PointIndices());
indices->indices.push_back(0);
indices->indices.push_back(1);
indices->indices.push_back(2);
// 创建提取索引滤波器
pcl::ExtractIndices<pcl::PointXYZRGB> filter;
filter.setInputCloud(cloud);
filter.setIndices(indices);
filter.setNegative(false);
// 执行提取索引滤波
filter.filter(*cloud_filtered);
// 保存滤波后的点云数据
pcl::io::savePCDFile<pcl::PointXYZRGB>("cloud_filtered.pcd", *cloud_filtered);

The above code realizes the operation of extracting the point cloud data whose indexes are 0, 1, and 2 in the point cloud data, and saves the extracted point cloud data to a file. In practical applications, different index ranges can be set according to needs, so as to obtain more accurate point cloud data.

downsampling filter

The main purpose of downsampling filtering is to reduce the density of point cloud data, so as to reduce the amount of calculation and memory usage. Downsampling filtering can be used to remove redundant information in point cloud data, thereby improving the processing speed and efficiency of point cloud data.

voxel filtering

Voxel filtering constructs a 3D voxel grid based on a given point cloud and performs downsampling to achieve the filtering effect. Create a 3D voxel grid through the input point cloud data
, and then approximate all the points in each voxel with the representative point (center of gravity) in the voxel, which greatly reduces the amount of data. The voxel filter can achieve the function of downsampling without destroying the geometric structure of the point cloud itself, but it will move the position of the point. In addition, the voxel filter can remove a certain degree of noise points and outliers.

Features: It is often used for down-sampling processing of large amounts of data, reducing the number of points, reducing point cloud data, and maintaining the shape characteristics of the point cloud at the same time. It can down-sample the point cloud to the same distance, and the initial density has little effect. It is mainly based on Sets the size of voxels. Especially as preprocessing before registration and surface reconstruction. Can improve the processing speed of the program very well.
The specific operation steps are as follows:

  1. Create a point cloud data object, such as a pcl::PointCloudpcl::PointXYZRGB object.
  2. Add the point cloud data that needs to be discretized to the point cloud data object.
  3. Create filter objects such as pcl::VoxelGridpcl::PointXYZRGB objects.
  4. Set the discretization parameters of the filter, such as setting the size of the voxel.
  5. Perform voxel filtering.

Voxel filtering can be implemented through various point cloud processing libraries or software, such as PCL (Point Cloud Library). In PCL, you can use the pcl::VoxelGrid class to implement voxel filtering. The specific code is as follows:

pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZRGB>);
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_filtered(new pcl::PointCloud<pcl::PointXYZRGB>);
// 加载点云数据
pcl::io::loadPCDFile<pcl::PointXYZRGB>("cloud.pcd", *cloud);
// 创建体素滤波器
pcl::VoxelGrid<pcl::PointXYZRGB> filter;
filter.setInputCloud(cloud);
// 设置体素的大小
filter.setLeafSize(0.01f, 0.01f, 0.01f);
// 执行体素滤波
filter.filter(*cloud_filtered);
// 保存滤波后的点云数据
pcl::io::savePCDFile<pcl::PointXYZRGB>("cloud_voxelized.pcd", *cloud_filtered);

The above code realizes the operation of discretizing point cloud data, and saves the discretized point cloud data to a file. In practical applications, different voxel sizes can be set according to needs, so as to obtain more accurate or rougher discretized point cloud data.

Uniform sampling filtering

The main purpose of Uniform Sampling Filter
is to reduce the density of point cloud data to reduce the amount of calculation and memory usage. The basic idea of ​​uniform sampling filtering is to uniformly sample a certain number of points in the point cloud data, so as to obtain a point cloud data similar to the original point cloud data but with a smaller number. This method can adjust the density of point cloud data by setting the sampling interval or sampling ratio, while preserving the overall shape and characteristics of point cloud data.

Uniform sampling filtering is basically equivalent to voxel filtering, but it does not change the position of the points. After downsampling, the point cloud distribution is basically uniform, but the accuracy of the point cloud is better than voxel filtering because there is no moving point position.

The specific operation steps of uniform sampling filtering are as follows:

  1. Create a point cloud data object, such as a pcl::PointCloudpcl::PointXYZRGB object.
  2. Add the point cloud data whose density needs to be reduced to the point cloud data object.
  3. Create filter objects such as pcl::UniformSamplingpcl::PointXYZRGB objects.
  4. Set the sampling interval or sampling ratio of the filter.
  5. Perform uniform sampling filtering.

Various point cloud processing libraries or software can be used to achieve uniform sampling filtering, such as PCL (Point Cloud Library) and so on. In PCL, you can use the pcl::UniformSampling class to implement uniform sampling filtering. The specific code is as follows:

pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZRGB>);
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_filtered(new pcl::PointCloud<pcl::PointXYZRGB>);
// 加载点云数据
pcl::io::loadPCDFile<pcl::PointXYZRGB>("cloud.pcd", *cloud);
// 创建均匀采样滤波器
pcl::UniformSampling<pcl::PointXYZRGB> filter;
filter.setInputCloud(cloud);
// 设置采样间隔或采样比例
filter.setRadiusSearch(0.01);
// 执行均匀采样滤波
filter.filter(*cloud_filtered);
// 保存滤波后的点云数据
pcl::io::savePCDFile<pcl::PointXYZRGB>("cloud_uniform_sampled.pcd", *cloud_filtered);

The above code realizes the uniform sampling of point cloud data, and saves the sampled point cloud data to a file. In practical applications, different sampling intervals or sampling ratios can be set according to needs, so as to obtain more accurate or rougher sampling point cloud data.

Remove noise point filter

statistical filtering

Statistical Outlier Removal Filter is used to remove obvious outliers. Outliers are characterized by being sparsely distributed in space. Laser scanning often produces point cloud datasets with varying point densities, and measurement errors can also lead to sparse outliers/outliers. Considering the characteristics of outliers, it can be defined that a certain point cloud is less than a certain density, that is, the point cloud is invalid. The specific steps are that for each point, calculate the average distance from it to its nearest k points. By assuming that the resulting distribution of distances between points in the point cloud is a Gaussian distribution with mean and standard deviation, points whose average distance is outside the standard range for a given mean and variance can be defined as outliers and removed from the data .

Features: It mainly removes outliers (denoising) according to the density, and has a better effect on outliers with large differences in density.
The specific operation steps of statistical filtering are as follows:

  1. Create a point cloud data object, such as a pcl::PointCloudpcl::PointXYZRGB object.
  2. Add the point cloud data that needs to remove outliers to the point cloud data object.
  3. Create filter objects such as pcl::StatisticalOutlierRemovalpcl::PointXYZRGB objects.
  4. Set the parameters of the filter, such as setting the number of neighborhood points, mean distance threshold, etc.
  5. Perform statistical filtering.

Various point cloud processing libraries or software can be used to implement statistical filtering, such as PCL (Point Cloud Library) and so on. In PCL, you can use the pcl::StatisticalOutlierRemoval class to implement statistical filtering. The specific code is as follows:

pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZRGB>);
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_filtered(new pcl::PointCloud<pcl::PointXYZRGB>);
// 加载点云数据
pcl::io::loadPCDFile<pcl::PointXYZRGB>("cloud.pcd", *cloud);
// 创建统计滤波器
pcl::StatisticalOutlierRemoval<pcl::PointXYZRGB> filter;
filter.setInputCloud(cloud);
// 设置滤波器的参数
filter.setMeanK(50);
filter.setStddevMulThresh(1.0);
// 执行统计滤波
filter.filter(*cloud_filtered);
// 保存滤波后的点云数据
pcl::io::savePCDFile<pcl::PointXYZRGB>("cloud_statistical_filtered.pcd", *cloud_filtered);

The above code implements statistical filtering of point cloud data, and saves the filtered point cloud data to a file. In practical applications, different parameters can be set according to needs, such as the number of neighborhood points and the mean distance threshold, etc., so as to obtain more accurate or looser filtering effects

radius filter

Radius Outlier Removal Filter (Radius Outlier Removal Filter) calculates the distance between each point and surrounding points to determine whether the point is an outlier point and remove it from the point cloud data.
Radius filters are simpler and cruder than statistical filters. Draw a circle with a certain point as the center to calculate the number of points falling in the center of the circle. When the number is greater than the given value, the point will be kept, and if the number is less than the given value, the point will be eliminated. This algorithm runs fast, and the points left by sequential iterations must be the densest, but the radius of the circle and the number of points in the circle need to be manually specified.

Specifically, the operation steps of radius filtering are as follows:

  1. Create a point cloud data object, such as pcl::PointCloudpcl::PointXYZ object.
  2. Add the point cloud data that needs to remove outliers to the point cloud data object.
  3. Create radius filter objects, such as pcl::RadiusOutlierRemovalpcl::PointXYZ objects.
  4. Set the parameters of the radius filter, such as the size of the radius and the number of neighborhood points.
  5. Perform radius filtering.
  6. Get filtered point cloud data.

In PCL (Point Cloud Library), you can use the pcl::RadiusOutlierRemoval class to implement radius filtering. Here is a sample code that demonstrates how to use the radius filter for point cloud filtering:

pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZRGB>);
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_filtered(new pcl::PointCloud<pcl::PointXYZRGB>);
// 加载点云数据
pcl::io::loadPCDFile<pcl::PointXYZRGB>("cloud.pcd", *cloud);
// 创建统计滤波器
pcl::StatisticalOutlierRemoval<pcl::PointXYZRGB> filter;
filter.setInputCloud(cloud);
// 设置滤波器的参数
filter.setMeanK(50);
filter.setStddevMulThresh(1.0);
// 执行统计滤波
filter.filter(*cloud_filtered);
// 保存滤波后的点云数据
pcl::io::savePCDFile<pcl::PointXYZRGB>("cloud_statistical_filtered.pcd", *cloud_filtered);

The above code implements statistical filtering of point cloud data, and saves the filtered point cloud data to a file. In practical applications, different parameters can be set according to needs, such as the number of neighborhood points and the mean distance threshold, so as to obtain more accurate or looser filtering effects.

Gaussian filter

The main purpose of Gaussian Filter is to smooth point cloud data to remove noise. The basic idea of ​​the Gaussian filter is to weight the points around each point with a Gaussian function to achieve the effect of smoothing the point cloud data. Its Li Yongle Gaussian function still has the characteristics of Gaussian function after Fourier transform, so that the weight of the specified area is Gaussian distribution, so as to filter out high-frequency noise points. In point cloud processing, Gaussian filtering is usually used to remove high-frequency noise.
Features: The smoothing effect of Gaussian filtering is better, but the edge corners will also be smoothed more.

The specific operation steps of Gaussian filtering are as follows:

  1. Create a point cloud data object, such as a pcl::PointCloudpcl::PointXYZRGB object.
  2. Add the point cloud data to be smoothed to the point cloud data object.
  3. Create a Gaussian filter object, such as pcl::GaussianKernel class or pcl::GaussianFilter class.
  4. Set the parameters of the Gaussian filter, such as standard deviation, kernel size, etc.
  5. Perform Gaussian filtering.

Various point cloud processing libraries or software can be used to implement Gaussian filtering, such as PCL (Point Cloud Library) and so on. In PCL, you can use the pcl::GaussianKernel class or pcl::GaussianFilter class to implement Gaussian filtering. The specific code is as follows:

pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZRGB>);
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_filtered(new pcl::PointCloud<pcl::PointXYZRGB>);
// 加载点云数据
pcl::io::loadPCDFile<pcl::PointXYZRGB>("cloud.pcd", *cloud);
// 创建高斯滤波器
pcl::GaussianKernel<pcl::PointXYZRGB, pcl::PointXYZRGB> kernel;
kernel.setInputCloud(cloud);
kernel.setSigma(0.01);
// 创建高斯滤波对象
pcl::GaussianFilter<pcl::PointXYZRGB, pcl::PointXYZRGB> filter;
filter.setKernel(kernel);
// 执行高斯滤波
filter.filter(*cloud_filtered);
// 保存滤波后的点云数据
pcl::io::savePCDFile<pcl::PointXYZRGB>("cloud_gaussian_filtered.pcd", *cloud_filtered);

The above code implements Gaussian filtering of point cloud data, and saves the filtered point cloud data to a file. In practical applications, different parameters, such as standard deviation and kernel size, can be set according to needs, so as to obtain more accurate or looser filtering effects.

bilateral filtering

The main purpose of Bilateral Filter is to smooth the point cloud data to remove noise while retaining the edge and detail information of the point cloud data. The basic idea of ​​the bilateral filter is to weight the points around each point with a Gaussian function and a distance function, so as to achieve the effect of smoothing point cloud data. Bilateral filtering can not only smooth point cloud data, but also preserve edge and detail information, so it is widely used in point cloud processing.

Bilateral filtering is a nonlinear filter, which can achieve the effect of maintaining edges and smoothing noise reduction. To a certain extent, it compensates for the shortcomings of Gaussian filtering. Bilateral filtering works better for Gaussian noise. Bilateral filtering adds a weight in one dimension to the Gaussian filtering that simply considers the position of the spatial domain point. In point cloud processing, it can be called a feature domain, that is, the normal vector of the current point and the normal vector of adjacent points. Balance smoothing and edge preservation by changing the variance of Gaussian filtering on both domains. The denoising effect needs to be based on the actual point cloud situation, not all situations that require smoothing and edge preservation; there are two parameters that need to be adjusted, and multiple experiments are required.

Features : Bilateral filtering is a compromise process that combines the spatial [pixel range domain (range domain)] proximity and pixel value similarity of the image, while considering the spatial domain [spatial domain (spatial domain)] information and gray similarity, To achieve the purpose of edge preservation and denoising (not only effectively denoise the surface of the spatial 3D model, but also maintain the geometric feature information in the point cloud data, and avoid the 3D point cloud data from being transitionally smooth). Smooth the small-scale fluctuation noise of point cloud data.

Note : A point cloud that can use bilateral filtering must contain an intensity field. Among the existing points types, only PointXYZI and PointXYZINormal have intensity information. FastBilateralFilter only applies to ordered point clouds.

The specific operation steps of bilateral filtering are as follows:

  1. Create a point cloud data object, such as a pcl::PointCloudpcl::PointXYZRGB object.
  2. Add the point cloud data to be smoothed to the point cloud data object.
  3. Create a bilateral filter object, such as the pcl::BilateralFilter class.
  4. Set the parameters of the bilateral filter, such as the standard deviation of the Gaussian function, the standard deviation of the distance function, etc.
  5. Perform bilateral filtering.

Various point cloud processing libraries or software can be used to implement bilateral filtering, such as PCL (Point Cloud Library) and so on. In PCL, you can use the pcl::BilateralFilter class to implement bilateral filtering. The specific code is as follows:

pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZRGB>);
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_filtered(new pcl::PointCloud<pcl::PointXYZRGB>);
// 加载点云数据
pcl::io::loadPCDFile<pcl::PointXYZRGB>("cloud.pcd", *cloud);
// 创建双边滤波器对象
pcl::BilateralFilter<pcl::PointXYZRGB> filter;
filter.setInputCloud(cloud);
filter.setSigmaS(10); // 距离函数的标准差
filter.setSigmaR(0.1); // 高斯函数的标准差
// 执行双边滤波
filter.filter(*cloud_filtered);
// 保存滤波后的点云数据
pcl::io::savePCDFile<pcl::PointXYZRGB>("cloud_bilateral_filtered.pcd", *cloud_filtered);

The above code realizes the bilateral filtering operation of the point cloud data, and saves the filtered point cloud data to a file. In practical applications, different parameters can be set according to needs, such as the standard deviation of the distance function and the standard deviation of the Gaussian function, etc., so as to obtain a more accurate or looser filtering effect.

random sampling consensus filtering

The main purpose of Random Sample Consensus Filter (RANSAC Filter) is to remove outliers in point cloud data. The basic idea of ​​the random sampling consistent filter is to randomly select a set of points as a model, calculate the distance from other points to the model, and find the best model, and use the points on the model as inliers, and use other points Delete as outliers. Random sampling consistent filtering can not only remove outliers, but also preserve the shape and structure information of point cloud data, so it is widely used in point cloud processing.
First randomly select a sample subset from the sample, then use the minimum variance estimation algorithm to calculate the model parameters for this subset, then calculate the deviation of all samples from the model, and then use a preset threshold to compare with the deviation , when the deviation is less than the threshold, the point is marked as an in-sample point, otherwise it is eliminated. Record the number of internal points, and then repeat this process. For each repetition, record the best model parameters (that is, the maximum number of internal points in the sample). After each iteration, the expected error rate and total number of samples will be calculated. , The current number of iterations calculates an iteration end evaluation factor, and determines the end of the iteration based on this. (LMedS minimum median variance estimation algorithm, calculates the deviation of the sample whose deviation value is in the middle among all samples, and the model parameters obtained by this calculation, no need to set the threshold in advance)

Features : It is mainly used to exclude error samples, and can estimate mathematical model parameters iteratively from a set of observation data containing "outside points".

The specific operation steps of random sampling consistent filtering are as follows:

  1. Create a point cloud data object, such as a pcl::PointCloudpcl::PointXYZRGB object.
  2. Add the point cloud data that needs to be filtered to the point cloud data object.
  3. Create a random sampling consensus filter object, such as the pcl::RandomSampleConsensus class.
  4. Set the parameters of the random sampling consensus filter, such as model type, distance threshold, etc.
  5. Perform random sampling consistent filtering.

Various point cloud processing libraries or software can be used to implement random sampling consistent filtering, such as PCL (Point Cloud Library) and so on. In PCL, you can use the pcl::RandomSampleConsensus class to implement random sampling consistent filtering. The specific code is as follows:

pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZRGB>);
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_filtered(new pcl::PointCloud<pcl::PointXYZRGB>);
// 加载点云数据
pcl::io::loadPCDFile<pcl::PointXYZRGB>("cloud.pcd", *cloud);
// 创建随机采样一致滤波器对象
pcl::RandomSampleConsensus<pcl::PointXYZRGB> ransac;
ransac.setInputCloud(cloud);
ransac.setModelType(pcl::SACMODEL_PLANE); // 设置模型类型为平面
ransac.setDistanceThreshold(0.01); // 设置距离阈值
// 执行随机采样一致滤波
ransac.filter(*cloud_filtered);
// 保存滤波后的点云数据
pcl::io::savePCDFile<pcl::PointXYZRGB>("cloud_ransac_filtered.pcd", *cloud_filtered);

The above code implements random sampling and consistent filtering of point cloud data, and saves the filtered point cloud data to a file. In practical applications, different parameters, such as model type and distance threshold, can be set according to needs, so as to obtain more accurate or looser filtering effects.

projection filtering

投影滤波(Projection Filter)其主要目的是将点云数据投影到某个平面上,并去除该平面上的点云数据,从而达到滤波的效果。投影滤波器的基本思想是将点云数据投影到某个平面上,计算该平面上的点云数据,从而找到需要保留的点云数据,并将该点云数据保留,将其他点云数据删除。投影滤波器既可以去除某个平面上的点云数据,又可以保留点云数据的形状和结构信息,因此在点云处理中应用广泛。

The specific operation steps of projection filtering are as follows:

  1. Create a point cloud data object, such as a pcl::PointCloudpcl::PointXYZRGB object.
  2. Add the point cloud data that needs to be filtered to the point cloud data object.
  3. Create projection filter objects, such as the pcl::ProjectInliers class.
  4. Set the parameters of the projection filter, such as the projection plane, projection method, etc.
  5. Perform projection filtering.

Projection filtering can be implemented using various point cloud processing libraries or software, such as PCL (Point Cloud Library), etc. In PCL, you can use the pcl::ProjectInliers class to implement projection filtering. The specific code is as follows:

pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZRGB>);
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_filtered(new pcl::PointCloud<pcl::PointXYZRGB>);
// 加载点云数据
pcl::io::loadPCDFile<pcl::PointXYZRGB>("cloud.pcd", *cloud);
// 创建投影滤波器对象
pcl::ModelCoefficients::Ptr coefficients(new pcl::ModelCoefficients);
coefficients->values.resize(4);
coefficients->values[0] = 0;
coefficients->values[1] = 0;
coefficients->values[2] = 1;
coefficients->values[3] = 0;
pcl::ProjectInliers<pcl::PointXYZRGB> proj;
proj.setModelType(pcl::SACMODEL_PLANE); // 设置模型类型为平面
proj.setInputCloud(cloud);
proj.setModelCoefficients(coefficients); // 设置投影平面
// 执行投影滤波
proj.filter(*cloud_filtered);
// 保存滤波后的点云数据
pcl::io::savePCDFile<pcl::PointXYZRGB>("cloud_projected_filtered.pcd", *cloud_filtered);

The above code realizes the operation of projecting and filtering the point cloud data, and saves the filtered point cloud data to a file. In practical applications, different parameters, such as the projection plane and projection method, can be set according to needs, so as to obtain more accurate or looser filtering effects.

Guess you like

Origin blog.csdn.net/Man_1man/article/details/130167933