欢迎光临
我们一直在努力

九八云百度小程序教程:swan.ai.advancedGeneralIdentify

  • swan.ai.advancedGeneralIdentify
    • 方法参数
      • object 参数说明
      • success 返回参数说明
      • result 返回值说明
    • 示例
      • 图片示例
      • 代码示例
      • 返回值示例

    swan.ai.advancedGeneralIdentify

    解释:通用物体及场景识别,即对于输入的一张图片(可正常解码,且长宽比适宜),输出图片中的多个物体及场景标签。
    Web 态说明:受宿主环境限制,Web 态暂不支持 AI 能力相关接口。在 Web 态会做 打开百度 App 对应小程序页面 的降级处理。

    方法参数

    Object object

    object 参数说明

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

    image

    String

    图像资源地址

    success

    Function

    接口调用成功的回调函数

    fail

    Function

    接口调用失败的回调函数

    complete

    Function

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

    success 返回参数说明

    参数 类型 说明

    log_id

    Number

    唯一的 log id ,用于问题定位

    result_num

    Number

    返回结果数目,及 result 数组中的元素个数

    result

    Array

    标签结果数组

    result 返回值说明

    参数名 参数类型 说明
    keyword String 图片中的物体或场景名称
    score Number 置信度, 0-1 。
    root String 识别结果的上层标签,有部分钱币、动漫、烟酒等 tag 无上层标签。

    示例

    跳转编辑工具

    在开发者工具中打开

    在 WEB IDE 中打开

    扫码体验

    代码示例

    请使用百度APP扫码

    图片示例

    代码示例

    • JS
    
     
    1. Page({
    2. advancedGeneralIdentify() {
    3. swan.chooseImage({
    4. success: res => {
    5. let image = res.tempFilePaths[0];
    6. // AI系列的api有宿主使用限制,只可在百度App中使用,建议使用时加一层判断防止代码报未知错误
    7. let host = swan.getSystemInfoSync().host;
    8. if (host === 'baiduboxapp') {
    9. swan.ai.advancedGeneralIdentify({
    10. // 暂不支持识别网络图片
    11. image,
    12. success: res => {
    13. console.log('advancedGeneralIdentify res', res.result);
    14. },
    15. fail: err => {
    16. console.log('advancedGeneralIdentify err', err);
    17. }
    18. });
    19. }
    20. else {
    21. swan.showToast({
    22. title: '此api目前仅可在百度App上使用',
    23. icon: 'none'
    24. });
    25. }
    26. }
    27. })
    28. }
    29. });

    返回值示例

    • JSON
    
     
    1. {
    2. "log_id": $log_id,
    3. "result_num": 5,
    4. "result": [
    5. {
    6. "score": 0.371429,
    7. "root": "",
    8. "keyword": "Shop BGM & J-Clef 카페이야기 Vol.7 (商店音乐 & J-Clef 咖啡故事 Vol.7)"
    9. },
    10. {
    11. "score": 0.25045,
    12. "root": "商品-容器",
    13. "keyword": "水壶"
    14. },
    15. {
    16. "score": 0.169905,
    17. "root": "商品-生活用品",
    18. "keyword": "功夫茶具"
    19. },
    20. {
    21. "score": 0.095448,
    22. "root": "交通工具-汽车",
    23. "keyword": "汽车"
    24. },
    25. {
    26. "score": 0.019755,
    27. "root": "商品-食物",
    28. "keyword": "咖啡"
    29. }
    30. ]
    31. }

    赞(0) 打赏
    未经允许不得转载:九八云安全 » 九八云百度小程序教程:swan.ai.advancedGeneralIdentify

    评论 抢沙发