Skip to content

Commit

Permalink
Fix another exif face bug
Browse files Browse the repository at this point in the history
  • Loading branch information
derneuere committed Sep 13, 2023
1 parent 9d2525a commit 2003445
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions api/models/photo.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,38 +692,38 @@ def _extract_faces(self, second_try=False):
bottom = int((correct_y * image_height) + half_height)
left = int((correct_x * image_width) - half_width)

face_image = image[top:bottom, left:right]
face_image = PIL.Image.fromarray(face_image)
face_image = image[top:bottom, left:right]
face_image = PIL.Image.fromarray(face_image)

# Figure out which face idx it is, but reading the number of the faces of the person
idx_face = api.models.face.Face.objects.filter(person=person).count()
image_path = self.image_hash + "_" + str(idx_face) + ".jpg"
# Figure out which face idx it is, but reading the number of the faces of the person
idx_face = api.models.face.Face.objects.filter(person=person).count()
image_path = self.image_hash + "_" + str(idx_face) + ".jpg"

import face_recognition
import face_recognition

face_encodings = face_recognition.face_encodings(
image, known_face_locations=[(top, right, bottom, left)]
)
face_encodings = face_recognition.face_encodings(
image, known_face_locations=[(top, right, bottom, left)]
)

face = api.models.face.Face(
image_path=image_path,
photo=self,
location_top=top,
location_right=bottom,
location_bottom=left,
location_left=right,
encoding=face_encodings[0].tobytes().hex(),
person=person,
cluster=unknown_cluster,
)
face_io = BytesIO()
face_image.save(face_io, format="JPEG")
face.image.save(face.image_path, ContentFile(face_io.getvalue()))
face_io.close()
face.save()
person._calculate_face_count()
person._set_default_cover_photo()
logger.debug(f"Created face {face} from {self.main_file.path}")
face = api.models.face.Face(
image_path=image_path,
photo=self,
location_top=top,
location_right=right,
location_bottom=bottom,
location_left=left,
encoding=face_encodings[0].tobytes().hex(),
person=person,
cluster=unknown_cluster,
)
face_io = BytesIO()
face_image.save(face_io, format="JPEG")
face.image.save(face.image_path, ContentFile(face_io.getvalue()))
face_io.close()
face.save()
person._calculate_face_count()
person._set_default_cover_photo()
logger.debug(f"Created face {face} from {self.main_file.path}")
return

import face_recognition
Expand Down

0 comments on commit 2003445

Please sign in to comment.