美文网首页
图像仿射变换 — OpenCV& Python

图像仿射变换 — OpenCV& Python

作者: WZChan | 来源:发表于2017-10-09 16:48 被阅读0次
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

相关文章

网友评论

      本文标题:图像仿射变换 — OpenCV& Python

      本文链接:https://www.haomeiwen.com/subject/bbrpyxtx.html