欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

opencv_17_翻转和旋转

最编程 2024-05-02 09:06:09
...

 一、图像翻转

1)void flip_test(Mat& image);

2)void ColorInvert::flip_test(Mat& image) {
    Mat dst;
    //flip(image, dst, 0); //上下翻转
    flip(image, dst, 1); //左右翻转
    // flip(image, dst, -1); //180度翻转
    imshow("图像旋转", dst);
}

二、图像旋转

 coInvert.rotate(src);

void ColorInvert::rotate(Mat& image) {
    Mat dst,M;
    int w = image.cols;
    int h = image.rows;
    M = getRotationMatrix2D(Point2f(w / 2, h / 2), 45, 1.0);
    double cos = abs(M.at<double>(0, 0));
    double sin = abs(M.at<double>(0, 1));
    int nw = cos * w + sin * h;
    int nh = sin * w + cos * h;
    M.at<double>(0, 2) += (nw / 2 - w / 2);
    M.at<double>(1, 2) += (nh / 2 - h / 2);
    warpAffine(image, dst, M, Size(nw, nh), INTER_LINEAR, 0, Scalar(255, 255, 0));
    imshow("旋转演示", dst);
}

​​​​​​​ 

推荐阅读