Ask Your Question

finding chessboard corners doesn't work on thresholded images

asked 2018-07-23 14:04:04 -0500

kevinkayaks gravatar image

I have some images like this which cv2.findchessboardcorners fails on.

image description

I thought this was a lighting issue, so I thought I'd simplify the problem by preprocessing the images with a custom thresholding scheme:

image description

However, findchessboardcorners never succeeds on images like this. Can anyone explain to me why, and perhaps offer suggestions for preprocessing to help the algorithm along?


edit retag flag offensive close merge delete



Actually it is not recommended to pre-process the input image before finding the corners, because this will alter the corner position on the Image. So better maintain good lighting so that brightness uniform across the Image.

Balaji R gravatar imageBalaji R ( 2018-07-24 02:08:09 -0500 )edit

Thanks Balaji. Lighting is a difficult task: the view is underwater and I lack waterproof lights.

kevinkayaks gravatar imagekevinkayaks ( 2018-07-24 12:34:55 -0500 )edit

2 answers

Sort by ยป oldest newest most voted

answered 2018-07-23 17:56:07 -0500

i think patternsize is the key.

Size patternsize(19, 3); //interior number of corners

you can test the code below

#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/calib3d.hpp"

using namespace cv;
using namespace std;

int main( int argc, char** argv )
    Mat img = imread("15323725004322727.png");
    imshow("image", img);

    Size patternsize(19, 3); //interior number of corners
    Mat gray;
    cvtColor(img, gray, COLOR_BGR2GRAY);//source image
    vector<Point2f> corners; //this will be filled by the detected corners

                             //CALIB_CB_FAST_CHECK saves a lot of time on images
                             //that do not contain any chessboard corners
    bool patternfound = findChessboardCorners(gray, patternsize, corners,

    drawChessboardCorners(img, patternsize, Mat(corners), patternfound);

    imshow("result", img);
edit flag offensive delete link more


Thanks @sturkmen: Actually I got the patternsize correct. On the large set of calibration images, before the preprocessing I indicated, findchessboardcorners fails on some of them. After preprocessing, findchessboard corners fails on all of them.

I'm confused, because I thought preprocessing would help the algorithm to perform better

kevinkayaks gravatar imagekevinkayaks ( 2018-07-23 21:07:22 -0500 )edit

Actually internally the algorithm does something similar, so you are now rerunning the edge filtering on top of the already filtered image, which screws stuff up. Also, the find chessboard pattern corners functionality is not coping with a small black edge around the white squares. Notice that this is gone in the examples.

StevenPuttemans gravatar imageStevenPuttemans ( 2018-07-24 03:56:56 -0500 )edit

answered 2020-08-21 15:29:39 -0500

I was also having trouble getting findchessboardcorners to work, but when I removed the black border from my calibration target, it worked perfectly. When we think of a chessboard, we tend to imagine one with a dark border, but for OpenCV to find the targets properly, the border around the chessboard needs to be white.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2018-07-23 14:04:04 -0500

Seen: 1,646 times

Last updated: Jul 23 '18