from aip import AipFace
import os,base64
from PIL import Image
APP_ID = '78342652'
API_KEY = 'GxUtWL0pUHZjO6ToUFyKA36c'
SECRET_KEY = '6dXDwLnWB51BktcaEQlZqH7nJofEDumr'
client = AipFace(APP_ID, API_KEY, SECRET_KEY)
pic_lst=os.listdir('image')
for pic in pic_lst:
fo=open('image/'+pic,'rb')
image=fo.read()
fo.close()
img=Image.open('image/'+pic)
image= str(base64.b64encode(image), 'utf-8')
imageType = "BASE64"
options = {}
options["face_field"] = "age"
options["max_face_num"] = 10
options["face_type"] = "LIVE"
options["liveness_control"] = "LOW"
result=client.detect(image, imageType, options)
face_num=result['result']['face_num']
for n in range(face_num):
x1=result['result']['face_list'][n]['location']['left']
y1=result['result']['face_list'][n]['location']['top']
x2=x1+result['result']['face_list'][n]['location']['width']
y2=y1+result['result']['face_list'][n]['location']['height']
new_pic = img.crop([x1, y1, x2, y2])
new_pic.save(str(n + 1) + '.jpg')
人脸识别 Tgu
最新推荐文章于 2024-08-12 16:47:32 发布