In-browser CVChess

Oblique chess-board extraction

Canvas CV No backend 11 photo dataset

Dataset image

Loading

load detect rectify classify readout
Detected board, 8x8 grid, and occupied-square overlay
Homography-rectified board used for square sampling

Pipeline

  1. Edges and board outline. The image is downscaled, converted to luminance, and passed through Sobel gradients. Strong edges are dilated; the largest plausible rectangular component proposes the board outline.
  2. Perspective normalization. Four corners define a homography from unit-square board coordinates to image pixels. Every square sample is pulled through that transform, so oblique boards become a square 8x8 grid.
  3. Square occupancy. Each square is sampled in its interior. Center-versus-ring contrast, local variance, and tiny gradient energy are combined into an occupancy score.
  4. Readout. Adaptive thresholding splits empty and occupied squares. Occupied squares are labeled P or p by relative luminance, then packed into a FEN-like board string.
Sobel edge mask and candidate board component
Rectified grid sampled through the homography
Per-square occupancy score heat map
for each candidate photo:
  gray = luminance(image)
  edges = sobel(gray) > percentile(74)
  board = largest_dilated_component(edges)
  H = homography(unit_square, board_corners)
  for each square:
    score = center_delta + variance + edge_energy
  threshold = robust_gap_or_otsu(scores)
  fen = pack_8x8(occupied)

Evaluation loop

Dataset run

Images11
Board success-
Exact occupancy subset-
Mean count error-

The final heuristic came from three passes over the dataset: first a pure edge component detector, then a homography rectifier, then a more conservative occupancy threshold after close-up images over-fired on board texture.

Image View Board Occupancy Notes

Failure modes

Very low board height. Side-on boards collapse several ranks into only a few pixels. The corner homography still lands, but individual pieces shadow multiple squares.

Close-up partial boards. Images that do not contain all four board corners are treated as visual demos, not exact board extraction. The uploaded-photo path reports lower confidence in this case.

Piece type limits. This submission scores occupancy only. Full piece recognition would need a local classifier trained on rectified square crops and included with the page.