All Projects → linrock → chessboard-recognizer

linrock / chessboard-recognizer

Licence: MIT license
Uses neural networks to extract chess positions from images

Programming Languages

python
139335 projects - #7 most used programming language
CSS
56736 projects

Projects that are alternatives of or similar to chessboard-recognizer

ChessBoardScanner
Java based Chess Board Scanner, which converts 2D chess board image into a machine readable format a.k.a. Forsyth–Edwards Notation (FEN). It uses OpenCV and Deeplearning4j frameworks, complemented with some proprietary algorithms implemented for realizing the goal. It currently supports the chess board and pieces sets of the most common online c…
Stars: ✭ 32 (-45.76%)
Mutual labels:  chess, chessboard
ChessLib
C# chess library containing a complete data structure and move generation.
Stars: ✭ 37 (-37.29%)
Mutual labels:  chess, chessboard
stockfish-chess-web-gui
Responsive chess web GUI to play against the Stockfish 10 chess engine. Multiple web GUI implementations have also been included.
Stars: ✭ 21 (-64.41%)
Mutual labels:  chess, chessboard
FDChessboardView
An iOS / Mac view controller for chess boards
Stars: ✭ 75 (+27.12%)
Mutual labels:  chess, chessboard
Online-Chess
A chess website where people can play against each other online.
Stars: ✭ 28 (-52.54%)
Mutual labels:  chess, chessboard
Zerofish
An implementation of the AlphaZero algorithm for chess
Stars: ✭ 34 (-42.37%)
Mutual labels:  chess
Chessman
Chess analysis Universal Windows 10 application.
Stars: ✭ 14 (-76.27%)
Mutual labels:  chess
liPGN
This program uses the lichess REST API to retrieve all the games of a user and transform them into a big PGN file that you can then import into your favourite game analysis tool (ie. scid)
Stars: ✭ 14 (-76.27%)
Mutual labels:  chess
bevy chess
Chess demo in Bevy
Stars: ✭ 59 (+0%)
Mutual labels:  chess
chess-api
Chess API: REST API for playing chess and storing highscores
Stars: ✭ 39 (-33.9%)
Mutual labels:  chess
lila-openingexplorer
Opening explorer for lichess.org that can handle all the variants and billions of unique positions
Stars: ✭ 89 (+50.85%)
Mutual labels:  chess
Chess.NET
[No longer maintained] A .NET chess library, written in C#
Stars: ✭ 48 (-18.64%)
Mutual labels:  chess
chess-openings
An aggregated data set of chess opening names
Stars: ✭ 223 (+277.97%)
Mutual labels:  chess
protochess
Online multiplayer chess website that lets you build custom pieces/boards. Written in Svelte + Rust.
Stars: ✭ 95 (+61.02%)
Mutual labels:  chess
Mzinga
Open-source software to play the board game Hive.
Stars: ✭ 57 (-3.39%)
Mutual labels:  chess
php-chess
A chess library for PHP.
Stars: ✭ 42 (-28.81%)
Mutual labels:  chess
shogi-pieces
Shogi (Japanese Chess) pieces and boards
Stars: ✭ 25 (-57.63%)
Mutual labels:  chess
ChineseChessOL
Online Heads-Up version of Chinese Chess built with Unity 3D
Stars: ✭ 15 (-74.58%)
Mutual labels:  chess
ymir-js
This toolkit is created to make it easier for you to develop games like chess, checkers, go, match 3 puzzle and more. It is still under development.
Stars: ✭ 30 (-49.15%)
Mutual labels:  chess
Demolito
UCI Chess Engine
Stars: ✭ 41 (-30.51%)
Mutual labels:  chess

Chessboard recognizer

Uses a convolutional neural network to recognize the positions of pieces on a chessboard image.

If you have an image of a chessboard in chessboard.png

Run the program like this

./recognize.py chessboard.png

To get the chessboard position in FEN notation

3rkb1r/1pp2ppp/2n1q1n1/p3Pb2/2Pp4/PN3NB1/1P1QPPPP/3RKB1R

Sample results

Chess puzzle from a book:

Predicted: 2r2k1r/6bp/p3q3/4pp1Q/1p1n2P1/N7/PPP3BP/2KR1R2 (99.633% confidence)

Lichess analysis board diagram with arrows:

Predicted: 5r1k/2q1r1pp/2p4n/2P2B2/pPQ1pR2/P5P1/4R2P/7K (99.997% confidence)

Getting started

You'll need python 3 and Tensorflow 2

Set up your virtualenv and install python dependencies

virtualenv venv
source venv/bin/activate
pip3 install -r requirements.txt

You'll need a neural network model to use ./recognize.py

To use a pre-trained model, download nn.zip and unzip in the project root folder.

To train your own model, you'll first need lots of images of chessboards

  • For the images used in the pre-trained model, download training-images.zip and unzip in the project root directory
  • Or generate your own training images with this script:
    • ./generate_chessboards.py downloads a bunch of chessboard images with randomly-placed pieces

Then run this script to convert the chessboard images into 32x32 PNGs of each square of the board

  • ./generate_tiles.py converts these downloaded chessboard images into 32x32 PNGs used for training

Once you have tiles images ready for the training inputs, run this:

  • ./train.py creates a new neural network model

Once you have a neural network model ready, run ./recognize.py with a path to a chessboard image:

./recognize.py ~/Desktop/chessboard.png

Debugging

To verify that the generated 32x32 PNG tile images match the source chessboard image, use this script:

  • ./view_images.py for a convenient way to manually verify the generated images

Then open images.html to view the chessboard and tile images with their corresponding pieces.

To debug the predicted outputs, open debug.html after running ./recognize.py to view the actual/predicted boards

image

Each prediction shows the actual board, the predicted board, the prediction confidence for each square, and a link to a board editor so you can edit the actual FEN in case the predicted FEN is wrong.

Incorrect or low-confidence predictions are a great source of training chessboard images.

For a convenient way to add a training image, use this script:

  • ./save_chessboard.py chessboard.png <subdirectory> <actual fen>

Then you can generate more tiles and re-train the model for more-accurate future predictions.

Acknowledgements

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].