How to imRotate with OpenCV 2.4.3?

How can I implement imrotate (Mat src, Mat dst, double angle) using OpenCV 2.4.3 ? there is a warpAffine () function , but it is much more and confusing. and he will drop what is out of bounds.

I want him to make more canvas to fit everyone. and fill in the empty spots with black.

+3


source to share


2 answers


I solved it like this. thanks for your answer.



Mat rotateImage(const Mat source, double angle,int border=20)
{
    Mat bordered_source;
    int top,bottom,left,right;
    top=bottom=left=right=border;
    copyMakeBorder( source, bordered_source, top, bottom, left, right, BORDER_CONSTANT,cv::Scalar() );
    Point2f src_center(bordered_source.cols/2.0F, bordered_source.rows/2.0F);
    Mat rot_mat = getRotationMatrix2D(src_center, angle, 1.0);
    Mat dst;
    warpAffine(bordered_source, dst, rot_mat, bordered_source.size());  
    return dst;
}

      

+4


source


use copyMakeBorder

with scalar All (0) for original image, then use rotation matrix and transform with warpAffine

. The border must be large enough to contain the rotated image. Use warpAffine

with CV_WARP_FILL_OUTLIERS

, again with scalarAll (0)



+3


source







All Articles