From pixels to solutions — an AI-powered Sudoku solver that reads a puzzle straight out of a photograph.

star fork license GPL-3.0 lang Python + C++
What it does

Four pieces, one board.

GridVision takes a photograph of a Sudoku puzzle, finds the grid inside it with OpenCV, reads all eighty-one cells with OCR or a trained CNN, and hands the resulting 9×9 array to a C++ backtracking engine. What comes back is a finished board — in the terminal and in the GUI.

📸 OpenCV

Find the grid

Grayscale, Gaussian blur, adaptive threshold, contour detection, then a perspective warp that flattens a photographed puzzle into a clean square.

🔍 EasyOCR

Read the digits

Each of the eighty-one cells is cropped and passed through EasyOCR. Whatever comes back empty becomes a zero — the solver's marker for an open square.

🤖 TensorFlow / Keras

Or use the CNN

A custom convolutional model trained on digit images stands in for OCR when the photo is noisy, low-contrast, or shot at an angle.

🧮 C++ / g++

Solve it

Recursive backtracking in C++ — row, column and 3×3 box checks on every candidate digit, called from Python through a compiled binary.

How it works

The pipeline, end to end.

Step 1

Preprocess

Grayscale → blur → adaptive threshold → contour → warp.

Step 2

Recognize digits

EasyOCR or the CNN classifies every one of the 81 cells.

Step 3

Build board

Digits land in a 9×9 array. Blank cells are stored as 0.

Step 4

Solve

The C++ backtracker fills every zero, or reports no solution.

Step 5

Output

Printed to the CLI and drawn as a PNG for the PySide6 window.

See it in action

What the terminal prints.

extracted

Extracted Sudoku Board — 16 clues read off the photo. Every 0 is a cell the OCR pass found empty.

solved

Solved Sudoku Board — 65 cells filled by the C++ backtracker. The original clues stay amber.

clue read from the image filled by the solver
The CNN model

An alternative set of eyes.

OCR is fast and needs no training, but it gets brittle on shadows, glare and hand-drawn grids. The CNN path trades that setup cost for robustness: convolution and pooling stacks learn what a digit looks like under noise, so a photo that defeats EasyOCR can still be read cell by cell.

Conv2D MaxPooling2D Dropout Flatten Dense
Tech stack

What it is built on.

OpenCVgrid detection & warping
NumPycell arrays & board math
EasyOCRdigit recognition
TensorFlowCNN training
Kerasmodel definition
C++recursive backtracking solver
PySide6desktop interface
Pillowrendering the solved board
Matplotlibdebug & cell previews
Get started

Four commands to a solved board.

bash — GridVision
$ git clone https://github.com/ahmedyar7/GridVision.git $ cd GridVision $ pip install -r requirements.txt# opencv-python, numpy, easyocr, matplotlib, tensorflow, torch $ g++ sudoku_solver.cpp -o sudoku_solver# the solver lives in Helper/ $ python .\OCR-Implementation\main.py
Roadmap

Still open.