← worksCourse project · Computer vision202520/20
Chessboard photo to FEN
A digital twin of a physical chess game, comparing a classical OpenCV pipeline against YOLOv8 and U-Net corner heatmaps.

With Félix Martins, Francisco da Ana and João Torre Pereira · Computer Vision, FEUP
Take a photo of a chessboard and output the full game state as a FEN string. Three tasks, from hand-built classical vision to a detection + geometry pipeline.
Task 1: classical pipeline
Board found by intersecting Canny edges with a white-colour threshold, contours merged by convex-hull proximity, perspective corrected, grid lines from a Hough transform with missing lines filled from the median spacing, pieces segmented with GrabCut and watershed, and orientation from template-matching the horse logo in the corners.

Task 2: counting pieces with regression
Started from ResNet50 + MSE and improved greedily: RandAugment beat manual augmentation, EfficientNetV2-S beat ResNeXt and Swin, a learnable-scale ReLU beat the sigmoid head, L1 loss beat MSE, and Optuna tuned the rest. Final rounded MAE: 0.0056 on the test set.
Task 3: the digital twin
Piece detection with YOLO (YOLOv8n, YOLOv8x, YOLO11s trained on ChessReD; YOLOv8x: mAP50 0.995, mAP50-95 0.875). Board geometry turned out to be the hard part. Five corner-finding strategies were tried:
| Approach | Idea | Test MED |
|---|---|---|
| A | Classical CV corners | unreliable |
| B | YOLO11-pose keypoints | did not converge |
| C | EfficientNetV2-S corner regression | 0.45% |
| D | U-Net mask + ResNet orientation | 0.49% |
| E | U-Net corner heatmaps (ResNet34 encoder) | 0.31% |
The final pipeline pairs YOLOv8x with the heatmap U-Net: warp the board, map the lower-centre of each piece box to its 8×8 square, emit FEN.
