# How does OpenCV find chessboard corners?

What are the internal workings of the OpenCV function findChessboardCorners?

The source code of OpenCV is available, so I'd recommend just taking some time going through the code. The relevant file for this particular function is:

calib3d/src/calibinit.cpp

I've not looked into it in detail, but it looks like

CV_IMPL
int cvFindChessboardCorners( const void* arr, CvSize pattern_size,
CvPoint2D32f* out_corners, int* out_corner_count,
int flags )


is the main implementation of this method. In here they

1. Use cvCheckChessboard to determine if a chessboard is in the image
2. Convert to binary (B&W) and dilate to split the corners apart
3. Use icvGenerateQuads to find the squares.

The code then seems to go though a set of checks to condense these quads to chessboard corners, including icvFindConnectedQuads, icvCleanFoundConnectedQuads to remove extra corners, icvCheckQuadGroup, and icvCheckBoardMonotony.

All of these functions are implemented in the same file, apart from cvCheckChessboard which is in calib3d/src/checkchessboard.cpp. Depending how well you wanted to understand the code, there seem to be a number of debugging lines, which can be included if you #define DEBUG_CHESSBOARD, that may help you see what's going on.

• Thanks for your answer. I know I could look it up, but I was just curious, but not curious enough to go through the source code. I hoped someone figured this out some time, and could explain the principles :) – Geerten Jul 5 '12 at 8:35
• I Found a nicely written paper...that also offers an alternative method that is more stable and faster (according to the author) researchgate.net/publication/… – philippe Apr 13 '18 at 15:41