坐标变换
1获取透视矩阵
def get_Perspective_matrix(src_img, dst_img):
h_src, w_src = src_img.shape[:2]
h_dst, w_dst = dst_img.shape[:2]
src = np.array([
[0, 0],
[w_src, 0],
[w_src, h_src],
[0, h_src],
], dtype="float32")
dst = np.array([
[0, h_dst],
[0, 0],
[w_dst, 0],
[w_dst, h_dst],
], dtype="float32")
M = cv2.getPerspectiveTransform(src, dst)
return M
2由透视矩阵,将原坐标变换成新的坐标
def get_Perspective_matrix(src_img, dst_img):
h_src, w_src = src_img.shape[:2]
h_dst, w_dst = dst_img.shape[:2]
src = np.array([
[0, 0],
[w_src, 0],
[w_src, h_src],
[0, h_src],
], dtype="float32")
dst = np.array([
[0, h_dst],
[0, 0],
[w_dst, 0],
[w_dst, h_dst],
], dtype="float32")
M = cv2.getPerspectiveTransform(src, dst)
return M