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.
✅ 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
- 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)
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
git clone https://github.com/yourusername/rubik-cube-solver.git
cd rubik-cube-solverpip install -r requirements.txtpython 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:
- Delete all rows in
dataset.csv(or you can test with existing ones first). - Add the header row exactly as:
L,A,B,label(no spaces). - Start collecting samples for your cube faces.
- After around 3k-4k samples, train the model using
train_model.py.
- Delete all rows in
- 3900+ rows collected in varying lighting conditions
- Stored in
dataset.csv - Trained with Random Forest
- Align each cube face in the webcam grid (order: U → R → F → D → L → B)
- App predicts facelet colors → assembles full cube string
- Kociemba’s algorithm computes optimal solve sequence
- Voice + overlay guides you through each move
- Animated progress bar shows steps left
- 🎉 Done! Cube Solved.
Vinit Kumar Gupta 🔗 LinkedIn | GitHub
This project is licensed under MIT License.
If you like this project, ⭐ Star it on GitHub and share! Pull requests and issues are welcome.