Image Translation using OpenCV | Python
Translation refers to the rectilinear shift of an object i.e. an image from one location to another. If we know the amount of shift in horizontal and the vertical direction, say (tx, ty) then we can make a transformation matrix e.g.
where tx denotes the shift along the x-axis and ty denotes shift along the y-axis i.e. the number of pixels by which we need to shift about in that direction.
Now, we can use the
cv2.wrapAffine() function to implement these translations. This function requires a 2×3 array. The numpy array should be of float type.
Below is the Python code for Image Translation:
numpy as np
, quarter_width], [
cv2.warpAffine(image, T, (width, height))
Advantages/application of image translation are:
- Hiding a part of the image
- Cropping an image
- Shifting an image
- Animating an image using image translations in loop.
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses
are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!