通过对硬件摄像头进行标定,实现人与镜头之间的距离测算,目前可以支持 8m 的检测,误差在 5%以内。
支持平台 | Android、iOS |
---|---|
支持输入格式 | RGBA8888、BGRA8888 |
内存占用 | <42M (测试设备OPPO R11) |
检测速度 | <5ms(测试设备OPPO R11) |
详细接口说明查看头文件: bef_effect_ai_human_distance.h
BEF_SDK_API bef_effect_result_t bef_effect_ai_human_distance_create( bef_effect_handle_t *handle );
参数说明
参数名 | 参数类型 | 参数说明 |
---|---|---|
handle | bef_effect_handle_t* | 创建的距离估计算法句柄 |
加载距离估计算法模型
BEF_SDK_API bef_effect_result_t bef_effect_ai_human_distance_load_model( bef_effect_handle_t handle, bef_human_distance_model_type mode_type, const char *path );
参数说明
参数名 | 参数类型 | 参数说明 |
---|---|---|
handle | bef_effect_handle_t | 创建的距离估计算法句柄 |
mode_type | bef_human_distance_model_type | 模型类型,详细查看头文件,固定值 |
path | const char * | 模型的路径 |
返回值
成功返回 BEF_RESULT_SUC, 失败返回相应错误码, 具体请参考 bef_effect_ai_public_define.h
BEF_SDK_API bef_effect_result_t bef_effect_ai_human_distance_setparam( bef_effect_handle_t handle, bef_ai_human_distance_param_type param_type, float value );
参数说明
参数名 | 参数类型 | 参数说明 |
---|---|---|
handle | bef_effect_handle_t | 创建的距离估计算法句柄 |
aparam_type | bef_ai_human_distance_param_type | 参数类型 |
value | float | 参数值 |
距离估计参数类型
typedef enum{ BEF_HumanDistanceEdgeMode, BEF_HumanDistanceCameraFov // 设备相机fov,一般设置这个即可 }bef_ai_human_distance_param_type;
返回值
成功返回 BEF_RESULT_SUC, 失败返回相应错误码, 具体请参考 bef_effect_ai_public_define.h
BEF_SDK_API bef_effect_result_t bef_effect_ai_human_distance_detect_V2( bef_effect_handle_t handle, const unsigned char *src_image_data, bef_ai_pixel_format pixel_format, int width, int height, int image_stride, const char *device_name, bool is_front, bef_ai_rotate_type orientation, const bef_ai_face_info *ptr_base_info, const bef_ai_face_attribute_result *ptr_attr_info, bef_ai_human_distance_result *ptr_human_distance_info );
参数说明
参数名 | 参数类型 | 参数说明 |
---|---|---|
handle | bef_effect_handle_t | 已创建的距离检测句柄 |
src_image_data | const unsigned char * | 输入图片的数据指针 |
pixel_format | bef_ai_pixel_format | 输入图片的格式 |
width | int | 输入图像的宽度 (以像素为单位) |
height | int | 输入图像的高度 (以像素为单位) |
image_stride | int | 输入图像每一行的步长 (以像素为单位) |
device_name | const char * | 设备名称 |
is_front | bool | 前后摄 |
ptr_human_distance_info | bef_ai_human_distance_result * | 距离估计检测结果 |
其他info依赖人脸检测和人脸属性结果。详细可查看示例BEHumanDistanceAlgorithmTask.m的代码
距离检测结果:
typedef struct bef_ai_human_distance_result_st { float distances[BEF_MAX_FACE_NUM]; int face_count; // {zh} 有效的人脸个数,即表示attr_info中的前face_count个人脸是有效的 }bef_ai_human_distance_result;
返回值
成功返回 BEF_RESULT_SUC, 失败返回相应错误码, 具体请参考 bef_effect_ai_public_define.h
BEF_SDK_API void bef_effect_ai_human_distance_destroy( bef_effect_handle_t handle );
参数说明
参数名 | 参数类型 | 参数说明 |
---|---|---|
handle | bef_effect_handle_t | 已创建的距离检测句柄 |
返回值
成功返回 BEF_RESULT_SUC, 失败返回相应错误码, 具体请参考 bef_effect_ai_public_define.h
// 离线授权 BEF_SDK_API bef_effect_result_t bef_effect_ai_human_distance_check_license(bef_effect_handle_t handle, const char *licensePath); // 在线授权 BEF_SDK_API bef_effect_result_t bef_effect_ai_human_distance_check_online_license(bef_effect_handle_t handle, const char *licensePath);
参数说明
参数名 | 参数类型 | 参数说明 |
---|---|---|
handle | bef_effect_handle_t | 距离估计算法句柄 |
licensePath | const char * | 授权路径 |
返回值
成功返回 BEF_RESULT_SUC, 失败返回相应错误码, 具体请参考 bef_effect_ai_public_define.h
接口说明
详细接口说明查看文件:com.bytedance.labcv.effectsdk.HumanDistance.java
int init(Context context, String faceModelPath, String faceAttrModel, String fovModelPath, String licensePath, boolean onlineLicense)
参数说明
参数名 | 参数类型 | 参数说明 |
---|---|---|
context | String | java context |
faceModelPath | String | 人脸模型绝对路径 |
faceAttrModel | String | 人脸属性模型绝对路径 |
fovModelPath | String | 距离估计模型绝对路径 |
licensePath | String | 授权文件绝对路径 |
onlineLicense | boolean | 授权类型 |
返回值
成功返回BEF_RESULT_SUC,否则返回对应的错误码
int setParam(int paramType, float value)
参数说明
参数名 | 参数类型 | 参数说明 |
---|---|---|
paramType | int | 参数类型 |
value | float | 参数值 |
参数类型可以查看BytedEffectConstants.HumanDistanceParamType
BefDistanceInfo detectDistance(ByteBuffer imgdata, PixlFormat pixel_format, int width, int height, int stride, String deviceName, boolean isFront, Rotation orientation)
参数说明
参数名 | 参数类型 | 参数说明 |
---|---|---|
imagedata | ByteBuffer | 输入图片数据 |
pixel_format | PixlFormat | 输入图片的格式 |
width | int | 输入图像的宽度 (以像素为单位) |
height | int | 输入图像的高度 (以像素为单位) |
stride | int | 输入图像每一行的步长 (以像素为单位) |
deviceName | String | 设备名称 |
is_front | bool | 前后摄 |
orientation | Rotation | 方向 |
返回值
成功返回distanceInfo,否则返回对应的错误码
BefDistanceInfo { private FaceRect[] faceRects; // 人脸矩形区域 private float[] dists; // 距离 private int faceCount; // 人脸个数 }
void release()
答:建议首先查看以下tag输出Error类型的日志:
bef_effect_ai 和SMASH_E_LOG 以及 EffectSDK
错误码请参考错误码表