【发布时间】:2020-07-23 15:38:33
【问题描述】:
信息:
我已经校准了我的相机,发现相机的内在矩阵 (K) 及其失真系数 (d) 如下:
import numpy as np
K = np.asarray([[556.3834638575809,0,955.3259939726225],[0,556.2366649196925,547.3011305411478],[0,0,1]])
d = np.asarray([[-0.05165940570900624],[0.0031093602070252167],[-0.0034036648250202746],[0.0003390345044343793]])
从这里,我可以使用以下三行来消除我的图像失真:
final_K = cv2.fisheye.estimateNewCameraMatrixForUndistortRectify(K, d, (1920, 1080), np.eye(3), balance=1.0)
map_1, map_2 = cv2.fisheye.initUndistortRectifyMap(K, d, np.eye(3), final_K, (1920, 1080), cv2.CV_32FC1)
undistorted_image = cv2.remap(image, map_1, map_2, interpolation=cv2.INTER_LINEAR, borderMode=cv2.BORDER_CONSTANT)
生成的未失真图像似乎是正确的Left image is distorted, right is undistorted,但是当我尝试使用cv2.remap() 对图像点进行非失真处理时,点并没有映射到与图像中相应像素相同的位置。我使用
ret, corners = cv2.findChessboardCorners(gray, (6,8),cv2.CALIB_CB_ADAPTIVE_THRESH+cv2.CALIB_CB_FAST_CHECK+cv2.CALIB_CB_NORMALIZE_IMAGE)
corners2 = cv2.cornerSubPix(gray, corners, (3,3), (-1,-1), (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 0.1))
然后以下列方式重新映射这些点:
remapped_points = []
for corner in corners2:
remapped_points.append(
(map_1[int(corner[0][1]), int(corner[0][0])], map_2[int(corner[0][1]), int(corner[0][0])])
)
In these horizontally concatenated images,左图显示在失真图像中检测到的点,而右图显示右图中点的重新映射位置。
另外,我无法使用cv2.fisheye.undistortPoints() 获得正确的结果。我有以下功能来不扭曲点:
def undistort_list_of_points(point_list, in_K, in_d):
K = np.asarray(in_K)
d = np.asarray(in_d)
# Input can be list of bbox coords, poly coords, etc.
# TODO -- Check if point behind camera?
points_2d = np.asarray(point_list)
points_2d = points_2d[:, 0:2].astype('float32')
points2d_undist = np.empty_like(points_2d)
points_2d = np.expand_dims(points_2d, axis=1)
result = np.squeeze(cv2.fisheye.undistortPoints(points_2d, K, d))
fx = K[0, 0]
fy = K[1, 1]
cx = K[0, 2]
cy = K[1, 2]
for i, (px, py) in enumerate(result):
points2d_undist[i, 0] = px * fx + cx
points2d_undist[i, 1] = py * fy + cy
return points2d_undist
This image 显示使用上述函数不失真时的结果。
(这一切都在 Python 3.6.8 的 Ubuntu 18.04 上的 OpenCV 4.2.0 中运行)
问题
为什么图像坐标的重新映射不能正常工作?我是否错误地使用了map_1 和map_2?
为什么使用cv2.fisheye.undistortPoints() 的结果与使用map_1 和map_2 的结果不同?
【问题讨论】:
标签: python opencv camera-calibration calibration fisheye