January 2018
Intermediate to advanced
268 pages
6h 20m
English
In this section, we will discuss shifting an image. Let's say we want to move the image within our frame of reference. In computer vision terminology, this is referred to as translation. Let's go ahead and see how we can do that:
import cv2import numpy as npimg = cv2.imread('images/input.jpg')num_rows, num_cols = img.shape[:2]translation_matrix = np.float32([ [1,0,70], [0,1,110] ])img_translation = cv2.warpAffine(img, translation_matrix, (num_cols, num_rows), cv2.INTER_LINEAR)cv2.imshow('Translation', img_translation)cv2.waitKey()
If you run the preceding code, you will see something like the following:

Read now
Unlock full access