v9.1.1
Menu

Checkerboard Corner Detection

hardPROCamera CalibrationCalibrationCV: Structure from Motion and SLAM

Implement simplified checkerboard corner detection for camera calibration, a crucial step in Structure from Motion and SLAM. This task involves identifying the corners of a checkerboard pattern in an image, which is essential for estimating camera parameters.

Checkerboard corners are used in camera calibration because they provide high precision, known 3D geometry, and are easy to detect. The corners of a checkerboard can be represented by a grid of points in 3D space, with each point having a known position xi,yi,zix_i, y_i, z_i. When projected onto a 2D image, these points form a grid of corners, which can be detected using corner detection algorithms.

To detect these corners, the following steps are involved:

  1. Apply a corner detector to the image, which calculates the Harris response R=det⁡(M)−k⋅tr⁡2(M)R = \det(\mathbf{M}) - k \cdot \operatorname{tr}^2(\mathbf{M}), where M\mathbf{M} is the structure tensor.
  2. Filter the detected corners by their pattern, ensuring they form a grid.
  3. Refine the corner locations to sub-pixel accuracy.

Return the corners as (x,y)(x, y) pixel coordinates (exactly rows ×\times cols of them), or None if fewer corners than that are found.

R=det⁡[IxxIxyIxyIyy]−k⋅(Ixx+Iyy)2R = \det\begin{bmatrix} I_{xx} & I_{xy} \\ I_{xy} & I_{yy} \end{bmatrix} - k \cdot (I_{xx} + I_{yy})^2

This technique is widely used in robotics and computer vision applications, such as autonomous vehicles and augmented reality systems.

Example

Input
image = checkerboard image
board_size = (6, 9)  # 6×9 internal corners
Output
List of 54 corner coordinates
Reasoning
  • Input: image is a 140×200140 \times 200 grayscale array of 20×2020 \times 20 px squares (7 ×\times 10 squares). board_size = (6, 9) counts internal corners, where four squares meet: x∈{20,40,…,180}x \in \{20, 40, \dots, 180\}, y∈{20,40,…,120}y \in \{20, 40, \dots, 120\}.
  • Structure tensor at a true corner such as (20,20)(20, 20) both directions change, so Ixx≈Iyy≈2.81×105I_{xx} \approx I_{yy} \approx 2.81 \times 10^5 and Ixy≈143I_{xy} \approx 143. Then det⁡≈7.88×1010\det \approx 7.88 \times 10^{10}, (Ixx+Iyy)2≈3.15×1011(I_{xx}+I_{yy})^2 \approx 3.15 \times 10^{11} and, with k=0.04k = 0.04, R≈6.6×1010R \approx 6.6 \times 10^{10}, the maximum of RR, shared by every internal corner.
  • On an edge such as (20,10)(20, 10): only one direction changes (Iyy=Ixy=0I_{yy} = I_{xy} = 0, Ixx≈3.9×105I_{xx} \approx 3.9 \times 10^5), so det⁡=0\det = 0 and R≈−6.1×109R \approx -6.1 \times 10^9. Flat interiors give R=0R = 0.
  • Output: a list of 6×9=546 \times 9 = 54 (x,y)(x, y) points at the strong positive peaks of RR, row by row.
  • A blank image has no gradients, so R=0R = 0 everywhere and the result is None.

Constraints

  • image: Grayscale image with checkerboard
  • board_size: (rows, cols) of internal corners
  • Return: List of corner coordinates

Learn this in

More from CV: Structure from Motion and SLAM

PRO

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test results

Sign in to run your code against the test cases.