kyc_karo / utils /face_match.py
manthanbachu's picture
Add application file and utils
1290ec4
raw
history blame contribute delete
729 Bytes
from deepface import DeepFace
from PIL import Image
import tempfile
def save_temp_image(image_file):
"""Save uploaded image temporarily."""
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".jpg")
image = Image.open(image_file)
image.save(temp_file.name)
return temp_file.name
def match_faces(id_image, selfie_image):
"""Match faces using DeepFace."""
try:
id_image_path = save_temp_image(id_image)
selfie_path = save_temp_image(selfie_image)
result = DeepFace.verify(img1_path=id_image_path, img2_path=selfie_path, model_name="VGG-Face")
return result["verified"]
except Exception as e:
print("Face Matching Error:", e)
return False