1. 畸变模型采用
K = np.array([[6.2597563231075685e+02, 0., 1.1601088601848592e+03],[0., 6.2525998102575511e+02, 1.1634786618991664e+03],[0., 0., 1.]])
2. 直接使用
initUndistortRectifyMap和remap时注意调节视野的大小,为了方便得到想要的大小需要借助
estimateNewCameraMatrixForUndistortRectify
参数
fov_scale=1.0时,调整后的新的内参如下:
[[1.02625557e+02 0.00000000e+00 1.16010886e+03], [0.00000000e+00 1.02508230e+02 1.16347352e+03], [0.00000000e+00 0.00000000e+00 1.00000000e+00]]
f/f_new=6.2597563231075685e+02/1.02625557e+02=6.0996076475449175881208615510852
fov_scale=0.5时,调整后的新的内参如下:
[[2.05251114e+02 0.00000000e+00 1.16121771e+03], [0.00000000e+00 2.05016460e+02 1.16794704e+03], [0.00000000e+00 0.00000000e+00 1.00000000e+00]]
fov_scale=0.2时,调整后的新的内参如下:
[[5.13127786e+02 0.00000000e+00 1.16454428e+03], [0.00000000e+00 5.12541149e+02 1.18136761e+03], [0.00000000e+00 0.00000000e+00 1.00000000e+00]]
3. 完整代码如下:
K = np.array([[6.2597563231075685e+02, 0., 1.1601088601848592e+03],[0., 6.2525998102575511e+02, 1.1634786618991664e+03],[0., 0., 1.]])D = np.array([[0.069],[-2.24e-03],[-0.01487],[3.78e-03]])img = cv2.imread("D:/ISP/FourFisheyeLensStitching/images/ENCMFUR/square.png")imgHeight, imgWidth, imgDeep = img.shape# new_K = cv2.fisheye.estimateNewCameraMatrixForUndistortRectify(K, D, (1280, 720), np.eye(3), balance=1)# map1, map2 = cv2.fisheye.initUndistortRectifyMap(K, D, np.eye(3), new_K, (1280, 720), cv2.CV_16SC2)# undistorted_img = cv2.remap(img, map1, map2, interpolation=cv2.INTER_CUBIC, borderMode=cv2.BORDER_CONSTANT)# new_K = cv2.fisheye.estimateNewCameraMatrixForUndistortRectify(K, D, (1280, 720), np.eye(3), balance=1,# new_size=(3400, 1912), fov_scale=1)# map1, map2 = cv2.fisheye.initUndistortRectifyMap(K, D, np.eye(3), new_K, (3400, 1912), cv2.CV_16SC2)# undistorted_img = cv2.remap(img, map1[575:1295, 23:3119, :], map2[575:1295, 23:3119],# interpolation=cv2.INTER_LINEAR, borderMode=cv2.BORDER_CONSTANT)new_K = cv2.fisheye.estimateNewCameraMatrixForUndistortRectify(K, D, (imgWidth, imgHeight), np.eye(3), balance=1.0,new_size=(imgWidth, imgHeight), fov_scale=1.0)map1, map2 = cv2.fisheye.initUndistortRectifyMap(K, D, np.eye(3), new_K, (imgWidth, imgHeight), cv2.CV_16SC2)undistorted_img = cv2.remap(img, map1, map2,interpolation=cv2.INTER_LINEAR, borderMode=cv2.BORDER_CONSTANT)cv2.imwrite('D:/ISP/FourFisheyeLensStitching/images/ENCMFUR/undistorted_square_balance_1.0_fov_scale_1.0.png', undistorted_img)