def retrieve_backrefs(self):
     """
     Finds the media references pointing to the current image
     """
     backrefs = self.dbstate.db.find_backlink_handles(
         self.get_current_handle())
     for (reftype, ref) in backrefs:
         if reftype == "Person":
             person = self.dbstate.db.get_person_from_handle(ref)
             gallery = person.get_media_list()
             for mediaref in gallery:
                 referenced_handles = mediaref.get_referenced_handles()
                 if len(referenced_handles) == 1:
                     handle_type, handle = referenced_handles[0]
                     if handle_type == "Media" and handle == self.get_current_handle(
                     ):
                         rect = mediaref.get_rectangle()
                         if rect is None:
                             rect = (0, 0, 100, 100)
                         coords = self.selection_widget.proportional_to_real_rect(
                             rect)
                         region = Region(*coords)
                         region.person = person
                         region.mediaref = mediaref
                         self.regions.append(region)
    def detect_faces_clicked(self, event):
        self.uistate.push_message(self.dbstate, _("Detecting faces..."))
        media = self.get_current_object()
        image_path = media_path_full(self.dbstate.db, media.get_path())
        faces, img_size = facedetection.detect_faces(image_path, MIN_FACE_SIZE,
                                                     SENSITIVITY)
        # verify and enlarge found faces regions
        for (x, y, width, height) in faces:
            # calculate enlarged region
            new_x1 = x - width / 5
            new_y1 = y - height / 3
            new_x2 = x + width * 6 / 5
            new_y2 = y + height * 7 / 5
            # prevent overflow image size
            new_y1 = 0 if new_y1 < 0 else new_y1
            new_y2 = img_size[0] if img_size[0] < new_y2 else new_y2
            new_x1 = 0 if new_x1 < 0 else new_x1
            new_x2 = img_size[1] if img_size[1] < new_x2 else new_x2

            region = Region(new_x1, new_y1, new_x2, new_y2)

            if (DETECT_INSIDE_EXISTING_BOXES
                    or self.enclosing_region(region) is None):
                self.regions.append(region)

        self.refresh()
        self.uistate.push_message(self.dbstate, _("Detection finished"))
 def retrieve_backrefs(self):
     """
     Finds the media references pointing to the current image
     """
     backrefs = self.dbstate.db.find_backlink_handles(self.get_current_handle())
     for (reftype, ref) in backrefs:
         if reftype == "Person":
             person = self.dbstate.db.get_person_from_handle(ref)
             gallery = person.get_media_list()
             for mediaref in gallery:
                 referenced_handles = mediaref.get_referenced_handles()
                 if len(referenced_handles) == 1:
                     handle_type, handle = referenced_handles[0]
                     if handle_type == "Media" and handle == self.get_current_handle():
                         rect = mediaref.get_rectangle()
                         if rect is None:
                             rect = (0, 0, 100, 100)
                         coords = self.selection_widget.proportional_to_real_rect(rect)
                         region = Region(*coords)
                         region.person = person
                         region.mediaref = mediaref
                         self.regions.append(region)
 def detect_faces_clicked(self, event):
     self.uistate.push_message(self.dbstate, _("Detecting faces..."))
     media = self.get_current_object()
     image_path = media_path_full(self.dbstate.db, media.get_path())
     faces = facedetection.detect_faces(image_path, MIN_FACE_SIZE)
     for ((x, y, width, height), neighbors) in faces:
         region = Region(x - DETECTED_REGION_PADDING,
                         y - DETECTED_REGION_PADDING,
                         x + width + DETECTED_REGION_PADDING,
                         y + height + DETECTED_REGION_PADDING)
         if DETECT_INSIDE_EXISTING_BOXES or self.enclosing_region(region) is None:
             self.regions.append(region)
     self.refresh()
     self.uistate.push_message(self.dbstate, _("Detection finished"))