Skip to content

mapleleafu/chess-vision-tf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Chess Vision: Real-Time Board Recognition & Analysis

Python TensorFlow License

A computer vision application that recognizes chess positions from screenshots and provides engine analysis. Combines deep learning, computer vision, and chess engine integration into a cross-platform pipeline.

Analysis Board Preview

Architecture

Screen Capture → Chessboard Detection → Grid Segmentation → CNN Inference → FEN Generation → Stockfish Analysis

Input: Cross-platform screen capture (mss on Linux/Mac, win32gui on Windows) with automatic browser window detection.

Vision: Chessboard detection via OpenCV (Canny edge detection, contour analysis), 8×8 grid segmentation with coordinate mapping (A1-H8), image preprocessing (100×100 normalization).

Inference: Custom CNN model (TensorFlow/Keras) for 13-class piece classification (6 black pieces, 6 white pieces, empty square).

Engine: FEN generation from predictions using python-chess, Stockfish integration for evaluation and best move calculation.

Setup

Prerequisites

  • Python 3.10+
  • Stockfish binary (download)

Installation

  1. Clone and setup environment:

    git clone <repository-url>
    cd chess-vision-tf
    python -m venv venv
    source venv/bin/activate  # Windows: venv\Scripts\activate
    pip install -r requirements.txt
  2. Install Stockfish binary:

    • Place executable in engines/ directory:
      • Windows: engines/stockfish.exe
      • Linux/Mac: engines/stockfish
    • Or ensure Stockfish is in system PATH
  3. Place trained model at models/model.h5

Platform Notes

Windows: Automatically detects and captures browser windows.

Linux/Mac: Captures primary monitor by default. For window-specific capture, install xdotool or wmctrl.

Usage

python main.py

Two input methods:

  • Screenshot Analysis: Captures screen, detects chessboard, classifies pieces, opens analysis window
  • FEN Input: Directly load a position using Forsyth-Edwards Notation

Main Window

License

MIT License - see LICENSE file for details.

About

Real-Time Board Recognition & Analysis using TensorFlow Image Recognition Machine Learning Model

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages