Skip to content

Commit

Permalink
Another edge case when reading faces
Browse files Browse the repository at this point in the history
  • Loading branch information
derneuere committed Sep 9, 2023
1 parent 46db8f9 commit 52cd620
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions api/models/photo.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,6 @@ def _extract_faces(self, second_try=False):

if region_info:
logger.debug(f"Extracted region_info for {self.main_file.path}")
# Log region_info
logger.debug(f"region_info: {region_info}")
# Extract faces
for region in region_info["RegionList"]:
Expand All @@ -633,10 +632,25 @@ def _extract_faces(self, second_try=False):
person = api.models.person.get_unknown_person(owner=self.owner)
# Create face from the region infos
image = np.array(PIL.Image.open(self.thumbnail_big.path))
if region["Area"]["Unit"] == "normalized":
area = region.get("Area")
applied_to_dimensions = region.get("AppliedToDimensions")
if (area and area.get("Unit") == "normalized") or (applied_to_dimensions and applied_to_dimensions.get("Unit") == "pixel"):
# To-Do: Not sure, when to use this instead of the thumbnail size tbh
#if applied_to_dimensions:
# image_width = applied_to_dimensions.get("W")
# image_height = applied_to_dimensions.get("H")

# To-Do: Rotation, this is already handled by thumbnail creation?!
#if region.get("Rotation"):
# rotation = region.get("Rotation")
# if rotation == 90:
# image = np.rot90(image, 1)
# elif rotation == 180:
# image = np.rot90(image, 2)
# elif rotation == 270:
# image = np.rot90(image, 3)
image_width = image.shape[1]
image_height = image.shape[0]
area = region["Area"]
if not area.get("X") or not isinstance(
area.get("X"), numbers.Number
):
Expand Down Expand Up @@ -666,6 +680,8 @@ def _extract_faces(self, second_try=False):
)
continue



correct_w = float(area["W"])
correct_h = float(area["H"])

Expand Down

0 comments on commit 52cd620

Please sign in to comment.