TADBot / FER /face_detection.py
ryefoxlime's picture
updated face recognition; added support for ipykernel and ipywidgets; included .gitignore
8cc5e9d
raw
history blame
624 Bytes
from deepface import DeepFace
import numpy as np
import time
def face_detection(img_path):
currtime = time.strftime("%H%M%S")
face_objs = DeepFace.extract_faces(
np.array(img_path), detector_backend="opencv", enforce_detection=False
)
coordinates = face_objs[0]["facial_area"]
image = img_path
cropped_image = image.crop(
(
coordinates["x"],
coordinates["y"],
coordinates["x"] + coordinates["w"],
coordinates["y"] + coordinates["h"],
)
)
cropped_image.save(f"FER/Images/test_{currtime}.jpg")
return cropped_image