prishitakadam / Real-Time-Sudoku-Solver

In this project we aim to create a real time Sudoku solver which recognise the elements of Sudoku puzzle and providing a digital solution using Computer vision.

Home Page:https://youtu.be/zGhy8oxCUzM

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Real Time Sudoku Solver

Overview

Sudoku is one of the most popular puzzle of all time.The goal of Sudoku is to fill 9x9 grid such that each row,each column and 3x3 grid contains all of the digits between 1 to 9. In this project we aim to create a real time Sudoku solver which recognise the elements of Sudoku puzzle and providing a digital solution using Computer vision.

Steps

  1. Grab the Sudoko Grid from the Webcam Image
  2. Extract and Detect the Digits
  3. Solve the puzzel and Print the Solution

1. Grab the Sudoko Grid from the Webcam Image

(Click on the points to expand)

Extracting the Contour with biggest area
  1. Convert image to Gray scale (cv2.cvtColor)
  2. Blur the image using Gaussian Blur (cv2.GaussianBlur)
  3. Apply adaptive thresholding (cv2.adaptiveThreshold)
  4. Extract the contour with biggest area (cv2.contourArea)

Extract Sudoku Grid Use cv2.warpPerspective to get stable Sudoku Grid

2. Extract and Detect the Digits

(Click on the points to expand)

Process the Extracted Grid Use cv2.morphologyEx and Invert the image

Get Individual Cells of the grid and Predict the Digit

Model used for prediction has been trained on subset of Chars4K Dataset which contains digits only (0-9). Model can be viewed here

While predicting the digits, blank cells would be predicted as 0. Blank cells can be identified by calculating sum of all the pixels (sum would be large)

3. Solve the puzzel and Print the Solution

(Click on the points to expand)

Solution and Final Result

To solve Sudoko, backtracking has been used. Sudoku Backtracking is a recursive algorithm which goes through each cells and sequentially assigns numbers from 1 to 9 if the cell is empty. Notebook for the same can be viewed here.

To display the result use cv2.putText.

About

In this project we aim to create a real time Sudoku solver which recognise the elements of Sudoku puzzle and providing a digital solution using Computer vision.

https://youtu.be/zGhy8oxCUzM

License:MIT License


Languages

Language:Jupyter Notebook 100.0%