This is the repository for a Computer Vision project I developed during my studies at University of Padova. The goal of the project was to come up with an original CV algorithm to extrapolate a FEN notation string from a digital image representing a chess game.
As always, the task is conceptually made out of two sub tasks:
- Detect the chess pieces
- Detect the chessboard cells
The first task is a instance of an object detection problem; for this, a ML approach using CNN-based models is used. For this implementation, I trained a YOLOv8n model for object detection using the publicly available Chess Pieces Dataset for experiments.
The second task is the one that this algorithm tackles; the process is essentialy as follows:
- Preprocess the image by resizing to a predefined resolution, converting to grayscale and computing the Canny edge detector
- Compute the Hough transform of the image, and detect the most prominent peaks
- Run twice a RANSAC algorithm to estimate the two vanishing points of the two bundle of parallel lines that define the chessboard
- From each of the two inliers group, sample 2 lines acting as opposing lines, assuming they belong to the chessboard but not knowing which ones
- For every combination of possible line indices, compute the homography, mapping the chessboard cells accordingly to the indices sampled
- Compute a "chessboard" filter, and compute the response of this filter with the Canny edge detector processed image
- Keep the highest response chessboard as the detected one
See notebooks/chessboard_detection.ipynb
for an in depth explanation and examples.