优秀的摄影作品网站/互联网营销师培训课程免费
一、什么是仿射变换?
仿射变换代表的是两幅图之间的关系。
1、一个任意的仿射变换都能表示为 乘以一个矩阵 (线性变换) 接着再 加上一个向量 (平移).
2、用仿射变换来处理,旋转 (线性变换),平移 (向量加),缩放操作 (线性变换)
1、仿射变换 - 平移
python实现
import cv2
import numpy as np
import matplotlib.pyplot as plt# Affine
def affine(img, a, b, c, d, tx, ty):H, W, C = img.shape# temporary imageimg = np.zeros((H+2, W+2, C), dtype=np.float32)img[1:H+1, 1:W+1] = _img# get new image shapeH_new = np.round(H * d).astype(np.int)W_new = np.round(W * a).astype(np.int)out = np.zeros((H_new+1, W_new+1, C), dtype=np.float32)# get position of new imagex_new = np.tile(np.arange(W_new), (H_new, 1))y_new = np.arange(H_new).re