> For the complete documentation index, see [llms.txt](https://docs.sensecrypt.com/opencv-face-recognition-server/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sensecrypt.com/opencv-face-recognition-server/publish-your-docs/face-compare.md).

# Face Compare

Face Compare API allows you to compare two face images to determine if they correspond to the same person. A score higher than 0.7 is a good indicator that the two images belong to the same person.&#x20;

You can also use a score of 0.67 or higher if the images are of the same person but taken at different times (years apart). The score is a number between 0 and 1, where 1 is a perfect match and 0 is a perfect mismatch. The score is calculated using a deep learning model trained on millions of face images.

\
If the liveness check is enabled in the provided server, you can check the liveness with the face compare feature in a single API call.&#x20;

## 1:1 Face Compare&#x20;

<mark style="color:green;">`POST`</mark> `/compare`

This endpoint is for 1:1 face compare, no person enrollment needed

**Headers**

| Name         | Value              |
| ------------ | ------------------ |
| Content-Type | `application/json` |
| x-api-key    | `<your-api-key>`   |

**Body**

<table><thead><tr><th width="348">Name</th><th>Description</th></tr></thead><tbody><tr><td><code>check_liveness</code></td><td><p>Required: yes</p><p>Type: boolean<br>Default value: false <br>Accepted values: false, true</p><p>Example:</p><pre class="language-json"><code class="lang-json">"check_liveness": false,
</code></pre><p>If set to true, the liveness check is performed during 1:N face search if the face is found. If no face is found, liveness is not checked.<br><br>Check <a href="/opencv-face-recognition-server/publish-your-docs/liveness-detection.md"><mark style="color:red;"><strong>liveness image requirement here</strong></mark></a></p></td></tr><tr><td><code>face_base_64</code></td><td><p>Required: Yes </p><p>Type: string<br>Example: </p><pre class="language-json"><code class="lang-json">"face_base_64": "U2Vjb25kIGltYWdl",
</code></pre><p>The image should contain a single face. Liveness will be checked on this face if enabled.</p></td></tr><tr><td><code>min_similarity_score</code></td><td><p>Required: Yes </p><p>Type: float<br>Default value: 0.7 <br><br>Example: </p><pre class="language-json"><code class="lang-json">"min_similarity_score": 0.7
</code></pre><p>The default value is a good indicator to confirm the match. You can also use a score of 0.67 or higher if the images are of the same person but taken at different times (years apart).</p></td></tr><tr><td><code>ref_face_base_64</code></td><td><p>Required: Yes</p><p>Type: string<br>Example: </p><pre class="language-json"><code class="lang-json">"ref_face_base_64": "Rmlyc3QgaW1hZ2U="
</code></pre><p>Each reference image should contain a single face.</p></td></tr></tbody></table>

**Response**

{% tabs %}
{% tab title="200" %}

```json
{
  "is_match": true
}
```

{% endtab %}

{% tab title="400" %}
A face could not be detected in the image(s)

```json
{
  "code": "ERR_FACE_NOT_DETECTED",
  "message": "A face could not be detected in the image(s)."
}
```

{% endtab %}

{% tab title="401" %}
Please use an API Key to access this endpoint

```json
{
  "code": "ERR_API_KEY_NOT_PRESENT",
  "message": "The API key is missing from the request."
}
```

{% endtab %}

{% tab title="403" %}
API Key is invalid. Please provide a valid API Key

```json
{
  "code": "ERR_API_KEY_NOT_VALID",
  "message": "The API key is not valid."
}
```

{% endtab %}

{% tab title="404" %}
The collection with the specified name does not exist

```json
{
  "code": "ERR_NOT_FOUND",
  "message": "The requested entity could not be found."
}
```

{% endtab %}

{% tab title="412" %}
Liveness error. The metadata contains the code that provides specifics about the error\
\
Common codes are:\
\
`EYES_CLOSED` || `FACE_CLOSE_TO_BORDER` || `FACE_CROPPED` || `FACE_NOT_LIVE` || `FACE_TOO_CLOSE` || `FACE_ANGLE_TOO_LARGE` || `FACE_IS_OCCLUDED` || `FACE_NOT_FOUND` || `FACE_TOO_SMALL` || `LICENSE_ERROR` || `TOO_MANY_FACES` || `UNKNOWN_ERROR`

```json
{
  "code": "ERR_LIVENESS_ERROR",
  "message": "A liveness error occurred. Please check the supplied image and the error metadata.",
  "metadata": {
    "code": "FACE_NOT_LIVE || .. || UNKNOWN_ERROR"
  }
}
```

{% endtab %}

{% tab title="422" %}
The images could not be decoded from base64

```json
{
  "code": "ERR_BASE64_IMAGE_CANNOT_BE_DECODED",
  "message": "The posted Base64 image(s) could not be decoded as JPEG/PNG bytes."
}  
```

{% endtab %}
{% endtabs %}
