Google-MediaPipe / facedetect.py
innat
upload
8478e62
raw
history blame
829 Bytes
import mediapipe as mp
from utils import read_n_resize
def mp_face_detect_fn(image):
mp_face_detection = mp.solutions.face_detection
mp_drawing = mp.solutions.drawing_utils
with mp_face_detection.FaceDetection(
min_detection_confidence=0.5, 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