Giter Club home page Giter Club logo

rt-sudoku's Introduction

cv-sudoku

Sudoku solver using rudimentary computer vision and optical character recognition techniques. OpenCV learning project.

Process

An image is first captured via the user's default desktop camera. The image is then taken into the script after resources are released for preprocessing.

Screenshot of sample sudoku puzzle

The preprocessing step involves converting the raw image to grayscale, applying a low-pass filter (in this case, a Gaussian blur), and then applying adaptive thresholding to make the image easier to analyze.

Screenshot of preprocessed sudoku puzzle

The next phase attempts to identify the corners of the largest contour in the image and perform a perspective warp on the image. This is done by generating a kernel of ones (except the matrix corners, which are 0), performing a dilation morphological operation, finding the contours using the kernel, and then reverse-ordering the contours based on area. Filtering each contour based on length and size determines the largest one. The image is then downsampled and a top-down view of only the board is obtained.

Screenshot of top-down view of sudoku puzzle

The downsampled image is then partitioned. The warped image is resized to fit a square and is divided into 9 X 9 images, each of which represent a cell in the board (some samples below).

Sample split cell (1) Sample split cell (2) Sample split cell (3) Sample split cell (4) Sample split cell (5)

Using PyTesseract, each of the 81 split images is preprocessed and then analyzed via number whitelisting. Identified numbers are put into an ndarray with shape (9, 9). Once all images have been passed, the numpy array is converted into a Python list. The solver attempts to determine a solution via backtracking, which is printed to console.

Sample sudoku puzzle result

rt-sudoku's People

Contributors

henchel-santillan avatar

Watchers

 avatar  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.