Python人工智能第二篇:人脸检测和图像识别

Python人工智能第二篇:人脸检测和图像识别

人脸检测

详细内容请看技术文档: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)

转载于:https://www.cnblogs.com/an-wen/p/11604106.html

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值