Python-PCL Tutorial

About Python-PCL

Python-PCL is a python interface for Point Cloud Library (PCL), a popular point cloud processing library written in C++. It can be used to segment, subsample, smooth, and perform other complex operations on point cloud data.

Installation

*Note that more detailed installation instructions can be found on Python-PCL's github page; however, for completeness, I have included some installation instructions.

Linux

  • If you're running Linux, the installation process is quite involved. You will need to run following commands:

> sudo apt-get install build-essential devscripts

> dget -u https://launchpad.net/ubuntu/+archive/primary/+files/pcl_1.7.2-14ubuntu1.16.04.1.dsc

> cd pcl-1.7.2

> sudo dpkg-buildpackage -r -uc -b

> sudo dpkg -i pcl_*.deb

  • Now, in this step, you will need to install several packages manually using dpkg, namely:

  1. libpcl1.7_1.7.2-14ubuntu1.16.04.1_amd64.deb

  2. libpcl1.7-dbg_1.7.2-14ubuntu1.16.04.1_amd64.deb

  3. libpcl-apps1.7_1.7.2-14ubuntu1.16.04.1_amd64.deb

  4. libpcl-common1.7_1.7.2-14ubuntu1.16.04.1_amd64.deb

  5. libpcl-dev_1.7.2-14ubuntu1.16.04.1_amd64.deb

  6. libpcl-doc_1.7.2-14ubuntu1.16.04.1_all.deb

  7. libpcl-features1.7_1.7.2-14ubuntu1.16.04.1_amd64.deb

  8. libpcl-filters1.7_1.7.2-14ubuntu1.16.04.1_amd64.deb

  9. libpcl-io1.7_1.7.2-14ubuntu1.16.04.1_amd64.deb

  10. libpcl-kdtree1.7_1.7.2-14ubuntu1.16.04.1_amd64.deb

  11. libpcl-keypoints1.7_1.7.2-14ubuntu1.16.04.1_amd64.deb

  12. libpcl-octree1.7_1.7.2-14ubuntu1.16.04.1_amd64.deb

  13. libpcl-outofcore1.7_1.7.2-14ubuntu1.16.04.1_amd64.deb

  14. libpcl-people1.7_1.7.2-14ubuntu1.16.04.1_amd64.deb

  15. libpcl-recognition1.7_1.7.2-14ubuntu1.16.04.1_amd64.deb

  16. libpcl-registration1.7_1.7.2-14ubuntu1.16.04.1_amd64.deb

  17. libpcl-sample-consensus1.7_1.7.2-14ubuntu1.16.04.1_amd64.deb

  18. libpcl-search1.7_1.7.2-14ubuntu1.16.04.1_amd64.deb

  19. libpcl-segmentation1.7_1.7.2-14ubuntu1.16.04.1_amd64.deb

  20. libpcl-surface1.7_1.7.2-14ubuntu1.16.04.1_amd64.deb

  21. libpcl-tracking1.7_1.7.2-14ubuntu1.16.04.1_amd64.deb

  22. libpcl-visualization1.7_1.7.2-14ubuntu1.16.04.1_amd64.deb

  23. pcl-tools_1.7.2-14ubuntu1.16.04.1_amd64.deb

  • Each of these packages should be in your pcl-1.7.2 directory and form a complex tree of dependencies; simply put, installing of these packages is a non-trivial process.

  • Next, you need to clone the Python-PCL repository and run the following commands:

> python setup.py build_ext -i

> python setup.py install

  • Finally, to verify that Python-PCL installed correctly. type import pcl in your python interpreter.


Mac OS

  • On Mac OS, the installation process is simple.

  • Install Homebrew and run the following commands:

> brew tap homebrew-science

> brew install pcl

  • Next, you need to clone the Python-PCL repository and run the following commands:

> python setup.py build_ext -i

> python setup.py install

  • Finally, to verify that Python-PCL installed correctly. type import pcl in your python interpreter.


Windows

See Python-PCL's Github page!

Processing Point Cloud Data


Subsampling Point Cloud Data

  • When processing point cloud data, raw data files typically have hundreds of millions of points, which are often repetitive. Subsampling provides a way to prune your point cloud data within minimal loss in fidelity. In this tutorial, we will explore a technique called voxel filtering; to learn more about voxel filtering, look here.

  • First, import pcl and load your point cloud data:

  • Notice that we need to bind the point cloud data to a PointCloud object.

  • Then, we will create a voxel filter from the point cloud, set a filter size, and apply the filter:

  • Now, we're finished! The size of the new point cloud data will depend on the size and density of the original point cloud; you should print the size of the new point cloud to verify that the filter was applied correctly.

Reducing

  • Python-PCL can also be used to find the k-th points closest to a single point in your point cloud.

  • This approach uses a KdTree, which you can read more about here.

  • First, import pcl and load your point cloud data:

  • Next, we will create a KdTree from our point cloud data , pick a point to start from, and run the search:

  • nearest_k_search_for_cloud() will return the indices of the points closest to the points we selected!