cv.resize(src,dsize,fx=0,fy=0,interpolation=cv2.INTER_LINEAR)
import numpy as np
import cv2 as cv
import matplotlib.pyplot as plt
kids=cv.imread('./汪学长的随堂资料/4/图像操作/dog.jpg')
plt.imshow(kids[:,:,::-1])
# 绝对尺寸
rows,cols=kids.shape[:2]
res=cv.resize(kids,(2*cols,2*rows))
plt.imshow(res[:,:,::-1])
# 相对尺寸
res1=cv.resize(kids,None,fx=0.5,fy=0.5)
plt.imshow(res1[:,:,::-1])
cv.warpAffine(img,M,dsize)
M=np.float32([[1,0,100],[0,1,50]])
res2=cv.warpAffine(kids,M,(cols,rows))
plt.imshow(res2[:,:,::-1])
cv.getRotationMatrix2D(center,angle,scale)
M=cv.getRotationMatrix2D((cols/2,rows/2),45,1)
res3=cv.warpAffine(kids,M,(cols,rows))
plt.imshow(res3[:,:,::-1])
点线关系的仿射结果在原图像是一样的,但是线长度,线与线的角度会发生变化
# 原始位置
pts1=np.float32([[50,50],[200,50],[50,200]])
# 仿射后的位置
pts2=np.float32([[100,100],[200,50],[100,250]])
M=cv.getAffineTransform(pts1,pts2)
res4=cv.warpAffine(kids,M,(cols,rows))
plt.imshow(res4[:,:,::-1])
pst1=np.float32([[56,65],[368,52],[28,387],[389,390]])
pst2=np.float32([[100,145],[300,100],[80,290],[310,300]])
T=cv.getPerspectiveTransform(pst1,pst2)
res5=cv.warpPerspective(kids,T,(cols,rows))
plt.imshow(res5[:,:,::-1])
imgup=cv.pyrUp(kids)
plt.imshow(imgup[:,:,::-1])
imgdown=cv.pyrDown(kids)
plt.imshow(imgdown[:,:,::-1])