Rotate image

void warpAffine(InputArray src, OutputArray dst, InputArray M, Size dsize, int flags=INTER_LINEAR, int borderMode=BORDER_CONSTANT, const Scalar& borderValue=Scalar())

Parameters:
  • src – input image.
  • dst – output image that has the size dsize and the same type as src .
  • M2\times 3 transformation matrix.
  • dsize – size of the output image.
  • flags – combination of interpolation methods (see resize() ) and the optional flag WARP_INVERSE_MAP that means that M is the inverse transformation ( \texttt{dst}\rightarrow\texttt{src} ).
  • borderMode – pixel extrapolation method (see borderInterpolate()); when borderMode=BORDER_TRANSPARENT , it means that the pixels in the destination image corresponding to the “outliers” in the source image are not modified by the function.
  • borderValue – value used in case of a constant border; by default, it is 0.

The "rotate" function takes an image and returns the rotated image.

Example:

-----------
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>

using namespace cv;
using namespace std;

Mat rotate(Mat src, double angle)
{
    Mat dst;
    Point2f pt(src.cols/2., src.rows/2.);    
    Mat r = getRotationMatrix2D(pt, angle, 1.0);
    warpAffine(src, dst, r, Size(src.cols, src.rows));
    return dst;
}

int main()
{
    Mat src = imread("lena.jpg");

    Mat dst;
    dst = rotate(src, 10);

    imshow("src", src);
    imshow("dst", dst);
    waitKey(0);
    return 0;
}
-----------

Result:


4 comments:

  1. Very interesting story. I didn't find it boring to read. In fact, I really had a fun reading your post. Thanks.

    Shella
    www.gofastek.com

    ReplyDelete
  2. Those look interesting. Keep posting.

    Count
    www.imarksweb.org

    ReplyDelete