3

The following image is passed on to cv.findChessboardCorners and for reasons I can't understand, it just does not give me the corner locations. The chessboard is quite evident and the white line thickness is quite prominent too.

Do you know why this won't work?

The image size is 960X1280 and the mesh size is [15,11] i.e 15 internal corners per row and 11 internal corners per column.

The output is always an empty matrix. I tried changing the parameters and the function used histogram equalization so I'm assuming the pixel distribution won't be a problem.

Checkerboard image projected on a Wall

Rakshit Kothari
  • 399
  • 1
  • 5
  • 16
  • just note, that your projected chessboard there already looks distorted – berak Dec 16 '13 at 10:29
  • I don't think, to be honest I thought this would be quite a simple case for the algorithm to work on but I guess the door was the problem. Histogram adjustment does it! – Rakshit Kothari Dec 17 '13 at 14:16

3 Answers3

3

I hope that you don't mind an answer in Python, as opposed to matlab. (They use the same openCV library and I hope the correspondence between commands is clear.)

Your image unchanged works fine for me with the code below which finds the corners and displays them with colored points in a window:

#!/usr/bin/python
import cv2.cv as cv
import sys

filename = sys.argv[1]
im = cv.LoadImage(filename, cv.CV_LOAD_IMAGE_GRAYSCALE)
im3 = cv.LoadImage(filename, cv.CV_LOAD_IMAGE_COLOR)
chessboard_dim = (15, 11)
found_all, corners = cv.FindChessboardCorners( im, chessboard_dim )
cv.DrawChessboardCorners( im3, chessboard_dim, corners, found_all )
cv.ShowImage("Chessboard with corners", im3)
cv.WaitKey()

The output image (slightly cropped) looks like:

Checkerboard with corners highlighted

John1024
  • 109,961
  • 14
  • 137
  • 171
  • man! Why is this not working on MATlab?!? Thanks anyway, I ended up adjusting the histogram to increase the contrast and then it worked just fine, but then why doesn't it work for me without the adjustment? – Rakshit Kothari Dec 16 '13 at 03:42
  • @RakshitKothari If it makes any difference, I am using OpenCV version 2.3.1 (Debian Wheezy). – John1024 Dec 16 '13 at 04:06
  • Hmm! I see, well it still isn't working for me though. One of the answers suggest cropping out the door region and it seems it works fine after that. I guess the dark door to lighter wall confused the algorithm. – Rakshit Kothari Dec 17 '13 at 14:15
  • 1
    @RakshitKothari In my experience, it often wants a large white region around the checkerboard. I was surprised that your image worked for me the first time without either increasing the white region or increasing the contrast. The existence of the dark door might have confused it on either account. – John1024 Dec 18 '13 at 00:40
  • 1
    @RakshitKothari Incidentally, here is another example of a problematic checkerboard: http://stackoverflow.com/questions/17993522/opencv-findchessboardcorners-function-is-failing-in-a-apparently-simple-scenar/20187143#20187143 – John1024 Dec 18 '13 at 00:43
2

I tried it in MATLAB using mexopencv (compiled against the latest OpenCV 2.4.7), and I had the same issue where no corners were detected.

Of course the problem was easily solved by cropping the image a little bit to focus more on the board. You will have to apply a consistent processing to all your images sequence, and make sure that the board is included in all of them.

% read grayscale image
img = imread('https://i.stack.imgur.com/5VsOP.jpg');

% crop image to the area of the chessboard
img2 = img(100:600, 200:1000);

% detect corners
c = cv.findChessboardCorners(img2, [15,11]);
if isempty(c), error('no corners found'); end

% show result
out = cv.drawChessboardCorners(repmat(img2,[1 1 3]), [15,11], c);
imshow(out)

corners_detected

Amro
  • 123,847
  • 25
  • 243
  • 454
  • 2
    you might wanna add `c = cv.cornerSubPix(img2, c);` after detection to refine the corners locations using sub-pixel accuracy. – Amro Dec 16 '13 at 17:00
  • Thank you! That means the door on the left was confusing the algorithm. I wonder why? After Histogram adjustment, it worked just fine for me. – Rakshit Kothari Dec 17 '13 at 14:13
2

If you have the Computer Vision System Toolbox, you can use the detectCheckerboardPoints function. It works without any pre-processing, and it gives you sub-pixel accuracy.detected checkerboard

Dima
  • 38,860
  • 14
  • 75
  • 115