cekong

导航

菜品识别 SDK调用

 1 from aip import AipImageClassify
 2 import os
 3 
 4 
 5 """ 填入参数 """
 6 APP_ID = 'your APP_ID'
 7 API_KEY = 'your API_KEY'
 8 SECRET_KEY = 'your SECRET_KEY'
 9 client = AipImageClassify(APP_ID, API_KEY, SECRET_KEY)
10 
11 
12 """ 读取图片 """
13 def get_file_content(filePath):
14     with open(filePath, 'rb') as fp:
15         return fp.read()
16 
17 
18 def dish_Detect():
19     dish_path = os.getcwd()
20     dish_path = dish_path + '/dish'
21     folderlist = os.listdir(dish_path)
22     for folder in folderlist:
23         filePath=dish_path + '/'+folder
24         image = get_file_content(filePath)
25         """ 调用菜品识别 """
26         results=client.dishDetect(image)
27         result = results['result'][0]
28         print(folder,
29               '\t菜品为:',result['name'],
30               '\t置信度:', result['probability'],
31               '\t卡路里:', result['calorie'])
32 
33 if __name__ == '__main__':
34     dish_Detect()

AipImageClassify是图像识别的Python SDK客户端

首先pip install baidu_aip

posted on 2018-12-25 15:18  cekong  阅读(323)  评论(0编辑  收藏  举报