Code Monkey home page Code Monkey logo

sudokusolver's Introduction

SudokuSolver

SudokuSolver is a successor from my previous version. The newer version of the software will use OpenCV and Tesseract with the digits trained dataset.

The older software did not always work as intended. The objective is to make this software work flawlessly at any time.

Requirements

This project has been developed with JDK 17. It is recommended to use this version to avoid any obstacles with the software.

Usage

To run SudokuSolver, clone the project via your IDE or code editor and execute "Launch.java".

To obtain the best results, keep the opened browser in focus (IMPORTANT: remove pop ups if it is your first time visiting the website)

The SudokuSolver is tested with https://www.sudoku.com for now.

Software performance

Updates in the new performance test:

  • Added MRV (Minimum Remaining Values) heuristic
    • This improved the average runtime from 2142 milliseconds to 1630 milliseconds

I conducted a performance test of SudokuSolver using www.sudoku.com in evil mode with 100 iterations and an average performance of 1630 milliseconds. It is important to note that the hardware configuration can naturally affect the performance of the solver.

The steps included in this benchmark are:

  1. Opening the browser and the website
  2. Screenshot of the website
  3. Image processing
  4. OCR
  5. Solving the Sudoku
  6. Filling the Sudoku

Performance graph

Backtracking solving algorithm

The backtracking solving algorithm is a brute-force search algorithm that tries all the possible combinations of numbers until a solution is found that satisfies the constraints of the puzzle. Read more about it here

OpenCV algorithm

The objective of this algorithm is to identify and extract a Sudoku board from an image.

Board detection

  1. Image is converted to grayscale
  2. Blur filter is applied to the image to reduce noise
  3. Canny edge detection algorithm to identify the contours and selects the largest contour
  4. It adds a margin to remove any borderlines
  5. Finally, the image is extracted by using the coordinates of the bounding rectangle

board detection

The extra processing technique

In order to prepare for optimal contour detection and cell cropping, the board is preprocessed with the following steps:

  1. The output image is converted to grayscale
  2. Gaussian blur is applied to the grayscaled image to smooth the image
  3. Adaptive threshold to convert the image to black and white

extra processing

Digit detection in each cell

To ensure that the digit is in focus for the best OCR results, I had to design a solution that ensured the digit was cropped without any grid or borders included. This was because any non-cropped grid or border was often detected as either a '1' or a '7' which often resulted in incorrect solutions for the sudoku board. My solution was done with the following steps for each cell:

  1. Convert the cell image to grayscale
  2. Apply thresholding to create a binary image
  3. Find contours in the binary image
  4. Find the contour with the largest area (assumed to be the contour of the digit in the cell)
  5. Find the bounding rectangle of the largest contour
  6. Extract the region within the bounding rectangle

Tesseract

The objective of this algorithm is to perform OCR to identify the digit. The training dataset applied for this is specified for digit training.

result

Developer

This software is developed and designed by Hassan K

sudokusolver's People

Contributors

stonebank avatar

Stargazers

Jasser avatar Bowku avatar Declane avatar  avatar  avatar  avatar Hassan K avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.