Eggman
Eggman

Reputation: 63

OpenCV camera calibration with chessboard of different colours

A doubt came to my mind this morning: does the findChessboardCorners OpenCV function work with a chessboard of different colours, for example blue? If it's not the case, do you think that a quite straightforward thresholding would do the trick?

Upvotes: 1

Views: 1574

Answers (1)

GPPK
GPPK

Reputation: 6666

You can't pass coloured images to the findChessboardCorners because it only takes a greyscale image as @api55 pointed out in his comment.

You might be worth taking a look at the checkchessboard code provided here

// does a fast check if a chessboard is in the input image. This is a workaround to
// a problem of cvFindChessboardCorners being slow on images with no chessboard
// - src: input binary image
// - size: chessboard size
// Returns 1 if a chessboard can be in this image and findChessboardCorners should be called,
// 0 if there is no chessboard, -1 in case of error
int checkChessboardBinary(const cv::Mat & img, const cv::Size & size)
{
    CV_Assert(img.channels() == 1 && img.depth() == CV_8U);

    Mat white = img.clone();
    Mat black = img.clone();

    int result = 0;
    for ( int erosion_count = 0; erosion_count <= 3; erosion_count++ )
    {
        if ( 1 == result )
            break;

        if ( 0 != erosion_count ) // first iteration keeps original images
        {
            erode(white, white, Mat(), Point(-1, -1), 1);
            dilate(black, black, Mat(), Point(-1, -1), 1);
        }

        vector<pair<float, int> > quads;
        fillQuads(white, black, 128, 128, quads);
        if (checkQuads(quads, size))
            result = 1;
    }
    return result;
}

With the main loop being:

CV_IMPL
int cvFindChessboardCorners( const void* arr, CvSize pattern_size,
                             CvPoint2D32f* out_corners, int* out_corner_count,
                             int flags )

is the main implementation of this method. In here they

  1. Use cvCheckChessboard to determine if a chessboard is in the image
  2. Convert to binary (B&W) and dilate to split the corners apart Use
  3. icvGenerateQuads to find the squares.

So in answer to your question, as long as there is sufficient contrast in your image after you convert it to greyscale it will likely work, I would imagine a greyscaled blue and white image would be good enough, if it was a light aqua or yellow or something you might struggle without more processing

Upvotes: 1

Related Questions