Find the grid
Grayscale, Gaussian blur, adaptive threshold, contour detection, then a perspective warp that flattens a photographed puzzle into a clean square.
From pixels to solutions — an AI-powered Sudoku solver that reads a puzzle straight out of a photograph.
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.
Grayscale, Gaussian blur, adaptive threshold, contour detection, then a perspective warp that flattens a photographed puzzle into a clean square.
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.
A custom convolutional model trained on digit images stands in for OCR when the photo is noisy, low-contrast, or shot at an angle.
Recursive backtracking in C++ — row, column and 3×3 box checks on every candidate digit, called from Python through a compiled binary.
Grayscale → blur → adaptive threshold → contour → warp.
EasyOCR or the CNN classifies every one of the 81 cells.
Digits land in a 9×9 array. Blank cells are stored as 0.
The C++ backtracker fills every zero, or reports no solution.
Printed to the CLI and drawn as a PNG for the PySide6 window.
Extracted Sudoku Board — 16 clues read off the photo. Every 0 is a cell the OCR pass found empty.
Solved Sudoku Board — 65 cells filled by the C++ backtracker. The original clues stay amber.
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.
$ 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