示例#1
0
  private Mat rotateImage(Mat src, double angle) {
    Point center = new Point(src.cols() / 2, src.rows() / 2);
    double scale = 1.0;

    Mat rotateMat = Imgproc.getRotationMatrix2D(center, angle, scale);
    Mat dst = new Mat();
    Size frameSize = new Size(src.rows(), src.cols());

    // adjust dst center point
    double m[] = new double[6];
    rotateMat.get(0, 0, m);
    m[2] += (frameSize.width - src.cols()) / 2;
    m[5] += (frameSize.height - src.rows()) / 2;
    rotateMat.put(0, 0, m);

    Imgproc.warpAffine(
        src,
        dst,
        rotateMat,
        frameSize,
        Imgproc.INTER_LINEAR,
        Imgproc.BORDER_CONSTANT,
        Scalar.all(0));

    return dst;
  }
  public Mat onCameraFrame(Mat inputFrame) {
    inputFrame.copyTo(mRgba);
    Point center = new Point(mRgba.width() / 2, mRgba.height() / 2);
    double angle = -90;
    double scale = 1.0;

    Mat mapMatrix = Imgproc.getRotationMatrix2D(center, angle, scale);
    Imgproc.warpAffine(mRgba, mGrayMat, mapMatrix, mRgba.size(), Imgproc.INTER_LINEAR);
    return mGrayMat;
  }
示例#3
0
  /**
   * Rotate a Mat by the specified degree
   *
   * @param src The source Mat
   * @param angle The angle by which to rotate by
   * @return The rotated Mat
   */
  public static Mat rotate(Mat src, double angle) {
    int len = src.cols() > src.rows() ? src.cols() : src.rows();
    Point pt = new Point(len / 2.0, len / 2.0);
    Mat r = Imgproc.getRotationMatrix2D(pt, angle, 1.0);
    Mat dst = new Mat();

    Imgproc.warpAffine(src, dst, r, new Size(len, len));

    return dst;
  }
示例#4
0
  public Mat rotateImage(Mat image, int angle, boolean cropEdges) {

    Mat rotatedImage = new Mat();
    Mat M = Imgproc.getRotationMatrix2D(new Point(halfGenImageSize, halfGenImageSize), angle, 1);

    Imgproc.warpAffine(image, rotatedImage, M, new Size(genImageSize, genImageSize));

    if (cropEdges) {
      Rect roi =
          new Rect(
              (genImageSize - croppedImageSize) / 2,
              (genImageSize - croppedImageSize) / 2,
              croppedImageSize,
              croppedImageSize);
      rotatedImage = new Mat(rotatedImage, roi);
    }
    return rotatedImage;
  }