I Built a Chess Scanner That Converts Any Chess Image Into a FEN + Analyzes Games Like Chess.com
π Live website: https://chessscanner.seedrlite.in/
π§ Introduction
Chess engines are extremely powerful β but only when they have a FEN position or a PGN to analyze.
Most of the time, people see a board in a photo, a screenshot, or a video frame⦠and wish they could instantly analyze it.
So I built a web application called Chess Scanner that:
β
Detects the chessboard from any image
β
Identifies all 12 piece types (White/Black Γ King/Queen/Rook/Bishop/Knight/Pawn)
β
Generates a perfect FEN string
β
Lets you edit the detected board
β
Analyzes PGNs and classifies moves (Good, Great, Brilliant, Miss, Blunder, etc.)
β
Plays best moves using Stockfish
This post explains how I built it, the challenges I faced, and how it works under the hood.
β 1. The Idea
My goal was simple but ambitious:
βUpload any chess image β get instant FEN β analyze it like on chess.com.β
There are apps that do individual tasks, but none that combine:
- Computer vision
- FEN extraction
- Real-time board editing
- Game analysis
- Chess.com-like move classification
I wanted this all in one clean web app.
π 2. Architecture Overview
Frontend (React + Tailwind)
β Sends image
Backend (FastAPI + YOLOv8)
β Detects board + pieces
Board Processor β Generates FEN
Stockfish Engine β Analysis
Frontend Visualization β Move types + best moves
Tech Stack
- React + Tailwind for UI
- FastAPI (Python) for backend
- YOLOv8 (Ultralytics) for board & piece detection
- Custom dataset (Roboflow)
- Stockfish 17.1 for move evaluation
- SQLite authentication system
- JWT auth
- Cloud VPS (Ubuntu, Nginx)
π 3. Training the Vision Model
Dataset
I created my own labeled dataset using Roboflow:
-
Board Detection Model
- Segmentation + bounding box
- Trained on real + synthetic chessboard images
-
Piece Detection Model
- 12 classes (white/black for each piece)
- Augmented with flip/rotate/lighting variations
- Special training on dark boards, unconventional themes, and low-light images
Challenges
- Some chess sets have similar shapes (e.g., black pawns vs black bishops in bad lighting).
- Perspective distortion makes squares uneven.
- Large boards in mobile screenshots require high-resolution inference.
Results
My best YOLOv8 model achieves:
- mAP50: ~0.98
- mAP50-95: ~0.84
- High accuracy even with dark backgrounds
π§© 4. Converting Detection Output to FEN
This is the magical part.
Once pieces are detected:
- The board segmentation mask is used to warp the image into a perfect 8Γ8 grid.
- Each square is assigned a piece (if detection center falls inside).
- Empty-square compression creates the FEN row string.
- The final FEN is returned to frontend.
Example output:
7N/5p2/1p3P2/p7/kp6/1p6/1P6/1K6 w - - 0 1
You can then analyze or edit the board directly.
β 5. PGN Analyzer + Move Classification
Another major feature I added:
β Analyze any PGN
I process each move with Stockfish and compare:
- Eval before
- Eval after
- Best engine move
- Centipawn loss
- Sacrifices
- Move difficulty
Then I classify moves in categories inspired by Chess.com:
- Brilliant
- Great Move
- Good Move
- Book Move
- Inaccuracy
- Mistake
- Blunder
- Miss (Missed tactic)
This gives players a clean, human-friendly understanding of their game quality.
π¨ 6. UI/UX
The UI focuses on clarity and speed:
- Drop zone for uploading images
- Real-time board preview
- FEN editor
- Move list with evaluation graph
- Best move suggestions
- Dark/Light themes
- Full mobile support
I also added a Chess Scanner logo featuring a board + camera icon.
π 7. Deployment
Technical deployment stack:
- Ubuntu 22.04 VPS
- Nginx β Gunicorn β FastAPI
- Project served as
/api/inferendpoint - React frontend deployed with Nginx static hosting
- SSL via Certbot
- YOLO model files optimized with half precision
Everything runs smoothly even on a mid-tier VPS.
π 8. Whatβs Next?
Future improvements:
πΉ Real-time video scanning
πΉ Automatic PGN generation from detected positions
πΉ Opening explorer integration
πΉ ELO estimation based on move accuracy
πΉ Cloud account system + saved games
πΉ Mobile app (React Native, already under development)
π Live App: Chess Scanner
π Conclusion
Building a chess scanner that works reliably on ANY image was a challenging but rewarding project.
The combination of:
- YOLOv8
- Smart board geometry
- Stockfish evaluation
- React UX
makes the tool extremely powerful for:
- Chess learners
- Coaches
- Content creators
- Daily puzzle solvers
If you want to try it or want the repo, feel free to reach out.
Top comments (0)