详细内容请看技术文档:https://ai.baidu.com/docs#/Face-Python-SDK/top
from aip import AipFace import base64 """ 你的 APPID AK SK """ APP_ID = '你的 App ID' API_KEY = '你的 Api Key' SECRET_KEY = '你的 Secret Key' face_client = AipFace(APP_ID, API_KEY, SECRET_KEY) """ 读取图片 """ def get_file_content(filePath): with open(filePath, 'rb') as fp: return fp.read() bytes_str = base64.b64encode(get_file_content('people/1.jpg')) image = str(bytes_str, "utf8") imageType = "BASE64" options = {} options["face_field"] = "age,beauty" """ 调用人脸检测 """ res = face_client.detect(image, imageType, options) age = res.get("result").get("face_list")[0].get("age") beauty = res.get("result").get("face_list")[0].get("beauty") print(f"年龄:{age}岁", f"颜值:{beauty}分")
详细内容请看技术文档:https://ai.baidu.com/docs#/ImageClassify-Python-SDK/top
from aip import AipImageClassify """ 你的 APPID AK SK """ APP_ID = '你的 App ID' API_KEY = '你的 Api Key' SECRET_KEY = '你的 Secret Key' 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('erha.jpg') """ 如果有可选参数 """ options = {} options["top_num"] = 1 #返回预测得分top结果数,默认为6 options["baike_num"] = 5 #返回百科信息的结果数,默认不返回 """ 带参数调用动物识别 """ res = client.animalDetect(image, options) print(res)