def main(input_dir=None): # Input the faces of the Cube if input_dir is None: captured_faces, captured_imgs = capture_faces() else: input_imgs = load_imgs_from_dir(input_dir) captured_faces, captured_imgs = capture_faces_from_images(input_imgs) # Get the color classifier clf_yuv = get_classifier() # Predict the face colors from the input images faces = np.array(captured_faces) pred_colors_yuv, pred_proba_yuv = label_images(clf_yuv, [faces]) colors_cube = np.array(pred_colors_yuv).reshape((6, 3, 3)) # Inspect / adjust results if necessary. This step can modify pred_colors_yuv2. check_images(captured_imgs, captured_faces, colors_cube, clf_yuv) plt.show() # Define the cube using the updated colors c = Cube(colors_cube) # Solve and retain moves initial_state = c.export_state() s = Solver(c) s.solve() solve_moves = c.recorded_moves # Display the solution sg = SolutionGallery(initial_state, solve_moves) plt.show()
if self.i > 0: self.i = self.i - 1 # Undo the last move to put cube in previous state self.c.perform_move(opposite_move(self.solve_moves[self.i])) # Display the next move move = self.solve_moves[self.i] self.c.cube_plot(ax=self.ax1, title_str=move.replace('1', '')) add_move_annotation(self.ax1, move) else: self.c.cube_plot(ax=self.ax1, title_str='Initial State') plt.draw() return event if __name__ == '__main__': # Create a random cube c = Cube() c.randomize_state() initial_state = c.export_state() # Solve and retain moves s = Solver(c) s.solve() # Display the solution sg = SolutionGallery(s.initial_state, s.solve_moves) sg.show()