opencv处理图像
imread函数
imread python原型
retval = cv.imread( filename[, flags] )
imread函数需要两个参数,一个是图片文件名(相对路径或者绝对路径都可以),另一个是flags读取标记,选取读图的方式,默认值为IMREAD_COLOR,flag的设定与用什么颜色格式读取有关。
目前,支持下面的格式:
- Windows bitmaps - *.bmp, *.dib (always supported)
- JPEG files - *.jpeg, *.jpg, *.jpe (see the Note section)
- JPEG 2000 files - *.jp2 (see the Note section)
- Portable Network Graphics - *.png (see the Note section)
- WebP - *.webp (see the Note section)
- Portable image format - *.pbm, *.pgm, *.ppm *.pxm, *.pnm (always supported)
- PFM files - *.pfm (see the Note section)
- Sun rasters - *.sr, *.ras (always supported)
- TIFF files - *.tiff, *.tif (see the Note section)
- OpenEXR Image files - *.exr (see the Note section)
- Radiance HDR - *.hdr, *.pic (always supported)
- Raster and Vector geospatial data supported by GDAL (see the Note section)
flags的值有下面几种
resize
函数原型:
resize(src, dsize, dst=None, fx=None, fy=None, interpolation=None)
参数描述
- src 原图像 (必须参数)
- dsize 输出图像所需要的大小 (必须参数)
- fx 沿着水平轴的比例因子(可选参数)
- fy 沿着垂直轴的比例因子(可选参数)
- interpolation 插值方式 (可选参数)
插值方式
- cv.INTER_NEAREST 最近邻插值
- cv.INTER_LINEAR 双线性插值
- cv.INTER_CUBIC 双线性插值
- cv.INTER_AREA 使用像素区域关系重新采样。它可能是图像抽取的首选方法,因为它可以提供无莫尔条纹的结果。但是当图像被缩放时,它类似于INTER_NEAREST方法。