logo
On this page

Implement basic image processing


This document describes how to implement basic image processing with the ZegoEffects SDK.

Prerequisites

Before implementing the basic image processing functionality, make sure you complete the following steps:

Implementation steps

The following diagram shows the API call sequence of basic image processing with the ZegoEffects SDK:

image description text

Create a ZegoEffects object

  1. 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.

    Untitled
    // Specify the absolute path of the face recognition model, which is required for various features including Face detection, eyes enlarging, and face slimming.
    ArrayList<String> aiModeInfos = new ArrayList<>();
    aiModeInfos.add("sdcard/xxx/xxxxx/FaceDetectionModel.model");
    aiModeInfos.add("sdcard/xxx/xxxxx/Segmentation.model");  
    
    // Set the list of model paths, which must be called before calling the create method.
    ZegoEffects.setResources(aiModeInfos);
    
    1
    Copied!
  2. Deploy Advanced Configuration.

    Call the setAdvancedConfig interface to deploy advanced configuration items, such as configuring device performance levels. For details, please refer to Configure Device Performance Level.

    Untitled
    ZegoEffectsAdvancedConfig config = new ZegoEffectsAdvancedConfig();
    // Device performance level can be configured
    ZegoEffects.setAdvancedConfig(config);
    
    1
    Copied!
  3. Create Effects Object.

    Pass the AppID and AppSign obtained from the Prerequisites directly to the create interface. After internal authentication by the SDK, it will create an Effects object and return the corresponding error code.

    Untitled
    ZegoEffects mEffects = null;
    long appid = *******;
    String appSign = "*******";
    mEffects = ZegoEffects.create(appid, appSign, applicationContex);
    
    1
    Copied!

Initialize the ZegoEffects object

  1. Call the initEnv method to initialize the ZegoEffects object, passing in the width and height of the original image to be processed.

    Untitled
    // Initialize the ZegoEffects object, passing in the width and height of the original image to be processed.
    mEffects.initEnv(1280, 720);
    
    1
    Copied!
  2. Call the following methods to enable the AI features you want to use.

    • enableWhiten
    • enableBigEyes
    • setPortraitSegmentationBackgroundPath
    • enablePortraitSegmentation
    Untitled
    // 1. Enable the skin tone enhancement feature.
    // 2. Enable the eyes enlargeing feature.
    // 3. Enable the AI portrait segmentation feature, passing in the absolute path of the segmented background image.
    mEffects.enableWhiten(true)
            .enableBigEyes(true)
            .setPortraitSegmentationBackgroundPath("MY_BACKGROUND_PATH", ZegoEffectsScaleMode.ASPECT_FILL);
            .enablePortraitSegmentation(true);
    
    1
    Copied!

Perform image processing

Call the processTexturemethod to perform image processing. SDK also supports YUV, Texture, and other formats for image processing. For details, see the following table:

Video frame typePixel format / Texture IDMethod
Buff
  • BGRA32
  • RGBA32
processImageBufferRGB
Buff
  • NV21
  • NV12
  • I420
  • YV12
processImageBufferYUV
TextureTexture IDprocessTexture

The following sample code calls the processTexturemethod for image processing:

Untitled
ZegoEffectsVideoFrameParam zegoEffectsVideoFrameParam = new ZegoEffectsVideoFrameParam();
zegoEffectsVideoFrameParam.setFormat(ZegoEffectsVideoFrameFormat.RGBA32);
zegoEffectsVideoFrameParam.setWidth(width);
zegoEffectsVideoFrameParam.setHeight(height);
// Pass in the textureID of the original video frame to be processed, and return the textureID of the processed video frame.
zegoTextureId = mEffects.processTexture(mTextureId, zegoEffectsVideoFrameParam);

1
Copied!

Previous

Online Authentication

Next

Configure Device Performance Levels