zoukankan      html  css  js  c++  java
  • 吐嘈OpenCV的图像旋转功能 >_<7

      實在出乎我的意料!OpenCV竟然連這么簡單的功能都沒有封裝!還要讓本大爺自己動手寫!強烈要求OpenCV下一個版本添加本功能!

    函數功能和這個網頁一樣,只不過這個作者寫的太糟了,我把它變得簡潔了一點  ^_^

     1 void rotate(const Mat& src, Mat& dst, float angle)
     2 {
     3     CV_Assert(!src.empty());
     4 
     5     float radian = angle /180.0 * PI;
     6 
     7     int uniSize = max(src.cols, src.rows) * 2;
     8     int dx = (uniSize - src.cols) / 2;
     9     int dy = (uniSize - src.rows) / 2;
    10 
    11     copyMakeBorder(src, dst, dy, dy, dx, dx, BORDER_CONSTANT);
    12 
    13     //旋轉中心
    14     Point2f center(dst.cols/2, dst.rows/2);
    15     Mat affine_matrix = getRotationMatrix2D( center, angle, 1.0 );
    16 
    17     warpAffine(dst, dst, affine_matrix, dst.size());
    18 
    19     float sinVal = fabs(sin(radian));
    20     float cosVal = fabs(cos(radian));
    21 
    22     //旋轉后的圖像大小
    23     Size targetSize(src.cols * cosVal + src.rows * sinVal,
    24                  src.cols * sinVal + src.rows * cosVal);
    25 
    26     //剪掉四周边框
    27     int x = (dst.cols - targetSize.width) / 2;
    28     int y = (dst.rows - targetSize.height) / 2;
    29 
    30     Rect rect(x, y, targetSize.width, targetSize.height);
    31     dst = Mat(dst, rect);
    32 }
  • 相关阅读:
    提前期分类
    物料属性,MRP/MPS属性
    ASP.NET刷新页面的一些方法
    Nothing 和 Is
    三层架构与MVC
    ADO.NET
    软件工程之数据流程图(DFD Data Flow Diagram)
    VB.NET小结
    推荐开发人员看的具有影响力的书籍
    C++考试
  • 原文地址:https://www.cnblogs.com/easymind223/p/3330687.html
Copyright © 2011-2022 走看看