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 _build_output_puzzles(self): """ Constructs the final output puzzles that are to be returned by the multiple puzzle solver. Returns (List[Puzzle]): List of the final solved puzzles. """ solved_puzzles, _ = self._paikin_tal_solver.get_solved_puzzles() # Build the results information Puzzle.output_results_information_and_puzzles(PuzzleSolver.MultiPuzzle, self._image_filenames, self._paikin_tal_solver, solved_puzzles, self._start_timestamp) # Merge the pieces into a set of solved puzzles output_puzzles = [Puzzle.reconstruct_from_pieces(solved_puzzles[i], i) for i in xrange(0, len(solved_puzzles))] # Optionally export the solved image files. if MultiPuzzleSolver._SAVE_FINAL_PUZZLE_IMAGES: self._output_reconstructed_puzzle_image_files(output_puzzles) return output_puzzles