snehitvaddi / Real-Time-Sudoku-Solver-OpenCV-and-Keras

Solving Sukodu puzzle in realtime using Deep Learning and Computer Vision. Display the unsolved Sudoku in front of the camera and get the instant solution projecting right on the image.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Real-Time-Sudoku-Solver-OpenCV-and-Keras

Python application to solve Sudoku puzzle and overlays solution on to real image in real-time.

This project is solely inspired from AnhMinhTran's Youtube Video.

πŸ›  Sample output

🧠 Algorithim Used

In general Sudoku is solved using Backtracking approch, which is a bruteforce approch.
Here we are using Greedy Best First Search approch (An optimised version of Naive Back Tracking method) ie; Chooses a cell with least number of possibilities to search next.

πŸƒβ€β™‚οΈ How to Run!!

Step-1: Install all required libraries in requirements.txt or directly run pip install -r requirements.txt
Step-2: Directly run all cells of Sudoku testing.ipynb file. It does all the imports by itself.
Step-3: Nothing else, just get your Sudoku puzzle in front of your camera and solutions will be relayed over their respective positions.
Step-4: To stop the camera, click 'Q' on keyboard.

πŸ“‘ Step By Step Explanation

What's happening Image
Step-1: Reading image from real-time input or a video or an image.
Step-2: Convert input image to black and white. Apply threshold to remove unwanted noice.
Step-3: Get boundry of largest contour ie: Outline of sudoku matrix.
Step-4: In each cell of sudoku matrix, detect if any number is there or not by finding contours.
Step-5: Predict those detected numbers
Step-6: Input the predicted numbers into Sudoku Solving algorithm and get the out put.
Step-7: Overlay the corresponding calculated results on to live image/video.

✍ Note

I had trained a custom model for Number prediction. You can use either the existing one or a model of your own.

πŸ“ References

Algorithim:

For solving sudoku: https://norvig.com/sudoku.html
Tech With Tim: https://www.youtube.com/watch?v=lK4N8E6uNr4

Theoretical:

Sudoku extraction from image: https://medium.com/@neshpatel/solving-sudoku-part-ii-9a7019d196a2 (with python code)
Solving Sudoku Part1: https://medium.com/@neshpatel/solving-sudoku-part-i-7c4bb3097aa7
Solving Sudoku Part2: https://medium.com/@neshpatel/solving-sudoku-part-ii-9a7019d196a2

Code:

Code Reference:

Youtube:

Taha Emara: https://www.youtube.com/watch?v=Q5F8FteU3OY

Connect with Author

🀝 LinkedIn: Lets Connect

About

Solving Sukodu puzzle in realtime using Deep Learning and Computer Vision. Display the unsolved Sudoku in front of the camera and get the instant solution projecting right on the image.


Languages

Language:Jupyter Notebook 100.0%