用Python实现对菜品的图片识别
最近做项目需要对菜品进行图片识别功能,于是便自己动手做了一个小test
项目需要的东西(需要自己去申请自己的 APPID , AK , SK)
APP_ID = 'xxxx'
API_KEY = 'xxxxxx'
SECRET_KEY = 'xxxxxxx'
读取图片代码:
""" 读取图片 """
def get_file_content(filePath):
with open(filePath, 'rb') as fp:
return fp.read()
image = get_file_content('这里填自己图片地址')
调用菜品识别:
client.dishDetect(image)
如果有可选参数的话, 带参数调用菜品识别:
""" 如果有可选参数 """
options = {}
options["top_num"] = 10
options["filter_threshold"] = "0.7"
options["baike_num"] = 1
""" 带参数调用菜品识别 """
res = client.dishDetect(image, options)
for k in res:
print("%s->%s"%(k,res[k]))
完整代码:
from aip import AipImageClassify
""" 你的 APPID AK SK """
APP_ID = '你的APPID'
API_KEY = '你的AK'
SECRET_KEY = '你的SK'
client = AipImageClassify(APP_ID, API_KEY, SECRET_KEY)
""" 读取图片 """
def get_file_content(filePath):
with open(filePath, 'rb') as fp:
return fp.read()
image = get_file_content('你的图片地址')
""" 调用菜品识别 """
client.dishDetect(image)
""" 如果有可选参数 """
options = {}
options["top_num"] = 10
options["filter_threshold"] = "0.7"
options["baike_num"] = 1
""" 带参数调用菜品识别 """
res = client.dishDetect(image, options)
for k in res:
print("%s->%s"%(k,res[k]))
实例图片:
测试结果:
PS:如果你申请的百度智能云API,记得一定要先免费领取测试额度!
操作链接:点此处加载