栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

ai人脸识别

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

ai人脸识别

from aip import AipFace
import base64
import time
from PIL import  Image,ImageDraw,ImageFont
APP_ID = '24119354'
API_KEY = '05FFjyTy3Oj6A5RdXgi8ua6q'
SECRET_KEY = '4zudUSQkl8hFkuDEBovwR1nBg6SIjn8Y'
client = AipFace(APP_ID, API_KEY, SECRET_KEY)
image_f = '7.webp'
f_img = open('7.webp','rb')
img = f_img.read()
f_img.close()
imge =Image.open(image_f)
draw = ImageDraw.Draw(imge)
tfont =ImageFont.truetype('‪C:WindowsFontsSTSONG.TTF',16)
# imge.show()
# print(img)
image = str(base64.b64encode(img),"utf-8")
imageType = "BASE64"
options = {}
options["face_field"] = "age,beauty,gender,glasses"
options["max_face_num"] = 10
options["face_type"] = "LIVE"
result = client.detect(image, imageType, options)
time.sleep(0.5)
# print(result)
for each in result['result']['face_list']:
    print(each)
    print("$"*100,'n')
    age = each['age']
    beauty = each['beauty']
    glasses = each['glasses']
    if each['gender']['type'] == 'female':
        gender = '女'
    else:
        gender = '男'
    if each['glasses']['type'] =='common':
        glasses = '普通眼镜'
    if each['glasses']['type'] =='sun':
        glasses = '墨镜'
    else:
        glasses = '无眼镜'

    x1 =each['location']['left']
    y1 =each['location']['top']
    x2 =x1 + each['location']['width']
    y2 =y1 + each['location']['height']
    draw.rectangle((x1,y1,x2,y2),outline='purple')

    draw.text((x2+5,y1),'年龄:'+ str(age),'black',font=tfont)
    draw.text((x2 + 5, y1+15), '颜值:' + str(beauty), 'black', font=tfont)
    draw.text((x2 + 5, y1+30), '性别:' + str(gender), 'black', font=tfont)
    draw.text((x2 + 5, y1+45), '眼镜:' + str(glasses), 'black', font=tfont)
    print('年龄:',age)
    print('颜值:',beauty)
    print('性别:',gender)
    print('眼镜:',glasses)
imge.show()
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/980603.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号