程序笔记   发布时间:2022-07-11  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了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)

 

大佬总结

以上是大佬教程为你收集整理的python人工智能第二篇:人脸检测和图像识别全部内容,希望文章能够帮你解决python人工智能第二篇:人脸检测和图像识别所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。