Point Cloud Library (PCL) is an open source project focused on image processing algorithms for 3D point clouds. This article introduces the key features of PCL and demonstrates a simple point cloud de-noising technique.
Background
Initially published in 2010, PCL has now arguably become the most popular open-source 3D image processing library. Key functions including stitching, filtering, object recognition, surface generation and pose estimation. The primary programming interface is C++ with Python bindings available for rapid prototyping. PCL is cross-platform and distributed under the BSD license. The library is regularly updated and its usage is growing.
PCL depends on a number of 3rd party libraries, notably Boost for threading and Eigen for linear algebra. CMake is typically used as the build system. PCL has its own file format called PCD (Point Cloud Data), which was created because some existing point cloud file formats did not support a number of PCL features. Other point cloud file formats can nonetheless be used with PCL, including .ply and .stl files. In a similar fashion to OpenCV, PCL can be installed using pre-built binaries or can be built from source when more customization of the build process is required.
Point cloud de-noising demonstration
To demonstrate the basic usage of PCL, we’ll walk through a simple de-noising exercise using PCL’s Statistical Outlier Removal filter.
One of the main challenges when processing point clouds captured with 3D cameras and laser scanners is the effect of noise and varying point density. These issues interfere with point normal estimation which in turn affects the application of downstream techniques such as segmentation and surface matching. To a degree, point cloud noise and density variations can be cleaned up by applying local statistical techniques to each point’s neighborhood. To achieve this, PCL’s Statistical Outlier Removal filter calculates the distance between each point and a fixed number of surrounding neighbor points. The algorithm then fits a Gaussian distribution to the neighboring points and defines points which lie beyond a certain standard deviation as outliers, which are then removed from the point cloud.
The point cloud below was captured with a 3D camera producing a 352 x 264 image with 92928 points in total. The scene is the corner of a room with many reflective surfaces. The object of interest is a long rectangular box, upright in the center of the scene, which is rather difficult to identify given the noise and point density variations.
The short C++ program below demonstrates the application of PCL’s Statistical Outlier Removal filter to clean up the noise and density variations.
#include <iostream>
#include <pcl/io/ply_io.h>
#include <pcl/point_types.h>
#include <pcl/filters/statistical_outlier_removal.h>
int main (int argc, char** argv)
{
// declare pointers
pcl::PointCloud<pcl::PointXYZ>::Ptr point_cloud(new pcl::PointCloud<pcl::PointXYZ>);
pcl::PointCloud<pcl::PointXYZ>::Ptr point_cloud_filtered(new pcl::PointCloud<pcl::PointXYZ>);
// create a PLY reader object and read the .ply into memory
pcl::PLYReader reader;
reader.read<pcl::PointXYZ>("point_cloud_1.ply", *point_cloud);
std::cout << "Point cloud before filtering: " << std::endl;
std::cout << *point_cloud << std::endl;
// create and apply the filter object
pcl::StatisticalOutlierRemoval<pcl::PointXYZ> sor;
sor.setInputCloud(point_cloud);
sor.setMeanK(50);
sor.setStddevMulThresh(0.25);
sor.filter(*point_cloud_filtered);
std::cout << "Point cloud after filtering: " << std::endl;
std::cout << *point_cloud_filtered << std::endl;
pcl::PLYWriter writer;
writer.write<pcl::PointXYZ>("point_cloud_1_inliers.ply", *point_cloud_filtered, false);
return 0;
}
Lines 8 to 17 of the C++ program declare two pointers and load a point cloud in .ply format from disk. Lines 19 to 24 perform the filtering: a Statistical Outlier Removal object is declared to which we then specify two key parameters – the number of neighboring points to use and the standard deviation threshold beyond which points are considered outliers. The remaining lines then print the statistics of the processed point cloud and write it to disk.
The Statistical Outlier Removal filter cut the point cloud down from 92928 points to 82175 points, removing most of the noise and leaving smoother surfaces of more constant point density. Our upright box is now clearly visible in the processed point cloud below.
A close up of the processed point cloud around the box shows an even distribution of points on the front face of the box, which can now be more readily fed into downstream algorithms for segmentation and object recognition.
Conclusion
3D computer vision is increasing being adopted in industrial applications and Point Cloud Library (PCL) is considered the ‘go-to’ open source library in this field. With regular updates since 2010, PCL appears to have a promising future, helped by the fact that all point cloud formats are supported. As with most open source projects, experience with C++ and CMake is required to integrate the libraries.