# How to Add Face Matching of Liveness Video with a Reference Photo From Your Database

{% hint style="warning" %}
Please note: this guide applies to the non-container flow only.
{% endhint %}

This guide describes how to match a liveness video with a reference photo of a person that is already stored in your database.

However, if you prefer to include a photo ID capture step to your liveness process instead of using a stored photo, then you can refer to [another guide](https://doc.ozforensics.com/oz-knowledge/general/integration-quick-start-guides/face-matching/how-to-add-photo-id-capture-and-face-matching-to-your-web-or-mobile-application) in this section.

<figure><img src="https://2532558063-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5g6dgsxRbyrCvB0uAf8f%2Fuploads%2FiLZnzmk78AmRdBxsHhoR%2Ffacematching-scheme-v8.drawio.png?alt=media&#x26;token=4e4a64b4-0287-4ab7-9d27-f367e5d594aa" alt=""><figcaption></figcaption></figure>

By this time you should have already implemented liveness video recording and liveness check. If not, please refer to these guides:

* [Integration of Oz Liveness Web SDK](https://doc.ozforensics.com/oz-knowledge/general/integration-quick-start-guides/server-based-liveness/how-to-integrate-server-based-liveness-into-your-web-application)
* [Integration of Oz Liveness Mobile SDK](https://doc.ozforensics.com/oz-knowledge/general/integration-quick-start-guides/server-based-liveness/how-to-integrate-server-based-liveness-into-your-mobile-application)

In this scenario, you upload your reference image to the same folder where you have a liveness video, initiate the BIOMETRY analysis, and poll for the results.

#### 1. Get `folder_id`

Given that you already have the liveness video recorded and uploaded, you will be working with the same Oz API folder where your liveness video is. Obtain the folder ID as described below, and pass it to your back end.

* For a video recorded by Web SDK, get the `folder_id` as described [here](https://doc.ozforensics.com/oz-knowledge/guides/developer-guide/sdk/oz-liveness-websdk/configuration-and-usage/web-plugin/security-recommendations#retrieve-the-analysis-response-and-process-it-on-the-back-end).
* For a video recorded by Android or iOS SDK, retrieve the `folder_id` from the analysis’ results as shown below:

**Android**:

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

```kotlin
AnalysisRequest.Builder()
        ...
        .run(object : AnalysisRequest.AnalysisListener {
            override fun onSuccess(result: List<OzAnalysisResult>) {
                // save folder_id that is needed for the next step
                val folderId = result.firstOrNull()?.folderId
            }
            ...
        })
```

{% endtab %}

{% tab title="Java" %}

```java
private void analyzeMedia(List<OzAbstractMedia> mediaList) {
    new AnalysisRequest.Builder()
            ...
            .run(new AnalysisRequest.AnalysisListener() {
                @Override public void onStatusChange(@NonNull AnalysisRequest.AnalysisStatus analysisStatus) {}
                @Override
                public void onSuccess(@NonNull List<OzAnalysisResult> list) {
                    String folderId = list.get(0).getFolderId();
                    }
                }
                ...
    });
}
```

{% endtab %}
{% endtabs %}

**iOS**:

<pre class="language-swift"><code class="lang-swift">analysisRequest.run(
scenarioStateHandler: { state in }, 
uploadProgressHandler: { (progress) in }  
)   { (analysisResults : [OzAnalysisResult], error) in 
        // save folder_id that is needed for the next step
        let folderID = analysisResults.first?.folderID
    }
<strong>}
</strong></code></pre>

#### 2. Upload your reference photo

[Call](https://apidoc.ozforensics.com/#tag/Media/paths/~1api~1folders~1%7Bfolder_id%7D~1media/posthttps://apidoc.ozforensics.com/#tag/Media/paths/~1api~1folders~1%7Bfolder_id%7D~1media/post) `POST /api/folders/{{folder_id}}/media/` method, replacing the `folder_id` with the ID you’ve got in the previous step. This will upload your new media to the folder where your ready-made liveness video is located.&#x20;

Set the appropriate tags in the payload field of the request, depending on the nature of a reference photo that you have.

```json
{
  "media:tags": { 
    "photo1": [
        "photo_id", "photo_id_front" // for the front side of an ID
        // OR
        "photo_selfie" // for a non-ID photo
    ]
  }
}
```

#### 3. Initiate the analysis

To launch the analysis, [call](https://apidoc.ozforensics.com/#tag/Analyses/paths/~1api~1folders~1%7Bfolder_id%7D~1analyses/post) `POST /api/folders/{{folder_id}}/analyses/` with the `folder_id` from the previous step. In the request body, specify the biometry check to be launched.&#x20;

```json
{
    "analyses": [
        {
            "type": "biometry"
        }
    ]
}
```

#### 4. Poll for the results

Repeat [calling](https://apidoc.ozforensics.com/#tag/Analyses/paths/~1api~1analyses~1%7Banalyse_id%7D/get) `GET /api/analyses/{{analysis_id}}` with the `analysis_id` from the previous step once a second until the state changes from `PROCESSING` to something else. For a finished analysis:

* get the qualitative result from resolution (`SUCCESS` or `DECLINED`).&#x20;
* get the quantitative results from `analyses.results_data.min_confidence`

Here is the Postman collection for this guide.

{% file src="<https://2532558063-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5g6dgsxRbyrCvB0uAf8f%2Fuploads%2FABnmGyPVhB8ue0t5A0Ah%2FFace%20Matching%20with%20a%20Reference%20Photo.postman_collection.json?alt=media&token=545a3406-9049-4252-b472-7c7e97f2591d>" %}

With these steps completed, you are done with adding face matching via Oz API. You will be able to access your media and analysis results in Web UI via browser or programmatically via API.

Oz API methods can be combined with great flexibility. Explore Oz API using the [API Developer Guide](https://doc.ozforensics.com/oz-knowledge/guides/developer-guide/api/oz-api).
