大鸟哥向小伙伴推荐一本很不错的Python书,讲解一些大数据分析与机器学习的实用技巧和运行、统计的理论,更为可贵的是书中介绍的一些代码能够满足很多不同Python基础储备知识人群的需求。书皮如下图:
书中介绍一段很有趣的代码,能够通过人脸照片测试出颜值、性别、年龄,非常准确哦,代码如下:
from aip import AipFace
import base64
APP_ID = '16994639'
API_KEY = 'L9XnkKQEMnHhB5omF2P8D9OM'
SECRET_KEY = 'nnOZDoruZ6AjVglBs6ecvUjFRIAKrn9T'
aipFace = AipFace(APP_ID,API_KEY,SECRET_KEY)
filePath = r'01.jpg'
def get_file_content(filePath):
with open(filePath,'rb') as fp:
content = base64.b64encode(fp.read())
return content.decode('utf-8')
imageType = "BASE64"
options = {}
options["face_field"] = "age,gender,beauty"
result = aipFace.detect(get_file_content(filePath),imageType,options)
# print(result)
age = result['result']['face_list'][0]['age']
print('年龄预测为:'+str(age))
gender = result['result']['face_list'][0]['gender']['type']
print('性别预测为:'+str(gender))
beauty = result['result']['face_list'][0]['beauty']
print('颜值评分为:'+str(beauty))
你只需要将包含单个人脸的照片放到Python运行识别的文件夹即可。