Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/custom output extract faces #1279

Conversation

ProgramadorArtificial
Copy link
Contributor

What has been done

Changed extract_faces parameters to be possible to return face image (croped) as rgb, bgr or grayscale and flag for normalized. By default, all parameters will return the same as before (RGB and normalized).

How to test

Change parameters as desired:

faces = DeepFace.extract_faces(
    img_path = 'image.jpg',
    normalize_face=True,  # True or False
    color_face='bgr'  # rgb, bgr or gray
)

After extracting face can save to see the result:

Image.fromarray((faces[0]['face']*255).astype(np.uint8)).save('img.png')  # normalize_face == True
Image.fromarray((faces[0]['face']).astype(np.uint8)).save('img.png')  # normalize_face == False

@ProgramadorArtificial
Copy link
Contributor Author

ProgramadorArtificial commented Jul 15, 2024

@serengil
image
I recreated the PR... answering here :)
Ok. Can I add in documentation the "grayscale" parameter is deprecated? (keeping it working)

@ProgramadorArtificial
Copy link
Contributor Author

@serengil image I recreated the PR... answering here :) Ok. Can I add in documentation the "grayscale" parameter is deprecated? (keeping it working)

Added grayscale parameter again. If False obey color_face, if True obey grayscale and return a warning:
image

@@ -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,
Copy link
Owner

@serengil serengil Jul 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default values of color face and normalize face are rgb and True already, IMO we should not set them where it is being called if we are setting default values.

this is available also in representation, recognition, and more

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed them. I added it because grayscale was there.

@@ -239,7 +239,6 @@ def __extract_faces_and_embeddings(
img_objs = detection.extract_faces(
img_path=img_path,
detector_backend=detector_backend,
grayscale=False,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

restore this please

@@ -71,7 +71,6 @@ def represent(
img_objs = detection.extract_faces(
img_path=img_path,
detector_backend=detector_backend,
grayscale=False,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

restore this please

@@ -364,7 +363,6 @@ def __find_bulk_embeddings(
img_objs = detection.extract_faces(
img_path=employee,
detector_backend=detector_backend,
grayscale=False,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

restore this please

@@ -240,7 +240,6 @@ def find(
source_objs = detection.extract_faces(
img_path=img_path,
detector_backend=detector_backend,
grayscale=False,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

restore this please

@serengil serengil merged commit 7a5f249 into serengil:master Jul 15, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants