Capability Introduction

Separate display of scenes and people

Portrait segmentation refers to the separation of the portrait subject and background in an image. The portrait subject and background are divided into different sections distinguished by tags. The API demonstrates portrait segmentation in the image, and the segmentation results are displayed separately as the portrait and background.
Scenarios

Smart image enhancement, background editing

This API separates the portrait subject from the background in images, and is particularly relevant for background replacement, rendering, and blurring.

Background replacement

Image backgrounds are replaced, based on the segmentation results. For example, the background scenery in a portrait shot, can be replaced with another scene.

Background blurring

Image backgrounds are blurred based on the segmentation results, for a more aesthetically-pleasing effect.

Description

Request
Copy

SegmentationConfiguration sc = new SegmentationConfiguration();
 
 
 
sc.setSegmentationType
 
 
 
(SegmentationConfiguration.TYPE_PORTRAIT);

 
ImageSegmentation ssEngine = new ImageSegmentation(mContext);
 
 
 
ssEngine.setSegmentationConfiguration(sc);
 
 
 
Frame frame = new Frame();
 
 
 
frame.setBitmap(mBitmap);
 
 
 
ImageResult srt = ssEngine.doSegmentation(frame, null);
 
 
 
Bitmap newbmp = srt.getBitmap();

Response
Copy

{
   "resultCode":0
}

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

2When should I call the release() method?

The release() method will uninstall a model that has been loaded to the NPU chip. If the app is no longer using face detection, uninstall the model in a timely manner to free up resources.