A webcam-based 3x3x3 rubik's cube solver written in Python 3 and OpenCV.

Overview

Qbr

Qbr, pronounced as Cuber, is a webcam-based 3x3x3 rubik's cube solver written in Python 3 and OpenCV.

  • 🌈 Accurate color detection
  • 🔍 Accurate 3x3x3 rubik's cube detection
  • 🔠 Multilingual

Solve mode

solve mode

Calibrate mode

Isn't the default color detection working out for you? Use the calibrate mode to let Qbr be familiar with your cube's color scheme. If your room has proper lighting then this will give you a 99.9% guarantee that your colors will be detected properly.

Simply follow the on-screen instructions and you're ready to go.

calibrate mode calibrate mode success

Table of Contents

Introduction

The idea to create this came personally to mind when I started solving rubik's cubes. There were already so many professional programmers around the world who created robots that solve a rubik's cube in an ETA of 5 seconds and since 2016 in 1 second (link). That inspired me to create my own. I started using images only and eventually switched to webcam.

Installation

$ git clone --depth 1 https://github.com/kkoomen/qbr.git
$ cd qbr
$ python3 -m venv env
$ source ./env/bin/activate
$ pip3 install -r requirements.txt

Usage

Make sure you run source ./env/bin/activate every time you want to run the program.

Run Qbr:

$ ./src/qbr.py

This opens a webcam interface with the following things:

The first 9-sticker display (upper left corner)

This is preview mode. This will update immediately and display how Qbr has detected the colors.

The second 9-sticker display (upper left corner)

This is the snapshot state. When pressing SPACE it will create a snapshot in order to show you what state it has saved. You can press SPACE as many times as you'd like if it has been detected wrong.

Amount of sides scanned (bottom left corner)

The bottom left corner shows the amount of sides scanned. This is so you know if you've scanned in all sides before pressing ESC.

Interface language (top right corner)

In the top right corner you can see the current interface language. If you want to change the interface language you can press l to cycle through them. Continue to press l until you've found the right language.

Default language is set to English.

Available languages are:

  • English
  • Hungarian
  • Deutsch
  • French
  • Dutch
  • 简体中文

Full 2D cube state visualization (bottom right corner)

This visualization represents the whole cube state that is being saved and can be used to confirm whether the whole cube state has been scanned successfully.

Calibrate mode

The default color scheme contains the most prominent colors for white, yellow, red, orange, blue and green. If this can't detect your cube its colors properly then you can use calibrate mode.

Press c to go into calibrate mode in order to let Qbr be familiar with your cube's color scheme. Simply follow the on-screen instructions and you're ready to go.

Note: Your calibrated settings are automatically saved after you've calibrated your cube successfully. The next time you start Qbr it will automatically load it.

Tip: If you've scanned wrong, simple go out of calibrate mode by pressing c and go back into calibrate by pressing c again.

Getting the solution

Qbr checks if you have filled in all 6 sides when pressing ESC. If so, it'll calculate a solution if you've scanned it correctly.

You should now see a solution (or an error if you did it wrong).

How to scan your cube properly?

There is a strict way of scanning in the cube. Qbr will detect the side automatically, but the way you rotate the cube during the time you're scanning it is crucial in order for Qbr to properly calculate a solution. Make sure to follow the steps below properly:

  • Start off with the green side facing the camera and white on top, green being away from you. Start by scanning in the green side at this point.
  • After you've scanned in the green side, rotate the cube 90 or -90 degrees horizontally. It doesn't matter if you go clockwise or counter-clockwise. Continue to do this for the green, blue, red and orange sides until you are back at the green side.
  • You should now be in the same position like you started, having green facing the camera and white on top. Rotate the cube forward 90 degrees, resulting in green at the bottom and white facing the camera. Start scanning in the white side.
  • After you've scanned the white side, turn the cube back to how you started, having green in front again and white on top. Now rotate the cube backwards 90 degrees, resulting in green on top and yellow facing the camera. Now you can scan in the last yellow side.

If you've done the steps above correctly, you should have a solution from Qbr.

Keybindings

  • SPACE for saving the current state

  • ESC quit

  • c toggle calibrate mode

  • l switch interface language

Paramaters

You can use -n or --normalize to also output the solution in a "human-readable" format.

For example:

  • R will be: Turn the right side a quarter turn away from you.
  • F2 will be: Turn the front face 180 degrees.

Example runs

$ ./qbr.py
Starting position:
front: green
top: white

Moves: 20
Solution: U2 R D2 L2 F2 L U2 L F' U L U R2 B2 U' F2 D2 R2 D2 R2
$ ./qbr.py -n
Starting position:
front: green
top: white

Moves: 20
Solution: B2 U2 F' R U D' L' B' U L F U F2 R2 F2 D' F2 D R2 D2
1. Turn the back side 180 degrees.
2. Turn the top layer 180 degrees.
3. Turn the front side a quarter turn to the left.
4. Turn the right side a quarter turn away from you.
5. Turn the top layer a quarter turn to the left.
6. Turn the bottom layer a quarter turn to the left.
7. Turn the left side a quarter turn away from you.
8. Turn the back side a quarter turn to the right.
9. Turn the top layer a quarter turn to the left.
10. Turn the left side a quarter turn towards you.
11. Turn the front side a quarter turn to the right.
12. Turn the top layer a quarter turn to the left.
13. Turn the front side 180 degrees.
14. Turn the right side 180 degrees.
15. Turn the front side 180 degrees.
16. Turn the bottom layer a quarter turn to the left.
17. Turn the front side 180 degrees.
18. Turn the bottom layer a quarter turn to the right.
19. Turn the right side 180 degrees.
20. Turn the bottom layer 180 degrees.

Inspirational sources

Special thanks to HaginCodes for the main inspiration on how to improve my color detection.

https://github.com/HaginCodes/3x3x3-Rubiks-Cube-Solver

http://programmablebrick.blogspot.com/2017/02/rubiks-cube-tracker-using-opencv.html

https://gist.github.com/flyboy74/2cc3097f784c8c236a1a85278f08cddd

https://github.com/dwalton76/rubiks-color-resolver

License

Qbr is licensed under the MIT License.

Owner
Kim 金可明
Vim enthusiast; polyglot programmer; fullstack software engineer; QA engineer
Kim 金可明
Lightning Fast Language Prediction 🚀

whatthelang Lightning Fast Language Prediction 🚀 Dependencies The dependencies can be installed using the requirements.txt file: $ pip install -r req

Indix 152 Oct 16, 2022
Code for the "Sensing leg movement enhances wearable monitoring of energy expenditure" paper.

EnergyExpenditure Code for the "Sensing leg movement enhances wearable monitoring of energy expenditure" paper. Additional data for replicating this s

Patrick S 42 Oct 26, 2022
Qrcode Attendence System with Opencv and Pyzbar

Setup process Creates a virtual environment (Scripts that ensure executed Python code uses the Python interpreter and site packages installed inside t

Ganesh 5 Aug 01, 2022
Python Computer Vision Aim Bot for Roblox's Phantom Forces

Python-Phantom-Forces-Aim-Bot Python Computer Vision Aim Bot for Roblox's Phanto

drag0ngam3s 2 Jul 11, 2022
Text layer for bio-image annotation.

napari-text-layer Napari text layer for bio-image annotation. Installation You can install using pip: pip install napari-text-layer Keybindings and m

6 Sep 29, 2022
Generate text images for training deep learning ocr model

New version release:https://github.com/oh-my-ocr/text_renderer Text Renderer Generate text images for training deep learning OCR model (e.g. CRNN). Su

Qing 1.2k Jan 04, 2023
A simple Security Camera created using Opencv in Python where images gets saved in realtime in your Dropbox account at every 5 seconds

Security Camera using Opencv & Dropbox This is a simple Security Camera created using Opencv in Python where images gets saved in realtime in your Dro

Arpit Rath 1 Jan 31, 2022
Automatically fishes for you while you are afk :)

Dank-memer-afk-script A simple and quick way to make easy money in Dank Memer! How to use Open a discord channel which has the Dank Memer bot enabled.

Pranav Doshi 9 Nov 11, 2022
A post-processing tool for scanned sheets of paper.

unpaper Originally written by Jens Gulden — see AUTHORS for more information. Licensed under GNU GPL v2 — see COPYING for more information. Overview u

27 Dec 07, 2022
A Python wrapper for the tesseract-ocr API

tesserocr A simple, Pillow-friendly, wrapper around the tesseract-ocr API for Optical Character Recognition (OCR). tesserocr integrates directly with

Fayez 1.7k Dec 31, 2022
A Python script to capture images from multiple webcams at once and save them into your local machine

Capturing multiple images at once from Webcam Using OpenCV Capture multiple image by accessing the webcam of your system and save it to your machine.

Fazal ur Rehman 2 Apr 16, 2022
SRA's seminar on Introduction to Computer Vision Fundamentals

Introduction to Computer Vision This repository includes basics to : Python Numpy: A python library Git Computer Vision. The aim of this repository is

Society of Robotics and Automation 147 Dec 04, 2022
CTPN + DenseNet + CTC based end-to-end Chinese OCR implemented using tensorflow and keras

简介 基于Tensorflow和Keras实现端到端的不定长中文字符检测和识别 文本检测:CTPN 文本识别:DenseNet + CTC 环境部署 sh setup.sh 注:CPU环境执行前需注释掉for gpu部分,并解开for cpu部分的注释 Demo 将测试图片放入test_images

Yang Chenguang 2.6k Dec 29, 2022
Code for CVPR2021 paper "Learning Salient Boundary Feature for Anchor-free Temporal Action Localization"

AFSD: Learning Salient Boundary Feature for Anchor-free Temporal Action Localization This is an official implementation in PyTorch of AFSD. Our paper

Tencent YouTu Research 146 Dec 24, 2022
Camelot: PDF Table Extraction for Humans

Camelot: PDF Table Extraction for Humans Camelot is a Python library that makes it easy for anyone to extract tables from PDF files! Note: You can als

Atlan Technologies Pvt Ltd 3.3k Dec 31, 2022
Python Computer Vision application that allows users to draw/erase on the screen using their webcam.

CV-Virtual-WhiteBoard The Virtual WhiteBoard is a project I made using the OpenCV and Mediapipe Python libraries. Using your index and middle finger y

Stephen Wang 1 Jan 07, 2022
OpenCV-Erlang/Elixir bindings

evision [WIP] : OS : arch Build Status Ubuntu 20.04 arm64 Ubuntu 20.04 armv7 Ubuntu 20.04 s390x Ubuntu 20.04 ppc64le Ubuntu 20.04 x86_64 macOS 11 Big

Cocoa 194 Jan 05, 2023
Erosion and dialation using structure element in OpenCV python

Erosion and dialation using structure element in OpenCV python

Tamzid hasan 2 Nov 11, 2021
Assignment work with webcam

work with webcam : Press key 1 to use emojy on your face Press key 2 to use lip and eye on your face Press key 3 to checkered your face Press key 4 to

Hanane Kheirandish 2 May 31, 2022
This is the official PyTorch implementation of the paper "TransFG: A Transformer Architecture for Fine-grained Recognition" (Ju He, Jie-Neng Chen, Shuai Liu, Adam Kortylewski, Cheng Yang, Yutong Bai, Changhu Wang, Alan Yuille).

TransFG: A Transformer Architecture for Fine-grained Recognition Official PyTorch code for the paper: TransFG: A Transformer Architecture for Fine-gra

Ju He 307 Jan 03, 2023