原理:以原图的垂直中轴线为中心交换图像的左右两个部分
C++代码:
#include <opencv2/opencv.hpp>
using namespace cv;
int main()
{
/*载入图像并显示*/
Mat img = imread("C:\\Users\\Yang\\Desktop\\0.bmp", 0);
imshow("原图", img);
Mat newImg = Mat::zeros(img.rows, img.cols, CV_8UC1);
/*镜像*/
for (int i = 0; i < img.rows; i++)
{
for (int j = 0; j < img.cols; j++)
{
newImg.at<uchar>(i, j) = img.at<uchar>(i, img.cols - j-1);
}
}
imshow("效果图", newImg);
waitKey(0);
imwrite("C:\\Users\\Yang\\Desktop\\1.bmp", newImg);
return 0;
}