【发布时间】:2018-12-09 07:42:46
【问题描述】:
我正在尝试用浅黄色多边形替换下图右侧的道路:
所以我正在考虑使用 Homography 来实现它(我知道添加一个填充的多边形也可以,但我可能想使用一些其他源图像而不是简单的黄色多边形,例如未来的广告图片)。 这是一个关于它的tutorial,我只是复制其中的代码并对像素进行了一些更改。我使用的源图片是这样的:
这篇文章中的第一张图片是我的目标图片。
这是我完成这项工作的代码:
import cv2
import numpy as np
# source image
source_img = cv2.imread('lightyellow.jpg')
# get four corners of the source (clock wise)
pts_source = np.array([[0,0], [20,0], [20,30],[0,30]])
# destination image
dst_img = cv2.imread('0.png')
# four corners in destination image (also clock wise):
pts_dst = np.array([[292,0], [415,0], [578,120],[415,189]])
# calculate homography
h, status = cv2.findHomography(pts_source, pts_dst)
# warp source image to destination based on homography
img_out = cv2.warpPerspective(source_img, h, (dst_img.shape[1], dst_img.shape[0]))
cv2.imshow('warped', img_out)
cv2.waitKey(0)
但是,我得到的是这样的:
这是完全错误的,但我不知道为什么。有人可以给我一些指导吗?
【问题讨论】:
标签: python opencv projection perspective homography