通过组合矩阵进行的仿射变换:
import cv2
import numpy as np
# 三点决定仿射后的新的三个位置
img = cv2.imread('face.jpg', 1)
cv2.imshow('src', img)
imgInfo = img.shape
height = imgInfo[0]
width = imgInfo[1]
# 左上 左下 右上
matSrc = np.float32([[0, 0], [0, height - 1], [width - 1, 0]])
matDst = np.float32([[50, 50], [300, height - 200], [width - 300, 100]])
# 组合矩阵
matAffine = cv2.getAffineTransform(matSrc, matDst)
# 仿射变换: img, matAffine, info
dst = cv2.warpAffine(img, matAffine, (height, width))
cv2.imshow('dst', dst)
cv2.waitKey(0)
结果如下:
image.png
网友评论