python 人脸识别系统
import cv2
import face_recognition
import sys
face_image = face_recognition.load_image_file(input("请粘贴要识别的图片地址:"))
face_encodings = face_recognition.face_encodings(face_image)
face_locations = face_recognition.face_locations(face_image)
n = len(face_encodings)
if n > 2:
print('超过2个人')
face1 = face_encodings[0]
face2 = face_encodings[1]
result = face_recognition.compare_faces([face1], face2, tolerance=0.5)
face1 = face_encodings[0]
face2 = face_encodings[1]
result = face_recognition.compare_faces([face1],face2,tolerance=0.5)
if result == [True]:
print('人脸一致')
name = 'PASS'
else:
print('人脸不一致')
name = 'NO'
for i in range(len(face_encodings)):
face_encoding = face_encodings[(i-1)]
face_location = face_locations[(i-1)]
top,right,bottom,left = face_location
cv2.rectangle(face_image,(left,top),(right,bottom),(0,255,0),2)
cv2.putText(face_image,name,(left-10,top-10),cv2.FONT_HERSHEY_SIMPLEX,0.8,(0,0,255),2)
face_image_rgb = cv2.cvtColor(face_image,cv2.COLOR_BGR2RGB)
cv2.imshow('OutPut',face_image_rgb)
cv2.waitKey(0)