将透视变换后的图像坐标转换为源图像坐标

时间:2021-03-19 11:57:55

标签: python numpy opencv cv2

我正在研究线路检测。我对源图像实施透视变换并确定变换图像上的线坐标,但我想要做的是将此坐标转换为我的源图像。欢迎提出任何想法。

源图像 enter image description here

检测到的图像 enter image description here

还有我的转换代码。

def PerspectiveTransform(img):
global inversematrix
# Frame e perspective transform uygulanması.
IMAGE_H = img.shape[0]
IMAGE_W = img.shape[1]
src = np.float32([[170, IMAGE_H], [450, 505], [850, 520], [1040, IMAGE_H]])
dst = np.float32([[400, IMAGE_H], [400, 0], [950, 0],[950, IMAGE_H]])
M = cv2.getPerspectiveTransform(src, dst) # The transformation matrix
Minv = cv2.getPerspectiveTransform(dst, src) # Inverse transformation
inversematrix = Minv
warped_img = cv2.warpPerspective(img, M, (IMAGE_W, IMAGE_H)) # Image warping
return cv2.cvtColor(warped_img, cv2.COLOR_BGR2RGB)

0 个答案:

没有答案