← 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.

OpenCVUltralytics YOLOPyTorchOptuna

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.

Classical pipeline stages
Board detection, warp, grid extraction and piece masks with OpenCV.

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:

ApproachIdeaTest MED
AClassical CV cornersunreliable
BYOLO11-pose keypointsdid not converge
CEfficientNetV2-S corner regression0.45%
DU-Net mask + ResNet orientation0.49%
EU-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.

Photo of a chessboard and the reconstructed digital board
Input photo and the reconstructed digital twin.

loading 10 projects 0%