Python - Python 通过face++AI 平台进行人脸识别
1、注册face++ 帐号 并获取api_key 和密钥
地址 : https://console.faceplusplus.com.cn/
2、准备图片
3、编写代码
# 人脸识别
import requests
from json import JSONDecoder
url = 'https://api-cn.faceplusplus.com/facepp/v3/detect'
# 仅提供给懒得申请的测试用
api_key = '-VOTHoPU1fvEporGU9mLbgZRimBsutlQ'
api_secret = '8azum86h9YiygffYIsUGFRnxWIXB8QUR'
face_path = 'C:/Users/Administrator/Desktop/123/123.jpg'
files = {'image_file': open(face_path, 'rb')}
properties = 'gender,age,beauty,ethnicity,emotion,smiling,headpose'
data = {
'api_key': api_key,
'api_secret': api_secret,
'return_attributes': properties
}
if __name__ == '__main__':
response = requests.post(url, data=data, files=files)
return_value = response.content.decode('utf-8')
obj = JSONDecoder().decode(return_value)
if obj['faces']:
for face in obj['faces']:
if face['attributes']:
print('性别', face['attributes']['gender']['value'])
print('微笑打分', face['attributes']['smile']['value'])
print('年龄', face['attributes']['age']['value'])
print('快乐度打分', face['attributes']['emotion']['happiness'])
print('男性审美评分', face['attributes']['beauty']['male_score'])
print('女性审美评分', face['attributes']['beauty']['female_score'])
4、输出
性别 Female
微笑打分 100.0
年龄 20
快乐度打分 90.048
男性审美评分 61.602
女性审美评分 71.447