.. index:: 
  !Face comparison

.. _face_comparison:

================
Face comparison
================

Face comparison is the process of comparing a face template against a previously stored reference template.

The :ref:`FaceMatcher<id3_face_face_matcher_class>` module provides methods for comparing two :ref:`face templates<id3_face_face_template_class>` or two :ref:`face template lists<id3_face_face_template_list_class>`. The methods return a comparison score, from 0 to 65535 representing the degree of similarity between the two templates.

.. note:: 
  A :ref:`FaceTemplateList<id3_face_face_template_list_class>` should contain templates from a single user.

Decision threshold
==================
The decision is the result of the comparison between the biometric comparison similarity score of given biometric data and a predefined threshold to achieve the desired security level. If the score is not less than the predefined minimal matching score threshold, the biometric verification is successful.

.. image:: img/ideal_score_distribution.jpg

A decision threshold applied on the algorithm’s output score determines the operational FMR (False Match Rate), i.e. the probability of a system to falsely accept faces (impostors). Since FMR and FNMR (False Non-Match Rate) are in inverse proportion to each other, FNMR will increase with higher decision thresholds.

The decision threshold is defined according to the following table:

.. list-table:: 
  :width: 100%
  :widths: 30 70
  :header-rows: 1

  * - False Match Rate
    - Decision threshold
  * - 1.0%
    - 2000
  * - 0.1%
    - 3000
  * - 0.01%
    - 4000
  * - 0.001%
    - 5000
  * - 0.0001%
    - 6000
  * - 0.00001%
    - 7000
  * - 0.000001%
    - 8000
  * - 0.000001%
    - 9000
  * - 0.0000001%
    - 10000

.. hint::
  To obtain a value between 0 and 100, we recommend applying the following formula to the matching score (**S**):
  
  :math:`S' = MIN(100, S * 8 / 250)`


Example
=======

The example below demonstrates how to compare two faces:

.. tab-set::

  .. tab-item:: Python
    :sync: Python

    .. literalinclude:: /../samples/sample.py
      :language: python
      :start-after: [face_comparison]
      :end-before: [face_comparison]
      :dedent: 4

See also
========

- :ref:`id3_face_face_encoder_class`
- :ref:`id3_face_face_matcher_class`
