繁体   English   中英

OpenCV(cv2)中的undistortPoints与Python错误结果

[英]undistortPoints in OpenCV (cv2) with Python wrong results

我尝试校正图像和该图像上的一些要点。 纠正图像效果很好(这部分代码不是我提供的):

(mapx, mapy) = cv2.initUndistortRectifyMap(camera_matrix,dist_coefs,np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]]),newCameraMatrix,(int(resolution*w), int(resolution*h)), cv2.CV_32FC1)
RectImg = cv2.remap(img, mapx,mapy,cv2.INTER_LINEAR )

但是,当我使用undistortPoints和相同的参数校正点时,我得到错误的坐标。

point_file = np.loadtxt(fn)
point_matrix = np.zeros(shape=(nr_points,1,2))

# fill Pointfile in n x 1 x 2-Matrix
for each in range(0, nr_points):
    point_matrix[each][0][0] = point_file[each][0]
    point_matrix[each][0][1] = point_file[each][1]

point_matrix_new = cv2.undistortPoints(point_matrix, newCameraMatrix, dist_coefs)

这些是我正在使用的参数(newCameraMatrix和dist_coefs):

    [[  4.93906295e+02   0.00000000e+00   1.24539714e+03]
     [  0.00000000e+00   4.92616567e+02   1.03814593e+03]
     [  0.00000000e+00   0.00000000e+00   1.00000000e+00]]
    [  5.93179211e-01   3.59577119e-02  -3.34062329e-05  -8.92301489e-05
      -5.27895858e-04   9.28762999e-01   1.46636733e-01   0.00000000e+00]

我也不确定实际输出是什么。 结果值是图像坐标还是传感器坐标,并且是哪个单位? 我只能找到cv的undistortPoints文档( http://docs.opencv.org/modules/imgproc/doc/geometric_transformations.html ),而cv2没有。

示例 (图像尺寸= 2448 x 2048像素/传感器尺寸= 8.6 x 6.6毫米

输入(point_matrix):

[[[    0.     0.]]

 [[ 2448.     0.]]

 [[    0.  2048.]]

 [[ 2448.  2048.]]

 [[ 1224.  1024.]]]

输出(point_matrix_new):

[[[-6.49236118 -5.42726306]]

 [[ 6.39989444 -5.5358653 ]]

 [[-6.50237385  5.28935346]]

 [[ 6.58981334  5.54673511]]

 [[-0.04336093 -0.02874159]]]

谢谢您的帮助!

所以我发现了自己的错误:我必须像在cv2.initUndistortRectifyMap中那样在cv2.undistortPoints中使用新旧相机矩阵。

因此,要纠正它,我只使用了以下代码:

point_matrix_new = cv2.undistortPoints(point_matrix,camera_matrix,dist_coefs,P=newCameraMatrix)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM