Take a picture of an unsolved Sudoku and have SnapSudoku solve it for you! This repository also consists of an Android application which harnesses an API endpoint created using Django REST Framework.
$ git clone https://github.com/ymittal/SnapSudoku.git
$ cd SnapSudoku
$ pip install -r requirements.txt
$ python snapsudoku/sudoku.py <path>
You can read the directions to test the Android application here.
- Basic image preprocessing - Thresholding
- Crop out approx. Sudoku puzzle (largest contour)
- Get the grid square verticles (need for improvement)
- Get the largest contour of the image
- Get the largest bounding rectangle within the contour
- Compute the grid corners
- Do a warp perspective on the Sudoku
- Extract cells by slicing the grid evenly
- Isolate cells as follows
- Extract the largest connected component, giving more priority to the center pixels
- Remove all major noise in a cell
- Predict digits using a Neural Network
The Neural Network created was trained with around 250 digits. The constants used in the training phase and the training dataset can be found in the repository itself.
Here's a Sudoku image from a smartphone:
The current code produces the following output:
Note: For a detailed step-by-step demo, check out this.
- Improve algorithm to get better Sudoku grid extraction and make it more robust against blurs.
- Improve empty cell detection. Only a basic logic is being used right now.
- prajwalkr Prajwal Renukanand
- cclauss
- lakshmanaram
- ymittal Yash Mittal
We are happy to get new ideas to make the application more accurate. Feel free to submit a pull request or open an issue. 😄