What does cvFindChessboardCorners want?


cvCheckChessboard asks for IplImage* src and cvFindChessboardCorners asks for const void* image.

I have been successful with cvCheckChessboard but what exactly do I pass to cvFindChessboardCorners?

of 007, Xcode 4.1.2

thanks in advance, don

cvFindChessboardCorners also takes an IplImage*

i’m not really sure why it’s a void*. in practice, void* means “a pointer to anything”. this is used when you have multiple things you might be pointing to. but in this case, i’m pretty sure only IplImage* is valid.

thanks for the quick reply.

yes, i figured that it was a pointer to anything and did use an IplImage*. things worked for cvCheckChessBoard but not cvFindChessboardCorners. i am able to get cvCheckChessBoard to return 1 but not cvFindChessboardCorners

	if (vidGrabber.isFrameNew()){  
		int totalPixels = camWidth*camHeight*3;  
		pixels = vidGrabber.getPixels();  
        int r,j = 0; // convert to BW  
		for (int i = 0; i < totalPixels/3; i++){  
            r = 0;  
            for (j = 0; j < 3; j++) {  
                r += pixels[i*3+j];  
			videoBW[i] = r/3;  
		videoTexture.loadData(videoBW, camWidth, camHeight, GL_LUMINANCE);  
    cv::Mat img = cv::Mat(camHeight, camWidth, CV_8UC3, pixels);  
    cv::Mat imgBW = cv::Mat(camHeight, camWidth, CV_8UC1, videoBW);  
    IplImage * colourimagetocheck = new IplImage(img);  
    IplImage * BWimagetocheck = new IplImage(imgBW);  
    // Skip every board_dt frames to allow user to move chessboard  
    if( frame++ % board_dt == 0 ){  
        quickcheck = cvCheckChessboard(BWimagetocheck, board_sz);  
        foundchessboard = cvFindChessboardCorners(colourimagetocheck, board_sz, corners, &corner_count, CV_CALIB_CB_ADAPTIVE_THRESH +CV_CALIB_CB_NORMALIZE_IMAGE + CV_CALIB_CB_FILTER_QUADS);  

first, i would try sending the cvFindChessboardCorners function your bw image instead of your color image. technically, it should be able to take both – but if you have the bw image already you might as well use it.

i would also try a different collection of flags. maybe remove CV_CALIB_CB_NORMALIZE_IMAGE. i’ve found that CV_CALIB_CB_NORMALIZE_IMAGE can make it impossible to detect chessboards in some cases.

finally, you might try using the opencv2 interface instead, cv::findChessboardCorners. this wouldn’t be why your code is broken – i would just encourage you to use the C++ interface instead of the C one when possible.

I’ve been having trouble with the same thing only I was using kyle’s ofxcv addon. The calibration example just never finds a chessboard no matter how clear the damn thing is. To troubleshoot I tried using straight opencv calls from within the of app, and also tried don’s code, but no dice.

I’m kind of at a loss. I need to do some camera calibration and findchessboardcorners seems made to order but it just doesn’t seem to work and I’m not sure how to debug from here. Anyone got any ideas? (tried all the obvious stuff, different chessboards, different calibration flags, making sure kyle’s calibration thing had the right dimensions etc)

of 007 vs 2010

are you getting any info in the console? i mean, are there any error messages? could you also try different lighting, maybe using lighting in a similar position as your camera and in an environment where the background is not cluttered? also, if you can post any screenshots of example-calibration/ running but not detecting the chessboard, that would be helpful.

Thanks man. I’ve tried a variety of chessboards, lights and surfaces from printouts to projections to this smartphone, everything gives the same error. Here’s the log:

***** VIDEOINPUT LIBRARY - 0.1995 - TFW07 *****  
OF: OF_LOG_WARNING: ofBaseVideoGrabber::setPixelFormat not implemented  
SETUP: Setting up device 0  
SETUP: BisonCam, NB Pro  
SETUP: Couldn't find preview pin using SmartTee  
SETUP: Default Format is set to 640 by 480  
SETUP: trying format RGB24 @ 640 by 480  
SETUP: trying format RGB32 @ 640 by 480  
SETUP: trying format RGB555 @ 640 by 480  
SETUP: trying format RGB565 @ 640 by 480  
SETUP: trying format YUY2 @ 640 by 480  
SETUP: Capture callback set  
SETUP: Device is setup and ready to capture.  
OF: OF_LOG_ERROR: Calibration::add() failed, maybe your patternSize is wrong or  
the image has poor lighting?  
OF: OF_LOG_ERROR: Calibration::add() failed, maybe your patternSize is wrong or  
the image has poor lighting?  
OF: OF_LOG_ERROR: Calibration::add() failed, maybe your patternSize is wrong or  
the image has poor lighting?  

And here’s-the-screenie of example-calibration running. The original need for this thing was to calibrate a chessboard projected onto a big white wall, so that was about ideal in terms of background clutter and lighting. No dice though.


xCount: 5  
yCount: 4  
squareSize: 2.5  

for this one, obviously i’ve been updating it with different pattern sizes depending on what I’ve been trying, big and small, odd and even numbers of rows etc. debugger says the values are taking.

your chessboard needs a white background, not a black background. you might need to make it smaller in order to give it enough of a border for this.

Finally got a chance to follow this up! Thanks for the ideas but no dice. I had tried a bunch of these on white paper and projected onto a white wall and it didn’t get me very far. Fwiw here’s-the-sample-pdf with white border not being recognized.

Also tried with a couple other cameras and fiddled with lighting and distance for way too long with no luck so I’m wondering if it’s really about the image quality at all.

I’ll try building it in linux and just see if it’s a platform thing.


this is what solved it for me: in the Calibration constructor you see this code:

Calibration::Calibration() :
patternSize(cv::Size(10, 7)), squareSize(2.5), // based on Chessboard_A4.pdf, assuming world units are centimeters
reprojectionError(0) {


… this seems to imply that there are 10 squares on the long side and 7 squares on the short side. That also corresponds to the OpenCV calibration pattern I printed out some time ago. HOWEVER, OpenCV does not want the number of squares in the initialization, but the number of inner corners.

So when I changed the patternSize initialization to

patternSize(cv::Size(9, 6)), squareSize(2.5), // based on Chessboard_A4.pdf, assuming world units are centimeters

it worked.

Perhaps the standard calibration pattern was changed size the time that Kyle developed his code. Otherwise it wouldn’t have worked for him either, and it obviously did. Quite a sneaky problem this was.



I changed the patternSize initialization to patternSize(cv::Size(9, 6)), but still not work. Where I am wrong?

windows 8, vs2010, of_v0.8.4


Sorry, it is vs2012. How can I do?

Hi Don,

How did you get to use the cvCheckChessboard? I have ofxOpenCv added, but I can’t seem to be able to include #include "opencv2/calib3d/calib3d_c.h", which, from what I read, is where cvCheckChessboard is located.


Hey Sarah, I think if you just #include “ofxOpenCv.h” you should be able to call cv::cvCheckChessboard(). Also Kyle McDonald’s ofxCv is another wonderful addon for using openCV with oF.

1 Like

Thank you @TimChi! That worked.

I am trying to install ofxCv now, but I’m getting 324 errors trying to compile it.

I have made this post about it, maybe you have seen this error before?