【问题标题】:How to get the rotation angle from findHomography?如何从 findHomography 中获取旋转角度?
【发布时间】:2019-10-24 10:07:17
【问题描述】:

我想在不使用cv2.warpPerspective() 的情况下旋转图像。如何从cv2.findHomography()函数输出中获取角度?

It didn't help

# Find homography
H, mask = cv2.findHomography(points1, points2, cv2.RANSAC)

# for example my H:
array([[ 1.20001976e-01,  5.19205433e-04, -1.21739638e+01],
       [ 1.51272694e-03,  1.18686196e-01, -1.59772594e+01],
       [ 1.98308723e-06, -1.18197608e-07,  1.00000000e+00]])

# What should be the someFunction function?
angle = someFunction(H) # from 0 to 360

rotated = imutils.rotate(image, angle=angle)

【问题讨论】:

标签: python opencv math geometry homography


【解决方案1】:

如果两组点之间的变换是缩放 + 旋转 + 平移,那么单应性将只是一个仿射矩阵,其中 2x2 左上块是缩放旋转。在这种情况下,使用以下方法计算角度:

angle = math.atan2(H[1,0], H[0,0])

如果某些其他类型的变换可以潜入(剪切、投影),则首先执行 2x2 左上块的 SVD 分解以恢复旋转会更安全:

u, _, vh = numpy.linalg.svd(H[0:2, 0:2])
R = u @ vh
angle = math.atan2(R[1,0], R[0,0])

【讨论】:

    猜你喜欢
    • 2020-05-15
    • 1970-01-01
    • 1970-01-01
    • 2022-12-09
    • 2010-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多