🔗 Starting Guide
🔗 Contents
🔗 Prerequisites
-
A device running on Android 6.0 (API Level 23) or higher
-
Recommended hardware
-
Android 9.0 (or above)
-
Snapdragon 8xx series (or equivalent)
-
RAM 4.0 GB
-
-
An Android Studio project
-
The latest version of Android Studio
🔗 System Requirements
-
Recommended hardware
-
Android 9.0 (or above)
-
Snapdragon 8xx series (or equivalent)
-
RAM 4.0 GB
Note: HandCam only supports Android 9.0 or above.
Note: AccessoryCam only support Android 9.0 or above.
-
-
Minimum hardware
-
Android 6.0
-
Snapdragon 6xx series (or equivalent)
-
RAM 3.0 GB
Note: HandCam only supports Android 9.0 or above.
Note: AccessoryCam only support Android 9.0 or above.
-
-
Supported ABIs
-
armeabi-v7a
-
arm64-v8a
-
🔗 Add library to a project
-
Create a new project or open an existing project in Android Studio.
-
Create a new project (refer to this)
-
Open an existing project
-
Open Android Studio.
-
Click File > Open… to open an existing project.
-
-
-
Download the SDK (libraries.zip) from Console.
-
Copy the .aar files in the zip file to the libs folder of the project (usually app/libs/).
-
Add the .aar files as dependencies.
There are two ways to add these .aar files into the project.
-
Add .aar files manually.
Add the following code snippet in the root-level build.gradle file (Find the build.gradle file in the root folder of project).
allprojects { repositories { flatDir { /* Add this line here. */ dirs 'libs' /* Add this line here. */ } /* Add this line here. */ } }If the Gradle version is 3.0 or later, add .aar files as dependencies into the build.gradle file in the module to integrate the SDK.
For example:
dependencies { implementation(name: 'PerfectLibCameraKit', ext: 'aar') } -
Add the .aar files to dependencies with the GUI tool in the Android Studio (refer to this).
-
🔗 Use CameraKit
-
Add the CameraKit library to the app module.
dependencies { implementation(name: 'PerfectLibCameraKit', ext: 'aar') } -
Request camera permission in the manifest and at runtime.
<manifest> <uses-permission android:name="android.permission.CAMERA"/> </manifest> -
Prepare the CameraKit models.
-
Put the CameraKit model root under the app assets folder, for example assets/model/.
-
The model root must contain the CameraKit subfolders required by the SDK, including face_detection and bad_lighting.
-
If you prefer storing models in app files storage, keep the same folder structure and pass that folder path to
CameraKit.createFromFiles(...).
-
-
Initialize the SDK runtime and create the CameraKit instance.
If the app already initializes PerfectLib, set the CameraKit model path in
Configurationand create CameraKit after initialization completes.Configuration configuration = Configuration.builder() .setModelPath(PerfectLib.ModelPath.assets("model")) .build(); PerfectLib.init(getApplicationContext(), configuration, new PerfectLib.InitialCallback() { @Override public void onInitialized(Set<Functionality> availableFunctionalities, Map<String, Throwable> preloadErrors) { CameraKit.create(new CameraKit.CreateCallback() { @Override public void onSuccess(CameraKit cameraKit) { cameraKit.setCameraKitLevel(CameraKitLevel.RELAXED); } @Override public void onFailure(Throwable throwable) { Log.e(TAG, "CameraKit create failed", throwable); } }); } @Override public void onFailure(Throwable throwable, Map<String, Throwable> preloadErrors) { Log.e(TAG, "PerfectLib init failed", throwable); } });If you want to create CameraKit with an explicit model path, use one of the following APIs after SDK initialization:
CameraKit.createFromAssets("model", createCallback); // or CameraKit.createFromFiles(modelFolderPath, createCallback); -
Connect the camera lifecycle and submit preview frames.
Call
onCameraOpened(...)after the camera is opened and before preview starts. For each preview frame, create aCameraFrame, set its orientation if needed, and pass it tosendCameraBuffer(...).cameraKit.onCameraOpened(isFrontCamera, cameraOrientation, previewWidth, previewHeight); CameraFrame frame = new CameraFrame(data, previewWidth, previewHeight, false); frame.setFrameOrientation(frameRotationDegrees); cameraKit.sendCameraBuffer(frame); -
Receive quality-check results and decide when capture is allowed.
cameraKit.setCameraKitQualityCheckCallback(result -> { boolean isReady = result.getFaceAreaQuality().isOk() && result.getFacePoseQuality().isOk() && result.getLightingQuality().isOk(); if (isReady) { Log.d(TAG, "CameraKit quality check passed"); } }); -
Select a preset level and optionally overwrite individual thresholds.
cameraKit.setCameraKitLevel(CameraKitLevel.RELAXED); CameraKitParameterBuilder parameterBuilder = cameraKit .getCurrentParameter() .getParameterBuilder(); parameterBuilder.setFaceYaw(12.0f); parameterBuilder.setLightingLower(0.60f); cameraKit.setCameraKitOverwrite(parameterBuilder.build());Available preset levels are
STRICT,MODERATE, andRELAXED. ApplyingsetCameraKitLevel(...)resets thresholds to that preset. ApplyingsetCameraKitOverwrite(...)keeps the current level and updates only the values provided in the built parameter. -
Release CameraKit when the screen is destroyed.
@Override protected void onDestroy() { if (cameraKit != null) { cameraKit.onDestroyed(); } super.onDestroy(); }