Skip to content

Latest commit

ย 

History

41 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

License: MIT GitHub Repo stars GitHub forks Medium

An intelligent Sudoku solver that combines Computer Vision, Optical Character Recognition (OCR), Deep Learning (CNN), and Recursive Backtracking (C++) to solve Sudoku puzzles directly from images.

This project demonstrates how classical Data Structures & Algorithms (DSA) can be blended with modern AI techniques to create robust and efficient systems.


๐Ÿš€ Features

  • ๐Ÿ“ธ Extract Sudoku puzzle from an image using OpenCV
  • ๐Ÿ” Recognize digits using EasyOCR
  • ๐Ÿงฎ Solve Sudoku efficiently with Recursive Backtracking (C++ implementation)
  • ๐Ÿค– Alternative digit recognition using Convolutional Neural Network (CNN)
  • ๐Ÿ–ฅ๏ธ CLI output and simple GUI interface
  • โšก Hybrid pipeline combining traditional algorithms + deep learning

Example Output:

alt text

Sudoku Project Visuals
Image 1
Image 2

๐Ÿ“‚ Project Structure


E
โ”œโ”€โ”€ OCR-Implementation
โ”‚ โ”œโ”€โ”€ gui.py # GUI interface for Sudoku solver
โ”‚ โ”œโ”€โ”€ img_processing.py # Image preprocessing & grid extraction
โ”‚ โ”œโ”€โ”€ main.py # Entry point for OCR + solver pipeline
โ”‚ โ”œโ”€โ”€ ocr_utils.py # OCR utilities (digit extraction, 2D board creation)
โ”‚ โ”œโ”€โ”€ solver.py # Python wrapper to call C++ solver
โ”‚ โ”œโ”€โ”€ utils.py # Helper functions
โ”‚
โ”œโ”€โ”€ Helper/sudoku_solver.cpp # C++ recursive backtracking solver
โ””โ”€โ”€ README.md


๐Ÿงญ System Design

The recognition stage is the only swappable part of the pipeline. Everything before it (grid extraction) and everything after it (board assembly, solving, output) is shared โ€” so EasyOCR and the custom CNN are drop-in alternatives for the same job.

flowchart TB
    IMG(["Sudoku photo"]) --> GUI["PySide6 GUI<br/>OCR-Implementation/main.py"]
    GUI --> PRE["OpenCV preprocessing<br/>grayscale, blur, adaptive threshold,<br/>contour detection, perspective warp"]

    PRE --> OCR["EasyOCR<br/>ocr_utils.py"]
    PRE -.->|alternative| CNN["Custom CNN<br/>TensorFlow / Keras<br/>CNN-Implementation/main.h5"]

    OCR --> BOARD["9x9 integer board<br/>empty cells stored as 0"]
    CNN -.-> BOARD

    BOARD --> SOLVE["Recursive backtracking<br/>Helper/sudoko_solver.cpp"]
    SOLVE --> OUT(["Solved board<br/>CLI grid + PNG render"])

    classDef io fill:#e2e8f0,stroke:#94a3b8,color:#0f172a
    classDef cv fill:#f2b134,stroke:#c98f22,color:#1a1206
    classDef ocr fill:#3ea6b8,stroke:#2d7d8b,color:#04181c
    classDef cnn fill:#e0537c,stroke:#b13e61,color:#2a0a14
    classDef data fill:#cbd5e1,stroke:#94a3b8,color:#0f172a
    classDef solve fill:#8b5cf6,stroke:#6d3fd4,color:#f5f0ff
    classDef done fill:#3ecf6e,stroke:#2fa557,color:#062814

    class IMG io
    class GUI data
    class PRE cv
    class OCR ocr
    class CNN cnn
    class BOARD data
    class SOLVE solve
    class OUT done
Loading

Solid arrows trace the default OCR path; the dotted branch is the CNN alternative, which trades setup cost for robustness on noisy or angled photos. A hand-drawn version of this diagram lives at assets/sysDesign.png.


โš™๏ธ How It Works

  1. Image Preprocessing

    • Convert to grayscale
    • Apply thresholding
    • Detect contours & warp perspective to get a clean Sudoku grid
  2. Digit Extraction (OCR / CNN)

    • EasyOCR is used to recognize digits from each cell
    • CNN model can be used for improved recognition accuracy
  3. Board Creation

    • Digits are arranged into a 9x9 2D array
    • Empty cells are represented as 0
  4. Solving

    • Board is passed to a C++ backtracking solver for fast computation
    • Output is displayed via CLI or GUI

๐Ÿ–ผ๏ธ Example Workflow

  • Input: Raw Sudoku image
  • Preprocessing: Grid extraction + thresholding
  • OCR/CNN: Digit recognition
  • Solver: C++ backtracking
  • Output: Solved Sudoku (CLI or GUI view)

Tech Stack:

OpenCV NumPy EasyOCR Matplotlib C++ G++ Clang PySide6 TensorFlow Keras Kaggle Pillow

๐Ÿ”ง Installation & Setup

  1. Clone the repository:

    git clone https://github.com/ahmedyar7/GridVision.git
    cd GridVision
  2. Install Python dependencies:

    pip install -r requirements.txt
  3. Compile the C++ solver:

    g++ sudoku_solver.cpp -o sudoku_solver
  4. Run the OCR pipeline:

     python .\OCR-Implementation\main.py

๐Ÿ“š Tech Stack

  • Python: OpenCV, EasyOCR, NumPy
  • C++: Recursive Backtracking for solving
  • Deep Learning: CNN model for digit recognition
  • GUI: Python (Tkinter / PyQt based, depending on your version)

๐ŸŽฏ Future Improvements

  • Real-time Sudoku solving from camera feed
  • Mobile app integration
  • More robust CNN training with larger datasets
  • Cloud API for solving uploaded puzzles

๐Ÿ“ License

This project is licensed under the GPL-License License โ€” feel free to use and modify.


๐Ÿ™Œ Acknowledgments

About

An intelligent AI Based Sudoku solvere that would solve the sudoku based upon the image that is provied by the person

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages