# Sample Application

{% embed url="<https://www.youtube.com/watch?v=9HM70PFa4lQ>" %}
NIST FRVT #1 Face Recognition, Liveness Detection Mobile SDK Demo
{% endembed %}

***

## Build Project

### - Download and Open Project

* Download [**Recognito\_Face\_iOS.zip \[21.8M\]**](https://www.dropbox.com/scl/fi/4utjjzb0w584fojs3pald/Recognito_Face_iOS.zip?rlkey=99m53grvy9ar5aixyg6ona9y0\&st=8jvf8lcs\&dl=0)
* Open the `FaceDemo` project in Xcode.

### - Setting Up SDK License Key

* Add your license to `license.txt` file:

{% code title="iOS-FaceRecognition-FaceLivenessDetection/license.txt" lineNumbers="true" %}

```
 jwIUC3mm7P9uJDPxx/gRUttdS3bDg5n3QFnyySRB/E776MSPQAMubdyFTuzFb7BCdOx4EuoHmcsO 
 rpeGfI+Z371p/7cInVsnxLZU7PcSJh45Dd7c6maTg0QPwNLDHqdyNzRLFwKXXOX/IVuQNh6Dsen1 
 mwk6RGQZfReSUU6nLvWzC5sPgYhBVemExbbIa3UdDbBC+Bm4qNeXQ2i/08s9GFrhhbuvdYyI5TGl 
 6aVFjSGoHQhm/ENI1916+ck7BiguXMA1KFRTlchSWKhyb9CllHOGTomkoBUD3ykLlMGkcuZE8wT6 
 qpaHrtnmz1TgkP3tjK7L61BaEpWNib3uH29hWA== 
```

{% endcode %}

* Build Project.

### - Integration Guide

* Activate and Initialize FaceSDK

```swift
override func viewDidLoad() {
    super.viewDidLoad()
    var ret = SDK_LICENSE_KEY_ERROR.rawValue
    if let filePath = Bundle.main.path(forResource: "license", ofType: "txt") {
        do {
            let license = try String(contentsOfFile: filePath, encoding: .utf8)
            ret = FaceSDK.setActivation(license)
        } catch {
            print("Error reading file: \(error)")
        }
    } else {
        print("File not found")
    }
    
    if(ret == SDK_SUCCESS.rawValue) {
        ret = FaceSDK.initSDK()
    }
```

* Detect Face from Camera Frame

```swift
func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {    
    guard let pixelBuffer: CVPixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else { return }
    
    CVPixelBufferLockBaseAddress(pixelBuffer, CVPixelBufferLockFlags.readOnly)
    let ciImage = CIImage(cvPixelBuffer: pixelBuffer)
    
    let context = CIContext()
    let cgImage = context.createCGImage(ciImage, from: ciImage.extent)
    let image = UIImage(cgImage: cgImage!)
    CVPixelBufferUnlockBaseAddress(pixelBuffer, CVPixelBufferLockFlags.readOnly)

    // Rotate and flip the image
    var capturedImage = image.rotate(radians: .pi/2)
    if(cameraLens_val == .front) {
        capturedImage = capturedImage.flipHorizontally()
    }
    
    let faceBoxes = FaceSDK.faceDetection(capturedImage)
```

* Extract Face Template

```swift
let faceBox = faceBoxes[0] as! FaceBox 
if(faceBox.liveness > livenessThreshold) {
    let templates = FaceSDK.templateExtraction(capturedImage, faceBox: faceBox)
    ...
```

* Calculate Similarity

```swift
let similarity = FaceSDK.similarityCalculation(templates, templates2: personTemplates)                    
```

***

## Application UI

<div><figure><img src="/files/gNM7fqcRqAeL7xwU0aIl" alt=""><figcaption></figcaption></figure> <figure><img src="/files/8CukMIvv7dOxOsiDjYzG" alt=""><figcaption></figcaption></figure> <figure><img src="/files/wgLcL2ti5csrbOHf5VkR" alt=""><figcaption></figcaption></figure> <figure><img src="/files/bOmqH54bNLg0Lokiltn0" alt=""><figcaption></figcaption></figure> <figure><img src="/files/XA8dMWBXwAM5aJtn6Bsp" alt=""><figcaption></figcaption></figure> <figure><img src="/files/E1qaQgqGVDLL3GQRggUu" alt=""><figcaption></figcaption></figure></div>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.recognito.vision/face-recognition-sdk/integration-guide/ios/sample-application.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
