(原)使用opencv的warpAffine函數對圖像進行旋轉


轉載請注明出處:

http://www.cnblogs.com/darkknightzh/p/5070576.html

參考網址:

http://stackoverflow.com/questions/7813376/rotate-cvmat-using-cvwarpaffine-offsets-destination-image  的plhn的回復

http://blog.csdn.net/xiaowei_cqu/article/details/7616044

http://docs.opencv.org/2.4/modules/imgproc/doc/geometric_transformations.html?highlight=warpaffine#void%20warpAffine%28InputArray%20src,%20OutputArray%20dst,%20InputArray%20M,%20Size%20dsize,%20int%20flags,%20int%20borderMode,%20const%20Scalar&%20borderValue%29

http://docs.opencv.org/2.4/doc/tutorials/imgproc/imgtrans/warp_affine/warp_affine.html

使用opencv的warpAffine函數對圖像進行旋轉

 1 Mat ImgRotate(const Mat& ucmatImg, double dDegree)
 2 {
 3     Mat ucImgRotate;
 4 
 5     double a = sin(dDegree  * CV_PI / 180);
 6     double b = cos(dDegree  * CV_PI / 180);
 7     int width = ucmatImg.cols;
 8     int height = ucmatImg.rows;
 9     int width_rotate = int(height * fabs(a) + width * fabs(b));
10     int height_rotate = int(width * fabs(a) + height * fabs(b));
11 
12     Point center = Point(ucmatImg.cols / 2, ucmatImg.rows / 2);
13 
14     Mat map_matrix = getRotationMatrix2D(center, dDegree, 1.0);
15     map_matrix.at<double>(0, 2) += (width_rotate - width) / 2;     // 修改坐標偏移
16     map_matrix.at<double>(1, 2) += (height_rotate - height) / 2;   // 修改坐標偏移
17 
18     warpAffine(ucmatImg, ucImgRotate, map_matrix, { width_rotate, height_rotate },
19         CV_INTER_CUBIC | CV_WARP_FILL_OUTLIERS, BORDER_CONSTANT, cvScalarAll(0));
20 
21     return ucImgRotate;
22 }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM