I want to correct the distortion image in the fisheye lens. I need to find the camera calibration (K) and distortion factor (D) values, but the K value is calculated and the D value is all zero and not calculated. I tried adding the data and changed the initial D value to a very small value, but the D value keeps coming out to zero.
Is there any other way to solve it?
Hello, here is my code :
import cv2
import numpy as np
import glob
patternSize = (3, 13)
objpoints = []
imgpoints = []
objp = np.zeros((1, patternSize[0] * patternSize[1], 3), np.float32)
objp[0,:,:2] = np.indices(patternSize).T.reshape(-1, 2)
img = cv2.imread('./img_0221/grid/0221095408.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
ret, centers = cv2.findCirclesGrid(img, patternSize, None, cv2.CALIB_CB_ASYMMETRIC_GRID+cv2.CALIB_CB_CLUSTERING)
if ret:
imgpoints.append(centers)
objpoints.append(objp)
K = np.zeros((3, 3))
D = np.zeros((4, 1))
retval, K, D, rvecs, tvecs = cv2.fisheye.calibrate(
objpoints,
imgpoints,
gray.shape[::-1],
K,
D,
None,
None,
cv2.fisheye.CALIB_RECOMPUTE_EXTRINSIC,
(cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 1e-6)
)
print("K:", K)
print("D:", D)
calibration doesn’t work on just a single picture.
I tested with single image and 50 to 80 images. But, i had same problem.