From 1711fd54d91fd100df618858cb53b2d57684d55d Mon Sep 17 00:00:00 2001 From: Scott Klum Date: Wed, 22 Jul 2020 15:08:12 -0600 Subject: [PATCH] Fix bug in rotation --- openbr/core/opencvutils.cpp | 4 ++-- openbr/plugins/imgproc/rotate.cpp | 17 ++--------------- openbr/plugins/metadata/grid.cpp | 2 +- 3 files changed, 5 insertions(+), 18 deletions(-) diff --git a/openbr/core/opencvutils.cpp b/openbr/core/opencvutils.cpp index 41cc1f1..820e254 100644 --- a/openbr/core/opencvutils.cpp +++ b/openbr/core/opencvutils.cpp @@ -654,10 +654,10 @@ QList OpenCVUtils::rotateRects(const QList &rects, const Mat &ro void OpenCVUtils::rotate(const br::Template &src, br::Template &dst, float degrees, bool rotateMat, bool rotatePoints, bool rotateRects, const QPointF ¢er) { - const Mat rotMatrix = getRotationMatrix2D(center.isNull() ? Point2f(src.m().rows/2,src.m().cols/2) : toPoint(center), degrees, 1.0); + const Mat rotMatrix = getRotationMatrix2D(center.isNull() ? Point2f(src.m().cols / 2, src.m().rows / 2) : toPoint(center), degrees, 1.0); if (rotateMat) { - warpAffine(src,dst,rotMatrix,Size(src.m().cols,src.m().rows),INTER_AREA,BORDER_REPLICATE); + warpAffine(src, dst, rotMatrix, Size(src.m().cols, src.m().rows), INTER_AREA, BORDER_REPLICATE); dst.file = src.file; } else dst = src; diff --git a/openbr/plugins/imgproc/rotate.cpp b/openbr/plugins/imgproc/rotate.cpp index d51a415..1fde5ff 100644 --- a/openbr/plugins/imgproc/rotate.cpp +++ b/openbr/plugins/imgproc/rotate.cpp @@ -1,5 +1,6 @@ #include #include +#include using namespace cv; @@ -19,21 +20,7 @@ class RotateTransform : public UntrainableTransform BR_PROPERTY(int, angle, -90) void project(const Template &src, Template &dst) const { - - if(angle == 270 || angle == -90){ - // Rotate clockwise 270 degrees - cv::transpose(src, dst); - cv::flip(dst, dst, 0); - }else if(angle == 180 || angle == -180){ - // Rotate clockwise 180 degrees - cv::flip(src, dst, -1); - }else if(angle == 90 || angle == -270){ - // Rotate clockwise 90 degrees - cv::transpose(src, dst); - cv::flip(dst, dst, 1); - }else { - dst = src; - } + OpenCVUtils::rotate(src, dst, angle); } }; diff --git a/openbr/plugins/metadata/grid.cpp b/openbr/plugins/metadata/grid.cpp index 10fdf18..2a7c6c6 100644 --- a/openbr/plugins/metadata/grid.cpp +++ b/openbr/plugins/metadata/grid.cpp @@ -52,7 +52,7 @@ class GridTransform : public UntrainableTransform landmarks.append(QPointF(x,y)); if (angle > 0) { - const Mat rotMatrix = getRotationMatrix2D(Point2f(src.m().rows/2,src.m().cols/2), angle, 1.0); + const Mat rotMatrix = getRotationMatrix2D(Point2f(src.m().cols / 2, src.m().rows / 2), angle, 1.0); landmarks = OpenCVUtils::rotatePoints(landmarks, rotMatrix); } -- libgit2 0.21.4