logo
On this page

Background segmentation


The ZegoEffects SDK provides various background segmentation features that can be used in a wide range of use cases, such as online education, video conferencing, short videos, and more.

Prerequisites

Before you begin to use the SDK's background segmentation feature in your project, make sure you complete the following steps:

Implementation steps

Background segmentation includes portrait segmentation, green screen segmentation, background blur, background mosaic, and other features.

Portrait segmentation

Note

Before using the portrait segmentation feature, please import the corresponding "SegmentationModel" model file first, otherwise the feature will not work. For details, see Quick Start - Import resources and models.

Call the setPortraitSegmentationBackgroundPath method to set the background path for portrait segmentation.

// Set the background path for portrait segmentation
ZegoEffectsPlugin.instance.setPortraitSegmentationBackgroundPath('MY_BACKGROUND_PATH', ZegoEffectsScaleMode.AspectFill);
  1. Call the enablePortraitSegmentation method to enable the portrait segmentation feature.
// Enable the portrait segmentation feature
ZegoEffectsPlugin.instance.enablePortraitSegmentation(true);

After enabling the portrait segmentation feature, you can further set background blur, background mosaic, and other features according to your needs.

Background blur for portrait segmentation

Call the enablePortraitSegmentationBackgroundBlur method to enable the background blur feature for portrait segmentation. After enabling the background blur feature, you can call the setPortraitSegmentationBackgroundBlurParam method to set the "intensity" parameter of the ZegoEffectsBlurParam object to adjust the intensity of background blur.

Note

After enabling the background blur feature for portrait segmentation, it will override the custom background and background mosaic features.

// Enable background blur for portrait segmentation
ZegoEffectsPlugin.instance.enablePortraitSegmentationBackgroundBlur(true);

// Set the background blur parameter for portrait segmentation
ZegoEffectsBlurParam param = ZegoEffectsBlurParam();
param.intensity = 100;
ZegoEffectsPlugin.instance.setPortraitSegmentationBackgroundBlurParam(param);

Background mosaic for portrait segmentation

Call the enablePortraitSegmentationBackgroundMosaic method to enable the background mosaic feature for portrait segmentation. After enabling the background mosaic feature, you can call the setPortraitSegmentationBackgroundMosaicParam method to set the "intensity" parameter of the ZegoEffectsMosaicParam object to adjust the intensity of background mosaic.

Note

After enabling the background mosaic feature for portrait segmentation, it will override the custom background and background blur features.

// Enable background mosaic for portrait segmentation
ZegoEffectsPlugin.instance.enablePortraitSegmentationBackgroundMosaic(true);

// Set the background mosaic parameter for portrait segmentation
ZegoEffectsMosaicParam param = ZegoEffectsMosaicParam();
param.intesity = 100;
ZegoEffectsPlugin.instance.setPortraitSegmentationBackgroundMosaicParam(param);

Green screen segmentation

  1. Call the setChromaKeyBackgroundPath method to set the background path for green screen segmentation.
// Set the background path for green screen segmentation
ZegoEffectsPlugin.instance.setChromaKeyBackgroundPath("MY_BACKGROUND_PATH", ZegoEffectsScaleMode.AspectFill);
  1. Call the enableChromaKey method to enable the green screen segmentation feature, and then call the setChromaKeyParam method to set the parameters, adjust the color tolerance, edge smoothness index, and other parameters.
// Enable the green screen segmentation feature
ZegoEffectsPlugin.instance.enableChromaKey(true);

// Set the green screen segmentation parameters
ZegoEffectsChromaKeyParam param = ZegoEffectsChromaKeyParam();
param.smoothness = 80;
param.opacity = 100;
param.keyColor = 65280;
param.similarity = 67;
ZegoEffectsPlugin.instance.setChromaKeyParam(param);

After enabling the green screen segmentation feature, you can further set background blur, background mosaic, and other features according to your needs.

Background blur for green screen segmentation

Call the enableChromaKeyBackgroundBlur method to enable the background blur feature for green screen segmentation. After enabling the background blur feature, you can call the setChromaKeyBackgroundBlurParam method to set the "intensity" parameter of the ZegoEffectsBlurParam object to adjust the intensity of background blur.

Note

After enabling the background blur feature for green screen segmentation, it will override the custom background and background mosaic features.

// Enable background blur for green screen segmentation
ZegoEffectsPlugin.instance.enableChromaKeyBackgroundBlur(true);

// Set the background blur parameter for green screen segmentation
ZegoEffectsBlurParam param = ZegoEffectsBlurParam();
param.intensity = 100;
ZegoEffectsPlugin.instance.setChromaKeyBackgroundBlurParam(param);

Background mosaic for green screen segmentation

Call the enableChromaKeyBackgroundMosaic method to enable the background mosaic feature for green screen segmentation. After enabling the background mosaic feature, you can call the setChromaKeyBackgroundMosaicParam method to set the "intensity" parameter of the ZegoEffectsMosaicParam object to adjust the intensity of background mosaic.

Note

After enabling the background mosaic feature for green screen segmentation, it will override the custom background and background blur features.

// Enable background mosaic for green screen segmentation
ZegoEffectsPlugin.instance.enableChromaKeyBackgroundMosaic(true);

// Set the background mosaic parameter for green screen segmentation
ZegoEffectsBlurParam param = ZegoEffectsBlurParam();
param.intensity = 100;
ZegoEffectsPlugin.instance.setChromaKeyBackgroundMosaicParam(param);

Previous

Makeups

Next

Filters