March 2019
Intermediate to advanced
532 pages
13h 2m
English
In order to translate an object, you need to create the 2 x 3 transformation matrix by using the NumPy array with float values providing the translation in both the x and y directions in pixels, as shown in the following code:
M = np.float32([[1, 0, x], [0, 1, y]])
This gives the following M transformation matrix:

Once this matrix has been created, the cv2.warpAffine() function is called, as shown in the following code:
dst_image = cv2.warpAffine(image, M, (width, height))
The cv2.warpAffine() function transforms the source image using the M matrix provided. The third (width, height) argument establishes the size of the ...