File size: 624 Bytes
18a9dce
 
 
 
 
 
8cc5e9d
 
 
 
18a9dce
 
 
 
 
 
 
 
 
 
 
8cc5e9d
18a9dce
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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