Camera Calibration w/ Checkerboard not working

Hi there!

I’m testing camera calibration using an iPhone UW camera. I take a video and slice it into 1s frequency frames. After that I feed it through the standard OpenCV camera checkerboard finder code.

#!/usr/bin/env python


import cv2
import numpy as np
import os
import glob

# Defining the dimensions of checkerboard
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 0.001)

# 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 = [] 

# 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
print('Loading images')
images = glob.glob('./images/*.jpg')
for fname in images:
    print(f'Processing {fname}')
    img = cv2.imread(fname)
    gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
    # Find the chess board corners
    # If desired number of corners are found in the image then ret = true
    ret, corners = cv2.findChessboardCorners(gray, CHECKERBOARD, cv2.CALIB_CB_ADAPTIVE_THRESH + cv2.CALIB_CB_FAST_CHECK +

    If desired number of corner are detected,
    we refine the pixel coordinates and display 
    them on the images of checker board
    if ret == True:
        print('Checkerboard found!')
        # refining pixel coordinates for given 2d points.
        corners2 = cv2.cornerSubPix(gray, corners, (11,11),(-1,-1), criteria)

        # Draw and display the corners
        img = cv2.drawChessboardCorners(img, CHECKERBOARD, corners2, ret)
        print(f'Not Found in {fname}')


h,w = img.shape[:2]

Performing camera calibration by 
passing the value of known 3D points (objpoints)
and corresponding pixel coordinates of the 
detected corners (imgpoints)
ret, mtx, dist, rvecs, tvecs = cv2.calibrateCamera(objpoints, imgpoints, gray.shape[::-1], None, None)

print("Camera matrix : \n")
print("dist : \n")
print("rvecs : \n")
print("tvecs : \n")

The expected result is that the intrinsics generate.
My result is the checkerboard is never found.

Here are some example images:

I have photos from all angles with the same results. Any suggestions or points of where I am going wrong?


try 7x7

Thanks for your suggestion! Unfortunately, no luck with (7, 7)

it’s requiring a WHITE quiet zone around the squares. your picture has a BLACK quiet zone.

cv.findChessboardCorners(image=255-im, patternSize=(7,7), ...)

invert your picture.

For camera calibration, you should use this chessboard pattern.