1图像转换
OpenCV提供了两个转换函数cv2.warpAffine和cv2.warpPerspective,可以使用它们进行各种转换。 cv2.warpAffine采用2x3变换矩阵,而cv2.warpPerspective采用3x3变换矩阵作为输入。
2图像缩放
缩放只是调整图像大小.为此,OpenCV附带了一个函数cv.resize().
cv2.resize(src, dsize[, dst[, fx[, fy[, interpolation]]]])
对shrinking,优选的interpolation方法:cv2.INTER_AREA该方法可以避免波纹的出现
对zooming,优选的interpolation方法:cv2.INTER_CUBIC和cv2.INTER_LINEAR(默认)
方法一
import numpy as np
import cv2
img = cv2.imread(messi5.jpg)
res = cv2.resize(img,None,fx=2, fy=2, interpolation = cv2.INTER_CUBIC)
方法二
import numpy as np
import cv2
height, width = img.shape[:2]
res = cv2.resize(img,(2*width, 2*height), interpolation = cv2.INTER_CUBIC)
3图像平移
平移是对象位置的转换。 如果你知道(x,y)方向的偏移,让它为(tx,ty),你可以创建变换矩阵M