Application for Raspberry PI to play chess games on a real chessboard against Stockfish chess engine.
Insert gif or link to demo
-
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.
-
When user makes a move a photo of their chessboard is taken
-
A first model detects corners of the chessboard
-
Image is cropped and transformed from 3D into 2D and squares position is mapped through a grid
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.
-
Pieces are detected with a second model
-
Piece positions are infered by intersecating bounding box areas with grid cells
-
FEN is written and it can be exported to Lichess or sent to a Stockfish API for analysis
The same process is described in the repo linked above.
We used YOLOv8n models to both train corners and pieces recognition. Some training details are shown below.
├── 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
- Raspberry (PI 3/4 suggested)
- Camera ![instert model]---------------- ????
- LCD display ------------------ ????
- INSERT CABLES
- Structure ....
- 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
Clone respository [TO UPDATE]
git clone https://github.com/aledevv/smarcess.git
Install requirements
pip install -r -requirements.txt
python main.py
-
YouTube Demo Video ADD LINK HERE
-
Presentation link (penso sia meglio Google Presentation)
MIT License click here for more details.