From 7f04e6b2987a18ee134c5821b88595587f2a08fc Mon Sep 17 00:00:00 2001 From: galthran-wq Date: Tue, 18 Feb 2025 09:49:25 +0000 Subject: [PATCH] mediapipe pseudo bathcing --- deepface/models/face_detection/MediaPipe.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/deepface/models/face_detection/MediaPipe.py b/deepface/models/face_detection/MediaPipe.py index 48bc2f8..86311bc 100644 --- a/deepface/models/face_detection/MediaPipe.py +++ b/deepface/models/face_detection/MediaPipe.py @@ -1,6 +1,6 @@ # built-in dependencies import os -from typing import Any, List +from typing import Any, List, Union # 3rd party dependencies import numpy as np @@ -43,10 +43,27 @@ class MediaPipeClient(Detector): ) return face_detection - def detect_faces(self, img: np.ndarray) -> List[FacialAreaRegion]: + def detect_faces(self, img: Union[np.ndarray, List[np.ndarray]]) -> Union[List[FacialAreaRegion], List[List[FacialAreaRegion]]]: """ Detect and align face with mediapipe + Args: + img (Union[np.ndarray, List[np.ndarray]]): pre-loaded image as numpy array or a list of those + + Returns: + results (Union[List[FacialAreaRegion], List[List[FacialAreaRegion]]]): A list or a list of lists of FacialAreaRegion objects + """ + if isinstance(img, np.ndarray): + return self._process_single_image(img) + elif isinstance(img, list): + return [self._process_single_image(single_img) for single_img in img] + else: + raise ValueError("Input must be a numpy array or a list of numpy arrays.") + + def _process_single_image(self, img: np.ndarray) -> List[FacialAreaRegion]: + """ + Helper function to detect faces in a single image. + Args: img (np.ndarray): pre-loaded image as numpy array