如何旋转和缩放单应性

Gus*_*avo 5 c algorithm math opencv augmented-reality

我需要帮助 ,

我从服务器接收单应性,所以我想将此单应性标准化为我的应用程序的坐标系,当我尝试用坐标表示对象时,服务器应用程序生成接下来的4个点:

收到[96.629539,217.31934; 97.289948,167.21941; 145.69249,168.28044; 145.69638,219.84604]

我的应用程序生成接下来的4点:

当地[126.0098,55.600437; 262.39163,53.98035; 259.41382,195.34763; 121.48138,184.95235]

我用图形表示这一点,R(收到),P(本地)

在此输入图像描述

它看起来像生成的方块旋转和缩放,所以我想知道是否有任何方法将这个旋转应用于服务器单应性,以便能够具有与我的应用程序单应性相同的单应性.

谢谢,我需要更多信息请问我.


非常感谢您的快速答案,最后我使用其他近似,就像从服务器获取点并使用findhomography获得逆单应性一样简单.

homography = findHomography(srcPoints,dstPoints,match_mask,RANSAC,10);

谢谢!!!

mev*_*ron 4

我想我已经明白了这一点。下面是两个单应性的更准确的图。其中蓝色是“收到的”单应性,红色是“本地”单应性。

在此输入图像描述

您可以使用 OpenCV 函数getAffineTransform来计算关联 3 个点对的仿射变换(我必须重新组织点对,因为它们的顺序错误)。我在 numpy 中运行如下:

r = array([[97.289948, 167.21941], [96.629539, 217.31934], [145.69638, 219.84604]], np.float32)
l = array([[126.0098, 55.600437], [121.48138, 184.95235], [259.41382, 195.34763]], np.float32)
A = cv2.getAffineTransform(r, l)
Run Code Online (Sandbox Code Playgroud)

这给我们提供了以下仿射关系:

array([[  2.81385763e+00,  -5.32961421e-02,  -1.38838108e+02],
       [  7.88519054e-02,   2.58291747e+00,  -3.83984986e+02]])
Run Code Online (Sandbox Code Playgroud)

我将其应用回来,r看看是否可以l确保它像这样工作:

# split affine warp into rotation, scale, and/or shear + translation matrix
T = mat(A[:, 2]).T
matrix([[-138.83810801],
        [-383.98498637]])

A = mat(A[:, 0:2])
matrix([[ 2.81385763, -0.05329614],
        [ 0.07885191,  2.58291747]])

# apply warp to r to get l
r = mat(r).T
A*r + T
# gives
matrix([[ 126.00980377,  121.48137665,  259.41381836],
        [  55.60043716,  184.9523468 ,  195.34762573]])
# which equals
l = mat(l).T
matrix([[ 126.00980377,  121.48137665,  259.41381836],
        [  55.60043716,  184.9523468 ,  195.34762573]], dtype=float32)
Run Code Online (Sandbox Code Playgroud)

Markus Jarderot另外值得注意的是,您可以使用 OpenCV 函数getPerspectiveTransform生成透视变换,如图所示。

希望有帮助!