通过transpose和flip实现图像旋转90/180/270度

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

               

 在fbc_cv库中,提供了对图像进行任意角度旋转的函数rotate,其实内部也是调用了仿射变换函数warpAffine。如果图像仅是进行90度倍数的旋转,是没有必要用warpAffine函数的。这里通过transpose和flip函数实现对图像进行顺时针90度、180度、270度的旋转。

 用fbc::transpose、fbc::flip和cv::transpose、cv::flip实现的结果是完全一致的。

 通过fbc_cv库实现代码如下:

#include "test_rotate90.hpp"#include <opencv2/opencv.hpp>#include <transpose.hpp>#include <flip.hpp>int test_rotate90(){ cv::Mat matSrc = cv::imread("E:/GitCode/OpenCV_Test/test_images/1.jpg", 1); if (!matSrc.data) {  std::cout << "read image fail" << std::endl;  return -1; } int width = matSrc.cols; int height = matSrc.rows; fbc::Mat_<uchar, 3> mat1(height, width, matSrc.data); fbc::Mat_<uchar, 3> matTranspose(width, height); fbc::transpose(mat1, matTranspose); // clockwise rotation  90 fbc::Mat_<uchar, 3> matRotate90(width, height); fbc::flip(matTranspose, matRotate90, 1); cv::Mat tmp2(width, height, CV_8UC3, matRotate90.data); cv::imwrite("E:/GitCode/OpenCV_Test/test_images/rotate_90.jpg", tmp2); // clockwise rotation 180 fbc::Mat_<uchar, 3> matRotate180(height, width); fbc::flip(mat1, matRotate180, -1); cv::Mat tmp3(height, width, CV_8UC3, matRotate180.data); cv::imwrite("E:/GitCode/OpenCV_Test/test_images/rotate_180.jpg", tmp3); // clockwise rotation 270 fbc::Mat_<uchar, 3> matRotate270(width, height); fbc::flip(matTranspose, matRotate270, 0); cv::Mat tmp4(matTranspose.rows, matTranspose.cols, CV_8UC3, matRotate270.data); cv::imwrite("E:/GitCode/OpenCV_Test/test_images/rotate_270.jpg", tmp4); return 0;}

 结果图像如下:

原图

顺时针旋转90度 

 顺时针旋转180度


                                                             顺时针旋转270度                                                                


 GitHubhttps://github.com/fengbingchun/OpenCV_Test


           

给我老师的人工智能教程打call!http://blog.csdn.net/jiangjunshow
这里写图片描述
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值