Skip to content

Pipeline to convert real-life chess boards into a 2D digital format(FEN) from images and live camera feeds. The system has 2 versions: one for real-time processing using the OAK-D Lite camera and another for high-precision analysis of static images. YOLO is used to detect chess pieces, and traditional cv methods determine board positioning

Notifications You must be signed in to change notification settings

siromermer/Dynamic-Chess-Board-Piece-Extraction

Repository files navigation

Dynamic Chess Board-Pieces Extraction

Computer vision system that automatically extracts chess board positions and piece placements from images or real-time video, converting them into standard FEN (Forsyth-Edwards Notation) format. This project uses YOLO object detection and image processing techniques to recognize chess pieces and their positions on the board.

Project Versions

There are two versions of this project:

  1. Extract the chessboard and pieces from an image (.jpeg, .png, etc.).
  2. Extract the chessboard and pieces using an OAK-D Lite Camera (utilizing DepthAI for real-time video and inference).

C++ version is also available : cpp-version/


For more project, you can check my personal blog website: https://visionbrick.com/


Image 5

Version 1: Conversion from image



Image 5

Version 2: real-time conversion with OAK D Lite camera (depthai)


There are two files for converting images to FEN format: the first uses a square-filling algorithm, and the second uses perspective transformation.

  • The square-filling algorithm works better with non-angled (straight) images.
  • Perspective transformation works better with images taken from different angles.

Perspective transformation Method

chess-perspective_transform


Square Filling Method

chess-diagram-square



Installation

CPU Version (Recommended for most users)

pip install -r requirements.txt

GPU Version (For CUDA-compatible systems)

There is an additional step for installing PyTorch with GPU support. Please check the end of the requirements-gpu.txt file.

pip install -r requirements-gpu.txt

Note: The GPU version requires NVIDIA CUDA toolkit to be installed on your system. If you're unsure, start with the CPU version.


Docker Setup

Running with Docker

For a containerized environment, you can use Docker to run the project without installing dependencies directly on your system.

Note: The Docker setup currently uses the CPU version (requirements.txt) only. GPU support is not included in the Docker configuration.

Build the Docker Image

docker build -t dynamic-chess-board-demo:latest .

Run with Jupyter Lab

docker run --rm -it -p 8888:8888 -v ${PWD}:/app -w /app dynamic-chess-board-demo:latest jupyter lab --ip=0.0.0.0 --no-browser --allow-root

Run Interactive Container

docker run --rm -it -v ${PWD}:/app -w /app dynamic-chess-board-demo:latest

Files

  • square_filling.py: Script for conversion using the square-filling algorithm.

  • square_filling-step-by-step.ipynb: Jupyter notebook for visualizing the entire process step by step.

  • perspective_transformation.py: Script for conversion using perspective transformation.

  • perspective_transformation-step-by-step.ipynb: Jupyter notebook for visualizing the entire process step by step.

  • chess-model-yolov8m.pt --> Trained YOLOv8 model for chess piece detection.

Folders

  • extracted-data --> It contains result (converted image), and all the information (coordinates,board ..)

  • test-images --> Collection of images for testing purposes.

  • example-results --> Contains various images along with their corresponding results.

  • Dephtai-chess (Folder) --> It contains real-life camera version with depthai library , It is not updated but it can still be used. I have different and better algorithms but this depthai version is not using them , it is old . I will update it (not updated)

Important Note: I didn't train the model enough because the first phase of this project was extracting the board and pieces dynamically with changing positions and different boards. As a result, the model cannot predict all the pieces correctly, but the positions are nearly perfect. You can train better models and use them with this code. In the future, I will train better models.

Example Images

for more example, check example-results folder

sample7

Example of image using the square-filling algorithm.



perspective_transformation_result_5

Example of conversion using perspective transformation.



sample5

Example of square-filling algorithm on an image.



About

Pipeline to convert real-life chess boards into a 2D digital format(FEN) from images and live camera feeds. The system has 2 versions: one for real-time processing using the OAK-D Lite camera and another for high-precision analysis of static images. YOLO is used to detect chess pieces, and traditional cv methods determine board positioning

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published