单应性变换的目标是通过给定的几个点(通常是4对点)来得到单应性矩阵。推导https://download.csdn.net/download/qq_27481087/20065885
import numpy as np
fp = np.array([[188, 261, 587, 542],
[124, 308, 266, 65]])
tp = np.array([[0, 0, 640, 640],
[0, 640, 480, 0]])
nbr_correspondences = fp.shape[1]
print(nbr_correspondences)
A = np.zeros((2 * nbr_correspondences, 9))
print(A)
for i in range(nbr_correspondences):
A[2 * i] = [-fp[0][i], -fp[1][i], -1, 0, 0, 0,
tp[0][i] * fp[0][i], tp[0][i] * fp[1][i], tp[0][i]]
A[2 * i + 1] = [0, 0, 0, -fp[0][i], -fp[1][i], -1,
tp[1][i] * fp[0][i], tp[1][i] * fp[1][i], tp[1][i]]
U, S, V = np.linalg.svd(A)
H = V[8].reshape((3, 3))
print(H)