It is a project in which a sudoku image is taken as input as a problem statement and same image is provided along with solution embedded on it as solution.
Version of python used: python 3.9.5
Required Libraries:
- OpenCv
- numpy
- tensorflow
- sys
- matplotlib
The entire working of the algorithm can be split into 4 major parts
- Preparing image easier to understand by the computer: Scanned image containing sudoku grid is taken as input. The image is scanned for finding biggest contour having 4 edges. Co-ordinates of the biggest contour are noted. The image is then cropped to fit the sudoku grid. Color of the image is changed to gray(1 channel) from BGR image type(3-channels).
- Predicting digits in Sudoku: Then the wrapped sudoku image is divided into 81 images by spliting on 9x9 grid lines. That is each digit is converted into image and all such images are stored in an array. The array is passed to digit classification models to predict digits(if any) on it. The information given by the model is then processed afterwhich a final 2-Dimensional grid is returned containing given clues in sudoku.
- Solving the sudoku and overlaying the solution on the input image: The grid is passed to sudoku solving function which works on the famous algorithm of backtracking, which return the same grid filled with the solution. Solved digits are then extracted from the solution and rendered on the original image. The imaged is then unwrapped and is passed as the final solution
- Training digit classification model to predict digits: Digit classification model used here uses the mnist data set containing 70,000 images handwritten digits. The model is trained on 5 layers neural network, runned 10 times on training data set to optimise accuracy of prediction. It is then saved .h5 extension which can be used directly by other programs to predict digits on images.




