背景分割 SDK提供从图像中实时提取人体轮廓的能力,支持多人同时分割,具备稳定性高、性能开销低、速度快等特点。
详细接口说明查看头文件:PortraitMatting.h
int HeidiPortraitMattingCreateHandle(HeidiHandle *handle);
参数说明
参数名 | 参数类型 | 参数说明 |
---|---|---|
handle | HeidiHandle | 创建的人体分割的检测句柄 |
返回值
成功返回 HEIDI_CODE_SUC, 失败返回相应错误码, 具体请参考 HeidiPublicDefines.h
int HeidiPortraitMattingSetModel( HeidiHandle handle, HeidiMattingModelType type, const char * strModelPath );
参数说明
参数名 | 参数类型 | 参数说明 |
---|---|---|
handle | HeidiHandle | 人体分割的检测句柄 |
type | HeidiMattingModelType | 模型类型,目前分大小模型,参见HeidiMattingModelType |
param_path | const char* | 模型文件的路径 |
返回值
成功返回 HEIDI_CODE_SUC, 失败返回相应错误码, 具体请参考 HeidiPublicDefines.h
int HeidiPortraitMattingSetParam( HeidiHandle handle, HeidiMattingParamType type, float value )
参数说明
参数名 | 参数类型 | 参数说明 |
---|---|---|
handle | HeidiHandle | 人体分割的检测句柄 |
type | HeidiMattingParamType | 算法参数,用来设置边界的模式、强制预测、短边长度,参考HeidiMattingParamType |
value | int | 默认为1 |
备注
HeidiMattingParamType 详细见PortraitMatting.h
/* * SDK参数 * edge_mode: * 算法参数,用来设置边界的模式 * - 0: 不加边界 * - 1: 加边界 * - 2: 加边界, 其中, 2 和 3 策略不太一样,但效果上差别不大,可随意取一个 * fresh_every: * 算法参数,设置调用多少次强制做预测,目前设置 15 即可 * MP_OutputMinSideLen: * 返回短边的长度, 默认值为128, 需要为16的倍数; * MP_OutputWidth 不设置,只做GetParam 兼容之前的调用 * MP_OutputHeight 不设置,只做GetParam 兼容之前的接口; **/ typedef enum { HEIDI_MP_EdgeMode = 0, HEIDI_MP_FrashEvery = 1, HEIDI_MP_OutputMinSideLen = 2, HEIDI_MP_OutputWidth = 3, HEIDI_MP_OutputHeight = 4, }HeidiMattingParamType;
返回值
成功返回 HEIDI_CODE_SUC, 失败返回相应错误码, 具体请参考 HeidiPublicDefines.h
int HeidiPortraitMattingGetParam( HeidiHandle handle, HeidiMattingParamType type, int *value );
参数说明
参数名 | 参数类型 | 参数说明 |
---|---|---|
handle | HeidiHandle | 人体分割的检测句柄 |
type | HeidiMattingParamType | 算法参数,用来设置边界的模式、强制预测、短边长度,参考HeidiMattingParamType |
value | int* | 输出参数 |
返回值
成功返回 HEIDI_CODE_SUC, 失败返回相应错误码, 具体请参考 HeidiPublicDefines.h
int HeidiPortraitMattingGetOutputShape( HeidiHandle handle, int width, int height, int *output_width, int *output_height );
参数说明
参数名 | 参数类型 | 参数说明 |
---|---|---|
handle | HeidiHandle | 人体分割的检测句柄 |
width | int | 输入图的宽度 |
height | int | 输入图的高度 |
output_width | int* | 输出mask的宽度 |
output_height | int* | 输出mask的高度 |
返回值
成功返回 HEIDI_CODE_SUC, 失败返回相应错误码, 具体请参考 HeidiPublicDefines.h
int HeidiPortraitMattingDetect( HeidiHandle handle, const unsigned char *src_image_data, ColorSpaceType pixel_format, int width, int height, int image_stride, ClockwiseRotateType orient, bool need_flip_alpha, HeidiMattingRet *ret );
参数说明
参数名 | 参数类型 | 参数说明 |
---|---|---|
handle | HeidiHandle | 人体分割的检测句柄 |
src_image_data | const unsigned char* | 为传入图像的大小 |
pixel_format | ColorSpaceType | 传入图像的类型 |
width | int | 传入图像的宽 |
height | int | 传入图像的高 |
image_stride | int | 传入图像的步长 |
orient | ClockwiseRotateType | 传入图像旋转角 |
need_flip_alpha | bool | 传出图像是否需要翻转 |
ret | HeidiMattingRet* | 传出图像 |
返回值
成功返回 HEIDI_CODE_SUC, 失败返回相应错误码, 具体请参考 HeidiPublicDefines.h
int HeidiPortraitMattingReleaseHandle(HeidiHandle handle);
参数说明
参数名 | 参数类型 | 参数说明 |
---|---|---|
handle | HeidiHandle | 人体分割的检测句柄 |
int HeidiPortraitMattingCheckLicense( HeidiHandle handle, const char* licensePath );
参数说明
参数名 | 参数类型 | 参数说明 |
---|---|---|
handle | HeidiHandle | 人体分割的检测句柄 |
licensePath | const char * | 授权文件字符串 |
返回值
成功返回 HEIDI_CODE_SUC, 失败返回相应错误码, 具体请参考 HeidiPublicDefines.h