(原)使用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/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 }
posted on 2015-12-23 17:18 darkknightzh 阅读(9318) 评论(4) 编辑 收藏 举报