Basic geometric transformations – OpenCV 3.4 with python 3 Tutorial 12

import cv2
import numpy as np

img = cv2.imread("red_panda.jpg")
rows, cols, ch = img.shape

print("Height: ", rows)
print("Width: ", cols)

scaled_img = cv2.resize(img, None, fx=1/2, fy=1/2)

matrix_t = np.float32([[1, 0, -100], [0, 1, -30]])
translated_img = cv2.warpAffine(img, matrix_t, (cols, rows))

matrix_r = cv2.getRotationMatrix2D((cols/2, rows/2), 90, 0.5)
rotated_img = cv2.warpAffine(img, matrix_r, (cols, rows))

cv2.imshow("Original image", img)
cv2.imshow("Scaled image", scaled_img)
cv2.imshow("Translated image", translated_img)
cv2.imshow("Rotated image", rotated_img)


  1. red_panda.jpg

Learn to build Computer Vision Software easily and efficiently.

This is a FREE Workshop where I'm going to break down the 4 steps that are necessary to build software to detect and track any object.

Sign UP for FREE