官方API文档:参考链接
对应头文件:#include <opencv2/imgproc.hpp>
1.参数解释
src:输入图像
dst:输出图像
dsize:输出图像的尺寸,如果传入参数0,则按照以下公式计算
dsize = Size(round(fx*src.col, fy*src.rows))
fx:水平方向的缩放因子,如果取默认参数0,则按照以下公式计算
(double)dsize.width / src.cols
fy:垂直方向的缩放因子,如果取默认参数0,则按照以下公式计算
(double)dsize.height / src.rows
interpolation:插值方法,对于缩小图片的情况,cv::resize()函数会
默认选择INTER_AREA作为插值方法,对于放大图片的操作,通常最
最好选用cv::INTER_CUBIC(较慢),或者使用快速效果稍弱的
cv::INTER_LINER插值方法
注意:dsize和(fx,fy)参数不能同时取0
2.插值标记
InterpolationFlags是一个元组:
enum cv::InterpolationFlags |
在头文件:#include <opencv2/imgproc.hpp> 中定义
官方API文档:参考链接
2.1 INTER_NEAREST
nearest neighbor interpolation 最近邻插值
2.2 INTER_LINEAR
nearest neighbor interpolation 双线性插值
2.3 INTER_CUBIC
bicubic interpolation 双三次插值
2.4 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 像素区域重采样插值
该方法是缩小图像时的推荐方法,不会产生摩尔纹;当该方法被用于放大图片的时候,其效果与最近邻插值的效果相似
2.5 INTER_LANCZOS4
Lanczos interpolation over 8x8 neighborhood
使用Lanczos resampling方法的插值方法,该方法以Cornelius Lanczos的名字命名,使用Lanczos Kernel 来进行重建插值
OpenCV提供的是8*8像素区域的邻域的采样
2.6 INTER_LINEAR_EXACT
Bit exact bilinear interpolation 位精确双线性插值
2.7 INTER_MAX
mask for interpolation codes 掩码插值
2.8 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 填充满放大后的目标图像,如果目标图像中对应原图的像素已经溢出,则将其置0
2.9 WARP_INVERSE_MAP
flag, inverse transformation 反变换
For example, linearPolar or logPolar transforms:
- flag is not set: dst(ρ,ϕ)=src(x,y)
- flag is set: dst(x,y)=src(ρ,ϕ)
当使用这个Flag的时候,对应的变换反过来
3.Demo