logo
On this page

Implement basic image processing


Prerequisites

Before implementing basic AI Effects features, please ensure that:

  • You have registered an account on ZEGOCLOUD Console and obtained the AppID and AppSign required for SDK initialization.
  • You have obtained the unique authentication file for the ZegoEffects SDK from ZEGOCLOUD technical support.
  • You have integrated the SDK into your project. For details, see Integrate the SDK.
  • You have integrated ZegoExpressSDK into your project. For details, see Quick start.
  • You have imported ZegoEffects resources and models into your project. For details, see Import resources and models.

Implementation Steps

1. Import AI resources or models

Before using the AI Effects features, you must call the setResources method to import AI resources or models. For details, see Import resources and models.

ZegoEffectsPlugin.instance.setResources();

2. Create an Effects object

Note

When calling this method, you must add the await keyword before it.

// Ensure that the [setResources] method has been called to load resources and models.

// appID and appSign are parameters obtained from the prerequisites and must add the await keyword
await ZegoEffectsPlugin.instance.create(appID,appSign);

3. Initialize SDK and enable AI Effects features

Note

Ensure that the Express SDK has been initialized. For details, see Implement video call document.

1

Enable custom video pre-processing

Call the enableCustomVideoProcessing method to enable custom video preprocessing.

// Enable custom video preprocessing for ExpressEngine
ZegoCustomVideoProcessConfig config = ZegoCustomVideoProcessConfig(ZegoVideoBufferType.GLTexture2D);
if (Platform.isIOS) {
  config.bufferType = ZegoVideoBufferType.CVPixelBuffer;
} else if (Platform.isAndroid) {
  config.bufferType = ZegoVideoBufferType.GLTexture2D;
}

// Enable custom video pre-processing
ZegoExpressEngine.instance.enableCustomVideoProcessing(true, config);
2

Enable image processing

Call the enableImageProcessing method to enable image processing.

// Use AI Effects custom processing
ZegoEffectsPlugin.instance.enableImageProcessing(true);
3

Start Preview

Call Express's createCanvasView method to create a view for preview, and call Express's startPreview to start preview.

// Must be called after ZegoExpressSDK successfully creates an engine
ZegoExpressEngine.instance.createCanvasView((viewID) {
    _previewId = viewID;
    print('createCanvasView viewId: $viewID');
    startPreview(_previewId);
}).then((widget) {
    print('createCanvasView widget: $widget');
    setState(() {
        _previewViewWidget = widget!;
    });
}).catchError((err) {
    // Output related error codes
    print('createCanvasView Error: $err');
});
4

Enable face beautification

Call the enableSmooth/enableFaceLifting method to enable face beautification.

// Enable and configure smooth effect to achieve better beautification effect
ZegoEffectsPlugin.instance.enableSmooth(true);
ZegoEffectsSmoothParam smoothParam = ZegoEffectsSmoothParam();
smoothParam.intensity = 100;
ZegoEffectsPlugin.instance.setSmoothParam(smoothParam);

// Enable face lifting effect to create a smaller face appearance
ZegoEffectsPlugin.instance.enableFaceLifting(true);
ZegoEffectsFaceLiftingParam faceLiftingParam = ZegoEffectsFaceLiftingParam();
faceLiftingParam.intensity = 100;
ZegoEffectsPlugin.instance.setFaceLiftingParam(faceLiftingParam);

Previous

Import Resources and Models

Next

Face Beautification