Skip to content

ymittal/SnapSudoku

 
 

Repository files navigation

SnapSudoku

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.

How to use

$ 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.

Algorithm

  • 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.

Working

Here's a Sudoku image from a smartphone:

Input Image

The current code produces the following output:

Final Result

Note: For a detailed step-by-step demo, check out this.

TODO

  • 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.

Contributors

We are happy to get new ideas to make the application more accurate. Feel free to submit a pull request or open an issue. 😄

Releases

No releases published

Packages

No packages published

Languages

  • Python 86.8%
  • Java 13.2%