【OpenCV教程】对图像的各种常用操作
1.图片读取
CV_EXPORTS_W Mat imread( const String& filename, int flags = IMREAD_COLOR );
enum ImreadModes {
IMREAD_UNCHANGED = -1,
//!< If set, return the loaded image as is (with alpha channel, otherwise it gets cropped). Ignore EXIF orientation.
IMREAD_GRAYSCALE = 0,
//!< If set, always convert image to the single channel grayscale image (codec internal conversion).
IMREAD_COLOR = 1,
//!< If set, always convert image to the 3 channel BGR color image.
IMREAD_ANYDEPTH = 2,
//!< If set, return 16-bit/32-bit image when the input has the corresponding depth, otherwise convert it to 8-bit.
IMREAD_ANYCOLOR = 4,
//!< If set, the image is read in any possible color format.
IMREAD_LOAD_GDAL = 8,
//!< If set, use the gdal driver for loading the image.
IMREAD_REDUCED_GRAYSCALE_2 = 16,
//!< If set, always convert image to the single channel grayscale image and the image size reduced 1/2.
IMREAD_REDUCED_COLOR_2 = 17,
//!< If set, always convert image to the 3 channel BGR color image and the image size reduced 1/2.
IMREAD_REDUCED_GRAYSCALE_4 = 32,
//!< If set, always convert image to the single channel grayscale image and the image size reduced 1/4.
IMREAD_REDUCED_COLOR_4 = 33,
//!< If set, always convert image to the 3 channel BGR color image and the image size reduced 1/4.
IMREAD_REDUCED_GRAYSCALE_8 = 64,
//!< If set, always convert image to the single channel grayscale image and the image size reduced 1/8.
IMREAD_REDUCED_COLOR_8 = 65,
//!< If set, always convert image to the 3 channel BGR color image and the image size reduced 1/8.
IMREAD_IGNORE_ORIENTATION = 128
//!< If set, do not rotate the image according to EXIF's orientation flag.
};2.创建窗口
参数
含义
3.图片显示
参数
含义
4.图片保存
参数
含义
5.视频输入输出
5.1 filename
5.2 index
5.3 fourcc
代码
含义
5.4 apiPreference(not important)
5.5 演示
6.通道分离与合并
6.1 分离
API(一)
参数
含义
API(二)
参数
含义
6.2 合并
API(一)
参数
含义
API(二)
参数
含义
7.图片色彩模式转换
7.1 API
参数
含义
7.2 转换类型和转换码
8.改变图片的对比度和亮度
8.1 概述
8.2 手动(使用saturate_cast函数确保输出值不溢出范围)

8.3 API
参数
含义
8.4 效果

9.图片混合
参数
含义
10.图片尺寸调整
参数
含义
10.1 插值算法(not important)
10.2 注意事项
11.图像金字塔(常用于神经网络的池化层,对图像进行成倍的放大或缩小)
参数
含义
12.二值化(对灰度图)
参数
含义
12.1 阈值类型
阈值二值化(Threshold Binary)

阈值反二值化(Threshold Binary Inverted)

截断(Truncate)

阈值取零(Threshold To Zero)

阈值反取零(Threshold To Zero Inverted)

13.图片裁剪
13.1 方式一
13.2 方式二

13.3 Rect类构造
14.基本变换
14.1 翻转
参数
含义
flipCode 可选值
含义
效果

14.2 90°旋转
参数
含义

15.仿射变换
15.1 API
参数
含义
15.2 平移
效果

15.3 任意角度旋转
获得变换矩阵M
参数
含义
效果

15.4 仿射(不破坏几何关系)
获得变换矩阵M
参数
含义
16.透射变换(破坏几何关系)
16.1 API
进行变换
参数
含义
已知变换后图片,逆推变换矩阵M
参数
含义
获得变换矩阵M
参数
含义
16.2 效果

最后更新于