Skip to main content

Library for extracting Sudokus from images using scikit-image

Project description


Library for extracting Sudokus from images using scikit-image.


  • numpy>=1.9.2
  • scipy>=0.15.1
  • scikit-image<0.12.0
  • Pillow>=3.1.0
  • pyefd>=0.1.2
  • dlxsudoku>=0.10.0


Install via pip:

$ pip install sudokuextract

SudokuExtract is a tool for parsing Sudokus from images, this primarily to be able to send it forward to some kind of solver. It applies some image analysis on the input image and then uses a K-Nearest Neighbours classifier to determine which digits that are present in which box.

SudokuExtract can be used as a command line tool:

parse-sudoku -p /path/to/sudoku_image.jpg

which prints the parsed Sudoku in the terminal. In can also be called with an url to an image:

parse-sudoku -u

It can also be used as a regular Python package:

In [1]: from sudokuextract.extract import extract_sudoku, load_image, predictions_to_suduko_string

In [2]: img = load_image('/path/to/sudoku_image.jpg')

In [3]: predictions, sudoku_box_images, whole_sudoku_image = extract_sudoku(img)

In [4]: print(predictions_to_suduko_string(predictions))

There are possibilities of using a classifier of your own creation when predicting digits; see the documentation for more details.


Run tests with pytest:

$ py.test




This library includes classifiers trained with data from the MNIST dataset (This data is also included in SudokuExtract).

[1] LeCun et al. (1999): The MNIST Dataset Of Handwritten Digits

The current parsing strategy for the sudokuextract package is inspired by this blog entry:

[2] AI: SuDoKu Grabber with OpenCV

v0.8.6 (2016-04-16)

  • Changed the main function of sudokuextract.extract to print and not return anything.

v0.8.5 (2016-03-10)

  • Replace ndi.binary_fill_holes with a binary_erosion and increased number of blobs to test to 2.

v0.8.4 (2016-03-10)

  • New classifiers.
  • New data with additional data of 1:s.

v0.8.3 (2016-03-09)

  • Disabled the Corners parsing solution again.
  • Warping image now creates a much smaller image to prevent memory issues.
  • This also increased speed with a factor of at least 4.
  • apply_gaussian now applies a Gaussian on entire image first.
  • Testing can now use a tar-file of images that can be downloaded from the web.
  • Also removed lambda functions in favour of functools.partial.

v0.8.2 (2016-03-07)

  • Restricted scikit-image version to < 0.12.

v0.8.1 (2016-03-06)

  • New classifiers with both SudokuExtract and MNIST data.
  • New data.
  • MNIST data stored separately from SudokuExtract data.
  • Number of Nearest Neighbours increased to 10 due to larger training data.
  • Several small bugfixes for new features added in v0.8.0.

v0.8.0 (2016-03-05)

  • New classifiers with MNIST data.
  • New multi-attempt approach to Sudoku parsing.
  • Using DLXSudoku to attempt classification of correct parsing of Sudoku.
  • Removed a lot of deprecated code.

v0.7.0 (2016-02-26)

  • Two different extraction methods:
    • Local thresholding
    • Adaptive thresholding for entire image
  • Refactored extensively and updated classifiers.

v0.6.1 (2016-02-20)

  • Patch for tests in Python 3.

v0.6.0 (2016-02-19)

  • Simplified blob extraction.
  • Added adaptive block_size for to_binary_adaptive.
  • Added tests that fetch Sudokus from Xanadoku.

v0.5.0 (2016-02-18)

  • Removed hard dependency on scikit-learn.
  • Included an own K-Nearest-Neighbors classifier as default.

v0.4.0 (2016-02-17)

  • Initial release on PyPI

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for sudokuextract, version 0.8.6
Filename, size File type Python version Upload date Hashes
Filename, size sudokuextract-0.8.6-py2.py3-none-any.whl (12.2 MB) File type Wheel Python version 3.4 Upload date Hashes View
Filename, size sudokuextract-0.8.6.tar.gz (12.2 MB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page