Beispiel #1
0
    def __resize_image(self, img_original):
        """
        Resize the input image
        """
        print_nicer("RESIZE IMAGE - START")
        start_time = time.time()
        img, scale_factor = image_resize(img_original, self.resize_width,
                                         self.resize_height, cv2.INTER_CUBIC)
        print_time_info(start_time, "RESIZE IMAGE - END")
        print(f"\tResized image shape: {img.shape}")
        print(f"\tScale factor: {scale_factor}")
        print("-" * 50)
        self.show_image_main('pipeline_input', img, height=405, width=720)

        return img, scale_factor
Beispiel #2
0
    def __paintings_and_people_localization(self, paintings_detected):
        """
        Execute People Localization using Information about the detected paintings.
        """

        print_nicer("PEOPLE LOCALIZATION - START")
        start_time = time.time()
        people_room = locale_paintings_and_people(paintings_detected,
                                                  self.generator,
                                                  self.show_image,
                                                  self.print_next_step,
                                                  self.print_time)
        print_time_info(start_time, "PEOPLE LOCALIZATION - END")
        print("-" * 50)

        return people_room
Beispiel #3
0
    def __painting_segmentation(self, img_original, paintings_detected):
        """
        Execute Painting Segmentation of the input image.
        """

        print_nicer("PAINTING SEGMENTATION - START")
        start_time = time.time()
        painting_contours = [p.frame_contour for p in paintings_detected]
        segmented_img_original = create_segmented_image(
            img_original, painting_contours)
        print_time_info(start_time, "PAINTING SEGMENTATION - END")
        print("  Segmented shape: ", segmented_img_original.shape)
        print("-" * 50)
        # self.show_image_main('segmented_img_original_size', segmented_img_original, height=405, width=720)

        return segmented_img_original
Beispiel #4
0
 def __draw_painting_and_people(self, img_original, paintings_detected,
                                people_bounding_boxes, people_room,
                                scale_factor):
     """
     Draw information about Paintings and People found.
     """
     print_nicer("DRAW PAINTINGS AND PEOPLE INFORMATION - START")
     start_time = time.time()
     # First draw the info on the paintings...
     draw_paintings_info(img_original, paintings_detected, scale_factor)
     # ...and then the info on the people, so as to respect the prospect...
     draw_people_bounding_box(img_original, people_bounding_boxes,
                              scale_factor)
     # ...at the end the information about the room
     draw_room_info(img_original, people_room, scale_factor)
     print_time_info(start_time,
                     "DRAW PAINTINGS AND PEOPLE INFORMATION - END")
     print("-" * 50)
Beispiel #5
0
    def __painting_detection(self, img, scale_factor):
        """
        Execute Painting Detection on the input image.
        """

        print_nicer("PAINTING DETECTION - START")
        start_time = time.time()
        paintings_detected = detect_paintings(img,
                                              self.generator,
                                              self.show_image,
                                              self.print_next_step,
                                              self.print_time,
                                              scale_factor=scale_factor)
        print_time_info(start_time, "PAINTING DETECTION - END")
        print("-" * 50)

        self.num_paintings_detected += len(paintings_detected)

        return paintings_detected
Beispiel #6
0
    def __painting_rectification(self, img_original, paintings_detected):
        """
        Execute Rectification of the painting received
        """
        print_nicer("PAINTING RECTIFICATION - START")
        start_time = time.time()
        for i, painting in enumerate(paintings_detected):
            x, y, w_rect, h_rect = painting.bounding_box
            sub_img_original = img_original[y:y + h_rect, x:x + w_rect]
            corners = translate_points(painting.corners, -np.array([x, y]))
            painting.image = rectify_painting(sub_img_original, corners)
        print_time_info(start_time, "PAINTING RECTIFICATION - END")
        print("-" * 50)

        if self.task == Task.painting_rectification:
            for i, painting in enumerate(paintings_detected):
                x, y, w_rect, h_rect = painting.bounding_box
                sub_img_original = img_original[y:y + h_rect, x:x + w_rect]
                # self.show_image_main(f"sub_img_original_{i}", sub_img_original)
                self.show_image_main(f"painting_rectified_{i}", painting.image)
Beispiel #7
0
    def __painting_retrieval(self, paintings_detected, scale_factor):
        """
        Execute Painting Retrieval on the input image.
        """
        print_nicer("PAINTING RETRIEVAL - START")
        start_time = time.time()
        retrieve_paintings(paintings_detected,
                           self.paintings_db,
                           self.generator,
                           self.show_image,
                           self.print_next_step,
                           self.print_time,
                           match_db_image=self.match_db_image,
                           histo_mode=self.histo_mode,
                           scale_factor=scale_factor)
        print_time_info(start_time, "PAINTING RETRIEVAL - END")
        print("-" * 50)

        for p in paintings_detected:
            if p.title is not None:
                self.num_paintings_retrieved += 1
Beispiel #8
0
    def __people_detection(self, img, paintings_detected, scale_factor):
        """
        Execute People Detection on the input image.
        """
        print_nicer("PEOPLE DETECTION - START")
        start_time = time.time()
        max_percentage = 0.85
        people_bounding_boxes = detect_people(img,
                                              self.people_detector,
                                              paintings_detected,
                                              self.generator,
                                              self.show_image,
                                              self.print_next_step,
                                              self.print_time,
                                              scale_factor=scale_factor,
                                              max_percentage=max_percentage)
        print_time_info(start_time, "PEOPLE DETECTION - END")
        print("-" * 50)

        self.num_people_detected += len(people_bounding_boxes)

        return people_bounding_boxes