【问题标题】:JavaCV or OpenCV Image RotationJavaCV 或 OpenCV 图像旋转
【发布时间】:2017-11-21 09:30:24
【问题描述】:

我的目标是将图像旋转一定角度(例如 30 度)。 tenta4 给出了在 OpenCV 中旋转 90 度的一种可能方式,但不幸的是,它只执行 90 度翻转。

另一种可能的方法是JavaCV samples 中给出的方法“SkewGrayImage”,它执行“小角度旋转”,似乎适用于大约 45 - 50 度的旋转,但不适用于任何其他更高的值。

所以 - 我的问题是,OpenCV 或 JavaCV 中是否有适当的方式/方法来实际执行图像或对象的角度旋转?

【问题讨论】:

  • 参见here 获取 C++ 示例。

标签: opencv image-processing javacv image-rotation


【解决方案1】:

Meta 解释了如何计算相对于图像中心的旋转矩阵,然后执行如下旋转:

    Mat rotated_image;
    warpAffine(src, rotated_image, rot_mat, src.size());

【讨论】:

    【解决方案2】:

    有一种叫做warp的操作,它既可以旋转,也可以对图像做一些其他的变换。

    这里有一些有用的链接

    希望对你有帮助;)

    【讨论】:

      【解决方案3】:

      Martin 基于 Mat 变量给出了 IplImage 旋转的更详细答案,然后可以转换并返回为 IplImage,如下所示:

      Mat source = imread(argv[1], CV_LOAD_IMAGE_COLOR);
      Mat rotation_matrix = getRotationMatrix2D(src_center, angle, 1.0);
      Mat destinationMat;
      warpAffine(source, destinationMat, rotation_matrix, source.size());
      IplImage iplframe = IplImage(destinationMat);
      

      【讨论】:

        【解决方案4】:

        希望这会有所帮助!使用 JavaCV 为我工作。

        Mat raw = ... // your raw mat
        
        // Create your "new" Mat and the center of your Raw Mat
        Mat result = new Mat(raw.size(), [your Image Type]); // my Img type was CV_8U
        Point2f rawCenter = new Point2f(raw.cols() / 2.0F, raw.rows() / 2.0F);
        
        // Scale and Rotation of new Mat
        double scale = 1.0;
        int rotation = -5;
        
        // Rotation Matrix
        Mat rotationMatrix = getRotationMatrix2D(rawCenter, rotation, scale);
        
        // Rotate 
        warpAffine(raw, result, rotationMatrix, raw.size());
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2020-03-17
          • 1970-01-01
          • 2014-07-03
          • 2011-02-21
          • 1970-01-01
          • 1970-01-01
          • 2011-10-15
          • 1970-01-01
          相关资源
          最近更新 更多