Affine Transform in geometry means a linear transformation of one vector space, followed by a translation of another.
img = cv2.imread(img_path)
points = get_points(img)
origin_points = np.float32(points)
trans_points = np.float32([[65, 90, 1], [95, 90, 1], [80, 120, 1]])
a = np.dot(f,g.T)
b = inv(np.dot(g, g.T))
M = np.dot(a,b)
new_img = np.zeros((190, 160, 3))
for i in range(new_img.shape[0]):
for j in range(new_img.shape[1]):
new_pixel = np.float32([j, i, 1]).reshape(-1,1)
original_pixel=np.dot(M, new_pixel)
# turn negative numbers into 0
original_pixel = np.where(original_pixel>0, original_pixel, 0)
# Corresponding back to the original picture pixel
new_img[i, j] = img[int(original_pixel[1]), int(original_pixel[0])]
cv2.imwrite(save_path, new_img)
- original image/processed image