def run_paikin_tal_driver(img_files, puzzle_type, piece_width): """ Runs the Paikin and Tal image solver. Args: img_files ([str]): An array of one or more image file path(s). puzzle_type (Optional PuzzleType): Type of the puzzle to solve piece_width (Optional int): Width of a puzzle piece in pixels. """ image_filenames = config.add_image_folder_path(img_files) # Print the names of the images being solved: logging.info("Standard Paikin & Tal Driver") puzzle_importer.log_puzzle_filenames(image_filenames) # When skipping placement, simply import the solved results. if SKIP_PLACEMENT: paikin_tal_solver = PaikinTalSolver.pickle_import_after_standard_run_placement(image_filenames, puzzle_type) else: paikin_tal_solver = run_paikin_tal_solver(image_filenames, puzzle_type, piece_width) # Get the results paikin_tal_solver.segment(color_segments=True, perform_segment_cleaning=True) (pieces_partitioned_by_puzzle_id, _) = paikin_tal_solver.get_solved_puzzles() timestamp = time.time() Puzzle.output_results_information_and_puzzles( PuzzleSolver.PaikinTal, image_filenames, paikin_tal_solver, pieces_partitioned_by_puzzle_id, timestamp )
def run_multipuzzle_solver_driver(image_files, puzzle_type, piece_width): """ Runs the multipuzzle solver on a set of images. Args: image_files (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 """ image_filenames = config.add_image_folder_path(image_files) logging.info("Starting Multipuzzle Solver Driver.") puzzle_importer.log_puzzle_filenames(image_filenames) multipuzzle_solver = build_multipuzzle_solver(image_filenames, puzzle_type, piece_width) # Run the solver multipuzzle_solver.run()
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()