一、编程环境:
OpenCV | 4.1.0 |
IDE | Visual Studio 2017 Enterprise (15.9.13) |
操作系统 | Windows 10 x64 中文专业版 (1903) |
二、OpenCV 中的图像翻转函数:flip()
//图像旋转函数
void flip(InputArray src, OutputArray dst, int flipCode);
//旋转标记 (即 int flipCode 的取值)
enum RotateFlags {
ROTATE_90_CLOCKWISE = 0, //顺时针旋转 90 度
ROTATE_180 = 1, //顺时针旋转 180 度
ROTATE_90_COUNTERCLOCKWISE = 2, //顺时针旋转 270 度
};
三、示例代码:
#include<opencv2/opencv.hpp>
#include<iostream>
using namespace cv;
using namespace std;
int main(int argc, char** argv) {
Mat src = imread("../images/test.png");
if (src.empty()) {
printf("不能加载图像...\n");
return -1;
}
imshow("1--原图", src);
Mat dst;
// X Flip 倒影
flip(src, dst, ROTATE_90_CLOCKWISE);
imshow("2--倒影(x轴)", dst);
// Y Flip 镜像
flip(src, dst, ROTATE_180);
imshow("3--翻转(y轴)", dst);
// XY Flip 对角
flip(src, dst, ROTATE_90_COUNTERCLOCKWISE);
imshow("4--翻转(xy轴同时)", dst);
waitKey(0);
return 0;
}
四、运行效果:(女神,对不住了对不住了)
![](https://img-blog.csdnimg.cn/20190620110422670.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2tpbmdrZWU=,size_16,color_FFFFFF,t_70)
![](https://img-blog.csdnimg.cn/20190620110513102.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2tpbmdrZWU=,size_16,color_FFFFFF,t_70)