The repository can either be cloned or downloaded as a zip.
Install tesseract by following the instructions here
Other requirements can be installed by running pip install -r requirements.txt
Execute the code as follows :
python main.py 'input.png'
Here the path of the input image is passed as a command line argument.
Preprocessing sudoku image (converting to grayscale, blurring, finding contours and dividing image into 81 squares). Our stackoverflow question summarises most of our work in this module.
The input sudoku image Converting image to grayscale Finding the 4 contours of the image Cropping and warping the image The final image that is divided into 81 images Processing of a single box in the sudoku board(Recognizes the digits from each of the 81 images and stores it in a list)
- The 81 images are stored in the directory temp
- Models trained on MNIST performed poor here as these digits were not handwritten. Hence we used pytesseract. This answer was helpful.
- If the box doesn't contain any number, the list holds
.
in it's place and0-9
otherwise.
Each digit predicted is checked with the user to see if it's predicted correctly. If not, the user will be able to correct it accordingly.
The list of length 81 is converted into a 9x9 array. Later we solve this board using backtracking and display the solved board to the user.
...
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. Better techniques for extracting digits from the sudoku image and digit recognition could be done.
Please make sure to update tests as appropriate.
Python solution to solve sudoku using backtracking in leetcode