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

这是违规的电话:

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

在哪里 image_points 是由返回的检测到的棋盘角的 numpy 数组 cv2.findChessboardCorners 并重新塑造以符合尺寸要求 cv2.undistortPoints, , 和 camera_matrixdistortion_coefficients 被返回 cv2.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. 。如果你看 函数的文档, ,它说签名是:

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

在哪里 dst 是未失真后的点数组,并且“如果 P 是恒等或省略,则它包含归一化点坐标”,意思是在使用校准矩阵投影到图像之前。

如果您设置,该函数应该执行您期望的操作 P 给你的 cameraMatrix.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top