.. _cpp-examples-face-detected:

Reacting to a vision event: face detected
=========================================

:ref:`\<\< return to C++ examples<cpp-examples>`

This section explains how to implement a module reacted to a complex event
and how to retrieve the information stored in this event.

Principle
---------

This example follows the same principle as here :ref:`cpp-examples-react-bumper`, but is based on
an event generated by ALVideoDevice: FaceDetetected.

This time, the data put into the memory corresponding to the "FaceDetected" key is
more complex than aboolean: it is an ALValue containing information about the
detected face(s).

To retrieve this information, use a proxy to ALMemory, and retrieve the data stored
in the corresponding key.


Example: OnFaceDetection module
-------------------------------

This example follows the same principle as here :ref:`cpp-examples-react-bumper`, but is based on
an event generated by ALVideoDevice: FaceDetetected. This time, the data put
into the memory corresponding to the "FaceDetected" key is more complex than a
boolean: it is an ALValue containing information about the detected face(s).

This example will make NAO say the number of faces it detects.

The whole example is available here: :download:`onfacedetection.zip <../onfacedetection.zip>`
Header:
+++++++

:download:`onfacedetection.h <onfacedetection.h>`

.. literalinclude:: onfacedetection.h
   :language: cpp

Source file:
++++++++++++

:download:`onfacedetection.cpp <onfacedetection.cpp>`

.. literalinclude:: onfacedetection.cpp
   :language: cpp

Main:
+++++

:download:`main.cpp <main.cpp>`

.. literalinclude:: main.cpp
   :language: cpp

CMakeLists.txt:
+++++++++++++++

The CMakeLists.txt file is:

:download:`CMakeLists.txt <CMakeLists.txt>`

.. literalinclude:: CMakeLists.txt
   :language: cmake

