from aip import AipImageClassify
import os,time
from openpyxl import Workbook
""" 你的 APPID AK SK """
APP_ID = '*'
API_KEY = '*'
SECRET_KEY = '*'
client = AipImageClassify(APP_ID, API_KEY, SECRET_KEY)
folder_path = './1'
image_list = os.listdir(folder_path)
result_list = [["图片名","菜名","卡路里"]]
""" 读取图片 """
for fn in image_list:
filename = './1/' + fn
fo = open(filename,'rb')
img = fo.read()
fo.close()
options = {}
options["filter_threshold"] = "0.6"
""" 调用菜品识别 """
result = client.dishDetect(img,options);
print(fn,
'菜品名:' + result["result"][0]["name"],
'卡路里:' + result["result"][0]["calorie"])
result_list.append(( '图件名:'+fn,
'菜品名:' + result["result"][0]["name"],
'卡路里:' + result["result"][0]["calorie"]))
time.sleep(0.5)
wb = Workbook()
sheet = wb.active
for row in result_list:
sheet.append(row)
wb.save("result.xlsx")
直接输出表格?