写文章不易,如果您觉得此文对您有所帮助,请帮忙点赞、评论、收藏,感谢您!
一. 仿射变换介绍:
二. 仿射变换 公式:
仿射变换过程,(x,y)表示原图像中的坐标,(x',y')表示目标图像的坐标 ↑
三. 仿射变换——图像平移 算法:
仿射变换—图像平移算法,其中tx为在横轴上移动的距离,ty为在纵轴上移动的距离 ↑
四. python实现仿射变换——图像平移
import cv2
import numpy as np
# 图像仿射变换->图像平移
def affine(img, a, b, c, d, tx, ty):
H, W, C = img.shape
# temporary image
tem = img.copy()
img = np.zeros((H+2, W+2, C), dtype=np.float32)
img[1:H+1, 1:W+1] = tem
# get new image shape
H_new = np.round(H * d).astype(np.int)
W_new = np.round(W * a).as