diff --git a/modules/core/perf/opencl/perf_arithm.cpp b/modules/core/perf/opencl/perf_arithm.cpp index 8d1e7a6288..04d343a136 100644 --- a/modules/core/perf/opencl/perf_arithm.cpp +++ b/modules/core/perf/opencl/perf_arithm.cpp @@ -374,6 +374,36 @@ OCL_PERF_TEST_P(FlipFixture, Flip, SANITY_CHECK(dst); } +///////////// Rotate //////////////////////// + +enum +{ + ROTATE_90_CLOCKWISE = 0, ROTATE_180, ROTATE_90_COUNTERCLOCKWISE +}; + +CV_ENUM(RotateType, ROTATE_90_CLOCKWISE, ROTATE_180, ROTATE_90_COUNTERCLOCKWISE) + +typedef tuple RotateParams; +typedef TestBaseWithParam RotateFixture; + +OCL_PERF_TEST_P(RotateFixture, rotate, + ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES, RotateType::all())) +{ + const RotateParams params = GetParam(); + const Size srcSize = get<0>(params); + const int type = get<1>(params); + const int rotateCode = get<2>(params); + + checkDeviceMaxMemoryAllocSize(srcSize, type); + + UMat src(srcSize, type), dst(srcSize, type); + declare.in(src, WARMUP_RNG).out(dst); + + OCL_TEST_CYCLE() cv::rotate(src, dst, rotateCode); + + SANITY_CHECK_NOTHING(); +} + ///////////// minMaxLoc //////////////////////// typedef Size_MatType MinMaxLocFixture; diff --git a/modules/core/perf/perf_arithm.cpp b/modules/core/perf/perf_arithm.cpp index c4cc7500a7..f14382059c 100644 --- a/modules/core/perf/perf_arithm.cpp +++ b/modules/core/perf/perf_arithm.cpp @@ -452,6 +452,33 @@ INSTANTIATE_TEST_CASE_P(/*nothing*/ , BinaryOpTest, ) ); +///////////// Rotate //////////////////////// + +typedef perf::TestBaseWithParam> RotateTest; + +PERF_TEST_P_(RotateTest, rotate) +{ + Size sz = get<0>(GetParam()); + int rotatecode = get<1>(GetParam()); + int type = get<2>(GetParam()); + cv::Mat a(sz, type), b(sz, type); + + declare.in(a, WARMUP_RNG).out(b); + + TEST_CYCLE() cv::rotate(a, b, rotatecode); + + SANITY_CHECK_NOTHING(); +} + +INSTANTIATE_TEST_CASE_P(/*nothing*/ , RotateTest, + testing::Combine( + testing::Values(szVGA, sz720p, sz1080p), + testing::Values(ROTATE_180, ROTATE_90_CLOCKWISE, ROTATE_90_COUNTERCLOCKWISE), + testing::Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_8SC1, CV_16SC1, CV_16SC2, CV_16SC3, CV_16SC4, CV_32SC1, CV_32FC1) + ) +); + + ///////////// PatchNaNs //////////////////////// template diff --git a/modules/core/test/test_arithm.cpp b/modules/core/test/test_arithm.cpp index 7733d33519..ed15c5dcba 100644 --- a/modules/core/test/test_arithm.cpp +++ b/modules/core/test/test_arithm.cpp @@ -831,6 +831,7 @@ struct ConvertScaleAbsOp : public BaseElemWiseOp namespace reference { +// does not support inplace operation static void flip(const Mat& src, Mat& dst, int flipcode) { CV_Assert(src.dims == 2); @@ -852,6 +853,26 @@ static void flip(const Mat& src, Mat& dst, int flipcode) } } +static void rotate(const Mat& src, Mat& dst, int rotateMode) +{ + Mat tmp; + switch (rotateMode) + { + case ROTATE_90_CLOCKWISE: + cvtest::transpose(src, tmp); + reference::flip(tmp, dst, 1); + break; + case ROTATE_180: + reference::flip(src, dst, -1); + break; + case ROTATE_90_COUNTERCLOCKWISE: + cvtest::transpose(src, tmp); + reference::flip(tmp, dst, 0); + break; + default: + break; + } +} static void setIdentity(Mat& dst, const Scalar& s) { @@ -898,6 +919,32 @@ struct FlipOp : public BaseElemWiseOp int flipcode; }; +struct RotateOp : public BaseElemWiseOp +{ + RotateOp() : BaseElemWiseOp(1, FIX_ALPHA+FIX_BETA+FIX_GAMMA, 1, 1, Scalar::all(0)) { rotatecode = 0; } + void getRandomSize(RNG& rng, vector& size) + { + cvtest::randomSize(rng, 2, 2, ARITHM_MAX_SIZE_LOG, size); + } + void op(const vector& src, Mat& dst, const Mat&) + { + cv::rotate(src[0], dst, rotatecode); + } + void refop(const vector& src, Mat& dst, const Mat&) + { + reference::rotate(src[0], dst, rotatecode); + } + void generateScalars(int, RNG& rng) + { + rotatecode = rng.uniform(0, 3); + } + double getMaxErr(int) + { + return 0; + } + int rotatecode; +}; + struct TransposeOp : public BaseElemWiseOp { TransposeOp() : BaseElemWiseOp(1, FIX_ALPHA+FIX_BETA+FIX_GAMMA, 1, 1, Scalar::all(0)) {} @@ -1550,6 +1597,7 @@ INSTANTIATE_TEST_CASE_P(Core_InRangeS, ElemWiseTest, ::testing::Values(ElemWiseO INSTANTIATE_TEST_CASE_P(Core_InRange, ElemWiseTest, ::testing::Values(ElemWiseOpPtr(new InRangeOp))); INSTANTIATE_TEST_CASE_P(Core_Flip, ElemWiseTest, ::testing::Values(ElemWiseOpPtr(new FlipOp))); +INSTANTIATE_TEST_CASE_P(Core_Rotate, ElemWiseTest, ::testing::Values(ElemWiseOpPtr(new RotateOp))); INSTANTIATE_TEST_CASE_P(Core_Transpose, ElemWiseTest, ::testing::Values(ElemWiseOpPtr(new TransposeOp))); INSTANTIATE_TEST_CASE_P(Core_SetIdentity, ElemWiseTest, ::testing::Values(ElemWiseOpPtr(new SetIdentityOp)));