Ask Your Question

Revision history [back]

findChessboardCornersSB irregular behavior

I am testing findChessboardCornersSB as an alternative to **findChessboardCorners', mainly to be able to use a calibration target which may overlap the image boundaries. While it works like expected in many cases, I always encounter strange detection misses and spurious detections: image description

and:

image description

even if I ignore the missed points in between, I would have no idea how to associate the detected points with their world coordinates.

Am I doing something wrong, or is findChessboardCornersSB unstable?

Here's the code:

import cv2
import numpy as np
import os
import glob

# Defining the dimensions of checkerboard
CHECKERBOARD = (5, 5)
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 500, 0.0001)

# Creating vector to store vectors of 3D points for each checkerboard image
objpoints = []
# Creating vector to store vectors of 2D points for each checkerboard image
imgpoints = []

colortable = [(255, 100, 100), (100, 255, 100), (100, 100, 255)]

# Defining the world coordinates for 3D points
objp = np.zeros((1, CHECKERBOARD[0] * CHECKERBOARD[1], 3), np.float32)
objp[0, :, :2] = np.mgrid[0:CHECKERBOARD[0], 0:CHECKERBOARD[1]].T.reshape(-1, 2)
prev_img_shape = None

# Extracting path of individual image stored in a given directory
images = glob.glob('./square/*.png')
for fname in images:
    img = cv2.imread(fname)
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    ret, corners, meta = cv2.findChessboardCornersSBWithMeta(img, CHECKERBOARD,
                                                             cv2.CALIB_CB_LARGER )

    if ret == True:
        objpoints.append(objp)
        imgpoints.append(corners)

        # Draw and display the corners
        cv2.convertScaleAbs(img, img, 0.4, 0.0)
        for corner, m in zip(corners, meta.ravel()):
            color = colortable[m]
            cv2.drawMarker( img, (corner[0][0], corner[0][1]), color, cv2.MARKER_CROSS, 30, 3)
    else:
        print("not found")

    cv2.imshow('img',cv2.resize(img, (0, 0), None, 0.5, 0.5))
    if (cv2.waitKey(0) == 27):
        break;

cv2.destroyAllWindows()