You need to enable JavaScript to run this app.
导航
距离估计算法
最近更新时间:2025.03.17 14:05:22首次发布时间:2025.03.17 14:05:22
我的收藏
有用
有用
无用
无用
简介

通过对硬件摄像头进行标定,实现人与镜头之间的距离测算,目前可以支持 8m 的检测,误差在 5%以内。

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

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

1.创建距离检测算法句柄

BEF_SDK_API bef_effect_result_t
bef_effect_ai_human_distance_create(
        bef_effect_handle_t *handle
);

参数说明

参数名参数类型参数说明
handlebef_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
        );

参数说明

参数名参数类型参数说明
handlebef_effect_handle_t创建的距离估计算法句柄
mode_typebef_human_distance_model_type模型类型,详细查看头文件,固定值
pathconst char *模型的路径

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

2.设置距离估计算法参数

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

);

参数说明

参数名参数类型参数说明
handlebef_effect_handle_t创建的距离估计算法句柄
aparam_typebef_ai_human_distance_param_type参数类型
valuefloat参数值

距离估计参数类型

typedef  enum{
    BEF_HumanDistanceEdgeMode,  
    BEF_HumanDistanceCameraFov   // 设备相机fov,一般设置这个即可
}bef_ai_human_distance_param_type;

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

3.距离检测

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
);

参数说明

参数名参数类型参数说明
handlebef_effect_handle_t已创建的距离检测句柄
src_image_dataconst unsigned char *输入图片的数据指针
pixel_formatbef_ai_pixel_format输入图片的格式
widthint输入图像的宽度 (以像素为单位)
heightint输入图像的高度 (以像素为单位)
image_strideint输入图像每一行的步长 (以像素为单位)
device_nameconst char *设备名称
is_frontbool前后摄
ptr_human_distance_infobef_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

4.销毁句柄

BEF_SDK_API void
bef_effect_ai_human_distance_destroy(
        bef_effect_handle_t handle
);

参数说明

参数名参数类型参数说明
handlebef_effect_handle_t已创建的距离检测句柄

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

5.距离估计授权

// 离线授权
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);

参数说明

参数名参数类型参数说明
handlebef_effect_handle_t距离估计算法句柄
licensePathconst char *授权路径

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

Java 接口说明

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

1.初始化距离估计句柄

int init(Context context, String faceModelPath, String faceAttrModel, String fovModelPath, String licensePath, boolean onlineLicense)

参数说明

参数名参数类型参数说明
contextStringjava context
faceModelPathString人脸模型绝对路径
faceAttrModelString人脸属性模型绝对路径
fovModelPathString距离估计模型绝对路径
licensePathString授权文件绝对路径
onlineLicenseboolean授权类型

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

2.设置参数

int setParam(int paramType, float value)

参数说明

参数名参数类型参数说明
paramTypeint参数类型
valuefloat参数值

参数类型可以查看BytedEffectConstants.HumanDistanceParamType

3.距离估计算法处理

BefDistanceInfo detectDistance(ByteBuffer imgdata, PixlFormat pixel_format, int width, int height, int stride, String deviceName, boolean isFront, Rotation orientation)

参数说明

参数名参数类型参数说明
imagedataByteBuffer输入图片数据
pixel_formatPixlFormat输入图片的格式
widthint输入图像的宽度 (以像素为单位)
heightint输入图像的高度 (以像素为单位)
strideint输入图像每一行的步长 (以像素为单位)
deviceNameString设备名称
is_frontbool前后摄
orientationRotation方向

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

BefDistanceInfo {
    private FaceRect[] faceRects;  // 人脸矩形区域
    private float[] dists;  // 距离
    private int faceCount;  // 人脸个数
}

4.释放句柄

void release() 

FAQ

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

答:建议首先查看以下tag输出Error类型的日志:
bef_effect_ai 和SMASH_E_LOG 以及 EffectSDK

错误码

错误码请参考错误码表