Change language

Translating Images Using OpenCV | python

| | |

Below is the Python code for translating images:

import cv2

import numpy as np

 

image = cv2.imread ( ’C: gfg tomatoes.jpg’ )

 
# Store image height and width

height, width = image.shape [: 2 ]

 

quarter_height, quarter_width = height / 4 , width / 4

 

T = np.float32 ([[ 1 , 0 , quarter_width ], [ 0 , 1 , quarter_height]])

 
# We use warpAffine to transformations
# image using matrix, T

img_translation = cv2.warpAffine (image, T, (width, height))

  

cv2.imshow ( "Originalimage" , image)

cv2.imshow ( ’Translation’ , img_translation)

cv2.waitKey ()

  
cv2.destroyAllWindows ()

Output:

Benefits / Uses of Image Translation:

  • Hiding Part of an Image
  • Cropping an Image
  • Shifting an Image
  • Animate an image using cyclic image translations.