镜像

水平镜像

#include <opencv2/opencv.hpp>
using namespace cv;

int main()
{
    /*载入图像并显示*/
    Mat img = imread("C:\\Users\\Yang\\Desktop\\0.bmp", 0);
    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;
}

 

垂直镜像     原理同上

#include <opencv2/opencv.hpp>
using namespace cv;

int main()
{
    /*载入图像并显示*/
    Mat img = imread("C:\\Users\\Yang\\Desktop\\0.bmp", 0);
    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>(img.rows-i-1, j);
        }
    }

    imshow("效果图", newImg);
    waitKey(0);
    imwrite("C:\\Users\\Yang\\Desktop\\1.bmp", newImg);

    return 0;

}

 

posted @ 2020-05-08 18:23  玥茹苟  阅读(253)  评论(0编辑  收藏  举报