OpenCV findHomography 应该 return 一个单位矩阵。为什么它 returning 这些意想不到的单应矩阵?

OpenCV findHomography should return an identity matrix. Why is it instead returning these unexpected homography matrices?

我使用 findHomography 将图像拼接在一起。但是当我用已经完全重叠的图片对其进行测试时,我得到了一些意想不到的结果。我原以为单应性总是一个单位矩阵,而且大多数时候都是这样,但有一次它返回了一个完全不同的矩阵。

我用返回这个意外矩阵的点做了一个简单的例子,我得到了不同的结果,但又不是单位矩阵。

import numpy as np
import cv2

image1_points = np.array([[56., 96.], [56., 219.], [56., 219.], [37., 667.], [56., 720.], [56., 780.], [56., 837.]])
image2_points = np.array([[56., 96.], [56., 219.], [56., 219.], [37., 667.], [56., 720.], [56., 780.], [56., 837.]])

homography, mask = cv2.findHomography(image2_points, image1_points, cv2.RANSAC)
# In stitching.py I get:
#  -23.58183,  -0.00000,  547.67250
# -176.30191, -13.80196, 9872.90692
#   -0.26432,  -0.00000,    1.00000

# Here I get:
#   -2.95431,  -0.00000,   88.10041
#  -28.36051,  -1.38109, 1588.18848
#   -0.04252,  -0.00000,    1.00000

那么,有人可以解释一下这里发生了什么吗?这是错误还是可以解决的特殊情况?

感谢任何帮助!

所以现在我测试了@ZWang 和@Micka 的建议。这是我的问题中提供的代码的更新版本,并添加了注释以供解释。我希望这会帮助一些人!

    import numpy as np
    import cv2
    
    # Original arrays were the problem occurs. There are enough points, but they lack the property to span a plane, wich is needed for finding a homography
    image1_points = np.array([[56., 96.], [56., 219.], [56., 219.], [37., 667.], [56., 720.], [56., 780.], [56., 837.]])
    image2_points = np.array([[56., 96.], [56., 219.], [56., 219.], [37., 667.], [56., 720.], [56., 780.], [56., 837.]])
    
    homography, mask = cv2.findHomography(image2_points, image1_points, cv2.RANSAC)
    print(homography)
    # In stitching.py I get:
    #  -23.58183,  -0.00000,  547.67250
    # -176.30191, -13.80196, 9872.90692
    #   -0.26432,  -0.00000,    1.00000
    
    # Here I get:
    #   -2.95431,  -0.00000,   88.10041
    #  -28.36051,  -1.38109, 1588.18848
    #   -0.04252,  -0.00000,    1.00000

    # No problems as long as there are at least 4 corresponding points and they span a plane!
    image1_points = np.array([[40., 96.], [56., 219.], [37., 667.], [56., 720.]])
    image2_points = np.array([[40., 96.], [56., 219.], [37., 667.], [56., 720.]])

    homography, mask = cv2.findHomography(image2_points, image1_points, cv2.RANSAC)
    print(homography)
    # Now I get the identity matrix that is to be expected:
    # 1.00000, 0.00000, 0.00000
    # 0.00000, 1.00000, 0.00000
    # 0.00000, 0.00000, 1.00000