多種人臉屬性識別(python)

2021-09-08 17:00:21 字數 2039 閱讀 7556

可檢測:年齡、 顏值、表情、臉型、性別、眼鏡、情緒等各種人臉屬性

程式**如下:

# -*- coding:utf-8 -*-

from aip import aipface

import base64

def shibe(file):

api_key = ''

secret_key = ''

with open(file, "rb") as f:

data = f.read()

encodestr = base64.b64encode(data) # 得到 byte 編碼的資料

images = str(encodestr, 'utf-8') # 重新編碼資料

image = images

imagetype = "base64"

""" 呼叫人臉檢測 """

# m = client.detect(image, imagetype)

""" 如果有可選引數 """

options = {}

options["face_field"] = "age,beauty,expression,face_shape,gender,glasses,emotion"

""" 帶引數呼叫人臉檢測 """

m = client.detect(image, imagetype, options)

if m["error_msg"] == "success":

mm = m["result"]

print(mm)

num = mm["face_num"]

mmm = mm["face_list"][0]

age = mmm["age"]

beauty = mmm["beauty"]

# 表情

exp =

expression = mmm["expression"]['type']

if expression in exp:

expressions = exp[expression]

else:

expressions = "未知"

# 臉型

face =

face_shape = mmm["face_shape"]['type']

if face_shape in face:

face_shapes = face[face_shape]

else:

face_shapes = "未知"

# 性別

gen =

gender = mmm["gender"]['type']

if gender in gen:

genders = gen[gender]

else:

genders = "未知"

# 眼鏡

gla =

glasses = mmm["glasses"]['type']

if glasses in gla:

glassess = gla[glasses]

else:

glassess = "未知"

# 情緒

emotion = mmm["emotion"]['type']

if emotion in emo:

emotions = emo[emotion]

else:

emotions = "未知"

print("人臉數:%d, 年齡:%d, 顏值:%d, 表情:%s, 臉型:%s, 性別:%s, 眼鏡:%s, 情緒:%s"

%(num, age, beauty, expressions, face_shapes, genders, glassess, emotions))

if __name__ == '__main__':

shibie("666.jpg") # 人臉位址

pip install aip

pip install base64

python人臉識別

talk is cheap,show you the code 參考自 這裡 無注釋版 注釋版 coding utf 8 import cv2 這裡的 cascadeclassifier 是 層級分類器 的意思。為什麼要 分層 呢?剛才提到在進行機器分析 時,其實是對整個從上到下,從左到右,乙個畫素...

python人臉識別

from numpy import 引入科學計算庫 import cv2 引入opencv庫 face cascade cv2.cascadeclassifier haarcascade frontalface alt.xml 載入haar特徵級聯表 img cv2.imread my.jpg 讀取...

python之人臉識別

執行準備 所需檔案 haarcascade frontalface default.xml 獲取方式 1.開啟cmd,輸入指令 pip install i cv2 2.在安裝python的目錄下面,依次開啟資料夾 lib site packages cv2 data 所需檔案就在裡面了 1.導入庫 ...