FaceUnity
The FaceUnity AR Filter extension uses 3D vision, 3D graphics, and deep learning technologies to provide industry’s leading AR portrait video effects for Video SDK. It enables you to add diverse special effects that provide full coverage of the human face, including:
- Basic beauty: Skin beautification, whitening, rosy.
- Advanced beauty: Video 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's AR filter capabilities in your app, you set extension properties using the key
and value
parameters in Video SDK. When you call setExtensionProperty
or setExtensionPropertyWithVendor
method of Video SDK and pass in a pair of key
and value
parameters, it 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. Currently, the extension encapsulates part of the APIs of the FaceUnity Nama SDK. For details, see the FaceUnity key-value overview.
Prerequisites
The development environment requirements are as follows:
- Android Studio 4.1 or higher.
- Android SDK API Level 24 or higher.
- A mobile device that runs Android 4.1 or higher.
-
A computer with Internet access.
Ensure that no firewall is blocking your network communication.
- Implemented SDK quickstart for Video Calling.
Project Setup
Open the SDK quickstart for Video Calling project you created earlier.
Get the FaceUnity extension
To get the FaceUnity extension, take the following steps:
-
Download the FaceUnity AR Filter package for your platform from the Extensions Marketplace.
-
Download the FaceUnity resource package.
-
Contact Agora for activation and obtain the
authpack
certificate file.
Add the extension to your project
-
Unzip the FaceUnity AR Filter package, and save all
.aar
files to the/app/libs
folder in your Android project. -
Save the certificate file
authpack.java
to the folder where the app module is located. For example, if the package name isio.agora.rte.extension.faceunity.example
, the certificate file should be saved to/app/src/main/java/io/agora/rte/extension/faceunity/example
). -
Save the model and prop files you need from the resource package to the
/app/src/main/assets
folder in your project. For details of files provided in the resource pack, see Resource package structure. -
In the
app/build.gradle
file, add the following line underdependencies
: -
To use the required classes, ensure that the following libraries are included in the list of
import
statements in your Android activity:
Integrate the extension
This section describes the call sequence you implement to use FaceUnity features in your app.
-
Enable the extension
When initializing
RtcEngine
, callenableExtension
before other APIs (includingenableVideo
andjoinChannel
) to enable the extension. -
Initialize the extension
After receiving the
onExtensionStarted
callback, callsetExtensionProperty
, and pass in the corresponding key and value pair: -
Configure beauty effects and body recognition
Call
setExtensionProperty
and pass in the corresponding keys and values.You can implement the following functions:
- Load props and adjust beautification intensity
- Recognize and track human faces, gestures, and bodies
You can call the method as needed. For a full list of keys and values, see the FaceUnity key-value overview.
-
Release the resources
When you do not need the extension, follow these steps to release the resources:
- Call
setExtensionProperty
and pass in thefuDestroyLibData
key. - After receiving the
fuDestroyLibData
callback, calldestroy
to destroy the Agora Engine.
- Call
Sample project
The complete Android FaceUnity sample code and project is available on GitHub.
Run the sample project
-
Clone the repository:
-
On the Extensions Marketplace Downloads page, download the Android package of FaceUnity AR Filter. Unzip the package, and save all
.aar
files to theFaceUnity/android/app/libs
path. -
Contact Agora to get the certificate file and resource package.
-
Save the certificate file
authpack.java
toFaceUnity/android/app/src/main/java/io/Agora/rte/extension/faceunity/example
. -
Save the required model and prop files from the resource package to
FaceUnity/android/app/src/main/assets/face_unity
under the project folder. -
Open the sample project
FaceUnity/android
in Android Studio. -
Sync the project with Gradle files.
-
Open the
FaceUnity/android/app/src/main/java/io/Agora/rte/extension/FaceUnity/example/Config.java
file, and replace<YOUR_APP_ID>
with your App ID. To get an App ID, see Getting Started with Agora. -
Connect an Android device (not an emulator), and run the project.
Reference
This section contains information that completes the information in this page, or points you to documentation that explains other aspects to this product.
FaceUnity key-value overview
This section lists the FaceUnity APIs you can use with Agora SDK.
The key corresponds to the name of the FaceUnity API, and the value corresponds to the parameters of the API. In this section, if the value is the same as the parameters of the FaceUnity API, the link leads to the FaceUnity documentation. If the value is different from the parameters of the FaceUnity API, the link leads to a section on this page.
Method keys
Method keys refer to the keys you pass in when calling the setExtensionProperty
or setExtensionPropertyWithVendor
method of the Video SDK.
Initialization
Method keys | Description |
---|---|
fuSetup | Initialize the extension and authenticate the user. Must be executed before other keys. |
fuLoadAIModelFromPackage | Preload AI capabilities. |
fuReleaseAIModel | Free up resources occupied by AI capabilities. |
Prop package loading
Method keys | Description |
---|---|
fuCreateItemFromPackage | Loads the prop package. |
fuLoadTongueModel | Loads tongue detection data. |
fuItemSetParam | Modifies or sets the value of a variable in the prop package. |
Destruction
Method keys | Description |
---|---|
fuDestroyItem | Destroys a specified item. |
fuDestroyAllItems | Destroys all loaded items and releases all occupied resources. |
fuOnDeviceLost | Resets the system's GL state. Use this key when the OpenGL context is released/destroyed by external resources. |
fuDestroyLibData | Frees up the memory allocated to the face tracking module after calling fuSetup . |
System functions
Method keys | Description |
---|---|
fuBindItems | Binds resource items to a target item. |
fuUnbindItems | Unbinds the resource items from a target item. |
fuIsTracking | Sets whether to get the number of faces being tracked. |
fuSetMaxFaces | Sets the maximum number of tarcked faces. |
fuSetDefaultRotationMode | Sets the default human face orientation. |
Algorithm functions
Method keys | Description |
---|---|
fuFaceProcessorSetMinFaceRatio | Sets the distance of face detection. |
fuSetTrackFaceAIType | Sets the fuTrackFace algorithm type. |
fuSetFaceProcessorFov | Sets the fov (equivalent to focal length) of the FaceProcessor algorithm module. |
fuHumanProcessorReset | Resets the state of the HumanProcessor algorithm module. |
fuHumanProcessorSetMaxHumans | Sets the number of bodies tracked by the HumanProcessor algorithm module. |
fuHumanProcessorGetNumResults | Sets whether to get the number of bodies tracked by the HumanProcessor algorithm module. |
fuHumanProcessorSetFov | Sets the fov (equivalent to focal length) used by the HumanProcessor algorithm module to track 3D key points on human bodies. |
fuHandDetectorGetResultNumHands | Sets whether to get the number of gestures tracked by the HandGesture algorithm module. Note that ai_gesture.bundle needs to be loaded. |
Method key description
fuSetup
Value parameters | Description |
---|---|
authdata | The path to the certificate file. |
fuLoadAIModelFromPackage
Value parameters | Description |
---|---|
data | String. The path of the AI capability model file ai_xxx.bundle . Such model files are located in the assets/AI_Model directory of the resource package. |
type | Int. The AI capability type corresponding to the bundle file. Possible values are listed in enum FUAITYPE. |
fuCreateItemFromPackage
Value parameters | Description |
---|---|
data | String. The path to the prop package you want to load. A prop package usually has a suffix *.bundle . |
fuLoadTongueModel
Value parameters | Description |
---|---|
data | String. The path of tongue model data tongue.bundle . |
fuItemSetParam
Value parameters | Description |
---|---|
obj_handle | String. The path of the prop package passed in when calling fuCreateItemFromPackage. |
name | String. The name of the variable to set in the prop package. |
value | Object. The variable value to be set. |
For details on the variable names and values in the prop package, refer to the FaceUnity documentation.
fuDestroyItem
Value parameters | Description |
---|---|
item | String. The path of the prop package passed in when calling fuCreateItemFromPackage. |
fuBindItems
Value parameters | Description |
---|---|
obj_handle | String. The path of the target item. |
p_items | String Array. The paths to the resource items you want to bind. |
fuUnbindItems
Value parameters | Description |
---|---|
obj_handle | String. The path of the target item. |
p_items | String Array, the paths to the resource items you want to unbind. |
fuIsTracking
Value parameters | Description |
---|---|
enable | Bool. Whether to get the number of faces being tracked. If set to true , you can receive the fuIsTracking callback. |
fuHumanProcessorGetNumResults
Value parameters | Description |
---|---|
enable | Bool. Whether to get the number of human bodies tracked by the HumanProcessor algorithm module. If set to true , you can receive the fuHumanProcessorGetNumResults callback. |
fuHandDetectorGetResultNumHands
Value parameters | Description |
---|---|
enable | Bool. Whether to get the number of gestures tracked by the HandGesture algorithm module. If set to true , you can receive the fuHandDetectorGetResultNumHands callback. |
Callback keys
Callback keys refer to the keys returned in the onEvent
callback of the Agora SDK.
Callback keys | Description |
---|---|
fuIsTracking | Returns the number of faces being tracked. |
fuHumanProcessorGetNumResults | Returns the number of human bodies tracked by the HumanProcessor algorithm module. |
fuHandDetectorGetResultNumHands | Returns the number of gestures tracked by the HandGesture algorithm module. |
fuDestroyLibData | Reports that the memory allocated to the face tracking module after calling fuSetup is released. |
Callback key description
fuIsTracking
Value parameters | Description |
---|---|
faces | Int. The number of faces being tracked. |
fuHumanProcessorGetNumResults
Value parameters | Description |
---|---|
people | Int. The number of bodies being tracked. |
fuHandDetectorGetResultNumHands
Value parameters | Description |
---|---|
hands | Int. The number of gestures being tracked. |
fuDestroyLibData
Its value contains no parameters.
API reference
-
addExtension in the
RtcEngineConfig
class -
enableExtension in the
RtcEngineConfig
class - setExtensionProperty
- onEvent