解释:用于菜品识别,即对于输入的一张图片(可正常解码,且长宽比适宜),输出图片的菜品名称、卡路里信息、置信度。
Web 态说明:受宿主环境限制,Web 态暂不支持 AI 能力相关接口。在 Web 态会做打开百度 App 对应小程序页面的降级处理。

创新互联是一家专注于成都做网站、成都网站设计与策划设计,洛阳网站建设哪家好?创新互联做网站,专注于网站建设十载,网设计领域的专业建站公司;建站业务涵盖:洛阳等地区。洛阳做网站价格咨询:028-86922220
Object object
| 属性名 | 类型 | 必填 | 默认值 | 说明 | 
|---|---|---|---|---|
| image | String | 是 | - | 图像资源地址 | 
| top_num | Number | 否 | 5 | 返回结果 top n,默认值为 5 | 
| filter_threshold | Number | 是 | - | 默认 0.95 ,可以通过该参数调节识别效果,降低非菜品识别率 | 
| success | Function | 否 | 接口调用成功的回调函数 | |
| fail | Function | 否 | 接口调用失败的回调函数 | |
| complete | Function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) | 
| 参数 | 类型 | 说明 | 
|---|---|---|
| log_id | Number | 唯一的 log id ,用于问题定位 | 
| result_num | Number | 返回结果数目,及 result 数组中的元素个数 | 
| result | Array | 菜品识别结果数组 | 
| 参数名 | 参数类型 | 说明 | 
|---|---|---|
| name | String | 菜名,示例:鱼香肉丝 | 
| has_calorie | Boolean | 菜品是否含有卡路里 | 
| calorie | String | 卡路里,每 100g 的卡路里含量 | 
| probability | String | 识别结果中每一行的置信度值,0-1 | 
跳转编辑工具
在开发者工具中打开
在 WEB IDE 中打开
扫码体验
代码示例
请使用百度APP扫码
Page({
dishClassify() {
swan.chooseImage({
success: res => {
let image = res.tempFilePaths[0];
// AI系列的api有宿主使用限制,只可在百度App中使用,建议使用时加一层判断防止代码报未知错误
let host = swan.getSystemInfoSync().host;
if (host === 'baiduboxapp') {
swan.ai.dishClassify({
image,
top_num: 5,
filter_threshold: 0.95,
success: res => {
console.log('dishClassify res', res.result);
},
fail: err => {
console.log('dishClassify res', err);
}
});
}
else {
swan.showToast({
title: '此api目前仅可在百度App上使用',
icon: 'none'
});
}
}
});
}
});
{
"log_id": $log_id,
"result_num": 5,
"result": [
{
"calorie": "119",
"has_calorie": true,
"name": "小炒黄牛肉",
"probability": "0.137841"
},
{
"calorie": "22",
"has_calorie": true,
"name": "牛肉粒",
"probability": "0.0870818"
},
{
"calorie": "120",
"has_calorie": true,
"name": "炒牛肉",
"probability": "0.0813015"
},
{
"calorie": "109",
"has_calorie": true,
"name": "炒田螺",
"probability": "0.0772957"
},
{
"calorie": "117",
"has_calorie": true,
"name": "干煸豆角",
"probability": "0.048997"
}
]
}