Chessboard detection: Difference between revisions

Content deleted Content added
wlnk
 
(20 intermediate revisions by 16 users not shown)
Line 1:
{{Orphan|date=December 2014}}
 
{{FeatureDetectionCompVisNavbox}}
 
Chessboards[[Chessboard]]s arise frequently in [[computer vision]] theory and practice because their highly structured geometry is well-suited for algorithmic [[detection]] and processing. The appearance of chessboards in computer vision can be divided into two main areas: [[Camera resectioning|camera calibration]] and [[Feature (computer vision)|feature extraction]]. This article provides a unified discussion of the role that chessboards play in the canonical methods from these two areas, including references to the seminal literature, examples, and pointers to software implementations.
 
==Chessboard camera calibration==
 
A classical problem in computer vision is [[3D reconstruction from multiple images|three-dimensional (3D) reconstruction]], where one seeks to infer 3D structure about a scene from two-dimensional (2D) images of it.<ref name=forsyth2002>D. Forsyth and J. Ponce. ''Computer Vision: A Modern Approach''. Prentice Hall. (2002). [http://www.amazon.com/Computer-Vision-Modern-Approach-Edition/dp/013608592X {{ISBN |978-0262061582]}}.</ref> Practical cameras are complex devices, and [[photogrammetry]] is needed to model the relationship between image sensor measurements and the 3D world. In the standard [[pinhole camera model]], one models the relationship between world coordinates <math>\mathbf{X}</math> and image (pixel) coordinates <math>\mathbf{x}</math> via the [[3D projection|perspective transformation]]
 
:<math>
Line 15 ⟶ 13:
where <math>\mathbb{P}^n</math> is the [[projective space]] of dimension <math>n</math>.
 
In this setting, [[Camera resectioning|camera calibration]] is the process of estimating the parameters of the <math>3 \times 4</math> matrix <math>M = K \begin{bmatrix} R & t \end{bmatrix}</math> of the perspective model. Camera calibration is an important step in the computer vision pipeline because many subsequent algorithms require knowledge of camera parameters as input.<ref name=szeliski2010>R. Szeliski. ''Computer Vision: Algorithms and Applications''. Springer Science and Business Media. (2010). [http://www.springer.com/computer/image+processing/book/978-1-84882-934-3 {{ISBN |978-1848829350]}}.</ref> Chessboards are often used during camera calibration because they are simple to construct, and their planar grid structure defines many natural [[Interest point detection|interest points]] in an image. The following two methods are classic calibration techniques that often employ chessboards.
 
===Direct linear transformation===
 
Direct linear transformation (DLT) calibration uses correspondences between world points and camera image points to estimate camera parameters. In particular, DLT calibration exploits the fact that the perspective pinhole camera model defines a set of similarity relations that can be solved via the [[direct linear transformation]] algorithm.<ref name=faugeras1993>O. Faugeras. ''Three-dimensional Computer Vision''. MIT Press. (1993). [http://www.amazon.com/Three-Dimensional-Computer-Vision-Artificial-Intelligence/dp/0262061589 {{ISBN |978-0262061582]}}.</ref> To employ this approach, one requires accurate coordinates of a non-degenerate set of points in 3D space. A common way to achieve this is to construct a camera calibration rig (example below) built from three mutually perpendicular chessboards. Since the corners of each square are equidistant, it is straightforward to compute the 3D coordinates of each corner given the width of each square. The advantage of DLT calibration is its simplicity; arbitrary cameras can be calibrated by solving a single [[System of linear equations#Homogeneous systems|homogeneous linear system]]. However, the practical use of DLT calibration is limited by the necessity of a 3D calibration rig and the fact that extremely accurate 3D coordinates are required to avoid [[Numerical stability|numerical instability]].<ref name=forsyth2002/>
 
{{multiple image
{{Auto images
|title=Example: calibration rig
|align=center
Line 53 ⟶ 51:
A chessboard contains natural corners at the boundaries between board squares, so one would expect corner detection algorithms to successfully detect them in practice. Indeed, the following figure demonstrates Harris corner detection applied to a perspective-transformed [[:Image:Perspective chessboard.png|chessboard image]]. Clearly, the Harris detector is able to accurately detect the corners of the board.
 
{{multiple image
{{Auto images
|title=Example: corner detection
|align=center
Line 61 ⟶ 59:
|width2=767|height2=548|image2=Harris corners detected on chessboard.png|caption2=Output of [[Corner detection#The Harris .26 Stephens .2F Plessey .2F Shi.E2.80.93Tomasi corner detection algorithm|Harris corner detector]]
}}
 
The following [[MATLAB]] code generates the above image using the [http://www.mathworks.com/products/image/ Image Processing Toolbox]:
 
<source lang="matlab">
% Load image
I = imread('Perspective_chessboard.png');
 
% Detect corners
C = corner(I,'Harris');
 
%--------------------------------------------------------------------------
% Display results
%--------------------------------------------------------------------------
% Original image
figure; imshow(I);
 
% Detected corners
 
figure; imshow(I); hold on;
plot(C(:,1),C(:,2),'ro');
%--------------------------------------------------------------------------
</source>
 
===Lines===
 
Lines are another natural local [[Feature (computer vision)|image feature]] exploited in many computer vision systems. Geometrically, the set of all lines in a 2D image can be parametrized by [[Polar coordinate system|polar coordinates]] <math>(\rho,\theta)</math> describing the distance and angle, respectively, of their [[Normal (geometry)|normal vectors]] with respect to the origin. The discrete [[Hough transform]] exploits this idea by transforming a spatial image into a matrix in <math>(\rho,\theta)</math>-space whose <math>(i,j)</math>-th entry counts the number of image edge points that lie on the line parametrized by <math>(\rho_i,\theta_j)</math>.<ref name=shapiro2001>L. Shapiro and G. Stockman. ''Computer Vision''. Prentice-Hall, Inc. (2001). [http://www.amazon.com/Computer-Vision-Linda-G-Shapiro/dp/0130307963 {{ISBN |978-0130307965]}}</ref><ref name=duda1972>R. Duda and P. Hart. "Use of the Hough transformation to detect lines and curves in pictures," Comm. ACM, vol. 15, pp. 11-15 (1972).</ref><ref name=hough1959>P. Hough. "Machine analysis of bubble chamber pictures." Proc. Int. Conf. High Energy Accelerators and Instrumentation. (1959).</ref> As such, one can detect lines in an image by simply searching for [[Maxima and minima|local maxima]] of its discrete Hough transform.
 
The grid structure of a chessboard naturally defines two sets of parallel lines in an image of it. Therefore, one expects that line detection algorithms should successfully detect these lines in practice. Indeed, the following figure demonstrates Hough transform-based line detection applied to a perspective-transformed [[:Image:Perspective chessboard.png|chessboard image]]. Clearly, the Hough transform is able to accurately detect the lines induced by the board squares.
Line 103 ⟶ 79:
The following [[MATLAB]] code generates the above images using the [http://www.mathworks.com/products/image/ Image Processing Toolbox]:
 
<sourcesyntaxhighlight lang="matlab">
% Load image
I = imread('Perspective_chessboard.png');
 
% Compute edge image
BW = edge(I, 'canny');
 
% Compute Hough transform
Line 116 ⟶ 92:
numpeaks = 19;
thresh = ceil(0.1 * max(H(:)));
P = houghpeaks(H, numpeaks, 'threshold', thresh);
 
% Extract image lines
lines = houghlines(BW, theta, rho, P, 'FillGap', 50, 'MinLength', 60);
 
% --------------------------------------------------------------------------
% Display results
% --------------------------------------------------------------------------
% Original image
figure; imshow(I);
Line 131 ⟶ 107:
 
% Hough transform
figure; image(theta, rho, imadjust(mat2gray(H)), 'CDataMapping', 'scaled');
hold on; colormap(gray(256));
plot(theta(P(:, 2)), rho(P(:, 1)), 'o', 'color', 'r');
 
% Detected lines
figure; imshow(I); hold on; n = size(I, 2);
for k = 1:length(lines)
% Overlay kth line
Line 142 ⟶ 118:
y = [lines(k).point1(2) lines(k).point2(2)];
line = @(z) ((y(2) - y(1)) / (x(2) - x(1))) * (z - x(1)) + y(1);
plot([1 n], line([1 n]), 'Color', 'r');
end
</syntaxhighlight>
%--------------------------------------------------------------------------
</source>
 
==ConclusionLimitations==
 
The main limitation of using chessboard patterns for geometric camera calibration is that due to their highly repetitive structure, they need to be completely visible in the camera image. This assumption may be violated e.g. when specular reflections due to inhomogenous lighting cause chessboard detection to fail in some of the corners. The measurement of camera distortions close to the image corners is also altered by the need of a completely visible chessboard target.
Chessboards are ubiquitous is computer vision because they provide a convenient way to benchmark/verify many common calibration and feature extraction algorithms.
 
To solve this issue, chessboard targets can be combined with some position encoding. One popular way is to place ArUco markers<ref name=gerrido2014>S. Garrido-Jurado et al. "Automatic generation and detection of highly reliable fiducial markers under occlusion." Pattern Recognition, vol. 47(6), pp. 2280-2292. https://dl.acm.org/doi/abs/10.1016/J.PATCOG.2014.01.005. (2014).</ref> inside the lightchessboard squares. The main advantage of such ChArUco targets<ref name=opencv>OpenCV. https://docs.opencv.org/3.4/df/d4a/tutorial_charuco_detection.html.</ref> is that all light chessboard squares are uniquely coded and identifiable. This also allows to do single image multiplane calibration by placing multiple targets with different ArUco in one scene.
 
An alternative way for adding position encoding to chessboard patterns is the PuzzleBoard pattern:<ref name=stelldinger2024>P. Stelldinger, et al. "PuzzleBoard: A New Camera Calibration Pattern with Position Encoding." German Conference on Pattern Recognition. (2024). https://users.informatik.haw-hamburg.de/~stelldinger/pub/PuzzleBoard/. (2024).</ref> Each chessboard edge is given one bit of information such that local parts of the pattern show a unique bit pattern. In comparison to ChArUco patterns, the position encoding can be read at much lower resolutions.
 
[[File:PuzzleBoard8x11.jpg|thumb|center|500px|alt=An example of a PuzzleBoard pattern with 8x11 chessboard corners.|An example of a PuzzleBoard pattern with 8x11 chessboard corners. Each 3x3 tile pattern is unique.]]
 
==See also==
Line 164 ⟶ 145:
*[[Structure tensor| Structure tensor matrix]]
*[[Hough transform]]
 
==External links==
 
The following links are pointers to popular [[MATLAB]] and [[OpenCV]] implementations of chessboard-related computer vision algorithms.
* [http://www.vision.caltech.edu/bouguetj/calib_doc/ Camera Calibration Toolbox for MATLAB] - MATLAB toolbox implementing many common camera calibration methods
* [http://docs.opencv.org/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html Camera Calibration and 3D Reconstruction] - OpenCV implementation of many common camera calibration methods
* [http://www.vision.caltech.edu/bouguetj/calib_doc/htmls/example.html Multiplane Camera Calibration From Multiple Chessboard Views] - MATLAB example of applying multiview auto-calibration to a series of chessboard images
* [http://www.mathworks.com/help/vision/ref/detectcheckerboardpoints.html MATLAB chessboard detection] - MATLAB function from the [http://www.mathworks.com/products/computer-vision/ Computer Vision System Toolbox] for detecting chessboards in images
* [http://docs.opencv.org/doc/tutorials/calib3d/camera_calibration_square_chess/camera_calibration_square_chess.html OpenCV chessboard detection] - OpenCV function for detecting chessboards in images
* [http://www.mathworks.com/help/images/ref/corner.html MATLAB Harris corner detection] - MATLAB function for performing Harris corner detection
* [http://docs.opencv.org/doc/tutorials/features2d/trackingmotion/harris_detector/harris_detector.html OpenCV Harris corner detection] - OpenCV function for performing Harris corner detection
* [http://www.mathworks.com/help/images/hough-transform.html MATLAB Hough transform] - MATLAB function for computing the Hough transform
* [http://docs.opencv.org/doc/tutorials/imgproc/imgtrans/hough_lines/hough_lines.html OpenCV Hough transform] - OpenCV function for computing the Hough transform
 
==Further reading==
Line 183 ⟶ 151:
# Z. Weixing, et al. "A fast and accurate algorithm for chessboard corner detection." 2nd International Congress on Image and Signal Processing. (2009).
# A. De la Escalera and J. Armingol. "Automatic chessboard detection for intrinsic and extrinsic camera parameter calibration." Sensors. vol. 10(3), pp.&nbsp;2027–2044 (2010).
# S. Bennett and [[Joan Lasenby|J. Lasenby]]. "ChESS - quick and robust detection of chess-board features." Computer Vision and Image Understanding. vol. 118, pp.&nbsp;197–210 (2014).
# J. Ha. "Automatic detection of chessboard and its applications." Opt. Eng. vol. 48(6) (2009).
# F. Zhao, et al. "An automated x-corner detection algorithm (axda)." Journal of Software. vol. 6(5), pp.&nbsp;791–797 (2011).
Line 192 ⟶ 160:
==References==
<references/>
 
==External links==
 
The following links are pointers to popular [[MATLAB]] and [[OpenCV]] implementations of chessboard-related computer vision algorithms.
* [http://www.vision.caltech.edu/bouguetj/calib_doc/ Camera Calibration Toolbox for MATLAB] - MATLAB toolbox implementing many common camera calibration methods
* [http://docs.opencv.org/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html Camera Calibration and 3D Reconstruction] - OpenCV implementation of many common camera calibration methods
* [http://www.vision.caltech.edu/bouguetj/calib_doc/htmls/example.html Multiplane Camera Calibration From Multiple Chessboard Views] - MATLAB example of applying multiview auto-calibration to a series of chessboard images
* [http://www.mathworks.com/help/vision/ref/detectcheckerboardpoints.html MATLAB chessboard detection] - MATLAB function from the [http://www.mathworks.com/products/computer-vision/ Computer Vision System Toolbox] for detecting chessboards in images
* [http://docs.opencv.org/doc/tutorials/calib3d/camera_calibration_square_chess/camera_calibration_square_chess.html OpenCV chessboard detection] - OpenCV function for detecting chessboards in images
* [http://www.mathworks.com/help/images/ref/corner.html MATLAB Harris corner detection] - MATLAB function for performing Harris corner detection
* [http://docs.opencv.org/doc/tutorials/features2d/trackingmotion/harris_detector/harris_detector.html OpenCV Harris corner detection] - OpenCV function for performing Harris corner detection
* [http://www.mathworks.com/help/images/hough-transform.html MATLAB Hough transform] - MATLAB function for computing the Hough transform
* [http://docs.opencv.org/doc/tutorials/imgproc/imgtrans/hough_lines/hough_lines.html OpenCV Hough transform] - OpenCV function for computing the Hough transform
* [https://github.com/dkogan/mrgingham/ mrgingham] - tool for detection of chessboards
 
[[Category:Feature detection (computer vision)]]