1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
| import cv2 import numpy as np
img = cv2.imread('test.jpg', 1) height = img.shape[0] width = img.shape[1]
matScale = np.float32([[0.5,0,0],[0,0.5,0]]) dst = cv2.warpAffine(img,matScale,(int(width/2),int(height/2))) cv2.imshow('test',dst) cv2.waitKey(0)
matSrc = np.float32([[0,0],[0,height-1],[width-1,0]]) matDst = np.float32([[50,50],[300,height-200],[width-300,100]]) matAffine = cv2.getAffineTransform(matSrc,matDst) dst = cv2.warpAffine(img,matAffine,(width,height)) cv2.imshow('test',dst) cv2.waitKey(0)
matRotate = cv2.getRotationMatrix2D((height*0.5,width*0.5),45,1) dst = cv2.warpAffine(img,matRotate,(height,width)) cv2.imshow('test',dst) cv2.waitKey(0)
pts1 = np.float32([[200,200],[500,200],[200,500],[500,500]]) pts2 = np.float32([[0,0],[300,0],[0,300],[300,300]]) M = cv2.getPerspectiveTransform(pts1,pts2) dst = cv2.warpPerspective(img,M,(300,300)) cv2.imshow('test',dst) cv2.waitKey(0)
img = cv2.imread('test.jpg',1) cv2.imshow('src',img) imgInfo = img.shape height = imgInfo[0] width = imgInfo[1] deep = imgInfo[2] newImgInfo = (height*2,width,deep) dst = np.zeros(newImgInfo,np.uint8) for i in range(0,height): for j in range(0,width): dst[i,j] = img[i,j] dst[height*2-i-1,j] = img[i,j] for i in range(0,width): dst[height,i] = (0,0,255) cv2.imshow('dst',dst) cv2.waitKey(0)
img = cv2.imread('test.jpg',1) imgInfo = img.shape height = imgInfo[0] width = imgInfo[1]
matShift = np.float32([[1,0,100],[0,1,200]]) dst = cv2.warpAffine(img,matShift,(height,width)) cv2.imshow('dst',dst) cv2.waitKey(0)
dst = np.zeros(img.shape,np.uint8) for i in range(0,height): for j in range(0,width-100): dst[i,j+100]=img[i,j] cv2.imshow('image',dst) cv2.waitKey(0)
|