在这里插入代码片
import base64
import cv2 as cv
import json
from aip import AipFace
APP_ID = '23575141'
API_KEY = 'GQmcZTPiqLU1I3bXHuqMgKNP'
SECRET_KEY = '4oiUxWaqC0whKKhGg65VkOdMv4GtfqyA'
client = AipFace(APP_ID, API_KEY, SECRET_KEY)
def photo_take():
cap = cv.VideoCapture(0)
while True:
success, frame = cap.read()
cv.imshow('video', frame)
Key = cv.waitKey(1) & 0xFF
if Key == ord(' '):
cv.imwrite('D:\\GraduateFrom_XCU\\CODE\\fingerPrint\\templates\\photo\\photo1.jpg', frame)
break
cap.release()
cv.destroyAllWindows()
def face_detect(filepath1,filepath2):
result = client.match([
{
'image': base64.b64encode(open(filepath1, 'rb').read()),
'image_type': 'BASE64',
},
{
'image': base64.b64encode(open(filepath2, 'rb').read()),
'image_type': 'BASE64',
}
])
a=result['result']['score']
print('相似度为:')
print(a) ,
print('%')
if a>80:
print('验证成功')
return 1
else:
print ('验证失败')
return 0
def face_search(filepath):
with open(filepath, 'rb') as fp:
image=base64.b64encode(fp.read())
imageType="BASE64"
groupIdList="face1"
result=client.search(image,imageType,groupIdList)
print (result['result'])
if(result['result']==None):
print ('验证失败')
return 0
print(result)
num=result['result']['user_list'][0]['score']
if num > 80:
print ('验证成功')
return 1
else:
print ('验证失败')
return 0
print(result['result']['user_list'][0]['score'])
print(result['result']['face_token'])
print(result['error_code'])
def face_add(filepath,unit,num):
with open(filepath,'rb') as fp:
image=image=base64.b64encode(fp.read())
imageType="BASE64"
groupid=unit
userid=num
result=client.addUser(image,imageType,groupid,userid)
if result['error_code']==0:
print("增加人脸成功")
else:
print("增加人脸失败")
def face_delete(filepath):
userId = "huge"
groupId = "face1"
result = client.deleteUser(groupId, userId);
print(result)
if result['error_code']==0:
print("删除人脸成功")
else:
print("删除人脸失败")
if __name__=='__main__':
face_search('D:\\CODE\\photo\\9.jpg')