仅使用径向畸变校准相机
Calibrate Camera with only radial distortion
我正在尝试 运行 在 python 中使用 opencv 进行相机校准。我正在使用:
cv2.calibrateCamera(objpoints, imgpoints, gray.shape[::-1],None,None)
而且它似乎适用于 5 个失真系数。但是,我想尝试 运行 它没有切向畸变并且可能只有 2 个径向畸变系数。这可能吗?
我找到了答案。
无切向畸变:
ret, mtx, dist, rvecs, tvecs = cv2.calibrateCamera(objpoints, imgpoints, gray.shape[::-1],None, 4,None,None,cv2.CALIB_ZERO_TANGENT_DIST,
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 2e-16))
对于只有 2 个径向失真系数,文档似乎建议使用 4 而不是 5 作为系数的数量。这似乎不起作用。相反,我修复了 k3 参数:
ret, mtx, dist, rvecs, tvecs = cv2.calibrateCamera(objpoints, imgpoints, gray.shape[::-1],None, 4,None,None,cv2.CALIB_ZERO_TANGENT_DIST+cv2.CALIB_FIX_K3,
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 2e-16))
distCoeffs – Output vector of distortion coefficients
of 4, 5, or 8 elements.
CV_CALIB_USE_INTRINSIC_GUESS cameraMatrix contains valid initial
values of fx, fy, cx, cy that are optimized further. Otherwise, (cx,
cy) is initially set to the image center ( imageSize is used), and
focal distances are computed in a least-squares fashion. Note, that if
intrinsic parameters are known, there is no need to use this function
just to estimate extrinsic parameters. Use solvePnP() instead.
CV_CALIB_FIX_K1,...,CV_CALIB_FIX_K6 The corresponding radial
distortion coefficient is not changed during the optimization. If
CV_CALIB_USE_INTRINSIC_GUESS is set, the coefficient from the supplied
distCoeffs matrix is used. Otherwise, it is set to 0.
CV_CALIB_ZERO_TANGENT_DIST Tangential distortion coefficients
are set to zeros and stay zero.
重要:在 Python 中,简历标志不要以 CV_
开头。所以我会从现在开始删除它们。
文档的意思是:
如果你已经一个相机矩阵和畸变系数向量,你可以将它们作为初始值提供给校准,让它从那里猜测(使用 CALIB_USE_INTRINSIC_GUESS
)。您可以使用 CALIB_FIX_K1
,...,CALIB_FIX_K6
标志来提供初始失真向量并使其中的某些组件成为静态的(将始终是提供的值)。
但是: 如果您设置 CALIB_FIX_K1
、CALIB_FIX_K2
、CALIB_FIX_K3
、CALIB_FIX_K4
、CALIB_FIX_K5
或CALIB_FIX_K6
如果不给出初步估计,它们将被设置为零。
请注意,结果 distCoeffs 向量将为:[K1
、K2
、tangential1
、tangential2
、K3
]。 OpenCV 只会在你用 CALIB_RATIONAL_MODEL
.
明确要求时给你 K4、K5 或 K6
因此,如果您不需要切向畸变因子而只需要两个径向畸变因子,您可以提供 flags=CALIB_FIX_K3 + CALIB_ZERO_TANGENT_DIST
。您不需要 distCoeffs
或将其作为 distCoeffs=None
.
传递
success, mtx, distCoeffs, rvecs, tvecs = cv2.calibrateCamera(
objectPoints, imagePoints, (width, height),
flags=CALIB_FIX_K3 + CALIB_ZERO_TANGENT_DIST)
print(distCoeffs)
这将导致像这样的失真向量:
[ 0.10509459 -0.31389323 0. 0. 0. ]
我正在尝试 运行 在 python 中使用 opencv 进行相机校准。我正在使用:
cv2.calibrateCamera(objpoints, imgpoints, gray.shape[::-1],None,None)
而且它似乎适用于 5 个失真系数。但是,我想尝试 运行 它没有切向畸变并且可能只有 2 个径向畸变系数。这可能吗?
我找到了答案。
无切向畸变:
ret, mtx, dist, rvecs, tvecs = cv2.calibrateCamera(objpoints, imgpoints, gray.shape[::-1],None, 4,None,None,cv2.CALIB_ZERO_TANGENT_DIST,
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 2e-16))
对于只有 2 个径向失真系数,文档似乎建议使用 4 而不是 5 作为系数的数量。这似乎不起作用。相反,我修复了 k3 参数:
ret, mtx, dist, rvecs, tvecs = cv2.calibrateCamera(objpoints, imgpoints, gray.shape[::-1],None, 4,None,None,cv2.CALIB_ZERO_TANGENT_DIST+cv2.CALIB_FIX_K3,
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 2e-16))
distCoeffs – Output vector of distortion coefficients
of 4, 5, or 8 elements.
CV_CALIB_USE_INTRINSIC_GUESS cameraMatrix contains valid initial values of fx, fy, cx, cy that are optimized further. Otherwise, (cx, cy) is initially set to the image center ( imageSize is used), and focal distances are computed in a least-squares fashion. Note, that if intrinsic parameters are known, there is no need to use this function just to estimate extrinsic parameters. Use solvePnP() instead.
CV_CALIB_FIX_K1,...,CV_CALIB_FIX_K6 The corresponding radial distortion coefficient is not changed during the optimization. If CV_CALIB_USE_INTRINSIC_GUESS is set, the coefficient from the supplied distCoeffs matrix is used. Otherwise, it is set to 0.
CV_CALIB_ZERO_TANGENT_DIST Tangential distortion coefficients
are set to zeros and stay zero.
重要:在 Python 中,简历标志不要以 CV_
开头。所以我会从现在开始删除它们。
文档的意思是:
如果你已经一个相机矩阵和畸变系数向量,你可以将它们作为初始值提供给校准,让它从那里猜测(使用 CALIB_USE_INTRINSIC_GUESS
)。您可以使用 CALIB_FIX_K1
,...,CALIB_FIX_K6
标志来提供初始失真向量并使其中的某些组件成为静态的(将始终是提供的值)。
但是: 如果您设置 CALIB_FIX_K1
、CALIB_FIX_K2
、CALIB_FIX_K3
、CALIB_FIX_K4
、CALIB_FIX_K5
或CALIB_FIX_K6
如果不给出初步估计,它们将被设置为零。
请注意,结果 distCoeffs 向量将为:[K1
、K2
、tangential1
、tangential2
、K3
]。 OpenCV 只会在你用 CALIB_RATIONAL_MODEL
.
因此,如果您不需要切向畸变因子而只需要两个径向畸变因子,您可以提供 flags=CALIB_FIX_K3 + CALIB_ZERO_TANGENT_DIST
。您不需要 distCoeffs
或将其作为 distCoeffs=None
.
success, mtx, distCoeffs, rvecs, tvecs = cv2.calibrateCamera(
objectPoints, imagePoints, (width, height),
flags=CALIB_FIX_K3 + CALIB_ZERO_TANGENT_DIST)
print(distCoeffs)
这将导致像这样的失真向量:
[ 0.10509459 -0.31389323 0. 0. 0. ]