
上QQ阅读APP看本书,新人免费读10天
设备和账号都新为新人
3.4.3 案例24:图像旋转
OpenCV中提供了将图像沿着坐标轴旋转的函数flip,其定义如下:

参数说明如下。
● src:输入图像。

图3.19
● flipCode:矩阵旋转标志,flipCode为0表示沿着x轴旋转,flipCode为正数也表示沿着x轴旋转,flipCode为负数表示沿着x轴和y轴旋转。
● dst:输出图像(返回值)。
flip函数的使用案例如下:

本案例使用的输入图像如图3.10所示,旋转后的结果如图3.20所示。

图3.20
另外,OpenCV中还提供了一种将图像按照角度旋转的函数rotate,其定义如下:

参数说明如下。
● src:输入图像。
● rotateCode:矩阵旋转标志,rotateCode为ROTATE_90_CLOCKWISE表示顺时针旋转90°,rotateCode为ROTATE_180表示顺时针旋转180°,rotateCode为ROTATE_90_COUNTERCLOCKWISE表示逆时针旋转90°。
● dst:输出图像(返回值)。
rotate函数的案例代码如下:

本案例使用的输入图像如图3.10所示,旋转后的结果如图3.21所示。

图3.21