Library for extracting Sudokus from images using scikit-image.
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 http://www.domain.com/sudoku.jpg
It can also be used as a regular Python package:
In : from sudokuextract.extract import extract_sudoku, load_image, predictions_to_suduko_string In : img = load_image('/path/to/sudoku_image.jpg') In : predictions, sudoku_box_images, whole_sudoku_image = extract_sudoku(img) In : print(predictions_to_suduko_string(predictions)) 800603001 057401630 000000000 006109800 400000007 001805400 000000000 072504310 900302004
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 tests.py
This library includes classifiers trained with data from the MNIST dataset (This data is also included in SudokuExtract).
The current parsing strategy for the sudokuextract package is inspired by this blog entry: