Skip to content

Instantly share code, notes, and snippets.

@palaashatri
Created August 12, 2020 06:02
Show Gist options
  • Save palaashatri/df69019d01a2c5babf34ae4637a993a6 to your computer and use it in GitHub Desktop.
Save palaashatri/df69019d01a2c5babf34ae4637a993a6 to your computer and use it in GitHub Desktop.
Demonstation of OpenCV image transformation techniques (Scaling and Rotation)
import numpy as np
import cv2
img = cv2.imread("image.jpg")
# Scale
img_half = cv2.resize(img,(0,0),fx=0.5,fy=0.5)
img_stretch = cv2.resize(img,(600,600))
img_stretch_near = cv2.resize(img,(600,600),interpolation=cv2.INTER_NEAREST)
cv2.inshow(img_half)
cv2.inshow(img_stretch)
cv2.inshow(img_stretch_near)
# Rotation
M = cv2.getRotationMatrix2D((0,0),-30,1) # Origin, Degrees and 1
rotated = cv2.warpAffine(img,M,(img.shape[1],img.shape[0]))
cv2.imshow("Rotated",rotated)
cv2.waitKey(0)
cv2.destroyAllWindows()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment