For geometric transformation, OpenCV provides the wrapAffine() function, which takes the image, transformation matrix, and dimension of the image as input. The transformation matrix for the translation is as follows:
Here, (tx, ty) tells us the amount of shift in the image. For example, the following code shifts the image by (100,100):
>>> import cv2>>> import numpy as np>>> img = cv2.imread("image.jpg")>>> r,c = img.shape[:2]>>> M = np.float32([[1,0,100],[0,1,100]])>>> new_img = cv2.warpAffine(img,M,(c,r))>>> cv2.imwrite("translation.jpg", new_img)>>> cv2.imshow("translation", new_img)
The following figure is the output of the ...