You need to enable JavaScript to run this app.
文档中心
智能美化特效

智能美化特效

复制全文
下载 pdf
智能美化特效
接口说明-特效
复制全文
下载 pdf
接口说明-特效
简介

特效SDK针对视频或者图片进行特效处理,包括美颜、美形、美体、美妆、滤镜和各种有趣的贴纸,主要应用在短视频、直播、图片修图等场景。

技术规格
项目具体规格
支持平台Android、iOS、Windows、Mac、Linux
支持输入Texture2D、YUV、RGBA

支持CPU架构

手机端支持(armeabi-v7,arm64-v8a),PC端支持(x86)
从V4.7.0版本开始,iOS 端 CV SDK 不再支持 armv7 架构。

支持角度yaw ≤ ±90° pitch ≤ ±90°
支持最大人脸数10
支持距离视频模式,人脸占屏幕短边1/8以上;图片模式,人脸占屏幕短边1/16以上
人脸检测速度<2ms(测试设备iphone7)
系统版本Android 6及以上,iOS 10及以上,Windows 7及以上,Mac 10.11 及以上 支持intel和m系列架构
输入输出格式

我们的接口支持的输入和输出格式如下表所示:

格式
glTexture2D
RGBA8888
BGRA8888(仅支持输入)
NV21
NV12
YUV420P

因为图像特效类算法主要在GPU中完成图像的处理和渲染过程,因此我们建议使用glTexture2D作为输入,从而减少数据在CPU内存和显存中进出导致的时间损耗;如果使用其他格式的数据作为输入,我们在底层使用Shader完成buffer数据向纹理的转换,再执行特效处理,这种方式会增加性能开销。

C接口

特效是多个功能的集合, 包括美颜、滤镜、美妆和贴纸等,其相关接口定义在头文件bef_effect_ai_api.h中。特效算法同时支持纹理输入和Buffer数据输入,具体支持的格式参考。 接口说明

1. 创建特效句柄

BEF_SDK_API
bef_effect_result_t bef_effect_ai_create(
bef_effect_handle_t *handle
);

参数说明

参数名参数类型参数说明
handlebef_effect_handle_t*创建特效句柄

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

2. 特效句柄授权

#ifdef __ANDROID__  
BEF_SDK_API
bef_effect_result_t bef_effect_ai_check_license(   
JNIEnv* env,  
jobject context,  
bef_effect_handle_t handle,  
const char *license_path   
);  
#else  
BEF_SDK_API
bef_effect_result_t bef_effect_ai_check_license(  
bef_effect_handle_t handle,   
const char *license_path
);  
#endif

参数说明

参数名参数类型参数说明
envJNIEnv *jni环境指针
contextjobjectjni对象
handlebef_effect_handle_t已创建的特效句柄
licensePathconst char *授权文件路径

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

3. 初始化特效句柄

在对特效句柄进行后续调用前,必须对该句柄进行授权码的验证,否则,后续调用都会失败。

BEF_SDK_API
bef_effect_result_t bef_effect_ai_init(
bef_effect_handle_t handle,
int width,
int height,
const char  *strModelDir,
const char * deviceName
);

初始化特效句柄时,请确保strModelDir是包含我们提供的深度学习模型的 参数说明

参数名参数类型参数说明
handlebef_effect_handle_t已创建的特效句柄
widthint输入纹理的宽度
heightint输入纹理的高度
strModelDirconst char *资源文件目录路径
deviceNameconst char *设备名一般输入空字符串即可""

返回值
成功返回 BEF_RESULT_SUC, 失败返回相应错误码, 具体请参考 bef_effect_ai_public_define.h
如果需要使用叠加特效功能(美颜、美形、美体、美妆等),还需要再进行 composer 初始化或者设置 composer 与贴纸共存,使用方式参考 18. 设置叠加特效是否与贴纸共存 19. 初始化 composer。

4. 设置输入帧宽高

BEF_SDK_API
bef_effect_result_t bef_effect_ai_set_width_height(
bef_effect_handle_t handle,
int width,
int height
);

参数说明

参数名参数类型参数说明
handlebef_effect_handle_t已创建的特效句柄
widthint纹理的宽度
heightint纹理的高度

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

5. 设置手机角度

设置手机的设备旋转角度,在处理图像数据之前必须设置手机当前的旋转角度。

BEF_SDK_API
bef_effect_result_t bef_effect_ai_set_orientation(
bef_effect_handle_t handle,
bef_ai_rotate_type orientation
);

参数说明

参数名参数类型参数说明
handlebef_effect_handle_t已创建的特效句柄
orientationbef_ai_rotate_type旋转角度

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

6. 设置美颜类型

设置美颜(磨皮、锐化)的资源

BEF_SDK_API 
bef_effect_result_t bef_effect_ai_set_beauty(
bef_effect_handle_t handle,
const char *strBeautyName
);

此接口适用于 2.6 版本及之前设置美颜,在 2.7 版本之后请务必使用 bef_effect_ai_composer_set_nodes 接口设置美颜等 参数说明

参数名参数类型参数说明
handlebef_effect_handle_t已创建的特效句柄
strBeautyNameconst char *美颜资源路径

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

7. 设置美妆类型

BEF_SDK_API
bef_effect_result_t bef_effect_ai_set_buildin_makeup(
bef_effect_handle_t handle,
const char* strMakeupName
);

此接口适用于 2.6 版本及之前设置美妆,在 2.7 版本之后请务必使用 bef_effect_ai_composer_set_nodes 接口设置美妆等 参数说明

参数名参数类型参数说明
handlebef_effect_handle_t已创建的特效句柄
strMakeupNameconst char *美妆资源路径

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

8. 设置美形类型

BEF_SDK_API
bef_effect_result_t bef_effect_ai_set_reshape_face(
bef_effect_handle_t handle,
const char *strPath
);

此接口适用于 2.6 版本及之前设置美形,在 2.7 版本之后请务必使用 bef_effect_ai_composer_set_nodes 接口设置美形等 参数说明

参数名参数类型参数说明
handlebef_effect_handle_t已创建的特效句柄
strPathconst char *塑形资源路径

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

9. 设置美形强度

BEF_SDK_API
bef_effect_result_t bef_effect_ai_update_reshape_face(
bef_effect_handle_t handle,
const float fIntensity
);

此接口适用于 2.6 版本及之前设置美形强度,在 2.7 版本之后请务必使用 bef_effect_ai_composer_update_node 接口设置美形强度等 参数说明

参数名参数类型参数说明
handlebef_effect_handle_t已创建的特效句柄
fIntensityconst float塑形强度

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

BEF_SDK_API
bef_effect_result_t bef_effect_ai_update_reshape_face_intensity(
bef_effect_handle_t handle,
const float eyeIntensity,
const float cheekIntensity
);

参数说明

参数名参数类型参数说明
handlebef_effect_handle_t已创建的特效句柄
eyeIntensityconst float大眼强度
cheekIntensityconst float瘦脸强度

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

10. 设置左右切换效果的滤镜

BEF_SDK_API
bef_effect_result_t bef_effect_ai_switch_color_filter_v2(
bef_effect_handle_t handle,
const char *leftFilterPath,
const char *rightFilterPath,
float position
);

参数说明

参数名参数类型参数说明
handlebef_effect_handle_t已创建的特效句柄
leftFilterPathconst char *左边资源路径
rightFilterPathconst char *右边资源路径
positionfloat分割位置

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

11. 设置滤镜

BEF_SDK_API
bef_effect_result_t bef_effect_ai_set_color_filter_v2(
bef_effect_handle_t handle,
const char *strPath
);

参数说明

参数名参数类型参数说明
handlebef_effect_handle_t已创建的特效句柄
strPathconst char *滤镜资源路径

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

12. 设置贴纸

BEF_SDK_API
bef_effect_result_t bef_effect_ai_set_effect(
bef_effect_handle_t handle,
const char *strPath
);

参数说明

参数名参数类型参数说明
handlebef_effect_handle_t已创建的特效句柄
strPathconst char *特效资源路径

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

13.设置虚拟背景图

该接口可用于更新虚拟背景或者绿幕背景,使用前请先设置虚拟背景或者绿幕背景(可使用设置贴纸的方式去设置虚拟背景或者绿幕背景的素材包)。

BEF_SDK_API bef_effect_result_t bef_effect_ai_set_render_cache_texture(
    bef_effect_handle_t handle, 
    const char* key, 
    const char* path);

参数说明

参数名参数类型参数说明
handlebef_effect_handle_t特效句柄
keyconst char*虚拟背景的Key,固定为*"BCCustomBackground"*
pathconst char*传入图片绝对路径,SDK 会将其解析成纹理

返回值
成功返回BEF_RESULT_SUC,失败返回错误码

14.设置虚拟背景buffer

该接口可用于更新虚拟背景或者绿幕背景,使用前请先设置虚拟背景或者绿幕背景。

BEF_SDK_API bef_effect_result_t bef_effect_ai_set_render_cache_texture_with_buffer(
    bef_effect_handle_t handle, 
    const char* key, 
    bef_ai_image* image);

参数说明

参数名参数类型参数说明
handlebef_effect_handle_t特效句柄
keyconst char*虚拟背景的Key,固定为*"BCCustomBackground"*
imagebef_ai_image图像数据,包含buffer,width,height,format等信息

返回值
成功返回BEF_RESULT_SUC,失败返回错误码

15.移除虚拟背景

BEF_SDK_API bef_effect_result_t 
bef_effect_ai_remove_render_cache_external_texture(
    bef_effect_handle_t handle, 
    const char* key);

参数说明

参数名参数类型参数说明
handlebef_effect_handle_t特效句柄
keyconst char*虚拟背景的Key,固定为*"BCCustomBackground"*

返回值
成功返回BEF_RESULT_SUC,失败返回错误码

16.设置虚拟背景纹理

4.7.1新增接口。
该接口可用于更新虚拟背景或者绿幕背景,使用前请先设置虚拟背景或者绿幕背景。

BEF_SDK_API bef_effect_result_t 
bef_effect_ai_set_render_cache_external_texture(
    bef_effect_handle_t handle, 
    const char* key, 
    int texture, 
    int width, 
    int height);

参数说明

参数名参数类型参数说明
handlebef_effect_handle_t特效句柄
keyconst char*虚拟背景的Key,固定为*"BCCustomBackground"*
textureint图像纹理ID
widthint纹理宽
heightint纹理高

返回值
成功返回BEF_RESULT_SUC,失败返回错误码

17.设置虚拟背景纹理(带角度信息)

4.7.1新增接口。
该接口可用于更新虚拟背景或者绿幕背景,使用前请先设置虚拟背景或者绿幕背景。

BEF_SDK_API bef_effect_result_t 
bef_effect_ai_set_render_cache_external_texture_with_rotation(
    bef_effect_handle_t handle, 
    const char* key, 
    int texture, 
    int width, 
    int height, 
    bef_ai_rotate_type rotation);

参数说明

参数名参数类型参数说明
handlebef_effect_handle_t特效句柄
keyconst char*虚拟背景的Key,固定为*"BCCustomBackground"*
textureint图像纹理ID
widthint纹理宽
heightint纹理高
rotationbef_ai_rotate_type旋转角度

返回值
成功返回BEF_RESULT_SUC,失败返回错误码

18. 执行算法检测

支持纹理输入的接口

BEF_SDK_API
bef_effect_result_t bef_effect_ai_algorithm_texture(
bef_effect_handle_t handle,
unsigned int textureid_src,
double timeStamp
);

参数说明

参数名参数类型参数说明
handlebef_effect_handle_t已创建的特效句柄
textureid_srcunsigned int输入纹理
timeStampdouble纹理时间戳

返回值
成功返回 BEF_RESULT_SUC, 失败返回相应错误码, 具体请参考 bef_effect_ai_public_define.h
支持 buffer 输入接口
该接口无法支持并行渲染,如有需要,直接使用 bef_effect_ai_algorithm_texture_with_buffer

BEF_SDK_API bef_effect_result_t
bef_effect_ai_algorithm_buffer(
        bef_effect_handle_t handle,
        const unsigned char *img_in,
        bef_ai_pixel_format fmt_in,
        int image_width,
        int image_height,
        int image_stride,
        double timestamp
);

参数说明

参数名参数类型参数说明
handlebef_effect_handle_t已创建的特效句柄
img_inconst unsigned char *输入 buffer
fmt_inbef_ai_pixel_format输入 buffer 格式
image_widthint输入 buffer 宽
image_heightint输入 buffer 高
timestampdouble时间戳

返回值
成功返回 BEF_RESULT_SUC, 失败返回相应错误码, 具体请参考 bef_effect_ai_public_define.h
支持纹理和算法同时输入
本接口可同时传入纹理和 buffer,也可单独传入纹理或 buffer,单独传纹理时,效果与 bef_effect_ai_algorithm_texture 一致。

BEF_SDK_API bef_effect_result_t bef_effect_ai_algorithm_texture_with_buffer(bef_effect_handle_t handle,
                                                                            unsigned int texture,
                                                                            const unsigned char *buffer,
                                                                            bef_ai_pixel_format buffer_format,
                                                                            int buffer_width,
                                                                            int buffer_height,
                                                                            int buffer_stride,
                                                                            double timeStamp);

参数说明

参数名参数类型参数说明
handlebef_effect_handle_t已创建的特效句柄
textureid_srcunsigned int输入纹理
img_inconst unsigned char *输入 buffer
fmt_inbef_ai_pixel_format输入 buffer 格式
image_widthint输入 buffer 宽
image_heightint输入 buffer 高
buffer_strideint输入 buffer 步长
timestampdouble时间戳

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

19. 执行特效处理

支持纹理输入的接口

BEF_SDK_API
bef_effect_result_t bef_effect_ai_process_texture(
bef_effect_handle_t handle,
unsigned int srcTexture,
unsigned int dstTexture,
double timeStamp
);

参数说明

参数名参数类型参数说明
handlebef_effect_handle_t已创建的特效句柄
srcTextureunsigned int输入纹理
dstTextureunsigned int输出纹理
timeStampdouble纹理时间戳

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

20. 设置强度

BEF_SDK_API
bef_effect_result_t bef_effect_ai_set_intensity(
bef_effect_handle_t handle,
bef_intensity_type intensityType,
float fIntensity
);

此接口适用于 2.6 版本及之前设置美颜强度 在 2.7 版本之后请务必使用 bef_effect_ai_composer_update_node 接口设置美颜强度 所有版本设置滤镜强度都使用此接口 参数说明

参数名参数类型参数说明
handlebef_effect_handle_t已创建的特效句柄
intensityTypebef_intensity_type强度类型
fIntensityfloat强度 [0.0, 1.0] 如果设为0则不工作

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

21. 设置叠加特效(美颜、美形、美妆)

BEF_SDK_API
bef_effect_result_t bef_effect_ai_composer_set_nodes(
bef_effect_handle_t handle,
const char *nodePaths[],
int nodeNum
);

参数说明

参数名参数类型参数说明
handlebef_effect_handle_t已创建的特效句柄
nodePathsconst char * []特效资源路径的数组
nodeNumint特效资源路径的数组长度

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

22. 设置特效强度(美颜、美形、美妆)

BEF_SDK_API
bef_effect_result_t bef_effect_ai_composer_update_node(
bef_effect_handle_t handle,
const char *nodePath,
const char *nodeTag,
float value
);

参数说明

参数名参数类型参数说明
handlebef_effect_handle_t已创建的特效句柄
nodePathsconst char *特效资源的路径
nodeTagconst char *特效的key
valuefloat设置组合特效的单个节点的强度

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

23. 设置叠加特效是否与贴纸共存

说明 本函数早期版本可用,410以上版本该接口无效,叠加情况请使用composer_set_nodes接口。 本函数需要在初始化时设置。

BEF_SDK_API 
bef_effect_result_t bef_effect_ai_composer_set_mode(
bef_effect_handle_t handle, 
int mode, 
int orderType);

参数说明

参数名参数类型参数说明
handlebef_effect_handle_t已创建的特效句柄
modeint模式,0:composer 与贴纸不可共存,1:二者可以共存
orderTypeint特效与贴纸渲染顺序,暂时不支持

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

24 初始化 composer

说明 在 SDK 中存在两种特效,分别是叠加特效(包括美颜、美形、美体、美妆等)和贴纸(包括贴纸、animoji 等),在叠加特效与贴纸不共存的环境中(是否共存需要通过 bef_effect_ai_composer_set_mode 设置,默认不共存),如果需要使用叠加特效的功能,需要先调用此函数初始化 composer ,而在特效与贴纸共存的环境中,无须调用此函数。

BEF_SDK_API
bef_effect_result_t bef_effect_ai_set_composer(
bef_effect_handle_t handle,
const char *strPath
);

参数说明

参数名参数类型参数说明
handlebef_effect_handle_t已创建的特效句柄
strPathconst char *composer资源文件路径

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

25. 获取人脸检测结果

BEF_SDK_API 
bef_effect_result_t bef_effect_ai_get_face_detect_result(
  bef_effect_handle_t handle, 
  bef_ai_face_info* result);

参数说明

参数名参数类型参数说明
handlebef_effect_handle_t已创建的特效句柄
resultbef_ai_face_info *人脸检测结果指针

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


26. 人脸遮挡检测

4.8.1 新增接口

BEF_SDK_API bef_effect_result_t bef_effect_ai_get_face_occlusion_result(bef_effect_handle_t handle, bef_ai_face_occlusion_info* result);

参数说明

参数名参数类型参数说明
handlebef_effect_handle_t已创建的人脸检测句柄
p_occ_infobef_ai_face_occlusion_info*人脸遮挡结果

27. 获取人手检测结果

BEF_SDK_API
bef_effect_result_t bef_effect_ai_get_hand_detect_result(
  bef_effect_handle_t handle, 
  bef_ai_hand_info *result);

参数说明

参数名参数说明
handlebef_effect_handle_t已创建的特效句柄
resultbef_ai_hand_info *人手检测结果指针

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

28. 获取人体检测结果

BEF_SDK_API
bef_effect_result_t bef_effect_ai_get_skeleton_detect_result(
  bef_effect_handle_t handle, 
  bef_ai_skeleton_result *result);

参数说明

参数名参数类型参数说明
handlebef_effect_handle_t已创建的特效句柄
resultbef_ai_skeleton_result *人体检测结果指针

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

29. 设置触摸事件

有些贴纸会使用到触摸事件,此时调用此函数将上层捕获到的事件传递给 sdk 以保证贴纸效果正常触发。

BEF_SDK_API 
bef_effect_result_t bef_effect_ai_process_touch_event(bef_effect_handle_t handle, 
        float x, float y);

参数说明

参数名参数类型参数说明
handlebef_effect_handle_t已创建的特效句柄
xfloat触摸点位置,宽高界限以传入的图像宽高为准
yfloat触摸点位置,宽高界限以传入的图像宽高为准

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

30. 设置并行渲染

默认关,开启之后 sdk 内部会将算法检测和特效渲染放在不同线程处理,以加速 sdk 处理。

BEF_SDK_API bef_effect_result_t bef_effect_ai_use_pipeline_processor(bef_effect_handle_t handle, bool usePipeline);

参数说明

参数名参数类型参数说明
handlebef_effect_handle_t已创建的特效句柄
usePipelinebool是否开启并行渲染

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

31.设置并行渲染多输入

并行渲染开启后,由于算法检测和特效渲染非线性,为了支持多线程处理,需要避免处理过程中连续帧的纹理 id/buffer 内存为同一个。 当该开关关闭时,表示上层传进来的连续帧纹理 id/buffer 内存为同一个,sdk 则会对传进来的纹理/buffer进行拷贝,以避免互相影响。 当该开关开启时,表示上层对传进来的纹理/buffer做了处理,sdk 不会再进行拷贝。(如上层维护一个纹理数组,循环传入以避免连续帧纹理相同问题,可参考 demo 实现) 默认关闭。
注意:该接口存在兼容问题,已废弃

BEF_SDK_API bef_effect_result_t bef_effect_ai_use_3buffer(bef_effect_handle_t handle, bool use3buffer);

参数说明

参数名参数类型参数说明
handlebef_effect_handle_t已创建的特效句柄
use3bufferbool是否使用了多输入

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

32. 清空并行渲染数据

并行渲染开启后,由于算法检测和特效渲染非线性,为了支持多线程处理,sdk 内部会保存上一帧的图像。当画面有可能会不连续(如切换相机,暂停等)的时候,可能会出现画面重新开始播放时闪现上一次画面最后一帧的情况,此时可以在画面不连续的时候调用此函数,清空 sdk 内部的缓存。

BEF_SDK_API bef_effect_result_t bef_effect_ai_clean_pipeline_processor_task(bef_effect_handle_t handle)

参数说明

参数名参数类型参数说明
handlebef_effect_handle_t已创建的特效句柄

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

33. 销毁句柄

BEF_SDK_API
void bef_effect_ai_destroy(
bef_effect_handle_t handle
);

参数说明

参数名参数类型参数说明
handlebef_effect_handle_t已创建的特效句柄

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

34. 判断设备是否支持黑科技道具(仅Android)

4.7.3新增接口。

bool bef_effect_ai_gpu_is_support()

返回值
支持返回true,不支持返回false。


Java接口

特效

特效是多个功能的集合,目前包括美颜、美形、美体、美妆、滤镜、贴纸、Animoj和AR扫一扫。对应的类文件RenderManager.java。

1. 初始化

// 默认初始化方式,打开并行渲染,使用离线授权,gles20版本
public int init(Context context, String modelDir, String licensePath);

// 使用离线鉴权方式,外部设置是否开启并行渲染与gles版本
public int init(Context context, String modelDir, String licensePath, boolean usePipeline,int renderApi);

// 标准初始化方式
public int init(Context context, String modelDir, String licensePath, boolean usePipeline, boolean onlineLicense,int renderApi);

// 设置模型缓存路径
public int init(Context context, String modelDir, String licensePath, String modelCachePath, boolean usePipeline, boolean onlineLicense,int renderApi);

// 设置是否将模型放在asset下进行读取
public int init(Context context, String modelDir, String licensePath, boolean usePipeline, boolean onlineLicense, boolean loadModelFromAsset, int renderApi);

// 设置模型缓存路径和是否将模型放在asset下进行读取
public int init(Context context, String modelDir, String licensePath, String modelCachePath, boolean usePipeline, boolean onlineLicense, boolean loadModelFromAsset, int renderApi);

参数说明

参数名参数类型参数说明
contextContext上下文
modelDirString模型文件的根目录,注意不是模型文件的绝对路径,该目录下文件层次和目录名称必须和Demo中提供的完全一致
licensePathString授权文件绝对路径
usePipelineboolean是否开启并行渲染
onlineLicenseboolean是否在线授权还是离线授权
renderApiint设置gles版本,0为gles20,1为gles30
modelCachePathString模型缓存路径
loadModelFromAssetboolean是否从asset中读取模型

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

2. 设置美颜素材

public boolean setBeauty(String resourcePath)

此接口适用于 2.6 版本及之前设置美颜,在 2.7 版本之后请务必使用 setComposerNodes 接口设置美颜等 参数说明

参数名参数类型参数说明
StringresourcePath素材绝对路径 如果传null或者空字符,则取消美颜效果

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

3. 设置美形素材

public boolean setReshape(String resourcePath)

此接口适用于 2.6 版本及之前设置美形,在 2.7 版本之后请务必使用 setComposerNodes 接口设置美形等 参数说明

参数名参数类型参数说明
StringresourcePath素材绝对路径 如果传null或者空字符,则取消塑形效果

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

4. 设置滤镜素材

public boolean setFilter(String resourcePath)

参数说明

参数名参数类型参数说明
StringresourcePath素材绝对路径 如果传null或者空字符,则取消滤镜效果

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

5. 设置美妆素材

public boolean setMakeUp(String resourcePath)

此接口适用于 2.6 版本及之前设置美妆,在 2.7 版本之后请务必使用 setComposerNodes 接口设置美妆等 参数说明

参数名参数类型参数说明
StringresourcePath素材绝对路径 如果传null或者空字符,则取消美妆效果

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

6. 设置贴纸素材

public boolean setSticker(String resourcePath)

参数说明

参数名参数类型参数说明
StringresourcePath素材绝对路径 如果传null或者空字符,则取消贴纸效果

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

7.重置贴纸

调用该接口,已设置的贴纸素材将被重置,序列帧重新开始播放

public boolean resetSticker()

返回值 成功返回true,失败返回false

8.设置虚拟背景图

该接口可用于更新虚拟背景或者绿幕背景,使用前请先设置虚拟背景或者绿幕背景(可使用设置贴纸的方式去设置虚拟背景或者绿幕背景的素材包)。

/**
  * 设置虚拟背景图
  *  @param key 虚拟背景的key,固定为"BCCustomBackground"
  *  @param path 背景图的绝对地址,贴纸内默认的图为chroma_matting_bg/AmazingFeature/image/background.png
  *  @return 
 */
public  int  setRenderCacheTexture(String key, String path);

参数说明

参数名参数类型参数说明
keyString虚拟背景的Key,固定为*"BCCustomBackground"*
pathString传入图片绝对路径,SDK 会将其解析成纹理

返回值
成功返回BEF_RESULT_SUC,失败返回错误码

9.设置虚拟背景buffer

该接口可用于更新虚拟背景或者绿幕背景,使用前请先设置虚拟背景或者绿幕背景。

/**
  * 设置虚拟背景纹理
  *  @param key 虚拟背景的key,固定为"BCCustomBackground"
  *  @param buffer 背景图的buffer
  *  @param width 宽
  *  @param height 高
  *  @param stride 步长
  *  @param format 格式
  *  @param rotation 旋转角度
  *  @return 
 */
public int setRenderCacheTextureWithBuffer(
    String key, 
    ByteBuffer buffer, 
    int width, 
    int height, 
    int stride, 
    EffectsSDKEffectConstants.PixlFormat format, 
    EffectsSDKEffectConstants.Rotation rotation);

参数说明

参数名参数类型参数说明
keyString虚拟背景的Key,固定为*"BCCustomBackground"*
bufferByteBuffer传入ByteBuffer,SDK 会将其解析成纹理
widthint宽
heightint高
strideint步长
formatPixlFormat只支持RGBA
rotationRotation旋转角度

返回值
成功返回BEF_RESULT_SUC,失败返回错误码

10.移除虚拟背景

/**
  * 移除虚拟背景纹理
  *  @param key 虚拟背景的key,固定为"BCCustomBackground"
  *  @return 
 */
public int removeRenderCacheExternalTexture(String key);

参数说明

参数名参数类型参数说明
keyString虚拟背景的Key,固定为*"BCCustomBackground"*

返回值
成功返回BEF_RESULT_SUC,失败返回错误码

11.设置虚拟背景纹理

4.7.1新增接口。
该接口可用于更新虚拟背景或者绿幕背景,使用前请先设置虚拟背景或者绿幕背景。

/**
  * 设置虚拟背景纹理
  *  @param key 虚拟背景的key,固定为"BCCustomBackground"
  *  @param textureid 纹理ID
  *  @param width 纹理宽
  *  @param height 纹理高
  *  @return 
 */
public int setRenderCacheExternalTexture(String key, int textureid, int width, int height)

参数说明

参数名参数类型参数说明
keyString虚拟背景的Key,固定为*"BCCustomBackground"*
textureidint纹理ID
widthint宽
heightint高

返回值
成功返回BEF_RESULT_SUC,失败返回错误码

12.设置虚拟背景纹理(带角度信息)

4.7.1新增接口。
该接口可用于更新虚拟背景或者绿幕背景,使用前请先设置虚拟背景或者绿幕背景。

/**
  * 设置虚拟背景纹理
  *  @param key 虚拟背景的key,固定为"BCCustomBackground"
  *  @param textureid 纹理ID
  *  @param width 纹理宽
  *  @param height 纹理高
  *  @param rotation 旋转角度
  *  @return 
 */
public int setRenderCacheExternalTextureWithRotation(String key, int textureid, int width, int height, EffectsSDKEffectConstants.Rotation rotation)

参数说明

参数名参数类型参数说明
keyString虚拟背景的Key,固定为*"BCCustomBackground"*
textureidint纹理ID
widthint宽
heightint高
rotationRotation旋转角度

返回值
成功返回BEF_RESULT_SUC,失败返回错误码

13. 处理纹理输入

public boolean processTexture(
int srcTextureId, 
int dstTextureId, 
int width, int height,
BytedEffectConstants.Rotation rotation,
double timestamp)

说明 该接口接收纹输入,经过SDK处理后完成特效的渲染,需要注意如下问题: 1、请确保输入纹理是texure2d格式,并且图像中人脸已经转正,一般Android设备采集到的纹理格式为GL_TEXTURE_EXTERNAL_OES,并且存在一定角度的旋转(前置270度,后置90度) 2、关于前置摄像头加镜像问题,请在输入纹理进入该接口之前进行镜像处理 3、时间戳是从SurfaceTexture对象中获取到的,如果无法获取SurfaceTexture的时间戳,请咨询我们的技术支持同学 参数说明

参数名参数类型参数说明
srcTextureIdint输入纹理ID,格式为Texture2D
dstTextureIdint输出纹理ID,格式为Texture2D
widthint纹理宽度
heightint纹理高度
rotationBytedEffectConstants.Rotation纹理旋转角
timestampdouble时间戳,从SurfaceTexture对象中获取

返回值
成功返回true,否则返回false

14. 处理buffer数据输入

说明 特效SDK不建议使用buffer输入,原因在输入输出格式中有相关说明。

public boolean processBuffer(
ByteBuffer inputdata, 
BytedEffectConstants.Rotation orient, 
int in_pixformat, 
int imagew, 
int imageh, 
int imagestride, 
byte[] outdata, 
int out_pixformat,
double timestamp)

参数说明

参数名参数类型参数说明
inputdataint输入数据
orientint旋转角,参考{@link BytedEffectConstants.Rotation
in_pixformatint数据格式 参考{@link BytedEffectConstants
imagewint图片宽度
imagehint图片高度
outdatabyte[]输出数据
imagestrideint图片步长
out_pixformatint输出结果格式
timestampdouble时间戳

返回值
成功返回true,否则返回false

15. 执行算法检测

说明 此方法需要与 11.执行特效渲染 一起使用,并在其之前调用。它们在一起使用的效果与直接使用单一的 8.处理纹理输入 或 9.处理buffer输入 效果一致,只是把上述两个方法进行了拆分,使得算法检测和特效处理可以分别传入不同的数据类型,以及自由决定调用时间。 处理纹理输入 此方法支持对输入的纹理进行算法检测,也可以同时把对应的 buffer 传递进去,进行加速。

public boolean algorithmTextureWithBuffer(int texture,
ByteBuffer buffer, 
BytedEffectConstants.Rotation orient,
int pixelFormat, 
int width, 
int height,
int stride,
long timeStamp)

参数说明

参数名参数类型参数说明
textureint输入纹理
bufferint输入数据
orientint旋转角,参考{@link BytedEffectConstants.Rotation
pixelFormatint数据格式 参考{@link BytedEffectConstants
widthint图片宽度
heightint图片高度
strideint图片步长
timestampdouble时间戳

返回值
成功返回true,否则返回false
处理 buffer 输入
此方法支持对输入的 buffer 进行算法检测。

public boolean algorithmBuffer(ByteBuffer buffer,
BytedEffectConstants.Rotation orient, 
int pixelFormat, 
int width, 
int height,
int stride, 
long timeStamp)

参数说明

参数名参数类型参数说明
bufferint输入数据
orientint旋转角,参考{@link BytedEffectConstants.Rotation
pixelFormatint数据格式 参考{@link BytedEffectConstants
widthint图片宽度
heightint图片高度
strideint图片步长
timestampdouble时间戳

返回值
成功返回true,否则返回false

16. 执行特效渲染

说明 此方法需要与 10.执行算法检测 一起使用,否则无法正常渲染。

processTextureOnly(int srcTexture, 
int dstTexture,
int width, 
int height, 
BytedEffectConstants.Rotation rotation, 
long timeStamp)

参数说明

参数名参数类型参数说明
srcTextureint输入纹理
dstTextureint输出纹理
widthint图片宽度
heightint图片高度
rotationint旋转角,参考{@link BytedEffectConstants.Rotation
timestampdouble时间戳

返回值
成功返回true,否则返回false

17. 设置强度

public boolean updateIntensity(
int intensitytype, 
float intensity)

此接口适用于 2.6 版本及之前设置美颜强度 在 2.7 版本之后请务必使用 updateComposerNodes 接口设置美颜强度 所有版本设置滤镜强度都使用此接口 参数说明

参数名参数类型参数说明
cheekintensityfloat瘦脸强度 0-1
eyeintensityfloat大眼参数 0-1

返回值
成功返回BEF_RESULT_SUC, 其他返回值查看{@link BytedEffectConstants}

18. 设置美形参数

public boolean updateReshape(
float cheekintensity, 
float eyeintensity)

此接口适用于 2.6 版本及之前设置美形强度,在 2.7 版本之后请务必使用 updateComposerNodes 接口设置美形强度等 参数说明

参数名参数类型参数说明
cheekintensityfloat瘦脸强度 0-1
eyeintensityfloat大眼参数 0-1

返回值
成功返回BEF_RESULT_SUC, 其他返回值查看{@link BytedEffectConstants}

19. 设置叠加特效(美颜、美形、美妆、美体)

public int setComposerNodes(String[] composerNodes)

参数说明

参数名参数类型参数说明
composerNodesString[]所选特效素材路径数组

返回值
成功返回BEF_RESULT_SUC, 其他返回值查看{@link BytedEffectConstants}

20. 设置特效强度(美颜、美形、美妆、美体)

public int updateComposerNodes(
String path, 
String key, 
float value)

参数说明

参数名参数类型参数说明
pathString特效素材对应路径
keyString特效 KEY
valuefloat强度值,0~1

返回值
成功返回BEF_RESULT_SUC, 其他返回值查看{@link BytedEffectConstants}

21. 获取人脸检测结果

public BefFaceInfo getFaceDetectResult();

返回值 成功返回 BefFaceInfo 对象,失败返回 null。

21. 获取人脸遮挡结果

4.8.1 新增接口

public BefFaceInfo getFaceOcclusionResult ()

返回值
成功返回 BefFaceInfo ,包含人脸遮挡信息

22. 获取人手检测结果

public BefHandInfo getHandDetectResult();

返回值 成功返回 BefHandInfo 对象,失败返回 null。

23. 获取人体检测结果

public BefSkeletonInfo getSkeletonDetectResult();

返回值 成功返回 BefSkeletonInfo 对象,失败返回 null。

24. 销毁句柄

public void release()

25. 判断设备是否支持黑科技道具

4.7.3新增接口。

public static boolean gpuIsSupport()

返回值 支持返回true,不支持返回false。

最近更新时间:2026.09.01 16:27:40
这个页面对您有帮助吗?
有用
有用
无用
无用