Abraham E. Tavarez
deepface import
52cc3e5
raw
history blame contribute delete
875 Bytes
from deepface import DeepFace
import os
def verify_faces(img1_path, img2_path, model_name="Facenet", detector_backend="opencv"):
"""
Compares two face images and returns whether they belong to the same person.
"""
try:
if not os.path.exists(img1_path) or not os.path.exists(img2_path):
raise Exception("Images not found. Please provide valid paths.")
result = DeepFace.verify(
img1_path,
img2_path,
model_name=model_name,
detector_backend=detector_backend,
enforce_detection=True
)
return {
"verified": result["verified"],
"distance": result["distance"],
"threshold": result["threshold"],
"model": model_name
}
except Exception as e:
return {"error": str(e)}