<commit_before>.. _template_alignment:

Aligning object templates to a point cloud
------------------------------------------

This tutorial gives an example of how some of the tools covered in the other tutorials can be combined to solve a higher level problem --- aligning a previously captured model of an object to some newly captured data.  In this specific example, we'll take a depth image that contains a person and try to fit some previously captured templates of their face; this will allow us to determine the position and orientation of the face in the scene.

.. raw:: html 

  <iframe width="560" height="349" style="margin-left:50px" src="http://www.youtube.com/embed/1T5HxTTgE4I" frameborder="0" allowfullscreen></iframe>

We can use the code below to fit a template of a person's face (the blue points) to a new point cloud (the green points). 


The code
--------

First, download the dataset `face_templates.tar.gz <http://dev.pointclouds.org/attachments/download/156/template_alignment_data.tar.gz>`_
and extract the files.

Next, copy and paste the following code into your editor and save it as ``template_alignment.cpp``.

.. literalinclude:: sources/template_alignment/template_alignment.cpp
   :language: cpp
   :linenos:

The explanation
---------------

Now, let's break down the code piece by piece.

We'll start by examining the *FeatureCloud* class.  This class is defined in order to provide a convenient method for computing and storing point clouds with local feature descriptors for each point.

The constructor creates a new *KdTreeFLANN* object and initializes the radius parameters that will be used when computing surface normals and local features.

.. literalinclude:: sources/template_alignment/template_alignment.cpp
   :language: cpp
   :lines: 24-28

Then we define methods for setting the input cloud, either by passing a shared pointer to a PointCloud or by providing the name of a PCD file to load.  In either case, after setting the input, *processInput* is called, which will compute the local feature descriptors as described later.

.. literalinclude:: sources/template_alignment/template_alignment.cpp
   :language: cpp
   :lines: 32-47

We also define some public accessor methods that can be used to get shared pointers to the points, surface normals, and local feature descriptors.

.. literalinclude:: sources/template_alignment/template_alignment.cpp
   :language: cpp
   :lines: 49-68<commit_msg>Added link to source file<commit_after>.. _template_alignment:

Aligning object templates to a point cloud
------------------------------------------

This tutorial gives an example of how some of the tools covered in the other tutorials can be combined to solve a higher level problem --- aligning a previously captured model of an object to some newly captured data.  In this specific example, we'll take a depth image that contains a person and try to fit some previously captured templates of their face; this will allow us to determine the position and orientation of the face in the scene.

.. raw:: html 

  <iframe width="560" height="349" style="margin-left:50px" src="http://www.youtube.com/embed/1T5HxTTgE4I" frameborder="0" allowfullscreen></iframe>

We can use the code below to fit a template of a person's face (the blue points) to a new point cloud (the green points). 


The code
--------

First, download the dataset `face_templates.tar.gz <http://dev.pointclouds.org/attachments/download/156/template_alignment_data.tar.gz>`_
and extract the files.

Next, copy and paste the following code into your editor and save it as ``template_alignment.cpp`` (or download the source file :download:`here <./sources/template_alignment/template_alignment.cpp>`).

.. literalinclude:: sources/template_alignment/template_alignment.cpp
   :language: cpp
   :linenos:

The explanation
---------------

Now, let's break down the code piece by piece.

We'll start by examining the *FeatureCloud* class.  This class is defined in order to provide a convenient method for computing and storing point clouds with local feature descriptors for each point.

The constructor creates a new *KdTreeFLANN* object and initializes the radius parameters that will be used when computing surface normals and local features.

.. literalinclude:: sources/template_alignment/template_alignment.cpp
   :language: cpp
   :lines: 24-28

Then we define methods for setting the input cloud, either by passing a shared pointer to a PointCloud or by providing the name of a PCD file to load.  In either case, after setting the input, *processInput* is called, which will compute the local feature descriptors as described later.

.. literalinclude:: sources/template_alignment/template_alignment.cpp
   :language: cpp
   :lines: 32-47

We also define some public accessor methods that can be used to get shared pointers to the points, surface normals, and local feature descriptors.

.. literalinclude:: sources/template_alignment/template_alignment.cpp
   :language: cpp
   :lines: 49-68
{'fraction_non_alphanumeric': 0.08743278231428002, 'fraction_numerical': 0.010754829715196175, 'mean_word_length': 3.987090367428004, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7579432', 'n_tokens_mistral': 1330, 'n_tokens_neox': 1232, 'n_words': 628}