A powerful GUI application that converts chess board screenshots into FEN notation and provides real-time analysis using the Stockfish chess engine. Perfect for chess enthusiasts, students, and competitive players!
- ๐ค Image Upload: Load chess board screenshots (PNG, JPG, JPEG, BMP)
- ๐ฒ Board Detection: Automatically detects chessboard regions using OpenCV image processing
- ๐ FEN Conversion: Converts chess positions to FEN notation with preset templates and custom input
- ๐ค Stockfish Integration: Deep position analysis with multi-second thinking time
- ๐ฏ Best Move Detection: Suggests optimal moves with evaluation scores
- โ๏ธ Attack/Defense Analysis:
- Detects forced checkmate sequences
- Identifies critical defending positions
- Evaluates position balance
- ๐ Top 3 Candidate Moves: Shows multiple strong alternatives with evaluations
- ๐จ Modern GUI: Dark theme Tkinter interface with status updates
- ๐ Real-time Processing: Live progress updates during analysis
- Python 3.8 or higher
- macOS, Linux, or Windows
- At least 200MB free disk space
The application requires the Stockfish chess engine installed on your system. Download it from:
- Official: https://stockfishchess.org/download/
All dependencies are automatically installed. Key packages:
python-chess- Chess logic and FEN handlingPillow- Image processingopencv-python- Board detection via image analysisstockfish- Python wrapper for Stockfish enginetkinter- GUI framework (usually pre-installed with Python)
macOS (Homebrew):
brew install stockfishUbuntu/Debian:
sudo apt-get install stockfishFedora/RHEL:
sudo dnf install stockfishWindows: Download from https://stockfishchess.org/download/ and install the executable.
Verify Installation:
stockfish --versionNavigate to the project directory:
cd /path/to/chess.aiCreate a virtual environment (optional but recommended):
python3 -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activateInstall dependencies:
pip install -r requirements.txtOr manually install:
pip install Pillow python-chess stockfish opencv-pythonpython script.pyOr if using the virtual environment:
.venv/bin/python script.py-
Upload an Image
- Click "๐ค Upload Chess Screenshot" button
- Select an image file of a chessboard (PNG, JPG, BMP)
- The image displays and becomes ready for analysis
-
Enter FEN Position
- Click "๐ Scan & Analyze Position"
- A dialog box appears with preset positions
- Select a preset or paste your custom FEN string
- Click "Analyze" to proceed
-
View Analysis Results
- Best Move: The strongest move recommended by Stockfish
- Evaluation: Position evaluation in pawns (ยฑX.XX)
- Status: Attack/Defense/Balanced assessment
- Top 3 Moves: Alternative candidate moves with evaluations
-
Clear Results
- Click "๐๏ธ Clear" to reset the application
The app includes built-in presets for quick testing:
- Starting Position - Fresh game
- Fool's Mate (Black Won) - Quick checkmate example
- Scholar's Mate - Classic attacking trap
- Endgame - King & Pawn - Endgame scenario
Enter any valid FEN string to analyze:
- Format:
rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1 - The app validates your FEN automatically
| Evaluation | Interpretation |
|---|---|
| >3.0 pawns | Strong attacking advantage |
| +1.0 to +3.0 | Moderate advantage |
| -1.0 to +1.0 | Balanced position |
| -1.0 to -3.0 | Moderate disadvantage |
| <-3.0 pawns | Critical defending position |
| Mate in N | Forced checkmate in N moves |
- ๐ข ATTACKING - You have advantage, press it
- ๐ DEFENDING - Play carefully, consolidate
- ๐ก BALANCED - Focus on positional play
- ๐ด CRITICAL - Take defensive measures
Solution:
# Verify Stockfish is installed
which stockfish # macOS/Linux
where stockfish # Windows
# If not found, install it:
brew install stockfish # macOS
sudo apt install stockfish # Ubuntu/DebianSolution:
# Verify you're in the virtual environment
source .venv/bin/activate # macOS/Linux
.venv\Scripts\activate # Windows
# Reinstall dependencies
pip install --upgrade -r requirements.txtSolution:
- Ensure image file is PNG, JPG, JPEG, or BMP
- Check file permissions
- Try a different image file
- Ensure image size is reasonable (under 50MB)
- This is normal! Stockfish deep analysis takes time
- Reduce thinking time by modifying
time=2.0in the code - Ensure no other CPU-intensive processes are running
Solution:
- Double-check FEN formatting
- Ensure 8 ranks (rows) separated by "/"
- Check piece notation (lowercase for black)
- Verify turn indicator: "w" (white) or "b" (black)
- Reference: https://www.chessclub.com/help/FEN-notation
FEN (Forsyth-Edwards Notation) represents chess positions as text:
rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1
Components:
-
Piece Placement:
rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR- Lowercase = black pieces
- Uppercase = white pieces
- Numbers = empty squares
/= row separator
-
Active Color:
w(white) orb(black) -
Castling Rights:
KQkq(kingside/queenside for white/black) -
En Passant:
-(no en passant) or square likee3 -
Halfmove Clock: Moves since last capture/pawn move
-
Move Number: Full move count
Resources:
- https://www.chessclub.com/help/FEN-notation
- https://en.wikipedia.org/wiki/Forsyth%E2%80%93Edwards_Notation
- Screenshot your current online chess game
- Upload the image
- Select or enter the FEN of your position
- Get instant analysis and the best move
- Use it to guide your next decision
- Use preset endgame positions
- Try different moves
- See Stockfish's evaluation instantly
- Understand positional dynamics
- Find a chess puzzle FEN online
- Input the FEN string
- Get Stockfish's recommended solution
- Learn why it's the best move
script.py
โโโ ChessScannerApp (Main GUI Application)
โ โโโ build_gui() - Creates Tkinter interface
โ โโโ upload_image() - Handles image selection
โ โโโ find_stockfish() - Locates engine
โ โโโ detect_fen_from_image() - Board detection
โ โโโ get_fen_from_user() - FEN input dialog
โ โโโ analyze_position() - Main analysis flow
โ โโโ get_best_moves() - Stockfish evaluation
โโโ Supporting Functions
โโโ show_stockfish_warning() - Error handling
โโโ clear_all() - Reset application
| Package | Purpose | Version |
|---|---|---|
tkinter |
GUI framework | Built-in |
python-chess |
Chess logic | 1.9+ |
Pillow |
Image processing | 9.0+ |
opencv-python |
Board detection | 4.5+ |
stockfish |
Engine wrapper | 3.0+ |
- Load Image โ OpenCV reads file
- Grayscale Conversion โ Reduce to single channel
- Edge Detection โ Canny algorithm finds edges
- Contour Analysis โ Identifies board region
- Board Extraction โ Isolates chessboard
- FEN Conversion โ User confirms/inputs position
Edit script.py and find:
info = engine.analyse(board, chess.engine.Limit(time=2.0))Change 2.0 to desired seconds (e.g., 5.0 for deeper analysis, 0.5 for quick analysis).
In the get_fen_from_user() method, add to the presets dictionary:
presets = {
"My Position": "r1bqkbnr/pppp1ppp/2n5/1B2p3/4P3/5N2/PPPP1PPP/RNBQK2R w KQkq - 2 4",
# ... other presets
}Export analysis results by reading the result_text widget and saving to file or sharing online.
- Image-to-FEN Detection: Currently relies on user input. Automatic piece detection requires trained ML model (future enhancement).
- Stockfish Version: Some features require Stockfish 14+. Ensure you have the latest version.
- Real-time Board Detection: Works best with:
- Clear board lighting
- Standard chess pieces
- Top-down camera angle
- No perspective distortion
- Train ML model for automatic piece detection
- Support for multiple board themes/piece styles
- Save analysis history to database
- Export analysis to PGN format
- Integration with chess.com API
- Move time calculation for blitz/bullet games
- Engine strength adjustment (ELO rating)
- Multi-language support
- Chess.com: https://www.chess.com/
- Lichess: https://lichess.org/
- Stockfish Documentation: https://stockfishchess.org/
- Python-Chess Docs: https://python-chess.readthedocs.io/
- FEN Notation: https://www.chessclub.com/help/FEN-notation
- Quick Testing: Use the preset positions to test the engine
- Move Comparison: Analyze the same position with different moves
- Learning Tool: Compare your moves with Stockfish's recommendations
- Performance: Close unnecessary applications for faster analysis
- Custom Positions: Create positions using chess.com's diagram tool and export as FEN
This project is open source and available for personal and educational use.
Want to improve the Chess Scanner? Feel free to:
- Report bugs
- Suggest features
- Contribute code improvements
- Improve documentation
For issues with:
- Stockfish: https://github.com/official-stockfish/Stockfish/issues
- Python-Chess: https://github.com/niklasf/python-chess/issues
- OpenCV: https://github.com/opencv/opencv/issues
This tool is perfect for:
- Chess students learning opening theory
- Coaches analyzing games with students
- Puzzle solving and training
- Research on chess engine evaluation
- Teaching chess strategy and tactics
Version: 1.0
Last Updated: March 2026
Python: 3.8+
Status: โ
Production Ready
Enjoy analyzing chess! โ๏ธ