人像分割

在直播、会议等场景实现虚拟背景,实时精准分割,支持自定义背景:




Android 集成指引

Android 集成 SDK 指引,请参见 独立集成美颜特效

方法

setEffect(String effectName, int effectValue, String resourcePath, Map<String, String> extraInfo)
具体参数说明参见 setEffect

虚拟背景设置

mXmagicApi.setEffect(EffectName.EFFECT_SEGMENTATION, 45, AppConfig.motionResPath + "/segmentMotionRes/video_segmentation_blur_45", null);

自定义背景设置

Map<String, String> extraInfo = new HashMap<>();
extraInfo.put("segType", "custom_background");
extraInfo.put("bgType", "0");
extraInfo.put("bgPath", imgPath);
mXmagicApi.setEffect(EffectName.EFFECT_SEGMENTATION, 0, AppConfig.motionResPath + "/segmentMotionRes/video_empty_segmentation", extraInfo);

iOS 集成指引

iOS 集成 SDK 指引,请参见 独立集成美颜特效

方法


- (void)setEffect:(NSString * _Nullable)effectName effectValue:(int)effectValue resourcePath:(NSString * _Nullable)resourcePath extraInfo:(NSDictionary * _Nullable)extraInfo;
具体参数说明参见 setEffect

虚拟背景设置

NSString *path = [[[NSBundle mainBundle] pathForResource:@"segmentMotionRes" ofType:@"bundle"] stringByAppendingPathComponent:@"video_segmentation_blur_75"];
[_xMagicKit setEffect:EFFECT_MOTION effectValue:0 resourcePath:path extraInfo:nil];

自定义背景设置

NSString *resourcePath = [[[NSBundle mainBundle] pathForResource:@"segmentMotionRes" ofType:@"bundle"] stringByAppendingPathComponent:@"video_empty_segmentation"];
NSMutableDictionary *dic = [NSMutableDictionary dictionary];
dic[@"segType"] = @"custom_background";
dic[@"bgType"] = 0;//自定义背景的类型。 0表示图片,1表示视频
dic[@"bgPath"] = @"/var/mobile/Containers/Data/Application/06B00BBC-9060-450F-8D3A-F6028D185682/Documents/MediaFile/image.png"; //自定义背景图片的绝对路径。如果自定义背景选择的是视频,需要对视频进行压缩转码处理,使用压缩转码处理后的绝对路径
[_xMagicKit setEffect:EFFECT_SEGMENTATION effectValue:0 resourcePath:resourcePath extraInfo:dic];