Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cv2
- import numpy as np
- img = cv2.imread('lena3.png', cv2.IMREAD_COLOR)
- h, w = img.shape[:2]
- scale = 1.0
- while(True):
- scale *= 1.001
- # Prepare transformation matrices
- # Translate to have origin at the center of the image
- M_translate_0 = np.array([[1,0,-w/2],[0,1,-h/2],[0,0,1]], dtype=np.float32)
- # Scale around the origin
- M_scale = np.array([[scale,0,0],[0,scale,0],[0,0,1]], dtype=np.float32)
- # Translate back to have origin at the top-left corner again
- M_translate_1 = np.array([[1,0,w/2],[0,1,h/2],[0,0,1]], dtype=np.float32)
- # Calculate the composite transformation matrix
- M = np.matmul(M_translate_1, np.matmul(M_scale, M_translate_0))
- # Apply transformation (dropping the last row of the matrix, since it's not needed here)
- result = cv2.warpAffine(img, M[:2,], (w, h))
- cv2.imshow('', result)
- cv2.waitKey(20)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement