Code Monkey home page Code Monkey logo

chessocr's Introduction

chessocr

A OCR application for chess boards

The goal of this application is to read an image, detect the chess boards in it and export them using the FEN notation (https://en.wikipedia.org/wiki/Forsyth–Edwards_Notation).

Setting stuff up

    virtualenv env
    source env/bin/activate
    pip install -r requirements.txt
    python src/main.py <filename>

Roadmap

Done

Board Detection

  • Read Image from file

Original Image

  • Convert image to grayscale.

Grayscale Image

  • Convert to black and white taking into account average image brightness.

BW Image

  • Find contours using cv2.findContours

Contours Image

  • Filter irrelevant contours:
    • Area either too small or too large.
    • Ratio height/width not close to 1.

Contours Image

Board Extraction/Perspective Correction

  • Draw each contour in an individual black buffer.

Contours bw Image

  • Find lines by using the standard Hough transform. This is done, iteratively, progressively decreasing the accumulator threshold parameter until there exactly 2 horizontal lines and 2 vertical lines (with some degree of freedom).
    • Lines that are too close to each other are ignored

Contour Lines Contour Lines

  • Calculate the perspective correction transformation using the 4 points of intersection.

Perspective Points

  • Apply the transformation to a copy of the original image and crop it to size.

Extracted Board

Doing

Grid Detection/Tile extraction

  • Using OpenCV to detect grids

  • Using Canny algorithm for edge detection Canny Edge Image

  • Find lines by using the standard Hough transform. This is done, iteratively, progressively decreasing the accumulator threshold parameter until there are at least 8 horizontal lines and 8 vertical lines. Lines that are too close to each other are ignored

    Hough Lines Image 1

    Hough Lines Image 2

  • Calculate the line intersections

    Detected Grid

To Do

Piece Detection

Rule-based Board Validation/Self-Correction

chessocr's People

Contributors

andresilva avatar npcardoso avatar yizhouzhao avatar

Watchers

 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.