Skip to content

Commit b267f17

Browse files
authored
Merge pull request #25633 from savuor:rv/rotate_tests
Tests for cv::rotate() added #25633 fixes #25449 ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake
1 parent f17b122 commit b267f17

3 files changed

Lines changed: 105 additions & 0 deletions

File tree

modules/core/perf/opencl/perf_arithm.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,36 @@ OCL_PERF_TEST_P(FlipFixture, Flip,
374374
SANITY_CHECK(dst);
375375
}
376376

377+
///////////// Rotate ////////////////////////
378+
379+
enum
380+
{
381+
ROTATE_90_CLOCKWISE = 0, ROTATE_180, ROTATE_90_COUNTERCLOCKWISE
382+
};
383+
384+
CV_ENUM(RotateType, ROTATE_90_CLOCKWISE, ROTATE_180, ROTATE_90_COUNTERCLOCKWISE)
385+
386+
typedef tuple<Size, MatType, RotateType> RotateParams;
387+
typedef TestBaseWithParam<RotateParams> RotateFixture;
388+
389+
OCL_PERF_TEST_P(RotateFixture, rotate,
390+
::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES, RotateType::all()))
391+
{
392+
const RotateParams params = GetParam();
393+
const Size srcSize = get<0>(params);
394+
const int type = get<1>(params);
395+
const int rotateCode = get<2>(params);
396+
397+
checkDeviceMaxMemoryAllocSize(srcSize, type);
398+
399+
UMat src(srcSize, type), dst(srcSize, type);
400+
declare.in(src, WARMUP_RNG).out(dst);
401+
402+
OCL_TEST_CYCLE() cv::rotate(src, dst, rotateCode);
403+
404+
SANITY_CHECK_NOTHING();
405+
}
406+
377407
///////////// minMaxLoc ////////////////////////
378408

379409
typedef Size_MatType MinMaxLocFixture;

modules/core/perf/perf_arithm.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,33 @@ INSTANTIATE_TEST_CASE_P(/*nothing*/ , BinaryOpTest,
452452
)
453453
);
454454

455+
///////////// Rotate ////////////////////////
456+
457+
typedef perf::TestBaseWithParam<std::tuple<cv::Size, int, perf::MatType>> RotateTest;
458+
459+
PERF_TEST_P_(RotateTest, rotate)
460+
{
461+
Size sz = get<0>(GetParam());
462+
int rotatecode = get<1>(GetParam());
463+
int type = get<2>(GetParam());
464+
cv::Mat a(sz, type), b(sz, type);
465+
466+
declare.in(a, WARMUP_RNG).out(b);
467+
468+
TEST_CYCLE() cv::rotate(a, b, rotatecode);
469+
470+
SANITY_CHECK_NOTHING();
471+
}
472+
473+
INSTANTIATE_TEST_CASE_P(/*nothing*/ , RotateTest,
474+
testing::Combine(
475+
testing::Values(szVGA, sz720p, sz1080p),
476+
testing::Values(ROTATE_180, ROTATE_90_CLOCKWISE, ROTATE_90_COUNTERCLOCKWISE),
477+
testing::Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_8SC1, CV_16SC1, CV_16SC2, CV_16SC3, CV_16SC4, CV_32SC1, CV_32FC1)
478+
)
479+
);
480+
481+
455482
///////////// PatchNaNs ////////////////////////
456483

457484
template<typename _Tp>

modules/core/test/test_arithm.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,7 @@ struct ConvertScaleAbsOp : public BaseElemWiseOp
831831

832832
namespace reference {
833833

834+
// does not support inplace operation
834835
static void flip(const Mat& src, Mat& dst, int flipcode)
835836
{
836837
CV_Assert(src.dims == 2);
@@ -852,6 +853,26 @@ static void flip(const Mat& src, Mat& dst, int flipcode)
852853
}
853854
}
854855

856+
static void rotate(const Mat& src, Mat& dst, int rotateMode)
857+
{
858+
Mat tmp;
859+
switch (rotateMode)
860+
{
861+
case ROTATE_90_CLOCKWISE:
862+
cvtest::transpose(src, tmp);
863+
reference::flip(tmp, dst, 1);
864+
break;
865+
case ROTATE_180:
866+
reference::flip(src, dst, -1);
867+
break;
868+
case ROTATE_90_COUNTERCLOCKWISE:
869+
cvtest::transpose(src, tmp);
870+
reference::flip(tmp, dst, 0);
871+
break;
872+
default:
873+
break;
874+
}
875+
}
855876

856877
static void setIdentity(Mat& dst, const Scalar& s)
857878
{
@@ -898,6 +919,32 @@ struct FlipOp : public BaseElemWiseOp
898919
int flipcode;
899920
};
900921

922+
struct RotateOp : public BaseElemWiseOp
923+
{
924+
RotateOp() : BaseElemWiseOp(1, FIX_ALPHA+FIX_BETA+FIX_GAMMA, 1, 1, Scalar::all(0)) { rotatecode = 0; }
925+
void getRandomSize(RNG& rng, vector<int>& size)
926+
{
927+
cvtest::randomSize(rng, 2, 2, ARITHM_MAX_SIZE_LOG, size);
928+
}
929+
void op(const vector<Mat>& src, Mat& dst, const Mat&)
930+
{
931+
cv::rotate(src[0], dst, rotatecode);
932+
}
933+
void refop(const vector<Mat>& src, Mat& dst, const Mat&)
934+
{
935+
reference::rotate(src[0], dst, rotatecode);
936+
}
937+
void generateScalars(int, RNG& rng)
938+
{
939+
rotatecode = rng.uniform(0, 3);
940+
}
941+
double getMaxErr(int)
942+
{
943+
return 0;
944+
}
945+
int rotatecode;
946+
};
947+
901948
struct TransposeOp : public BaseElemWiseOp
902949
{
903950
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
15501597
INSTANTIATE_TEST_CASE_P(Core_InRange, ElemWiseTest, ::testing::Values(ElemWiseOpPtr(new InRangeOp)));
15511598

15521599
INSTANTIATE_TEST_CASE_P(Core_Flip, ElemWiseTest, ::testing::Values(ElemWiseOpPtr(new FlipOp)));
1600+
INSTANTIATE_TEST_CASE_P(Core_Rotate, ElemWiseTest, ::testing::Values(ElemWiseOpPtr(new RotateOp)));
15531601
INSTANTIATE_TEST_CASE_P(Core_Transpose, ElemWiseTest, ::testing::Values(ElemWiseOpPtr(new TransposeOp)));
15541602
INSTANTIATE_TEST_CASE_P(Core_SetIdentity, ElemWiseTest, ::testing::Values(ElemWiseOpPtr(new SetIdentityOp)));
15551603

0 commit comments

Comments
 (0)