mirror of
https://github.com/serengil/deepface.git
synced 2025-06-06 11:35:21 +00:00
Add color_face option for extract_faces
This commit is contained in:
parent
bb8096ad97
commit
878564ee1c
@ -482,7 +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,
|
||||
) -> List[Dict[str, Any]]:
|
||||
@ -504,8 +504,8 @@ def extract_faces(
|
||||
|
||||
expand_percentage (int): expand detected facial area with a percentage (default is 0).
|
||||
|
||||
grayscale (boolean): 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').
|
||||
|
||||
normalize_face (boolean): Flag to enable normalization (divide by 255) of the output
|
||||
face image output face image normalization (default is True).
|
||||
@ -538,7 +538,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,
|
||||
)
|
||||
@ -591,7 +591,8 @@ def detectFace(
|
||||
detector_backend=detector_backend,
|
||||
enforce_detection=enforce_detection,
|
||||
align=align,
|
||||
grayscale=False,
|
||||
color_face='rgb',
|
||||
normalize_face=True,
|
||||
)
|
||||
extracted_face = None
|
||||
if len(face_objs) > 0:
|
||||
|
@ -123,7 +123,8 @@ def analyze(
|
||||
img_objs = detection.extract_faces(
|
||||
img_path=img_path,
|
||||
detector_backend=detector_backend,
|
||||
grayscale=False,
|
||||
color_face='rgb',
|
||||
normalize_face=True,
|
||||
enforce_detection=enforce_detection,
|
||||
align=align,
|
||||
expand_percentage=expand_percentage,
|
||||
|
@ -24,7 +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,
|
||||
) -> List[Dict[str, Any]]:
|
||||
@ -46,8 +46,8 @@ def extract_faces(
|
||||
|
||||
expand_percentage (int): expand detected facial area with a percentage.
|
||||
|
||||
grayscale (boolean): 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').
|
||||
|
||||
normalize_face (boolean): Flag to enable normalization (divide by 255) of the output
|
||||
face image output face image normalization (default is True).
|
||||
@ -118,8 +118,16 @@ def extract_faces(
|
||||
if current_img.shape[0] == 0 or current_img.shape[1] == 0:
|
||||
continue
|
||||
|
||||
if grayscale is True:
|
||||
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]
|
||||
@ -130,7 +138,7 @@ def extract_faces(
|
||||
h = int(current_region.h)
|
||||
|
||||
resp_obj = {
|
||||
"face": current_img if grayscale else current_img[:, :, ::-1],
|
||||
"face": current_img,
|
||||
"facial_area": {
|
||||
"x": x,
|
||||
"y": y,
|
||||
|
@ -240,7 +240,8 @@ def find(
|
||||
source_objs = detection.extract_faces(
|
||||
img_path=img_path,
|
||||
detector_backend=detector_backend,
|
||||
grayscale=False,
|
||||
color_face='rgb',
|
||||
normalize_face=True,
|
||||
enforce_detection=enforce_detection,
|
||||
align=align,
|
||||
expand_percentage=expand_percentage,
|
||||
@ -364,7 +365,8 @@ def __find_bulk_embeddings(
|
||||
img_objs = detection.extract_faces(
|
||||
img_path=employee,
|
||||
detector_backend=detector_backend,
|
||||
grayscale=False,
|
||||
color_face='rgb',
|
||||
normalize_face=True,
|
||||
enforce_detection=enforce_detection,
|
||||
align=align,
|
||||
expand_percentage=expand_percentage,
|
||||
|
@ -71,7 +71,8 @@ def represent(
|
||||
img_objs = detection.extract_faces(
|
||||
img_path=img_path,
|
||||
detector_backend=detector_backend,
|
||||
grayscale=False,
|
||||
color_face='rgb',
|
||||
normalize_face=True,
|
||||
enforce_detection=enforce_detection,
|
||||
align=align,
|
||||
expand_percentage=expand_percentage,
|
||||
|
@ -239,7 +239,8 @@ def __extract_faces_and_embeddings(
|
||||
img_objs = detection.extract_faces(
|
||||
img_path=img_path,
|
||||
detector_backend=detector_backend,
|
||||
grayscale=False,
|
||||
color_face='rgb',
|
||||
normalize_face=True,
|
||||
enforce_detection=enforce_detection,
|
||||
align=align,
|
||||
expand_percentage=expand_percentage,
|
||||
|
Loading…
x
Reference in New Issue
Block a user