Skip to content

Prototype of a chess pieces detection system from a real image to digital. This component is part of Smartchess project.

Notifications You must be signed in to change notification settings

aledevv/real-chessboard-to-fen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Smartchess

drawing

Author Author Author

Version Platform MIT License

Application for Raspberry PI to play chess games on a real chessboard against Stockfish chess engine.

Demo

Insert gif or link to demo

Files and directories

  • The notebook app.ipynb contains all the code for detection

  • The same code in the notebook is unified in main.py

  • images folder contains pictures to process.

Warning

Weights are tuned using my chessboard and my pieces. If you want to use yours you have to fine-tune a new model (this applies to both corner and pieces detection)

Tip

I found useful this notebook to train the YOLOv8 model.

Detection process

  1. When user makes a move a photo of their chessboard is taken

    User image

  2. A first model detects corners of the chessboard

    Corners

  3. Image is cropped and transformed from 3D into 2D and squares position is mapped through a grid Cropped and Transformed

Note

Since the camera has wide angle the image results to be distorted, as a result the grid could not be perfectly aligned to the squares. An offset parameter has been applied to adjust the grid position once the camera is set on a fixed position.

  1. Pieces are detected with a second model

    Detection

  2. Piece positions are infered by intersecating bounding box areas with grid cells

  3. FEN is written and it can be exported to Lichess or sent to a Stockfish API for analysis

    Lichess FEN chessboard

The same process is described in the repo linked above.

Training

We used YOLOv8n models to both train corners and pieces recognition. Some training details are shown below.

Corners

Confusion matrix Train plots Train labels Batch

Pieces

Confusion matrix Confusion matrix Train labels Correlogram

Project layout

├── 2fen_pgn.py
├── README.md
├── assets
│   ├── chess.png
│   ├── chess2.png
│   └── state_machine.png
├── engine.py
├── gui.py
├── images
│   ├── png
│   │   ├── 1.jpeg
│   │   └── chessboard.png
│   └── svg
│       └── chessboard.svg
├── libcairo.2.dylib
├── main.py
├── requirements.txt
└── weights
    ├── new_corners.pt
    └── pieces.pt

Requiremtnts

Hardware

  • Raspberry (PI 3/4 suggested)
  • Camera ![instert model]---------------- ????
  • LCD display ------------------ ????
  • INSERT CABLES
  • Structure ....

Software and Dependencies

  • How to set up the environment Rasperry, camera and see if they are working...
  • Considerations about AI model that it is traine on that chess board and if someone wants to do it as well they have to re-train the model... potremmo dire come fare brevemente

Installation

Clone respository [TO UPDATE]

git clone https://github.com/aledevv/smarcess.git

Install requirements

pip install -r -requirements.txt

Usage/Examples

python main.py

Links

  • YouTube Demo Video ADD LINK HERE

  • Presentation link (penso sia meglio Google Presentation)

Authors

License

MIT License click here for more details.

About

Prototype of a chess pieces detection system from a real image to digital. This component is part of Smartchess project.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published