/SudOCRu

Sudoku solver using OCR.

Primary LanguageC

SudOCRu

SudOCRu is a fully student-written OCR Sudoku Solver. This software automatically detects Sudoku Boards in an image, extract its cells, identify the digits in each cell, solves and reconstruct the original sudoku. This projet is fully written in C using SDL2, SDL2_image and glade.

How to use the SudOCRu app

  1. Launch App in bin/sudocru
  2. Click on Load File and chose a png/jpg file with a sudoku grid to solve
  3. Then, chose a nice threshold level to make the lines and numbers more clear and click on next
  4. Resize image if lines are not detected correctly and click on next
  5. Modify cells recognized by the neural network if needed by clicking on the cell and save, then click on next
  6. Sudoku grid is ready to save, chose the filetype to save on and close the window

Folders overview:

  • "app": UI app and utilities
  • "examples": Folder containing files used to demonstrate the different parts
  • "ipp": Image Processing Pipeline, Grid Detection and Cell extracton
  • "ocr": OCR Neural Network implementation
  • "solver": Sudoku Solver CLI

Requirements

  • SDL version 2
  • SDL_image version 2
  • Glade
  • C Compiler (gcc or clang)
  • GNU Make

Building

To generate all the necessary binaries please use the following command at the root of the repository:

$ make all

The folder "bin/" will be generated in each subfolder and at the root, they contain all the files that were used to compile the binaries.

To remove all the generated files and the binaraies, please ue the following command at the root of the repository:

$ make clean

Usage

The All-In-One CLI is still work in progress. Therefore, for the moment you may use the different available CLIs.

Solver

The solver program is a CLI sudoku solver. See the appropriate README in the solver folder for more details. Usage: solver <input_grid> [-<options...>] [arguments] Options:

  • "d" or debug: Show debug information about the loading/saving of the grid
  • "i" or interactive: Animate the sudoku solving process in the terminal (you must have ANSI escape codes enabled)
  • "p" or print: Print the before/after sudoku boards
  • "o" or output: Specify the output file where the solved board will be saved Note that these options can be combined, for example, "-pio" is valid.

Examples:

$ bin/solver examples/solver/grid_00 -p
$ bin/solver examples/solver/grid_00 -pio solved00

Grid Extraction

The ipp program is a sudoku grid extractor from images. See the appropriate README in the ocr folder for more details. Usage: ipp <input> [<options...>]

During the extraction process and for debugging purposes, many files could be generated upon running the command:

  • "grayscale.png": The grayscale version of the input image
  • "median.png": The input image filtered using a 3x3 median filter
  • "filtered.png": The input image filtered by the image processing pipeline.
  • "edges.png": The result of Canny Edge Detection being applied on filtered.png
  • "detected.png": The detected rects and lines by Hough Transform
  • "acc.png": The accumulator generated by the Hough Transform
  • "rotated.png": The automatically rotated back input image
  • "sudoku.png": The cropped and correctly rotated sudoku board
  • "cell/cell_i.png": Cell number i of the sudoku board padded by a leading 0

Note that these generated files will be deleted after running make clean.

Example:

$ bin/ipp examples/processing/image_05.jpg

OCR

The ocr program is a CLI OCR. See the appropriate README in the ocr folder for more details. Usage: ocr <command> [parameters...] [options...] Available commands:

  • train to train a predefined neural network on the XOR truth table. Parameters: ocr train <iterations> <learning_rate>. To specify the output file, use the -f option, example: ocr train -f <output> <iterations <rate>
  • eval to evaluate the outputs of a neural network by a given user input. Parameters: ocr eval <network_file> <user_input> where user_input is a comma-seperated list of floating-point numbers representing the values of the input neurons.

Example:

$ bin/ocr train -f net.bin 1000 10
[...]
$ bin/ocr eval net.bin 1,1

Rotate Utility

The rotimg program will rotate your image by a given angle in degrees. The result will be saved in "rotated.png" or, if defined, the output file Usage: rotimg <input_image> <angle> [output_file]

Example:

$ bin/rotimg examples/rotate/landscape.jpg 123 landscape.jpg

Authors

  • Sofiane Meftah (Head of the project)
  • Kevin Jamet
  • Mehdi El Alaoui El Aoufoussi