gpt4 book ai didi

python - 在 Python 中使用 OpenCV 对点进行不失真时的错误结果

转载 作者:太空狗 更新时间:2023-10-30 02:04:23 24 4
gpt4 key购买 nike

我在使用 OpenCV 的 Python 绑定(bind)使校准相机拍摄的图像上的点不失真时遇到问题。未失真点的坐标与图像中检测到的原始点完全不同。

这是有问题的调用:

undistorted = cv2.undistortPoints(image_points,
camera_matrix,
distortion_coefficients)

其中 image_points 是检测到的棋盘角的 numpy 数组,由 cv2.findChessboardCorners 返回并重新整形以匹配 cv2.undistortPoints 的尺寸要求, camera_matrixdistortion_coefficientscv2.calibrateCamera 返回。

camera_matrixdistortion_coefficients 在我看来还不错,image_points 也是。尽管如此,distorted 似乎与image_points 没有任何关系。以下是这些值的摘要:

>>> image_points
array([[[ 186.95303345, 163.25502014]],

[[ 209.54478455, 164.62690735]],

[[ 232.26443481, 166.10734558]],

...,

[[ 339.03695679, 385.97784424]],

[[ 339.20108032, 400.38635254]],

[[ 339.13067627, 415.30780029]]], dtype=float32)
>>> undistorted
array([[[-0.19536583, -0.07900728]],

[[-0.16608481, -0.0772614 ]],

[[-0.13660771, -0.07537176]],

...,

[[ 0.00228534, 0.21044853]],

[[ 0.00249786, 0.22910291]],

[[ 0.00240568, 0.24841554]]], dtype=float32)
>>> camera_matrix
array([[ 767.56947802, 0. , 337.27849576],
[ 0. , 767.56947802, 224.04766824],
[ 0. , 0. , 1. ]])
>>> distortion_coefficients
array([[ 0.06993424, -0.32645465, 0. , 0. , -0.04310827]])

我正在使用引用 C 代码,在我进行调用之前一切都匹配。出了什么问题?

最佳答案

我认为您忘记在调用 undistortPoints 时指定新相机矩阵。如果你看the documentation of the function ,它说签名是:

Python: cv.UndistortPoints(src, dst, cameraMatrix, distCoeffs, R=None, P=None) → None

其中 dst 是去畸变后的点数组,“如果 P 是相同的或被省略,那么它包含归一化的点坐标”,意思是在图像投影之前使用校准矩阵。

如果您将 P 设置为您的 cameraMatrix,该函数应该执行您期望的操作。

关于python - 在 Python 中使用 OpenCV 对点进行不失真时的错误结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22027419/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com