Skip to main content

Module chessboard

Module chessboard 

Source
Expand description

Pure-Rust port of OpenCV’s cv::findChessboardCorners (the classic contour-based detector, not findChessboardCornersSB).

This is the largest of the OpenCV routines being replaced. It is built bottom-up:

  1. binarization primitives ([binarize]) — histogram equalization (CALIB_CB_NORMALIZE_IMAGE) and adaptive-mean thresholding (CALIB_CB_ADAPTIVE_THRESH) — done, bit-exact vs OpenCV,
  2. quad generation from contours — done, all cross-checked vs OpenCV: contour finding (find_contours, Suzuki-Abe), polygon approximation (approx_poly_dp, Douglas-Peucker), and the convex-4-gon area filter (find_quads, with contour_area / is_contour_convex),
  3. linking quads into a board graph and ordering corners — done (synthetic tests): neighbor linking (link_quads), connected components (connected_components), consistent corner ordering (order_all_corners), board-lattice propagation (assign_grid), and row-major inner-corner readout (ordered_inner_corners),
  4. board validation (size, monotonicity) and corner extraction — done (synthetic tests): check_board_monotony and extract_board.

The stages are wired together in find_chessboard_corners, which on the OpenCV left*.jpg samples recovers OpenCV’s corner positions to <=0.17px on all 13 frames. Incomplete boards are filled at the lattice level (see extract_board). The only behavior not replicated is OpenCV’s exact output corner order, which is pose-dependent and not required for the pure-Rust calibrator.

The detector flags requested by the strand-braid C++ wrapper are CALIB_CB_ADAPTIVE_THRESH | CALIB_CB_NORMALIZE_IMAGE | CALIB_CB_FAST_CHECK.

Structs§

Contour
A traced border.
LinkedQuad
A quad participating in the board graph.
Quad
A candidate quadrilateral: four ordered corner pixels (x, y).

Functions§

adaptive_threshold_mean
Port of OpenCV adaptiveThreshold with ADAPTIVE_THRESH_MEAN_C and THRESH_BINARY.
approx_poly_dp
Approximate a polygonal curve with the Douglas–Peucker algorithm.
assign_grid
Propagate integer board-lattice coordinates across one connected component.
check_board_monotony
Port of OpenCV icvCheckBoardMonotony.
connected_components
Group quads into connected components following the neighbor links. Returns each component as a list of quad indices.
contour_area
Polygon area via the shoelace formula, matching OpenCV contourArea (absolute value, integer-exact for integer input).
corner_lattice
Every lattice point referenced by at least one quad corner, mapped to its averaged position and the number of referencing quad corners.
equalize_hist
Port of OpenCV equalizeHist for 8-bit single-channel images.
extract_board
Validate and extract a pattern_w x pattern_h board from a lattice-assigned connected component.
find_chessboard_corners
Detect a pattern_w x pattern_h (inner corners) chessboard in a grayscale image. Returns the inner corners row-major, or None if no board is found.
find_contours
Find all borders in a binary image.
find_quads
Extract candidate quads from contours, mirroring OpenCV’s per-contour logic in generateQuads: approximate with approxPolyDP at accuracy levels 1..=7 until four vertices remain, then keep convex quads with area >= min_area.
inner_corner_lattice
Inner board corners with their lattice coordinates (unordered).
is_contour_convex
Whether a polygon is convex, matching OpenCV isContourConvex.
link_quads
Build LinkedQuads from detected quads and link neighboring corners.
order_all_corners
Order the corners of every quad in place.
order_quad_corners
Reorder a quad’s corners into a consistent rotational order (by angle about the centroid), permuting the neighbors links the same way so each neighbors[i] still refers to corners[i].
ordered_inner_corners
Read out the inner board corners from an assigned grid, sorted row-major (by lattice row then column).

Type Aliases§

QuadGrid
Integer lattice coordinate of each of a quad’s four corners.