Video portrait segmentation

Capability Introduction

Video portrait, real-time segmentation

This API supports real-time processing of real-time video streams (e.g. mobile camera). A developer transmits each frame in the real-time video streams to the HiAI Engine. The algorithm segments the portraits in the video frames, and returns the mask results of the byte array to the user.

Video rendering, background replacement

This API can be used to segment portrait of each frame in the videos and can be applicable to scenarios based on the understanding of video content, such as video foreground rendering and background replacement.

Video foreground rendering

Renders the video foreground (people) through video portrait segmentation, such as blurring and beautification.

Background replacement

Processes video stream can be processed in real time, with video background replaced or removed, etc.



ImageSegmentation imageSegmentation = new ImageSegmentation(getApplicationContext());
SegConfiguration config = new SegConfiguration.Builder()
VisionImageMetadata.Builder builder = new VisionImageMetadata.Builder();
builder.setFormat(17); //nv21 format
int originalHeight = 200; //image height
int originalWidth = 200; //image width
builder.setRotation(270); //front camera
VisionImageMetadata metadata =;
byte[] yuvBytes = new byte[originalWidth * originalHeight * 3 / 2];
VisionImage image = VisionImage.fromByteArray(yuvBytes, metadata);
int resultCode = imageSegmentation.doSegmentation(image, mImageResult, null);
ImageResult mImageResult = new ImageResult();
byte[] resultBytes = mImageResult.getByteArray();



Start development here with Huawei

Service introduction

Service overview, application scenarios, and functions
Learn more

Access preparation

Preparation for access, such as registration, authentication, and agreement signing
Learn more

Sample code

Demonstration of sample code
Learn more

API description

Interface parameter definition, description, restrictions, and constraints
Learn more
1Can I call the faceCompare() method without calling the prepare() method of the API?

Yes, you can. The engine is started by default in the faceCompare() method. If the engine has already been started, it will not restart.

2What are the input requirements for video portrait segmentation?

Video portrait segmentation recommends input image size of 1080 pixels.

3Is the video portrait segmentation on-device or in-cloud?

Video portrait segmentation is an on-device API. If the phone is of Chinese version, it needs to download the APK to your phone in the lazyload mode through the Internet; if the phone is of oversease version, no Internet access is needed.