# Premium SDK - iOS

## Features

* [x] Face Detection
* [x] Face Liveness Detection
* [x] Face Recognition
* [x] Pose Estimation
* [x] 68 points Face Landmark Detection
* [x] Face Quality Calculation
* [x] Face Occlusion Detection
* [x] Eye Closure Detection
* [x] Age, Gender Estimation
* [x] Fully-Offline Works and On-Premise

## License

We offer `lifetime license(perpetual license)` tied to each  `bundle ID` for `iOS` `SDK`s.&#x20;

The license is available with a `one-time payment`—meaning once you purchase it, you can use our `SDK` indefinitely without any recurring fees.

To request a license, please contact us:

> **Email:** <contact@kby-ai.com>&#x20;
>
> **Telegram:** @kbyaisupport&#x20;
>
> **WhatsApp:** +19092802609&#x20;

## System Requirements

* **CPU:** 2 cores or more
* **RAM:** 150MB or more
* **OS:** iOS 13.0 or later
* **Architecture:** arm64-v8a

## Setup

1. Copy the SDK (`facesdk.framework` folder) to the `root` folder of your project.
2. Add `SDK framework` to the project in `Xcode`.

> Project Navigator -> General -> Frameworks, Libraries, and Embedded Content

<figure><img src="https://2589216230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1WwtQK0VFwKRGmIjGA3I%2Fuploads%2FTIjg6n66P4AlCcF79ip0%2Fimage.png?alt=media&#x26;token=46af8f4c-286e-46cf-9132-21a38eec10e2" alt=""><figcaption></figcaption></figure>

3. Add the bridging header to your project settings

> Project Navigator -> Build Settings -> Swift Compiler - General

<figure><img src="https://2589216230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1WwtQK0VFwKRGmIjGA3I%2Fuploads%2F5GWfkud6LOaflKklD1SB%2Fimage.png?alt=media&#x26;token=b2e5094d-1db8-4bd0-9eb4-9147bb6c369e" alt=""><figcaption></figcaption></figure>

## Initializing SDK

1. Step one

* To begin, you need to activate the SDK using the license that you have received.

```swift
FaceSDK.setActivation("...")
```

* If activation is successful, the return value will be `SDK_SUCCESS`. Otherwise, an error value will be returned.

2. Step Two

* After activation, call the SDK's initialization function.

```swift
FaceSDK.initSDK()
```

* If initialization is successful, the return value will be `SDK_SUCCESS`. Otherwise, an error value will be returned.

## Enums and Classes

### 1. SDK\_ERROR

This enumeration represents the return value of the `initSDK` and `setActivation` functions.

<table><thead><tr><th width="349.3333333333333">Feature</th><th width="99">Value</th><th>Name</th></tr></thead><tbody><tr><td>Successful activation or initialization</td><td>0</td><td>SDK_SUCCESS</td></tr><tr><td>License key error</td><td>-1</td><td>SDK_LICENSE_KEY_ERROR</td></tr><tr><td>AppID error (Not used in Server SDK)</td><td>-2</td><td>SDK_LICENSE_APPID_ERROR</td></tr><tr><td>License expiration</td><td>-3</td><td>SDK_LICENSE_EXPIRED</td></tr><tr><td>Not activated</td><td>-4</td><td>SDK_NO_ACTIVATED</td></tr><tr><td>Failed to initialize SDK</td><td>-5</td><td>SDK_INIT_ERROR</td></tr></tbody></table>

### 2. FaceBox

This class represents the output of the `face detection` function that contains the detected `face rectangle`, `liveness score`, and `facial angle`s such as `yaw`, `roll`, and `pitch`\`.

| Feature                   | Type  | Name                  |
| ------------------------- | ----- | --------------------- |
| Face rectangle            | int   | x1, y1, x2, y2        |
| Face angles (-45 \~ 45)   | float | yaw, roll, pitch      |
| Liveness score (0 \~ 1)   | float | liveness              |
| Face quality (0 \~ 1)     | float | face\_quality         |
| Face luminance (0 \~ 255) | float | face\_luminance       |
| Face occlusion (0 \~ 1)   | float | face\_occlusion       |
| Eye closure (0 \~ 1)      | float | left\_eye, right\_eye |
| Mouth opening (0 \~ 1)    | float | mouth\_opened         |
| Age, Gender               | int   | age, gender           |
| 68 points facial landmark | Data  | landmark              |

<div align="center"><figure><img src="https://2589216230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1WwtQK0VFwKRGmIjGA3I%2Fuploads%2Fj4XxekdSV6Q6cW9KZhPr%2Fimage.png?alt=media&#x26;token=5ace558a-3793-48f0-9324-e1ec8fe80561" alt="" width="524"><figcaption><p>Face angles</p></figcaption></figure></div>

<figure><img src="https://2589216230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1WwtQK0VFwKRGmIjGA3I%2Fuploads%2FUIRrOk6XwkLE9EFC5G4k%2Fimage.png?alt=media&#x26;token=564744e4-1b2f-4f00-9ace-afc84bb9f17e" alt="" width="563"><figcaption><p>68 points facial landmark</p></figcaption></figure>

## APIs

### 1. setActivation

To begin, you need to activate the SDK using the license that you have received.

```swift
var ret = FaceSDK.setActivation("...")
```

If activation is successful, the return value will be `SDK_SUCCESS`. Otherwise, an error value will be returned.

### 2. initSDK

After activation, call the SDK's initialization function.

```swift
ret = FaceSDK.initSDK()
```

If initialization is successful, the return value will be `SDK_SUCCESS`. Otherwise, an error value will be returned.

### 3. faceDetection

The SDK offers a single function for detecting face and liveness detection, which can be used as follows:

```swift
let templates = FaceSDK.templateExtraction(image, faceBox: faceBox)
```

This function takes a single parameter, which is a `UIImage` object.&#x20;

The return value of the function is a list of `FaceBox` objects.&#x20;

### 4. templateExtraction

The `FaceSDK` provides a function that can generate a `template` from a `UIImage`.&#x20;

This `template` can then be used to verify the identity of the individual captured in the image.

```swift
let templates = FaceSDK.templateExtraction(capturedImage, faceBox: faceBox)
```

The SDK's `template extraction` function takes two parameters: a `UIImage` object and an object of `FaceBox`.

The function returns `Data`, which contains the `template` that can be used for person verification.

### 5. similarityCalucation

The `similarityCalculation` function takes a `Data` of two `template`s as a parameter.

```java
float similarity = FaceSDK.similarityCalucation(templates1, templates1);
```

It returns the similarity value between the two `template`s, which can be used to determine the degree of similarity between the two individuals.

## Default Thresholds

```swift
let livenessThreshold = 0.7
let identifyThreshold = 0.8
let yawThreshold = 10.0
let rollThreshold = 10.0
let pitchThreshold = 10.0
let occlusionThreshold = 0.5
let eyeCloseThreshold = 0.8
let mouthOpeningThreshold = 0.5
```

* If the liveness score exceeds `0.7`, the face is a real face.&#x20;
* If the similarity between two faces is higher than `0.8`, the face matching is successful.&#x20;
* If the absolute values of the face angles are less than `10.0`, the face is identified as a fronted face.&#x20;
* If the occlusion value is higher than `0.5`, the face is occluded.
* If the eye close value is higher than `0.8`, it indicates that the eyes are closed.
* If the mouth opening value is higher than `0.5`, it indicates that the mouth is open.


---

# 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.kby-ai.com/help/product/face-liveness-detection-sdk-face-recognition-sdk/premium-sdk-mobile/premium-sdk-ios.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.
