AnomalyDetector / utils /face_match.py
anuradhakoppala's picture
Create utils/face_match.py
a291edb verified
raw
history blame contribute delete
450 Bytes
import face_recognition
import numpy as np
def compare_faces(reference_img, selfie_img):
try:
ref_encoding = face_recognition.face_encodings(reference_img)[0]
self_encoding = face_recognition.face_encodings(selfie_img)[0]
distance = np.linalg.norm(ref_encoding - self_encoding)
score = max(0, 100 - distance * 100) # scale to 0–100
return score
except IndexError:
return 0 # No face found