Point cloud data filtering processing (PCL implementation)

lead:

​​​​​​Point cloud data filtering processing (PCL implementation) - Brief Book

2020.01.03 14:29:02 Word count 942 Read 5,412

Point cloud data filtering processing (PCL implementation)

1. Filter introduction

The process of point cloud target recognition: data collection->filtering->point cloud segmentation->point cloud recognition, data collection can be collected by RGBD camera or laser radar and other equipment. Due to the influence of acquisition equipment accuracy, environmental factors, lighting factors, and object surface properties, noise will inevitably appear in point cloud data. The filtering process is to solve the problems of irregular and smooth point cloud data density, outliers, large data downsampling, holes, and noise data.
Point cloud data filtering processing (PCL implementation)

main filter

Pass-through filter, voxel filter, statistical filter, radius filter, bilateral filter, median filter, convolution filter, Gaussian filter, conditional filter

Bilateral filter:
Straight-through filter: It is to set a range of values ​​in the x, y, and z directions to filter out point clouds that are obviously not within the test distance range; using data collected by Intel RealSense or lidar, you can set a reasonable range for x, y, and z to filter out point clouds that we don’t need.

Voxel filter: If you use high-resolution cameras and other devices to collect point clouds, the point clouds will often be denser. Excessive number of point clouds will bring difficulties to the subsequent segmentation work. The voxel grid filter can achieve the function of downsampling without destroying the geometric structure of the point cloud itself. The point cloud geometric structure is not only the macroscopic geometric shape, but also its microscopic arrangement, such as horizontally similar dimensions and vertically the same distance.

Statistical filter: used to remove obvious outliers (outliers are often introduced by measurement noise). It is characterized by sparse distribution in space, which can be understood as: each point expresses a certain amount of information, and the denser the points in a certain area, the greater the amount of information may be. Noise information is useless information with a small amount of information. Therefore, the information expressed by outliers can be ignored. 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. Calculate the average distance from each point to its nearest k points. Then the distances of all points in the point cloud should constitute a Gaussian distribution.

Radius filter: The radius filter is simpler and more crude than the statistical filter. 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.

2. PCL filter source code

2.1 Pass-through filter

Pass-through filter code demonstration: first load a bicycle model from a file, visualize

1578042283(1).jpg

#include "stdafx.h"

#include <iostream>
#include <pcl/point_types.h>
#include <pcl/filters/passthrough.h>
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/io/pcd_io.h> 
#include <pcl/io/ply_io.h>
#include <pcl/filters/voxel_grid.h>
#include <pcl/filters/statistical_outlier_removal.h>
#include <pcl/filters/bilateral.h>
#include <pcl/filters/fast_bilateral.h>
#include <pcl/filters/fast_bilateral_omp.h>
#include <pcl/filters/radius_outlier_removal.h>

using namespace std;
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>);

    if (pcl::io::loadPLYFile<pcl::PointXYZ>("Bicycle.ply", *cloud) == -1) //* load the file 
    {
        PCL_ERROR("Couldn't read file test_pcd.pcd \n");
        system("PAUSE");
        return (-1);
    }

    pcl::PassThrough<pcl::PointXYZ> pass;
    pass.setInputCloud(cloud);
    pass.setFilterFieldName("z");
    pass.setFilterLimits(0.0, 2.4); //设置Z轴范围为0.0到2.4m
    pass.filter(*cloud_filtered);
    //显示滤波前的点云 
    pcl::visualization::PCLVisualizer viewer("passthrough viewer");
    pcl::visualization::PointCloudColorHandlerGenericField<pcl::PointXYZ> fildColor(cloud_filtered, "z");//按照z字段进行渲染
    viewer.addPointCloud(cloud_filtered, fildColor, "origin cloud");
    viewer.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 3, "origin clouds");
    
    while (!viewer.wasStopped()) {
        viewer.spinOnce();
    }
    return (0);
}

Call pass.setFilterLimits(0.0, 2.4) by setting; Set the Z-axis range from 0.0 to 2.4m, and filter out everything larger than 2.4m. The effect is as follows (the wall behind the bicycle is clipped):

1578042462.jpg

2.2 Voxel filters

For the voxel filter method, only the key code is pasted here, and other codes have been provided above

pcl::VoxelGrid<pcl::PointXYZ> sor;
sor.setInputCloud(cloud);
sor.setLeafSize(0.01f, 0.01f, 0.01f);//设置体素大小,米为单位
sor.filter(*cloud_filtered);

1578054606(1).jpg

2.3 Statistical filters

pcl::StatisticalOutlierRemoval<pcl::PointXYZ> sor;
sor.setInputCloud(cloud);
sor.setMeanK(5);
sor.setStddevMulThresh(1.0);
sor.filter(*cloud_filtered);

Point cloud before filtering

Filtered point cloud

The filtered point cloud clearly removes flying points

2.4 Radius filtering

pcl::RadiusOutlierRemoval<pcl::PointXYZ> outrem;
outrem.setInputCloud(cloud);
outrem.setRadiusSearch(0.01);
outrem.setMinNeighborsInRadius(5);
outrem.filter(*cloud_filtered);

1578055839(1).jpg

All PCL filters will be demonstrated once, to be continued...

reference:

Guess you like

Origin blog.csdn.net/u014090257/article/details/121167933