import cv2
import numpy as np
img_path = 'C:/Users/WZChan/Desktop/'
img = cv2.imread(img_path + 'Eason.jpg')
M_crop_Eason = np.array([
[1.6, 0, -150],
[0, 1.6, -240]
], dtype=np.float32)
img_Eason = cv2.warpAffine(img, M_crop_Eason, (350, 600))
cv2.imwrite(img_path + 'crop_Eason.jpg', img_Eason)
theta = 15 * np.pi / 180
M_shear = np.array([
[1, np.tan(theta), 0],
[0, 1, 0]
], dtype=np.float32)
img_sheard = cv2.warpAffine(img, M_shear, (350, 600))
cv2.imwrite(img_path + 'sheard_Eason.jpg', img_sheard)
M_rotate = np.array([
[np.cos(theta), -np.sin(theta), 0],
[np.sin(theta), np.cos(theta), 0]
], dtype=np.float32)
img_rotated = cv2.warpAffine(img, M_rotate, (350, 600))
cv2.imwrite(img_path + 'img_rotated.jpg', img_rotated)
M = np.array([
[1, 1.5, -400],
[0.5, 2, -100]
], dtype=np.float32)
img_transformed = cv2.warpAffine(img, M, (350, 600))
cv2.imwrite(img_path + 'img_transfromed.jpg', img_transformed)
crop_Eason.jpg
crop_Eason.jpg
img_rotated.jpg
img_transfromed.jpg