Rakshit Kothari
Rakshit Kothari

Reputation: 416

Why won't cv.findChessboardCorners work for me?

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

Upvotes: 3

Views: 3813

Answers (3)

Dima
Dima

Reputation: 39389

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

Upvotes: 2

Amro
Amro

Reputation: 124563

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.sstatic.net/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

Upvotes: 2

John1024
John1024

Reputation: 113864

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

Upvotes: 3

Related Questions