1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| import cv2 import numpy as np img = cv2.imread('YT.jpg', 1) cv2.namedWindow("src", cv2.WINDOW_FREERATIO) cv2.imshow('src', img) imgInfo = img.shape height = imgInfo[0] weight = imgInfo[1] matSrc = np.float32([[0, 0], [0, weight-1], [height-1, 0]]) matDst = np.float32([[100, 100], [300, height], [weight-300, 100]]) matAffine = cv2.getAffineTransform(matSrc, matDst)
dst = cv2.warpAffine(img, matAffine, (weight, height)) cv2.namedWindow("dst", cv2.WINDOW_FREERATIO) cv2.imshow('dst', dst) cv2.waitKey(0)
|