Image Translation
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. Now, we can use the cv2.wrapAffine() function to implement the translations. This function requires a 2×3 array. The numpy array should be of float type.
Example: Python OpenCV Image Translation
Python3
import cv2 import numpy as np image = cv2.imread( 'geeks.png' ) # Store height and width of the image 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 transform # the image using the matrix, T img_translation = cv2.warpAffine(image, T, (width, height)) cv2.imshow( 'Translation' , img_translation) cv2.waitKey( 0 ) cv2.destroyAllWindows() |
Output:
Getting Started with Python OpenCV
Computer Vision is one of the techniques from which we can understand images and videos and can extract information from them. It is a subset of artificial intelligence that collects information from digital images or videos.
Python OpenCV is the most popular computer vision library. By using it, one can process images and videos to identify objects, faces, or even handwriting of a human. When it is integrated with various libraries, such as NumPy, python is capable of processing the OpenCV array structure for analysis.
In this article, we will discuss Python OpenCV in detail along with some common operations like resizing, cropping, reading, saving images, etc with the help of good examples.