# API Reference

### setActivation

{% code overflow="wrap" %}

```dart
Future<int?> setActivation(String license)
```

{% endcode %}

<table data-header-hidden><thead><tr><th width="137"></th><th></th></tr></thead><tbody><tr><td><strong>Name</strong></td><td>setActivation</td></tr><tr><td><strong>Description</strong></td><td>Activate SDK</td></tr><tr><td><strong>Input</strong></td><td><ul><li><strong>license</strong>: The license string</li></ul></td></tr><tr><td><strong>Output</strong></td><td><p>The SDK activation status code.</p><ul><li>0: Success</li><li>Non-zero: Activation failed</li></ul></td></tr></tbody></table>

### init

{% code overflow="wrap" %}

```dart
Future<int?> init() 
```

{% endcode %}

<table data-header-hidden><thead><tr><th width="137"></th><th></th></tr></thead><tbody><tr><td><strong>Name</strong></td><td>init</td></tr><tr><td><strong>Description</strong></td><td>Initiate SDK</td></tr><tr><td><strong>Input</strong></td><td>None</td></tr><tr><td><strong>Output</strong></td><td><p>The SDK initialization status code.</p><ul><li>0: Success</li><li>-1: License Key Error</li><li>-2: License AppID Error</li><li>-3: License Expired</li><li>-4: Activate Error</li><li>-5: Initialize SDK Error</li></ul></td></tr></tbody></table>

### setParam

{% code overflow="wrap" %}

```dart
Future<void> setParam(Meap<String, Object> params)
```

{% endcode %}

<table data-header-hidden><thead><tr><th width="137"></th><th></th></tr></thead><tbody><tr><td><strong>Name</strong></td><td>setParam</td></tr><tr><td><strong>Description</strong></td><td>Set Face Detection parameters </td></tr><tr><td><strong>Input</strong></td><td><ul><li><p><strong>params</strong> face detection parameters</p><pre class="language-dart"><code class="lang-dart">'check_liveness_level'
0: liveness v1 -> more accurate model
1: liveness v2-fast -> lighter model
</code></pre></li></ul></td></tr><tr><td><strong>Output</strong></td><td>None</td></tr></tbody></table>

### extractFaces

{% code overflow="wrap" %}

```kotlin
Future<dynamic> extractFaces(String imagePath)
```

{% endcode %}

<table data-header-hidden><thead><tr><th width="137"></th><th></th></tr></thead><tbody><tr><td><strong>Name</strong></td><td>extractFaces</td></tr><tr><td><strong>Description</strong></td><td>Detect and extract face templates from image file</td></tr><tr><td><strong>Input</strong></td><td><ul><li><strong>imagePath</strong> : Image file path</li></ul></td></tr><tr><td><strong>Output</strong></td><td><p>Face detection result</p><pre><code>{
 "x1": face.x1,
 "y1": face.y1,
 "x2": face.x2,
 "y2": face.y2,
 "liveness": face.liveness,
 "yaw": face.yaw,
 "roll": face.roll,
 "pitch": face.pitch,
 "templates": templates,
 "faceJpg": faceJpg,
 "frameWidth": bitmap!!.width,
 "frameHeight": bitmap!!.height
}
</code></pre></td></tr></tbody></table>

### similarityCalculation

{% code overflow="wrap" %}

```dart
Future<double?> similarityCalculation(
Uint8List templates1, Uint8List templates2)
```

{% endcode %}

<table data-header-hidden><thead><tr><th width="137"></th><th></th></tr></thead><tbody><tr><td><strong>Name</strong></td><td>similarityCalculation</td></tr><tr><td><strong>Description</strong></td><td>Calculate similarity between two face features</td></tr><tr><td><strong>Input</strong></td><td><ul><li><strong>templates1</strong>: The first face template</li><li><strong>templates2</strong>: The second face template</li></ul></td></tr><tr><td><strong>Output</strong></td><td>A float value representing the similarity score between the two face templates<br>The score ranges from 0.0 to 1.0<br><strong>Default Threshold is 0.8</strong></td></tr></tbody></table>

### onFaceDetected&#x20;

```dart
void onFaceDetected(faces)
```

<table data-header-hidden><thead><tr><th width="137"></th><th></th></tr></thead><tbody><tr><td><strong>Name</strong></td><td>onFaceDetected</td></tr><tr><td><strong>Description</strong></td><td>callback function for face detection on camera stream</td></tr><tr><td><strong>Input</strong></td><td>None</td></tr><tr><td><strong>Output</strong></td><td>Face detection result in camera frame</td></tr></tbody></table>

callback function definition

```java
@Override
    public void onFrame(Bitmap bitmap) {

        ArrayList<HashMap<String, Object>> faceBoxesMap = new ArrayList<HashMap<String, Object>>();
        FaceDetectionParam param = new FaceDetectionParam();
        param.check_liveness = true;
        param.check_liveness_level = FaceDetectionFlutterView.livenessDetectionLevel;

        List<FaceBox> faceBoxes = FaceSDK.faceDetection(bitmap, param);
        for(int i = 0; i < faceBoxes.size(); i ++) {
            FaceBox faceBox = faceBoxes.get(i);
            byte[] templates = FaceSDK.templateExtraction(bitmap, faceBox);
           Bitmap faceImage = Utils.cropFace(bitmap, faceBox);
           ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
           faceImage.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
           byte[] faceJpg = byteArrayOutputStream.toByteArray();

            HashMap<String, Object> e = new HashMap<String, Object>();
            e.put("x1", faceBox.x1);
            e.put("y1", faceBox.y1);
            e.put("x2", faceBox.x2);
            e.put("y2", faceBox.y2);
            e.put("liveness", faceBox.liveness);
            e.put("yaw", faceBox.yaw);
            e.put("roll", faceBox.roll);
            e.put("pitch", faceBox.pitch);
            e.put("templates", templates);
            e.put("faceJpg", faceJpg);
            e.put("frameWidth", bitmap.getWidth());
            e.put("frameHeight", bitmap.getHeight());

            faceBoxesMap.add(e);
        }

        Message message = new Message();
        message.what = 1;
        message.obj = faceBoxesMap;
        channelHandler.sendMessage(message);
    }
```
