You need to enable JavaScript to run this app.
导航

皮肤分割

最近更新时间2023.06.28 14:42:36

首次发布时间2022.02.25 17:16:51

简介

识别人体皮肤区域进行分割,区别于人脸分割或者全身分割。

技术规格
支持平台Android、iOS
支持输入格式RGBA8888、BGRA8888、BGR888、RGB888
内存占用<6M (测试设备OPPO R11)
检测速度<17ms(测试设备OPPO R11)
C接口说明

详细接口说明查看头文件:bef_effect_ai_skin_segmentation.h

1.创建皮肤分割句柄

BEF_SDK_API bef_effect_result_t  
bef_effect_ai_skin_segmentation_create(bef_effect_handle_t *handle);

参数说明

参数名参数类型参数说明
handlebef_effect_handle_t创建的皮肤分割算法句柄

返回值
成功返回 BEF_RESULT_SUC, 失败返回相应错误码, 具体请参考 bef_effect_ai_public_define.h

2.从文件初始化模型参数

BEF_SDK_API bef_effect_result_t  
bef_effect_ai_skin_segmentation_init(
    bef_effect_handle_t handle,  
    const char* model_path);

参数说明

参数名参数类型参数说明
handlebef_effect_handle_t皮肤分割算法句柄
model_pathconst char*模型文件所在的文件夹路径

返回值
成功返回 BEF_RESULT_SUC, 失败返回相应错误码, 具体请参考 bef_effect_ai_public_define.h

3.设置SDK参数

// 设置const char *类型的参数接口
BEF_SDK_API bef_effect_result_t
bef_effect_ai_skin_segmentation_set_paramF(
    bef_effect_handle_t handle,
    bef_ai_skin_segmentation_param_type type,
    const char* value);

参数说明

参数名参数类型参数说明
handlebef_effect_handle_t皮肤分割算法的句柄
typebef_ai_skin_segmentation_param_type皮肤分割参数类型
valueconst char*皮肤分割参数值

返回值
成功返回 BEF_RESULT_SUC, 失败返回相应错误码, 具体请参考 bef_effect_ai_public_define.h

// 设置int类型的参数接口
BEF_SDK_API bef_effect_result_t
bef_effect_ai_skin_segmentation_set_paramI(
    bef_effect_handle_t handle,
    bef_ai_skin_segmentation_param_type type,
    int value);

参数说明

参数名参数类型参数说明
handlebef_effect_handle_t皮肤分割算法的句柄
typebef_ai_skin_segmentation_param_type皮肤分割参数类型
valueint皮肤分割参数值

返回值
成功返回 BEF_RESULT_SUC, 失败返回相应错误码, 具体请参考 bef_effect_ai_public_define.h

备注

bef_ai_skin_segmentation_param_type 详细见bef_effect_ai_skin_segmentation.h

/**
 * @brief 模型参数类型
 *
 */
typedef enum {
    BEF_AI_SKIN_SEG_MODEL_KEY = 0,     // 设置皮肤分割模型的key,默认tt_skin_seg, string
    BEF_AI_SKIN_SEG_IS_NEED_FACE = 1,  // 是否加载人脸模型以去除五官皮肤, int
} bef_ai_skin_segmentation_param_type;

4.进行皮肤分割操作

BEF_SDK_API bef_effect_result_t
bef_effect_ai_skin_segmentation_detect(
    bef_effect_handle_t handle,
    const unsigned char *image,
    bef_ai_pixel_format pixel_format,
    int image_width,
    int image_height,
    int image_stride,
    bef_ai_rotate_type orientation,
    bef_ai_skin_segmentation_ret *result);

参数说明

参数名参数类型参数说明
handlebef_effect_handle_t皮肤分割算法的句柄
imageconst unsigned char*为传入图像的大小
pixel_formatbef_ai_pixel_format传入图像的类型
image_widthint传入图像的宽
image_heightint传入图像的高
image_strideint传入图像的步长
orientationbef_ai_rotate_type传入图像旋转角
resultbef_ai_skin_segmentation_ret*算法处理返回结果

返回值
成功返回 BEF_RESULT_SUC, 失败返回相应错误码, 具体请参考 bef_effect_ai_public_define.h

备注

bef_ai_skin_segmentation_ret 详细见bef_effect_ai_skin_segmentation.h

/**
 * @brief 输出结果
 *
 */
typedef struct
{
    int width;             // 返回mask宽
    int height;            // 返回mask高
    uint8_t* mask;         // 皮肤分割mask数据
} bef_ai_skin_segmentation_ret;

5.释放句柄

BEF_SDK_API bef_effect_result_t
bef_effect_ai_skin_segmentation_release(bef_effect_handle_t handle);

参数说明

参数名参数类型参数说明
handlebef_effect_handle_t皮肤分割算法的句柄

返回值
成功返回 BEF_RESULT_SUC, 失败返回相应错误码, 具体请参考 bef_effect_ai_public_define.h

6.皮肤分割授权

// 离线license检测方式
BEF_SDK_API bef_effect_result_t
bef_effect_ai_skin_segmentation_check_license(
    bef_effect_handle_t handle,
    const char *licensePath);

// 在线license检测方式
BEF_SDK_API bef_effect_result_t
bef_effect_ai_skin_segmentation_check_online_license(
    bef_effect_handle_t handle,
    const char *licensePath);

参数说明

参数名参数类型参数说明
handlebef_effect_handle_t皮肤分割算法的句柄
licensePathconst char *授权文件字符串

返回值
成功返回 BEF_RESULT_SUC, 失败返回相应错误码, 具体请参考 bef_effect_ai_public_define.h

Java 接口说明

接口说明
详细接口说明查看文件:com.bytedance.labcv.effectsdk.SkinSegmentation.java

1.初始化皮肤分割句柄

public int init(
    Context context,
    String modelPath,
    String licensePath,
    boolean onlineLicense)

参数说明

参数名参数类型参数说明
contextContext应用上下文
modelpathString模型文件绝对路径
licensePathString授权文件绝对路径
onlineLicenseboolean授权类型

返回值
成功返回BEF_RESULT_SUC,否则返回对应的错误码

2.设置SDK参数

// 设置String类型的参数接口
public int setParamF(
    BytedEffectConstants.SkinSegmentationParamType paramType,
    String value)

参数说明

参数名参数类型参数说明
paramTypeBytedEffectConstants.SkinSegmentationParamType输入参数类型
valueString输入参数数值
// 设置int类型的参数接口
public int setParamI(
    BytedEffectConstants.SkinSegmentationParamType paramType,
    int value)

参数说明

参数名参数类型参数说明
paramTypeBytedEffectConstants.SkinSegmentationParamType输入参数类型
valueint输入参数数值

返回值
成功返回BEF_RESULT_SUC,否则返回对应的错误码

备注

关于BytedEffectConstants.SkinSegmentationParamType可参考com.bytedance.labcv.effectsdk.BytedEffectConstants.java,并且其定义与C接口bef_ai_skin_segmentation_param_type保持一致。

3.皮肤分割

public BefSkinSegInfo detect(
    ByteBuffer buffer,
    BytedEffectConstants.PixlFormat pixelFormat,
    int imageWidth,
    int imageHeight,
    int imageStride,
    BytedEffectConstants.Rotation orientation)

参数说明

参数名参数类型参数说明
bufferByteBuffer输入图像数据
pixelFormatBytedEffectConstants.PixlFormat输入数据格式
imageWidthint输入图像宽度
imageHeightint输入图像高度
imageStrideint输入图像步长
orientationBytedEffectConstants.Rotation输入图像旋转角

备注

类BefSkinSegInfo详细情况可以参考com.bytedance.labcv.effectsdk.BefSkinSegInfo.java,并且其定义与C接口bef_ai_skin_segmentation_ret保持一致。

/**
 * 皮肤分割算法结果
 */
public class BefSkinSegInfo {
    private int width;
    private int height;
    private byte[] mask;

    public byte[] getMask() {
        return mask;
    }

    public int getWidth() {
        return width;
    }

    public int getHeight() {
        return height;
    }

    @Override
    public String toString() {
        return String.format("l: %d w:%d, h:%d", mask.length, width, height);
    }
}

返回值
成功返回 类BefSkinSegInfo-皮肤分割结果

4.释放皮肤分割句柄

public void release()

FAQ

1.如果出现任何异常,请查看是否有以下类型日志

答:建议首先查看以下tag输出Error类型的日志:

bef_effect_ai 和SMASH_E_LOG 以及 EffectSDK

错误码

错误码请参考错误码表