Skip to content

VinitKumarGupta/rubik-cube-solver

Repository files navigation

🧠 3x3 Rubik's Cube Solver – ML + Computer Vision + Voice Guided

A Python project that scans a Rubik's Cube using your webcam, detects facelet colors via a trained ML model, solves it using Kociemba’s algorithm, and guides you step-by-step with voice instructions and visual overlays.

Features

Real-Time Facelet Detection – (LAB color space + Random Forest Classifier)
Trained on 3900+ samples – for robust color detection
Kociemba Solver Integration – for optimal solution
Voice Instructions – using gTTS (“Do U’, then R2…”)
Visual Overlays – with next move & progress bar
Progress Tracking – shows moves left & progress update bar
Error Handling – prevents duplicate face scans, invalid states
Modular Code – Easy to maintain & extend

Tech Stack

  • Python 3.10+
  • OpenCV (real-time webcam feed + UI overlays)
  • scikit-learn (Random Forest Classifier)
  • gTTS + playsound (voice instructions)
  • kociemba (cube solving)
  • NumPy, pandas (data handling)

Project Structure


rubik-cube-solver/
│
├── color_detector.py    # ML Model training & prediction
├── dataset.csv           # Labeled LAB color samples
├── model.pkl             # Trained Random Forest model
├── scanner.py            # Main executable program for scanning & guiding
├── solver.py             # Kociemba algorithm integration
├── voice.py              # gTTS voice functions
├── overlay.py            # Visual overlays during solving
├── utils.py              # Helper functions imported in scanner.py
├── train_model.py       # Train model from dataset
├── requirements.txt      # All dependencies needed
└── README.md             # This file

Installation

1️⃣ Clone this Repo

git clone https://github.com/yourusername/rubik-cube-solver.git
cd rubik-cube-solver

2️⃣ Install Dependencies

pip install -r requirements.txt

3️⃣ Run the App

python scanner.py

📌 Note: Before running the program, you need to train the model for your cube.

  • Start the program and press ‘T’ to collect color samples (cube must be in solved state).
  • It will automatically save LAB values to dataset.csv.
  • A dataset of ~3000+ rows is recommended for good accuracy.
  • After training, the confusion matrix & accuracy will show up in the terminal to help you assess the model quality.
  • The dataset uploaded in this repo is specific to my cube’s LAB values. For your cube:
    1. Delete all rows in dataset.csv (or you can test with existing ones first).
    2. Add the header row exactly as: L,A,B,label (no spaces).
    3. Start collecting samples for your cube faces.
    4. After around 3k-4k samples, train the model using train_model.py.

Dataset

  • 3900+ rows collected in varying lighting conditions
  • Stored in dataset.csv
  • Trained with Random Forest

How It Works

  1. Align each cube face in the webcam grid (order: U → R → F → D → L → B)
  2. App predicts facelet colors → assembles full cube string
  3. Kociemba’s algorithm computes optimal solve sequence
  4. Voice + overlay guides you through each move
  5. Animated progress bar shows steps left
  6. 🎉 Done! Cube Solved.

Author

Vinit Kumar Gupta 🔗 LinkedIn | GitHub

License

This project is licensed under MIT License.

Support

If you like this project, ⭐ Star it on GitHub and share! Pull requests and issues are welcome.

About

A Python project that scans a real Rubik’s Cube via webcam, predicts facelet colors using a Random Forest classifier trained on LAB values, and solves it using the Kociemba algorithm. Includes a real-time UI with move-by-move voice instructions and on-screen overlays to guide the user in solving the cube.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages