1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
|
.. _moving_least_squares:
Smoothing and normal estimation based on polynomial reconstruction
------------------------------------------------------------------
This tutorial explains how a Moving Least Squares (MLS) surface reconstruction
method can be used to smooth and resample noisy data. Please see an example in
the video below:
.. raw:: html
<iframe title="Smoothing and normal estimation based on polynomial reconstruction" width="480" height="390" src="http://www.youtube.com/embed/FqHroDuo_I8?rel=0" frameborder="0" allowfullscreen></iframe>
Some of the data irregularities (caused by small distance measurement errors)
are very hard to remove using statistical analysis. To create complete models,
glossy surfaces as well as occlusions in the data must be accounted for. In
situations where additional scans are impossible to acquire, a solution is to
use a resampling algorithm, which attempts to recreate the missing parts of the
surface by higher order polynomial interpolations between the surrounding data
points. By performing resampling, these small errors can be corrected and the
"double walls" artifacts resulted from registering multiple scans together can
be smoothed.
.. image:: images/resampling_1.jpg
On the left side of the figure above, we see the effect or estimating surface
normals in a dataset comprised of two registered point clouds together. Due to
alignment errors, the resultant normals are noisy. On the right side we see the
effects of surface normal estimation in the same dataset after it has been
smoothed with a Moving Least Squares algorithm. Plotting the curvatures at each
point as a measure of the eigenvalue relationship before and after resampling,
we obtain:
.. image:: images/resampling_2.jpg
To approximate the surface defined by a local neighborhood of points
**p1**, **p2** ... **pk** at a point **q** we use a bivariate polynomial height function
defined on a on a robustly computed reference plane.
.. raw:: html
<iframe title="Removing noisy data through resampling" width="480" height="390" src="http://www.youtube.com/embed/N5AgC0KEcw0?rel=0" frameborder="0" allowfullscreen></iframe>
The code
--------
First, create a file, let's say, ``resampling.cpp`` in your favorite
editor, and place the following inside it:
.. literalinclude:: sources/resampling/resampling.cpp
:language: cpp
:linenos:
You should be able to find the input file at *pcl/test/bun0.pcd*.
The explanation
---------------
Now, let's break down the code piece by piece.
.. literalinclude:: sources/resampling/resampling.cpp
:language: cpp
:lines: 10-12
as the example PCD has only XYZ coordinates, we load it into a
PointCloud<PointXYZ>. These fields are mandatory for the method, other ones are
allowed and will be preserved.
.. literalinclude:: sources/resampling/resampling.cpp
:language: cpp
:lines: 23
if normal estimation is not required, this step can be skipped.
.. literalinclude:: sources/resampling/resampling.cpp
:language: cpp
:lines: 21
the first template type is used for the input and output cloud. Only the XYZ
dimensions of the input are smoothed in the output.
.. literalinclude:: sources/resampling/resampling.cpp
:language: cpp
:lines: 27
polynomial fitting could be disabled for speeding up smoothing. Please consult
the code API (:pcl:`MovingLeastSquares <pcl::MovingLeastSquares>`) for default
values and additional parameters to control the smoothing process.
.. literalinclude:: sources/resampling/resampling.cpp
:language: cpp
:lines: 34-36
if the normals and the original dimensions need to be in the same cloud, the
fields have to be concatenated.
Compiling and running the program
---------------------------------
Add the following lines to your CMakeLists.txt file:
.. literalinclude:: sources/resampling/CMakeLists.txt
:language: cmake
:linenos:
After you have made the executable, you can run it. Simply do::
$ ./resampling
You can view the smoothed cloud for example by executing::
$ pcl_viewer bun0-mls.pcd
|