Python - Python 通過face++AI 平臺進行人臉識別

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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章