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

光线识别

最近更新时间2023.06.28 14:41:55

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

简介

光线识别SDK提供从图像中实时检测当前画面中的光线类型的能力,支持识别如下 7 种不同的光线。

类型值类别名称
0室内黄
1室内白
2室内弱光
3晴天
4多云
5夜晚
6背光
C接口说明

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

1.创建光线识别句柄

BEF_SDK_API bef_effect_result_t
bef_effect_ai_lightcls_create(
        bef_effect_handle_t *handle,
        const char *model_path,
        int fps
);

参数说明

参数名参数类型参数说明
handlebef_effect_handle_t创建的光线识别句柄
model_pathconst char *光线识别模型文件路径
fpsint检测间隔的帧数,即 fps 帧执行一次检测

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

2.进行光线检测

BEF_SDK_API bef_effect_result_t
bef_effect_ai_lightcls_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_light_cls_result *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_light_cls_result检测结果,具体参见bef_ai_light_cls_result_st

备注

typedef struct bef_ai_light_cls_result_st {
    int selected_index;		// 光线类型 0~6,分别是 室内黄、室内白、室内弱光、晴天、多云、夜晚、背光
    float prob;				// 可信度 0~1
} bef_ai_light_cls_result;

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

3.释放句柄

BEF_SDK_API bef_effect_result_t
bef_effect_ai_lightcls_release(
        bef_effect_handle_t handle
);

参数说明

参数名参数类型参数说明
handlebef_effect_handle_t光线检测句柄

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

4.光线检测授权

// android
BEF_SDK_API bef_effect_result_t
bef_effect_ai_lightcls_check_license(
        JNIEnv* env,
        jobject context,
        bef_effect_handle_t handle,
        const char *licensePath
        );
// ios
BEF_SDK_API bef_effect_result_t
bef_effect_ai_lightcls_check_license(
        bef_effect_handle_t handle,
        const char *licensePath
        );

参数说明

参数名参数类型参数说明
handlebef_effect_handle_t光线检测句柄
licensePathconst char *授权文件字符串
contextjobject对应 Android 中的 Context

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

Java 接口说明

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

1.初始化光线检测句柄

public int init(
    Context context,
    String modelPath,
    String license,
    int fps)

参数说明

参数名参数类型参数说明
contextContext应用上下文
modelpathString模型文件绝对路径
licenseString授权文件绝对路径
fpsint检测间隔的帧数,即 fps 帧执行一次检测

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

2.进行光线检测

public BefLightclsInfo detectLightCls(
        ByteBuffer buffer,
        BytedEffectConstants.PixlFormat pixlFormat,
        int imageWidth,
        int imageHeight,
        int imageStride,
        BytedEffectConstants.Rotation orientation) 

参数说明

参数名参数类型参数说明
bufferByteBuffersdk设置参数类型
pixlFormatBytedEffectConstants.PixlFormatsdk设置参数值
imageWidthint图片宽度
imageHeightint图片高度
imageStrideint图片步长
orientationBytedEffectConstants.Rotation图片旋转方向

备注

BytedEffectConstants.PixlFormat 见:

public enum PixlFormat {
    RGBA8888(0),
    BGRA8888(1),
    BGR888(2),
    RGB888(3),
    BEF_AI_PIX_FMT_YUV420P(5),
    BEF_AI_PIX_FMT_NV12(6),
    BEF_AI_PIX_FMT_NV21(7);
    private int value;
    PixlFormat(int value) {
        this.value = value;
    }
    public int getValue() {
        return value;
    }
}

BytedEffectConstants.Rotation 见:

public enum Rotation {
    /**
     * 图像不需要旋转,图像中的人脸为正脸
     * The image does not need to be rotated. The face in the image is positive
     */
    CLOCKWISE_ROTATE_0(0),
    /**
     * 图像需要顺时针旋转90度,使图像中的人脸为正
     * The image needs to be rotated 90 degrees clockwise so that the face in the image is positive
     */
    CLOCKWISE_ROTATE_90(1),
    /**
     * 图像需要顺时针旋转180度,使图像中的人脸为正
     * The image needs to be rotated 180 degrees clockwise so that the face in the image is positive
     */
    CLOCKWISE_ROTATE_180(2),
    /**
     * 图像需要顺时针旋转270度,使图像中的人脸为正
     * The image needs to be rotated 270 degrees clockwise so that the face in the image is positive
     */
    CLOCKWISE_ROTATE_270(3);
    public int id = 0;
    Rotation(int id) {
        this.id = id;
    }
}

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

3.释放句柄

public void release()

FAQ

错误码

错误码请参考错误码表