File size: 854 Bytes
8478e62
 
 
9c5e14a
8478e62
 
 
 
9c5e14a
 
8478e62
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import mediapipe as mp
from utils import read_n_resize

def mp_face_detect_fn(image, min_detect_conf=0.5):
    mp_face_detection = mp.solutions.face_detection
    mp_drawing = mp.solutions.drawing_utils 

    with mp_face_detection.FaceDetection(
        min_detection_confidence=min_detect_conf, model_selection=0
    ) as face_detection:
    
        resized_image_array = read_n_resize(image, read=False)
        
        # Convert the BGR image to RGB and process it with MediaPipe Face Detection.
        results = face_detection.process(resized_image_array)
        
        annotated_image = resized_image_array.copy()
        for detection in results.detections:
            mp_drawing.draw_detection(annotated_image, detection)
        resized_annotated_image = read_n_resize(annotated_image, read=False)
        return resized_annotated_image