opencv提供了2个转换函数,可以对图像进行任意转换。
cv.warpAffine和cv.warpPerspective.第一种采取2*3的矩阵作为输入。第二种采取3*3的矩阵作为输入。
1.缩放
函数:
cv.resize(src, dsize[, dst[, fx[, fy[, interpolation]]]])
参数:
src:输入图像
dsize:目标尺寸,整形,非0
dst:目标图像,大小为dsize,或由src.size()计算而来
fx:水平轴缩放比例,非0
fy:垂直轴缩放比例,非0
interpolation:插值算法,分为以下几种
INTER_NEAREST
Python: cv.INTER_NEAREST
nearest neighbor interpolation最邻近插值
INTER_LINEAR
Python: cv.INTER_LINEAR
bilinear interpolation双线性插值
INTER_CUBIC
Python: cv.INTER_CUBIC
bicubic interpolation双三次插值
INTER_AREA
Python: cv.INTER_AREA
resampling using pixel area relation. It may be a preferred method for image decimation, as it gives moire'-free results. But when the image is zoomed, it is similar to the INTER_NEAREST method.基于局部像素的重采样
INTER_LANCZOS4
Python: cv.INTER_LANCZOS4
Lanczos interpolation over 8x8 neighborhood.基于8x8像素邻域的Lanczos插值
INTER_LINEAR_EXACT
Python: cv.INTER_LINEAR_EXACT
Bit exact bilinear interpolation.位精确双线性插值
INTER_MAX
Python: cv.INTER_MAX
mask for interpolation codes.插补码掩码
WARP_FILL_OUTLIERS
Python: cv.WARP_FILL_OUTLIERS
flag, fills all of the destination image pixels. If some of them correspond to outliers in the source image, they are set to zero
WARP_INVERSE_MAP
Python: cv.WARP_INVERSE_MAP
flag, inverse transformation
For example, linear