示例#1
0
    def build_filename(pickle_descriptor, image_filenames, puzzle_type):
        """
        Creates the filename of the pickle output file.

        Args:
            pickle_descriptor (string): Descriptor of the pickle contents
            image_filenames (List[string]): Image file names
            puzzle_type (PuzzleType): Type of the puzzle being solved

        Returns (str): Pickle filename
        """
        assert PickleHelper.ENABLE_PICKLE
        pickle_root_filename = ""
        for i in range(0, len(image_filenames)):
            # Get the root of the filename (i.e. without path and file extension
            img_root_filename = Puzzle.get_filename_without_extension(image_filenames[i])
            # Append the file name to the information
            pickle_root_filename += "_" + img_root_filename

        pickle_root_filename += "_type_" + str(puzzle_type.value) + ".pk"
        return PickleHelper._PICKLE_DIRECTORY + pickle_descriptor + pickle_root_filename
示例#2
0
    def __init__(self, image_file_path, piece_width, puzzle_type, distance_function):

        # Store the information about the input image
        self._filename_root = Puzzle.get_filename_without_extension(image_file_path)
        self._file_extension = Puzzle.get_file_extension(image_file_path)
        # File extension should not include the period
        assert "." not in self._file_extension

        logging.info("Performing best buddy analysis for image: %s" % self._filename_root)

        self.puzzle_type = puzzle_type

        # Consider both interior and exterior best buddies.
        self._numb_wrong_exterior_bb = 0
        self._total_numb_interior_bb = 0
        self._numb_wrong_interior_bb = 0

        # Build a puzzle
        self._puzzle = Puzzle(0, image_file_path, piece_width)

        self.numb_pieces = self._puzzle.numb_pieces

        # Get the piece IDs
        self._puzzle.assign_all_piece_id_numbers_to_original_id()
        self._puzzle.assign_all_pieces_to_original_location()
        self._puzzle.assign_all_pieces_to_same_rotation(PuzzlePieceRotation.degree_0)

        # Calculate the inter-piece distance
        self._interpiece_distance = InterPieceDistance(self._puzzle.pieces, distance_function, puzzle_type)

        # Get the link between number of test buddies and accuracy
        self._numb_best_buddies_versus_accuracy = np.zeros((PuzzlePieceSide.get_numb_sides() + 1,
                                                            PuzzlePieceSide.get_numb_sides() + 1,
                                                            PuzzlePieceSide.get_numb_sides() + 1),
                                                           np.uint32)
        # Store the location of each piece
        self._piece_locations, _ = self._puzzle.build_placed_piece_info()