Will.Evo
Will.Evo

Reputation: 1177

OpenCV fails to find chess board corners

I am working with an IR camera and am trying to find out if we have any lens distortion. I am using the example from OpenCV here to guide my work. I used a chessboard template from here and attached it to the back of a book. Before taking any images I heated the book/paper and observed that the checkerboard pattern was coming in very clear.

I took ~50 still frames with the chessboard pattern tilted/moved so that every part of the frame contained some part of the pattern. An example of one of my images is below:

example calibration image

I used the following code which resulted in False for every image. I tried every combination of grid pattern sizes from (5-9, 5-9).

import numpy as np
import cv2
import glob2 as glob
import matplotlib.pyplot as plt

base = 'pathtoimages/'
files = glob.glob(base + '*.png')

for file in files:
    img = cv2.imread(file)
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    ret, corners = cv2.findChessboardCorners(gray, (6,8), None)

    print (ret)

I can't figure out why the algorithm is not finding the corners. Any ideas?

Edit May 30, 2019:

Today I took some more images with the camera. I took the photos in a more controlled environment without any external light sources present. These new images still fail the findchessboard corner detection. I tried increasing the contrast and brightness using cv2.convertScaleAbs to produce the following image as an example.

Increased Contrast

This also fails. If I use cv2.goodFeaturesToTrack to find corners I get the following result:

corners

It seems like the Opencv corner detection algorithm is actively avoiding my chess board corners. It will find any corner it can before finding one on the chessboard. I am truly stumped here.

As a sanity check I made sure that openCV can find the corners on the original chessboard I am using and it worked perfectly.

Any ideas?

Edit June 4, 2019:

I ended up writing a script that allows me to manually assign each of the corners. I was able to get the camera distortion model successfully. I still have no solution for why the corners couldn't automatically be found by openCV. I think if I were to do this again in IR, I would make a custom grid that increases the contrast between grid cells simply due to differing thermal properties between "white" and "black" grid cells (use different materials).

Upvotes: 3

Views: 6778

Answers (1)

Ethan Frantz
Ethan Frantz

Reputation: 31

I got findChessboardCorners to work with 2 adjustments.

  1. As said in one of the comments, openCV expects a white boarder around the chessboard. To achieve that you can 'invert' the image, essentially creating the equivalent to a photographic negative. Before I called findChessboardCorners, I did: image_inverted = numpy.array(256 – image_original, dtype=uint8)

  2. Only use the cv2.CALIB_CB_ADAPTIVE_THREASH flag when calling findChessboardCorners. CALIB_CB_FAST_CHECK and CALIB_CB_NORMALIZE_IMAGE flags seem to make findChessboardCorners not find the corners.

Good Luck

Upvotes: 3

Related Questions