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

Simplify and strengthen rotate_facial_area #1047

Merged

Conversation

AndreaLanfranchi
Copy link
Contributor

@AndreaLanfranchi AndreaLanfranchi commented Feb 27, 2024

This strengthen rotate_facial_area by :

  • constraining rotation angle in range [0, 360)
  • early bailout in case angle == 0
  • deriving direction of rotation from sign of angle : positive values for clockwise, negative for anti-clockwise

In previous implementation direction could be any number causing unwanted results.

Also fixes #1045


# Normalize the witdh of the angle so we don't have to
# worry about rotations greater than 360 degrees
angle = angle % 360
Copy link
Owner

Choose a reason for hiding this comment

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

angle will be positive always because of the module, so you can get rid of the direction because it will be 1 always

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's not right.
75 % 360 == 75
-75 % 360 == -75

Copy link
Owner

Choose a reason for hiding this comment

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

This is my experiment.

Python 3.9.16 (main, Jan 11 2023, 16:05:54)
[GCC 11.2.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> a = -75
>>> a % 360
285
>>>
>>>
>>> b = 75
>>> b % 360

Copy link
Owner

Choose a reason for hiding this comment

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

still, both outputs will work as is

never mind this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ouch ... python mod operator is pretty fucked up. Every other language and calculators keeps the sign of dividend not the divisor.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

@serengil
Copy link
Owner

Would you please run this code and share its output here

import matplotlib.pyplot as plt

img_paths = ["dataset/dataset/img11.jpg", "dataset/img11_reflection.jpg"]

for img_path in img_paths:
	results = DeepFace.extract_faces(img_path = img_path)
	img = results[0]["face"]
	plt.imshow(img)
	plt.show()

@serengil
Copy link
Owner

When I perform current implementation for dataset/img11_reflection.jpg, it is output is shown below - this is not correct!

This is sorted when i set direction to 1 by default

1

@AndreaLanfranchi
Copy link
Contributor Author

Just pushed a change which should correct the error.
This is the output you requested

image

@serengil
Copy link
Owner

It is the output for img11.jpg, I wonder the output of img11_reflection.jpg also.

@AndreaLanfranchi
Copy link
Contributor Author

Yep ... sorry

image

@serengil serengil merged commit 87f4893 into serengil:master Feb 27, 2024
2 checks passed
@AndreaLanfranchi AndreaLanfranchi deleted the al20220227-rotate-facial-area branch February 27, 2024 11:18
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.

Expand facial area logic is expanding the facial area twice of expected
2 participants