阅读(3802) 赞(0)

百度智能小程序 自定义图像审核

2020-08-13 16:00:52 更新

swan.ai.imageAudit

解释 :自定义图像审核。

方法参数

Object object

object 参数说明

属性名类型默认值必填说明

image

String

是

图像资源地址

imgUrl

String

否

网图 URL 地址,以网图形式请求,图片 Url 需要做 UrlEncode,不能与 image 并存。

success

Function

否

接口调用成功的回调函数

fail

Function

否

接口调用失败的回调函数

complete

Function

否

接口调用结束的回调函数(调用成功、失败都会执行)

success 返回参数说明

参数类型说明

log_id

Number

请求唯一 id

conclusion

String

审核结果描述,成功才返回,失败不返回。

conclusionType

Number

审核结果标识,成功才返回,失败不返回。

data

Array

审核项详细信息,响应成功并且 conclusion 为疑似或不合规时才返回,响应失败或 conclusion 为合规是不返回。

data 返回值说明

参数类型说明

type

Number

审核类型,1:色情、2:性感、3:暴恐、4:恶心、5:水印码、6:二维码、7:条形码、8:政治人物、9:敏感词、10:自定义敏感词、11: 存在公众人物。

msg

String

不合规项描述信息

probability

Number

不合规项置信度

words

String

审核不通过敏感词,仅在敏感词审核不通过时存在。

stars

Array

政治人物列表数组,仅在政治人物审核不通过时存在。

stars 返回值说明

参数类型说明

probability

Number

不合规项置信度

name

String

姓名

conclusion、conclusionType 参数说明

参数说明

1

合规

2

不合规

3

疑似

4

审核失败

示例 

在开发者工具中打开


图片示例

代码示例

Page({
    swan.chooseImage({
        success: res => {
            let image = res.tempFilePaths[0];
            // AI系列的api有宿主使用限制,只可在百度App中使用,建议使用时加一层判断防止代码报未知错误
            let host = swan.getSystemInfoSync().host;
            if (host === 'baiduboxapp') {
                swan.ai.imageAudit({
                    image, // 暂不支持识别网络图片
                    success: res => {
                        console.log('imageAudit res', res.conclusionType);
                    },
                    fail: err => {
                        console.log('imageAudit err', err); 
                    }
                });
            }
            else {
                swan.showToast({
                    title: '此api目前仅可在百度App上使用',
                    icon: 'none'
                });
            }
        }
    })
});

返回值示例

{
    "log_id": $log_id,
    "conclusion": "不合规",
    "conclusionType": 2,
    "data": [
        {
            "msg": "存在色情内容",
            "probability": 0.94308,
            "type": 1
        },
        {
            "msg": "存在性感内容",
            "probability": 0.94308,
            "type": 2
        },
        {
            "msg": "存在暴恐内容",
            "probability": 0.94308,
            "type": 3
        },
        {
            "msg": "存在恶心内容",
            "probability": 0.9688154,
            "type": 4
        },
        {
            "msg": "存在政治敏感内容",
            "stars": [
                {
                    "probability": 0.94308,
                    "name": "奥巴马"
                },
                {
                    "probability": 0.44308,
                    "name": "特朗普"
                }
            ],
            "type": 8
        },
        {
            "msg": "存在二维码内容",
            "probability": 0.94308,
            "type": 6
        },
        {
            "msg": "存在水印码内容",
            "probability": 0.94308,
            "type": 5
        },
        {
            "msg": "存在条形码内容",
            "probability": 0.94308,
            "type": 7
        },
        {
            "msg": "包含联系方式",
            "probability": 0.94308,
            "words": "包含联系方式",
            "type": 8
        }
    ]
}