def simplePerspectiveTransform(img, quad, shape=None,
interpolation=cv2.INTER_LINEAR,
inverse=False):
p = sortCorners(quad).astype(np.float32)
if shape is not None:
height, width = shape
else:
# get output image size from avg. quad edge length
width = int(round(0.5 * (np.linalg.norm(p[0] - p[1]) +
np.linalg.norm(p[3] - p[2]))))
height = int(round(0.5 * (np.linalg.norm(p[1] - p[2]) +
np.linalg.norm(p[0] - p[3]))))
dst = np.float32([[0, 0],
[width, 0],
[width, height],
[0, height]])
if inverse:
s0, s1 = img.shape[:2]
dst /= ((width / s1), (height / s0))
H = cv2.getPerspectiveTransform(dst, p)
else:
H = cv2.getPerspectiveTransform(p, dst)
return cv2.warpPerspective(img, H, (width, height), flags=interpolation)
simplePerspectiveTransform.py 文件源码
python
阅读 18
收藏 0
点赞 0
评论 0
评论列表
文章目录