1.扩展缩放
扩展缩放只是改变图像的尺寸大小。OpenCV 提供的函数 cv2.resize()
resize(src, dst, interpolation=CV_INTER_LINEAR)
import cv2 as cv
import numpy as np
img=cv.imread(‘D:/sixiang.JPG’)
res=cv.resize(img,None,fx=2,fy=2,interpolation=cv.INTER_CUBIC)
height,width=img.shape[:2]
res=cv.resize(img,(2width,2height),interpolation=cv.INTER_CUBIC)
while(1):
cv.imshow(‘res’,res)
cv.imshow(‘img’,img)
if cv.waitKey(1) & 0xFF == 27:
break
cv.destroyAllWindows()
2. 平移
平移使用函数 cv2.warpAffine(),就是将对象换一个位置。如果要沿(x,y)方向移动,移动的距离 是(tx,ty):
import cv2 as cv
import numpy as np
import matplotlib.pyplot as plt
img = cv.imread(‘D:/yu.JPG’,0)
rows,cols = img.shape #得到图像的高宽
M =np.float32([[1,0,200],[0,1,200]])
#x轴移动200 ,y轴移