- Documentation
- Virtual Avatar
- Guides
- Automatic avatar generation
Automatic avatar generation
Overview
The ZegoAvatar SDK provides the automatic avatar generation
feature. Based on the image taken using the camera or the uploaded image and AI algorithms for massive face analysis and training, the feature can recognize facial features and use the designed virtual avatar provided by ZEGOCLOUD to generate a virtual avatar that highly restores to the real image.
This feature can be widely used in various game scenarios.
Prerequisites
Before you implement the automatic avatar generation
feature, ensure that the following conditions are met:
- The ZegoAvatar SDK is integrated into the project. For more information, see Integrate the SDK.
- Preparations for creating a virtual avatar are completed by referring to Create a virtual avatar.
Implementation process
Refer to the following procedures to implement theautomatic avatar generation
feature.
1. Initialize ZegoAvatarService
Obtain the authentication license file by referring to Create a virtual avatar and introduce the correct AIPath to initialize the ZegoAvatarService SDK.
2. Create a virtual avatar
Prepare the UIImage required for creating a virtual avatar.
We recommend that you take a photo with the phone camera.
After the image is prepared, call the detectFaceFeature API and introduce the UIImage to generate a virtual avatar.
// Extract facial features based on the introduced image. ZegoFaceFeature *feature = [[[ZegoAvatarService sharedInstance] getInteractEngine] detectFaceFeature:image];
If no face is detected in the UIImage, nil is returned when the detectFaceFeature API is called.
3. Set avatar creation data
After a virtual avatar is created, call the applyFaceFeature
API of ZegoCharacterHelper and introduce the feature parameter to set the dimensions of facial parts. For more information about adjustable facial dimensions, see the following table.
// Set the appearance of the avatar based on facial features.
[_characterHelper applyFaceFeature:feature];
Adjustable facial dimensions include:
In the following dimensions, the shape in corresponding face positions (such as the length, thickness, height, size, and angle) varies with the value. That is, a larger value indicates a greater shape change in the corresponding position.
Dimension | Description | Value range | Default value |
---|---|---|---|
faceshape_brow_size_y |
Eyebrow thickness |
0.0 ~ 1.0 |
0.5 |
faceshape_brow_size_x |
Eyebrow length |
0.0 ~ 1.0 |
0.5 |
faceshape_brow_all_y |
Eyebrow height |
0.0 ~ 1.0 |
0.5 |
faceshape_brow_all_roll_z |
Eyebrow rotation |
0.0 ~ 1.0 |
0.5 |
faceshape_eye_size |
Eye size |
0.0 ~ 1.0 |
0.5 |
faceshape_eye_roll_y |
Eye height |
0.0 ~ 1.0 |
0.5 |
faceshape_eye_roll_z |
Eye rotation |
0.0 ~ 1.0 |
0.5 |
faceshape_eye_x |
Distance between two eyes |
0.0 ~ 1.0 |
0.5 |
faceshape_nose_all_x |
Nose width |
0.0 ~ 1.0 |
0.5 |
faceshape_nose_all_y |
Nose height |
0.0 ~ 1.0 |
0.5 |
faceshape_nose_all_roll_y |
Nose rotation |
0.0 ~ 1.0 |
0.5 |
faceshape_nostril_roll_y |
Nostril rotation |
0.0 ~ 1.0 |
0.5 |
faceshape_mouth_all_y |
Lip height |
0.0 ~ 1.0 |
0.5 |
faceshape_lip_all_size_y |
Lip thickness |
0.0 ~ 1.0 |
0.5 |
faceshape_lipcorner_y |
Mouth corner rotation |
0.0 ~ 1.0 |
0.5 |
faceshape_lip_upper_size_x |
Upper lip width |
0.0 ~ 1.0 |
0.5 |
faceshape_lip_lower_size_x |
Lower lip width |
0.0 ~ 1.0 |
0.5 |
faceshape_jaw_all_size_x |
Chin width |
0.0 ~ 1.0 |
0.5 |
faceshape_jaw_y |
Chin height |
0.0 ~ 1.0 |
0.5 |
faceshape_cheek_all_size_x |
Cheek width |
0.0 ~ 1.0 |
0.5 |
If you need to modify related data after avatar creation data is set for the generated virtual avatar, call the setFaceShape API. For more information, see Manual avatar creation.
Related features
After you generate a virtual avatar using an image, you can use the following features: