gpt4 book ai didi

python - 带有 Python 错误结果的 OpenCV (cv2) 中的 undistortPoints

转载 作者:太空宇宙 更新时间:2023-11-03 22:54:43 25 4
gpt4 key购买 nike

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

(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 ( http://docs.opencv.org/modules/imgproc/doc/geometric_transformations.html) 的 undistortPoints 文档,但找不到 cv2 的文档。

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

输入(点矩阵):

[[[    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)

关于python - 带有 Python 错误结果的 OpenCV (cv2) 中的 undistortPoints,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33040362/

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