Skip to content

Instantly share code, notes, and snippets.

@ChongyeWang
Created March 15, 2019 05:47
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/dc42aff02c0d257ae2da8b5cecb37bb4 to your computer and use it in GitHub Desktop.
Save ChongyeWang/dc42aff02c0d257ae2da8b5cecb37bb4 to your computer and use it in GitHub Desktop.
import cv2
import numpy as np
image = cv2.imread('images/input.jpg')
# Store height and width of the image
height, width = image.shape[:2]
quarter_height, quarter_width = height/4, width/4
# | 1 0 Tx |
# T = | 0 1 Ty |
# T is our translation matrix
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()
cv2.destroyAllWindows()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment