13518219792

建站动态

根据您的个性需求进行定制 先人一步 抢占小程序红利时代

创新互联百度小程序教程:swan.ai.animalClassify

swan.ai.animalClassify

解释 :该请求用于识别一张图片,即对于输入的一张图片(可正常解码,且长宽比较合适),输出动物识别结果。
Web 态说明:受宿主环境限制,Web 态暂不支持 AI 能力相关接口。在 Web 态会做 打开百度 App 对应小程序页面 的降级处理。

成都创新互联专注于桃山网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供桃山营销型网站建设,桃山网站制作、桃山网页设计、桃山网站官网定制、小程序开发服务,打造桃山网络公司原创品牌,更为您提供桃山网站排名全网营销落地服务。

方法参数

Object object

object 参数说明

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

image

String

-

图像资源地址

top_num

Number

6

返回预测得分 top 结果数,默认为 6

success

Function

接口调用成功的回调函数

fail

Function

接口调用失败的回调函数

complete

Function

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

success 返回参数说明

参数 类型 说明

log_id

Number

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

result

Array

识别结果数组

result 返回值说明

参数名 参数类型 说明
name String 动物名称,示例:蒙古马。
score String 置信度,示例:0.5321 。

示例

跳转编辑工具

在开发者工具中打开

在 WEB IDE 中打开

扫码体验

代码示例

请使用百度APP扫码

图片示例

代码示例

 
 
 
  1. Page({
  2. animalClassify() {
  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.animalClassify({
  10. image,
  11. top_num: 6,
  12. success: res => {
  13. console.log('animalClassify res', res.result);
  14. },
  15. fail: err => {
  16. console.log('animalClassify err', err);
  17. }
  18. });
  19. }
  20. else {
  21. swan.showToast({
  22. title: '此api目前仅可在百度App上使用',
  23. icon: 'none'
  24. });
  25. }
  26. }
  27. });
  28. }
  29. });

返回值示例

 
 
 
  1. {
  2. "log_id": $log_id,
  3. "result": [
  4. {
  5. "score": "0.989849",
  6. "name": "国宝大熊猫"
  7. },
  8. {
  9. "score": "0.00507955",
  10. "name": "秦岭四宝"
  11. },
  12. {
  13. "score": "0.00143795",
  14. "name": "团团圆圆"
  15. },
  16. {
  17. "score": "0.000770976",
  18. "name": "棕色大熊猫"
  19. },
  20. {
  21. "score": "0.000324621",
  22. "name": "圆仔"
  23. },
  24. {
  25. "score": "0.000130874",
  26. "name": "小熊猫"
  27. }
  28. ]
  29. }

分享标题:创新互联百度小程序教程:swan.ai.animalClassify
转载来于:http://cdbrznjsb.com/article/cccdojc.html

其他资讯

让你的专属顾问为你服务