How does warp Perspective work?
1.warp perspective with cv2
if __name__ == "__main__":
# coordinate: (y,x), left_top, right_rop, left_bottom, right_bottom
src = np.float32([[20.0, 0.0], [20.0 ,315.0], [186.0, 17.2], [181.0, 299.0]])
dst = np.float32([[0.0, 0.0], [0.0, 315.0], [202.0, 7.0], [200.0, 306.0]])
# load image
warp_img = cv2.imread("./my_wide_angle_orig.jpg")
warp_img = cv2.cvtColor(warp_img, cv2.COLOR_BGR2RGB)
print("warp_img: ",warp_img.shape) # (638, 958, 3)
width = int(warp_img.shape[1]/3)
height = int(warp_img.shape[0]/3)
warp_img = cv2.resize(warp_img, (width,height), interpolation=cv2.INTER_LINEAR)
print("warp_img.shape:",warp_img.shape) # (212, 319, 3)
## orig image
plt.subplot(121),
plt.title("warp_img")
plt.imshow(warp_img)
# cv2 warp perspective
cv2_matrix = cv2.getPerspectiveTransform(src, dst)
print("cv2_matrix:\n",cv2_matrix)
cv2_fix_img = cv2.warpPerspective(warp_img, cv2_matrix, (width,height))
plt.subplot(122),
plt.title('cv2_fix_img')
plt.imshow(cv2_fix_img)
plt.show()
2.Implement it in our way
Step1 calculate warp matrix:
my_warp_matrix reshape:
[[ 1.13729359e+00 -8.24289989e-18 -2.27458717e+01]
[-6.10786436e-02 9.69843448e-01 1.22157287e+00]
[-3.44743207e-04 -7.38466280e-05 1.00000000e+00]]
Step2. use the warp matrix to warp perspective
codes are:


