0

I'm trying to calibrate a Leap Moion device via OpenCV's calibration libraries and a chessboard pattern, but it is not finding the chessboard corners.

I'm using a 9x6 chessboard pattern printed on a DIN A3 sheet which in turn is mounted on a large white desk. When I take a snapshot of the scene and pass the image directly into OpenCV's findChessboardCorners function, nothing is found. I first thought, this is probably because of the large black vignetting effect in the Leap Motion's raw images. I read in the docs that a dark background is bad for the function and it probably won't work. So I figured out a way to "correct" this effect programatically, so that the edges get brighter (note: more light in the actual scene doesn't help at all). But it is still not detecting the corners.

Raw image

enter image description here

After vignetting correction

enter image description here

Here is some code

// img is the leap motion's raw image
leapMat.create(240, 640, CV_8UC1);
leapMat.data = const_cast<uchar*>(img.data());

// Vignetting correction
Mat leapMat_vig;
leapMat.copyTo(leapMat_vig);
for (int i = 0; i < leapMat_vig.rows; i++)
{
    for (int j = 0; j < leapMat_vig.cols; j++)
    {
        double u = (double)(i - leapMat_vig.rows / 2) / leapMat_vig.rows;
        double v = (double)(j - leapMat_vig.cols / 2) / leapMat_vig.cols;
        double w = pow(u, 2) + pow(v, 2);
        leapMat_vig.at<uchar>(i, j) += w * 2 * 255;
    }
}

vector<Point2f> foundPoints;

// findChessboardCorners is not detecting my chessboard pattern
const auto found = findChessboardCorners(leapMat_vig, Size(6, 9), foundPoints, CALIB_CB_ADAPTIVE_THRESH + CALIB_CB_NORMALIZE_IMAGE + CALIB_CB_FAST_CHECK);

I also tried zooming in the image a little, but that still does not work.

Does anyone have an idea what I'm doing wrong or what I could improve?

norway_sun
  • 91
  • 2
  • 5

1 Answers1

2

If the colours are causing the trouble, you could try to get rid of the black background by masking it white, leaving only the chessboard area (you might want to look into this question: klick!). Then, some histogram stretching/equalization (me!) would increase the contrast and hopefully solve your problem.

I have done something similar lately in Python where - after increasing the contrast and losing the bad information - it worked like a charm. The note at the end of the doc entry - which you refer to, I think? (please!) - supports this approach.

Alexander Mayer
  • 316
  • 2
  • 11
  • Thanks, for the answer. The histogram equalization helped a lot. However, I needed to add some further image preprocessing like zooming, sharpening and taking a region of interest (ROI). Still, the pattern won't be detected in any scene but only if it is very parallel to the camera lens. – norway_sun Oct 25 '19 at 19:38