This document describes how to implement basic image processing with the ZegoEffects SDK.
Before implementing the basic image processing functionality, make sure you complete the following steps:
The following diagram shows the API call sequence of basic image processing with the ZegoEffects SDK:
Import the AI resources and models.
To use the SDK's AI features, you must import the necessary AI resources or models by calling the setResources
method. For details, see Quick starts - Import resources and models.
// Specify the absolute path of the face recognition model, which is required for various features including Face detection, eyes enlarging, and face slimming.
NSString *faceDetectionModelPath = [[NSBundle mainBundle] pathForResource:@"FaceDetectionModel" ofType:@"bundle"];
// Specify the absolute path of the portrait segmentation model, which is required for AI portrait segmentation.
NSString *segmentationModelPath = [[NSBundle mainBundle] pathForResource:@"SegmentationModel" ofType:@"bundle"];
NSArray<NSString *> * modelList = @[faceDetectionModelPath, segmentationModelPath];
// Set the list of model paths, which must be called before calling the create method.
[ZegoEffects setResources:resourcesList];
Import the license file to create a ZegoEffects
object.
Call the create
method to create an instance of the ZegoEffects
class, passing in the content of the license file as the license
parameter.
// Create a ZegoEffects object, passing the content of the license file to the `license` parameter.
NSString* license = @"xxxxxxxx";
ZegoEffects* effects = [ZegoEffects create:license];
Call the initEnv
method to initialize the ZegoEffects
object, passing in the width and height of the original image to be processed.
// Initialize the ZegoEffects object, passing in the width and height of the original image to be processed.
[self.effects initEnv:CGSizeMake(1280, 720)];
Call the following methods to enable the AI features you want to use.
enableWhiten
enableBigEyes
setPortraitSegmentationBackgroundPath
enablePortraitSegmentation
// 1. Enable the skin tone enhancement feature.
[self.effects enableWhiten:YES];
// 2. Enable the eyes enlargeing feature.
[self.effects enableBigEyes:YES];
// 3. Enable the AI portrait segmentation feature, passing in the absolute path of the segmented background image.
[self.effects setPortraitSegmentationBackgroundPath: @"MY_BACKGROUND_PATH" mode:ZegoEffectsScaleModeAspectFill];
[self.effects enablePortraitSegmentation:YES];
Call the processImageBuffer
method to perform image processing, passing in the original video image to be processed, and the processed result will be written back to the original buffer.
// Pass in the original video image to be processed, and the processed result will be written back to the original buffer.
[self.effects processImageBuffer:pixelBuffer];