From 9300ed0dfd922c582646983326d0566499e12d62 Mon Sep 17 00:00:00 2001 From: Programador Artificial Date: Mon, 15 Jul 2024 10:45:05 -0300 Subject: [PATCH] Add grayscale parameter again --- deepface/DeepFace.py | 5 +++++ deepface/modules/detection.py | 24 ++++++++++++++++-------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/deepface/DeepFace.py b/deepface/DeepFace.py index 2cebe4a..cd0d4f7 100644 --- a/deepface/DeepFace.py +++ b/deepface/DeepFace.py @@ -482,6 +482,7 @@ def extract_faces( enforce_detection: bool = True, align: bool = True, expand_percentage: int = 0, + grayscale: bool = False, color_face: str = 'rgb', normalize_face: bool = True, anti_spoofing: bool = False, @@ -504,6 +505,9 @@ def extract_faces( expand_percentage (int): expand detected facial area with a percentage (default is 0). + grayscale (boolean): (Deprecated) Flag to convert the output face image to grayscale + (default is False). + color_face (string): Color to return face image output. Options: 'rgb', 'bgr' or 'gray' (default is 'rgb'). @@ -538,6 +542,7 @@ def extract_faces( enforce_detection=enforce_detection, align=align, expand_percentage=expand_percentage, + grayscale=grayscale, color_face=color_face, normalize_face=normalize_face, anti_spoofing=anti_spoofing, diff --git a/deepface/modules/detection.py b/deepface/modules/detection.py index 3596364..0c32aa4 100644 --- a/deepface/modules/detection.py +++ b/deepface/modules/detection.py @@ -24,6 +24,7 @@ def extract_faces( enforce_detection: bool = True, align: bool = True, expand_percentage: int = 0, + grayscale: bool = False, color_face: str = 'rgb', normalize_face: bool = True, anti_spoofing: bool = False, @@ -46,6 +47,9 @@ def extract_faces( expand_percentage (int): expand detected facial area with a percentage. + grayscale (boolean): (Deprecated) Flag to convert the output face image to grayscale + (default is False). + color_face (string): Color to return face image output. Options: 'rgb', 'bgr' or 'gray' (default is 'rgb'). @@ -118,16 +122,20 @@ def extract_faces( if current_img.shape[0] == 0 or current_img.shape[1] == 0: continue - if color_face == 'rgb': - current_img = current_img[:, :, ::-1] - elif color_face == 'bgr': - pass # image is in BGR - elif color_face == 'gray': + if grayscale is True: + logger.warn("Parameter grayscale is deprecated. Use color_face instead.") current_img = cv2.cvtColor(current_img, cv2.COLOR_BGR2GRAY) else: - raise ValueError( - f"The color_face can be rgb, bgr or gray, but it is {color_face}." - ) + if color_face == 'rgb': + current_img = current_img[:, :, ::-1] + elif color_face == 'bgr': + pass # image is in BGR + elif color_face == 'gray': + current_img = cv2.cvtColor(current_img, cv2.COLOR_BGR2GRAY) + else: + raise ValueError( + f"The color_face can be rgb, bgr or gray, but it is {color_face}." + ) if normalize_face: current_img = current_img / 255 # normalize input in [0, 1]