# Standard SDK - Android

## Features

* [x] Face Detection
* [x] Face Liveness Detection
* [x] Face Recognition
* [x] Pose Estimation
* [x] Fully-Offline Works and On-Premise

## License

We offer `lifetime license(perpetual license)` tied to each  `application ID` for `Android` `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
>
> **WhatsApp:** +19092802609&#x20;

## System Requirements

* **CPU:** 2 cores or more
* **RAM:** 100MB or more
* **OS:** Android 4.4 or later
* **Architecture:** arm64-v8a, armeabi-v7a

## Setup

1. Copy the SDK (`libfacesdk` folder) to the `root` folder in your project.
2. Add SDK to the project in `settings.gradle`

```gradle
include ':libfacesdk'
```

3. Add dependency to your `build.gradle`

```gradle
implementation project(path: ':libfacesdk')
```

## Initializing SDK

1. Step one

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

```java
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.

```java
FaceSDK.init(getAssets());
```

* 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 `init` 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 angles` 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         |

<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>

## APIs

### 1. setActivation

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

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

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

### 2. init

After activation, call the SDK's initialization function.

```kotlin
ret = FaceSDK.init(assets)
```

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:

```kotlin
FaceSDK.faceDetection(bitmap)
```

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

The return value of the function is a list of `FaceBox` objects.

### 4. templateExtraction

The SDK provides a function that can generate a template from a `bitmap` image.&#x20;

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

```java
byte[] templates = FaceSDK.templateExtraction(bitmap, faceBox);
```

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

The function returns a byte array, which contains the template that can be used for person verification.

### 5. similarityCalucation

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

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

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

### 6. yuv2Bitmap

The SDK provides a function called `yuv2Bitmap`, which converts a `yuv` frame to a `bitmap`.&#x20;

Since camera frames are typically in `yuv` format, this function is necessary to convert them to `bitmap`.&#x20;

The usage of this function is as follows:

```java
Bitmap bitmap = FaceSDK.yuv2Bitmap(nv21, image.getWidth(), image.getHeight(), 7);
```

The first parameter is an `nv21` byte array containing the `yuv` data.

The second parameter is the width of the `yuv` frame, and the third parameter is its height.

The fourth parameter is the `conversion mode`, which is determined by the camera orientation.

To determine the appropriate `conversion mode`, the following method can be used:

```
 1        2       3      4         5            6           7          8

 888888  888888      88  88      8888888888  88                  88  8888888888
 88          88      88  88      88  88      88  88          88  88      88  88
 8888      8888    8888  8888    88          8888888888  8888888888          88
 88          88      88  88
 88          88  888888  888888
```

## Default Thresholds

```kotlin
val livenessThreshold = 0.7
val identifyThreshold = 0.8
```

* 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;
