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:\Windows\Fonts\STSONG.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()
ai人脸识别
最新推荐文章于 2024-06-19 12:40:02 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)