1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| import cv2 import numpy as np
img_src = cv2.imread('figure/fruits_gray.png',cv2.IMREAD_COLOR) height, width = img_src.shape[:2]
img_zero = np.zeros((height, width, 3), dtype=np.uint8)
img_dst = cv2.resize(img_src, (int(width), int(height))) img_zero[0:int(height), 0:int(width),:] = img_dst
M = np.array([[1,0,int(width/4)],[0,1,int(height/4)]], dtype=float) img_dst = cv2.warpAffine(img_zero, M, (width, height))
cv2.imshow("dst", img_dst) cv2.waitKey() cv2.destroyAllWindows()
|