百度AI实现图像鉴别-python

from aip import AipImageClassify
APP_ID = 'baidu_id'
API_KEY = 'baiodu_key'
SECRET_KEY = 'baidu_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('2.jpg')
result = client.advancedGeneral(image);
print(result) ##python3 这里会显示为中文 print str(result).decode('unicode_escape') ##python2 需要转化下,否则显示为u'\u6cd5\u5170' 类型字符串。
u'name': u'\u5e03\u9c81\u585e\u5c14\u683c\u91cc\u82ac\u72ac'}]}


###############other############################
# 定义参数变量
options = {}
options["top_num"] = 5 # 输出前5个可能性预测
# 调用动物分类器
result=client.animalDetect(image,options)
# 调用汽车分类器
result=client.carDetect(image,options)
print(result)


猜你喜欢

转载自www.cnblogs.com/songfucai/p/9343063.html
今日推荐