基于百度云管理平台的人脸比对登录
def login_faceCheck(request):
cap = cv2.VideoCapture(0) # 调整参数实现读取视频或调用摄像头
while 1:
ret, frame = cap.read()
cv2.imwrite("face.png", frame)
cv2.imshow("cap", frame)
if cv2.waitKey(100) & cv2.waitKey(0):
# if cv2.waitKey(100) & 0xff == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
APP_ID = ' '
API_KEY = ' '
SECRET_KEY = ' '
client = AipFace(APP_ID, API_KEY, SECRET_KEY)
options = {}
options["quality_control"] = "NORMAL"
options["liveness_control"] = "LOW"
options["user_id"] = " "
options["max_user_num"] = 3
imageType = 'BASE64'
groupIdList = " "
def getImage(imagepath):
with open(imagepath, 'rb') as file:
image = file.read()
image = base64.b64encode(image)
image = str(image, encoding='utf-8')
return image
pass
image = getImage(' .png')
jsonResult = client.search(getImage('face.png'), imageType, groupIdList)
if jsonResult:
print(jsonResult)
jsonString = jsonResult["result"]
newjsonResult = jsonString["user_list"]
centerDirt = newjsonResult[0]
finalResult = centerDirt["score"]
if finalResult >= 80:
return render(request, 'index.html')
else:
return render(request, 'un_login.html')
pass