FaceUnity AR Filter
Updated
Integrate and use the FaceUnity AR Filter extension in your Android, iOS, or Flutter app.
The FaceUnity AR Filter extension uses 3D vision, 3D graphics, and deep learning technologies to provide advanced AR portrait video effects for the Agora Video SDK. It enables features such as:
- Basic beauty: Skin beautification, whitening, and rosy effects.
- Advanced beauty: Beauty effects for shape, face, and skin.
- Number detection: Detect the number of faces, humans, or gestures.
This page shows you how to integrate and use the FaceUnity AR Filter extension in your app.
Understand the tech
To quickly integrate FaceUnity AR filter capabilities in your app, set extension properties using the key and value parameters in the Video SDK. Calling setExtensionProperty with a pair of key and value parameters is equivalent to calling the corresponding FaceUnity API. The key is named after the FaceUnity API method, and value wraps the parameters required for that method in JSON.
Prerequisites
- Android Studio 4.1 or later.
- A physical device (not an emulator) running Android 5.0 or later.
- Implemented the SDK quickstart.
Project setup
To get started, use the FaceUnity sample project on GitHub:
-
Clone the repository:
git clone https://github.com/AgoraIO-Community/AgoraMarketPlace.git -
Complete the setup described in the README.
-
Contact support@agora.io for activation, provide your package name, and obtain the
authpackcertificate file. -
Download the FaceUnity AR Filter package and the FaceUnity resource package.
Integrate the extension
Add the extension to your project
-
Unzip the AR Filter package and save all
.aarfiles to/app/libs. -
Save
authpack.javato the path that matches the package name you registered. -
Save the required model and prop files from the resource package to
/app/src/main/assets. -
Add the following Gradle dependency:
implementation fileTree(dir: "libs", include: ["*.jar", "*.aar"]) -
Import the required Agora and FaceUnity classes.
Enable the extension
Call enableExtension before other APIs, including enableVideo and joinChannel.
RtcEngineConfig config = new RtcEngineConfig();
config.addExtension("AgoraFaceUnityExtension");
mRtcEngine = RtcEngine.create(config);
mRtcEngine.enableExtension("FaceUnity", "Effect", enabled);Initialize the extension
After receiving the onExtensionStarted callback, call setExtensionProperty to load the certificate and AI models.
private void initExtension() {
try {
JSONObject jsonObject = new JSONObject();
JSONArray jsonArray = new JSONArray();
for (byte it : authpack.A()) {
jsonArray.put(it);
}
jsonObject.put("authdata", jsonArray);
setExtensionProperty("fuSetup", jsonObject.toString());
} catch (JSONException e) {
Log.e(TAG, e.toString());
}
}Configure beauty effects and body recognition
Load props, adjust beautification intensity, and enable face, gesture, and human recognition by calling setExtensionProperty with the corresponding keys and values.
Release resources
When you stop using FaceUnity, call setExtensionProperty with the fuDestroyLibData key, and after receiving the callback, destroy the engine.
Reference
API reference
Error codes
| API | Error code | Description |
|---|---|---|
enableExtension | -3 (SDK layer) | The SDK cannot find the corresponding extension dynamic library. |
setExtensionProperty | -1 (extension layer) | Invalid or repeated extension initialization or model loading. |
setExtensionProperty | -2 (SDK layer or extension layer) | The timing of the call is wrong or the parameter is invalid. |
setExtensionProperty | -20 (extension layer) | The incoming key is not supported or the resource is already loaded or destroyed. |
