def build_multipuzzle_solver(image_filenames, puzzle_type, piece_width):
    """
    Build the multipuzzle solver object.

    Args:
        image_filenames (List[str]): List of puzzle file paths.
        puzzle_type (PuzzleType): Type of the puzzle to solve.
        piece_width (int): Puzzle piece width in number of pixels

    Returns (MultiPuzzleSolver): The multipuzzle solver object built from the input image files.
    """

    pieces, puzzles = Puzzle.get_combined_pieces_multiple_images(image_filenames, piece_width)

    pickle_filename = PickleHelper.build_filename("multipuzzle_distances", image_filenames, puzzle_type)

    # Initialize the distance information
    if _FORCE_RECALCULATE_DISTANCES or not os.path.exists(pickle_filename):
        multipuzzle_solver = MultiPuzzleSolver(image_filenames, pieces, top_level_calculate_asymmetric_distance,
                                               puzzle_type)

        if _POST_INITIAL_CONSTRUCTION_PICKLE_EXPORT:
            PickleHelper.exporter(multipuzzle_solver, pickle_filename)
        return multipuzzle_solver

    # Read the pickle information from the
    else:
        multipuzzle_solver = PickleHelper.importer(pickle_filename)
        multipuzzle_solver.reset_timestamp()
        return multipuzzle_solver
Beispiel #2
0
    def _local_pickle_export_helper(self, pickle_file_descriptor):
        """
        Helper function that handles the pickle export for a specific file description.

        Args:
            pickle_file_descriptor (str): File descriptor for the pickle file
        """
        pickle_filename = PickleHelper.build_filename(pickle_file_descriptor,
                                                      self._image_filenames,
                                                      self._paikin_tal_solver.puzzle_type)
        PickleHelper.exporter(self, pickle_filename)
def run_best_buddies_analyzer(image_file, piece_width, puzzle_type):
    """
    Runs the Best Buddy Analyzer on an image and outputs the best buddy results and generates a results image.

    Args:
        image_file (str): Path to an image file
        piece_width (int): Width of a puzzle piece in number of pixels
        puzzle_type (PuzzleType): Type of the puzzle to solve

    """
    pickle_file = PickleHelper.build_filename("bb_accuracy", [image_file], puzzle_type)

    filename_with_image_folder = config.add_image_folder_path([image_file])
    bb_results = ImageBestBuddyStatistics(filename_with_image_folder[0], piece_width, puzzle_type,
                                          top_level_calculate_asymmetric_distance)

    PickleHelper.exporter(bb_results, pickle_file)

    # Calculate the print the results.
    bb_results = PickleHelper.importer(pickle_file)
    bb_results.calculate_results()
    bb_results.print_results()