This project combines computer vision and algorithmic problem solving to tackle the classic Rubik's Cube puzzle. With the help of OpenCV for real-time color detection and Kociemba's algorithm for efficient cube-solving, the program can interpret a physical cube and provide optimized solution steps.
•Real-Time Color Detection: Utilizes OpenCV in Python to detect cube face colors from a live camera feed.
import numpy as np COLOR_RANGES = { 'orange': ((180, 95, 0), (240, 150, 130)), 'yellow': ((145, 180, 0), (200, 230, 50)), 'red': ((185, 26, 30), (255, 100, 130)), 'green': ((0, 139, 0), (70, 180, 70)), 'blue': ((0, 125, 200), (10, 160, 255)), 'white': ((140, 195, 210), (255, 255, 255)), } def color_in_range(r, g, b, low, high): return low[0] <= r <= high[0] and low[1] <= g <= high[1] and low[2] <= b <= high[2] def detect_color_name(r, g, b): for color_name, (low, high) in COLOR_RANGES.items(): if color_in_range(r, g, b, low, high): return color_name return 'unknown' def get_point_color(frame, x, y): b, g, r = frame[y, x] return detect_color_name(r, g, b) def pick_color(frame, start_x, start_y, region_size=10): points = [ (start_x + 25, start_y + 25), (start_x + region_size - 25, start_y + 25), (start_x + region_size - 25, start_y + region_size - 25), (start_x + 25, start_y + region_size - 25), (start_x + region_size // 2, start_y + region_size // 2), ] color_names = [get_point_color(frame, x, y) for x, y in points] most_frequent_color = max(set(color_names), key=color_names.count) return most_frequent_color
•Optimized Cube Solving: Implements Kociemba's two-phase algorithm to generate an efficient sequence of moves for solving the cube.
•2D Cube Representation: Displays a visual representation of the cube and its solution steps for easy understanding.
37 38 39 40 41 42 43 44 45 28 29 30 1 2 3 10 11 12 19 20 21 31 32 33 4 5 6 13 14 15 22 23 24 34 35 36 7 8 9 16 17 18 25 26 27 46 47 48 49 50 51 52 53 54 U L F R B D
•Dynamic Movement Handling in C: Manages cube rotations and movements with an efficient tree-like structure using C programming.
//part of movements.c #include <stdio.h> void flip(char vec[3][3]) { for (int i = 0; i < 3; ++i) { char temp = vec[i][0]; vec[i][0] = vec[i][2]; vec[i][2] = temp; } } void transpose(char vec[3][3]) { for (int i = 0; i < 3; ++i) { for (int j = i + 1; j < 3; ++j) { char temp = vec[i][j]; vec[i][j] = vec[j][i]; vec[j][i] = temp; } } } void F(char frontf[3][3], char upf[3][3], char rightf[3][3], char downf[3][3], char leftf[3][3]) { transpose(frontf); flip(frontf); char tmp[3]; tmp[0] = upf[2][0]; tmp[1] = upf[2][1]; tmp[2] = upf[2][2]; upf[2][0] = leftf[2][2]; upf[2][1] = leftf[1][2]; upf[2][2] = leftf[0][2]; leftf[0][2] = downf[0][0]; leftf[1][2] = downf[0][1]; leftf[2][2] = downf[0][2]; downf[0][0] = rightf[2][0]; downf[0][1] = rightf[1][0]; downf[0][2] = rightf[0][0]; rightf[0][0] = tmp[0]; rightf[1][0] = tmp[1]; rightf[2][0] = tmp[2]; }
There are no models linked
There are no datasets linked
There are no models linked
There are no datasets linked