Skip to content

Instantly share code, notes, and snippets.

@ChongyeWang
Created March 15, 2019 05:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChongyeWang/aa00c90832d457fdaacf2addaed586c4 to your computer and use it in GitHub Desktop.
Save ChongyeWang/aa00c90832d457fdaacf2addaed586c4 to your computer and use it in GitHub Desktop.
import cv2
import numpy as np
image = cv2.imread('images/input.jpg')
height, width = image.shape[:2]
# Divide by two to rototate the image around its centre
rotation_matrix = cv2.getRotationMatrix2D((width/2, height/2), 90, .5)
rotated_image = cv2.warpAffine(image, rotation_matrix, (width, height))
cv2.imshow('Rotated Image', rotated_image)
cv2.waitKey()
cv2.destroyAllWindows()
# Other Option to Rotate
img = cv2.imread('images/input.jpg')
rotated_image = cv2.transpose(img)
cv2.imshow('Rotated Image - Method 2', rotated_image)
cv2.waitKey()
cv2.destroyAllWindows()
# Let's now to a horizontal flip.
flipped = cv2.flip(image, 1)
cv2.imshow('Horizontal Flip', flipped)
cv2.waitKey()
cv2.destroyAllWindows()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment