我正在对OpenCV Function cv2.warpPerspective做一些实验,然后我决定从头开始编写它的代码,以便更好地理解它的流程.尽管我遵循了(希望)每一个理论步骤,但似乎我仍然遗漏了一些东西,我很难理解到底是什么.你能帮帮我吗?
SRC image (left) and True DST Image (right)个
Output of the cv2.warpPerspective overlapped on the True DST个
# Invert the homography SRC->DST to DST->SRC
hinv = np.linalg.inv(h)
src = gray1
dst = np.zeros(gray2.shape)
h, w = src.shape
# Remap back and check the domain
for ox in range(h):
for oy in range(w):
# Backproject from DST to SRC
xw, yw, w = hinv.dot(np.array([ox, oy, 1]).T)
# cv2.INTER_NEAREST
x, y = int(xw/w), int(yw/w)
# Check if it falls in the src domain
c1 = x >= 0 and y < h
c2 = y >= 0 and y < w
if c1 and c2:
dst[x, y] = src[ox, oy]
cv2.imshow(dst + gray2//2)
PS:输出的图像是估计DST和真实DST的重叠,以更好地突出差异.