1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-31 00:03:03 +04:00

Merge pull request #14757 from andrey-golubev:core_tests_update

G-API: Introduce new approach to write accuracy tests (#14757)

* G-API: Introduce new common accuracy test fixture

* Enable Range<> to Seq<> implicit conversion

* Fix shadowing parameters

* Update license headers

* Rename ALIGNED_TYPE to SAME_TYPE

* Move MkRange to tests

* Fix TODO(agolubev) in test instantiations

* Squash simple fixture declarations in one line

* Remove unused line

* Fix Windows issues with macro expansion

* Choose between 1 or 2 matrix initialization

* Redesign common class behavior

Use "views" for GetParam() provided by GTest
base class instead of doing segregation
(with copy!) of common and specific parameters:
request common or specific parameter directly
by index from GetParam()-returned parameters

* Refine user-level API and usage of new test model

* Fix -fpermissive errors

* Remove unnecessary init calls

* Replace GCompileArgs member variable with func ptr

* Rename initMatsRandN to make its behavior explicit

Rename initMatsRandN to initMatrixRandN to eliminate confusion:
initMatsRandN only initialized first matrix (similarly to
initMatrixRandU)

* Fix common of initNothing

* Update copyright dates in missed files

* Add check for specific parameters

* Fix coment stlye
This commit is contained in:
Andrey Golubev
2019-06-28 13:07:41 +03:00
committed by Alexander Alekhin
parent b95e93c20a
commit 75c567b6ab
9 changed files with 884 additions and 784 deletions
+76 -62
View File
@@ -2,7 +2,7 @@
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
//
// Copyright (C) 2018 Intel Corporation
// Copyright (C) 2018-2019 Intel Corporation
#ifndef OPENCV_GAPI_CORE_TESTS_HPP
@@ -46,16 +46,18 @@ struct PrintMathOpCoreParams
std::string operator()(const ::testing::TestParamInfo<TestParams>& info) const
{
std::stringstream ss;
cv::Size sz = std::get<4>(info.param);
ss<<MathOperations[std::get<0>(info.param)]
<<"_"<<std::get<1>(info.param)
<<"_"<<std::get<2>(info.param)
<<"_"<<(int)std::get<3>(info.param)
using AllParams = Params<mathOp,bool,double,bool>;
const AllParams::params_t& params = info.param;
cv::Size sz = AllParams::getCommon<1>(params); // size
ss<<MathOperations[AllParams::getSpecific<0>(params)] // mathOp
<<"_"<<AllParams::getSpecific<1>(params) // testWithScalar
<<"_"<<AllParams::getCommon<0>(params) // type
<<"_"<<(int)AllParams::getSpecific<2>(params) // scale
<<"_"<<sz.width
<<"x"<<sz.height
<<"_"<<(std::get<5>(info.param)+1)
<<"_"<<std::get<6>(info.param)
<<"_"<<std::get<7>(info.param);
<<"_"<<(AllParams::getCommon<2>(params)+1) // dtype
<<"_"<<AllParams::getCommon<3>(params) // createOutputMatrices
<<"_"<<AllParams::getSpecific<3>(params); // doReverseOp
return ss.str();
}
};
@@ -66,13 +68,15 @@ struct PrintCmpCoreParams
std::string operator()(const ::testing::TestParamInfo<TestParams>& info) const
{
std::stringstream ss;
cv::Size sz = std::get<3>(info.param);
ss<<CompareOperations[std::get<0>(info.param)]
<<"_"<<std::get<1>(info.param)
<<"_"<<std::get<2>(info.param)
using AllParams = Params<CmpTypes,bool>;
const AllParams::params_t& params = info.param;
cv::Size sz = AllParams::getCommon<1>(params); // size
ss<<CompareOperations[AllParams::getSpecific<0>(params)] // CmpType
<<"_"<<AllParams::getSpecific<1>(params) // testWithScalar
<<"_"<<AllParams::getCommon<0>(params) // type
<<"_"<<sz.width
<<"x"<<sz.height
<<"_"<<std::get<4>(info.param);
<<"_"<<AllParams::getCommon<3>(params); // createOutputMatrices
return ss.str();
}
};
@@ -83,12 +87,14 @@ struct PrintBWCoreParams
std::string operator()(const ::testing::TestParamInfo<TestParams>& info) const
{
std::stringstream ss;
cv::Size sz = std::get<2>(info.param);
ss<<BitwiseOperations[std::get<0>(info.param)]
<<"_"<<std::get<1>(info.param)
using AllParams = Params<bitwiseOp>;
const AllParams::params_t& params = info.param;
cv::Size sz = AllParams::getCommon<1>(params); // size
ss<<BitwiseOperations[AllParams::getSpecific<0>(params)] // bitwiseOp
<<"_"<<AllParams::getCommon<0>(params) // type
<<"_"<<sz.width
<<"x"<<sz.height
<<"_"<<std::get<3>(info.param);
<<"_"<<AllParams::getCommon<3>(params); // createOutputMatrices
return ss.str();
}
};
@@ -99,56 +105,64 @@ struct PrintNormCoreParams
std::string operator()(const ::testing::TestParamInfo<TestParams>& info) const
{
std::stringstream ss;
cv::Size sz = std::get<2>(info.param);
ss<<NormOperations[std::get<0>(info.param)]
<<"_"<<std::get<1>(info.param)
using AllParams = Params<compare_scalar_f,NormTypes>;
const AllParams::params_t& params = info.param;
cv::Size sz = AllParams::getCommon<1>(params); // size
ss<<NormOperations[AllParams::getSpecific<1>(params)] // NormTypes
<<"_"<<AllParams::getCommon<0>(params) // type
<<"_"<<sz.width
<<"x"<<sz.height;
return ss.str();
}
};
struct MathOpTest : public TestParams<std::tuple<mathOp,bool,int,double,cv::Size,int,bool,bool,cv::GCompileArgs>>{};
struct MulDoubleTest : public TestParams<std::tuple<int,cv::Size,int,bool,cv::GCompileArgs>>{};
struct DivTest : public TestParams<std::tuple<int,cv::Size,int,bool, cv::GCompileArgs>>{};
struct DivCTest : public TestParams<std::tuple<int,cv::Size,int,bool, cv::GCompileArgs>>{};
struct MeanTest : public TestParams<std::tuple<int,cv::Size,bool, cv::GCompileArgs>> {};
struct MaskTest : public TestParams<std::tuple<int,cv::Size,bool, cv::GCompileArgs>> {};
struct Polar2CartTest : public TestParams<std::tuple<cv::Size,bool, cv::GCompileArgs>> {};
struct Cart2PolarTest : public TestParams<std::tuple<cv::Size,bool, cv::GCompileArgs>> {};
struct CmpTest : public TestParams<std::tuple<CmpTypes,bool,int,cv::Size,bool, cv::GCompileArgs>>{};
struct BitwiseTest : public TestParams<std::tuple<bitwiseOp,int,cv::Size,bool, cv::GCompileArgs>>{};
struct NotTest : public TestParams<std::tuple<int,cv::Size,bool, cv::GCompileArgs>> {};
struct SelectTest : public TestParams<std::tuple<int,cv::Size,bool, cv::GCompileArgs>> {};
struct MinTest : public TestParams<std::tuple<int,cv::Size,bool, cv::GCompileArgs>>{};
struct MaxTest : public TestParams<std::tuple<int,cv::Size,bool, cv::GCompileArgs>>{};
struct AbsDiffTest : public TestParams<std::tuple<int,cv::Size,bool, cv::GCompileArgs>>{};
struct AbsDiffCTest : public TestParams<std::tuple<int,cv::Size,bool, cv::GCompileArgs>> {};
struct SumTest : public TestParams<std::tuple<int, cv::Size,bool, compare_scalar_f, cv::GCompileArgs>> {};
struct AddWeightedTest : public TestParams<std::tuple<int,cv::Size,int,bool, compare_f,cv::GCompileArgs>>{};
struct NormTest : public TestParams<std::tuple<NormTypes,int,cv::Size, compare_scalar_f, cv::GCompileArgs>>{};
struct IntegralTest : public TestWithParam<std::tuple<int,cv::Size, cv::GCompileArgs>> {};
struct ThresholdTest : public TestParams<std::tuple<int,cv::Size,int,bool, cv::GCompileArgs>> {};
struct ThresholdOTTest : public TestParams<std::tuple<int,cv::Size,int,bool, cv::GCompileArgs>> {};
struct InRangeTest : public TestParams<std::tuple<int,cv::Size,bool, cv::GCompileArgs>> {};
struct Split3Test : public TestParams<std::tuple<cv::Size, cv::GCompileArgs>> {};
struct Split4Test : public TestParams<std::tuple<cv::Size, cv::GCompileArgs>> {};
struct ResizeTest : public TestWithParam<std::tuple<compare_f, int, int, cv::Size, cv::Size, cv::GCompileArgs>> {};
struct ResizeTestFxFy : public TestWithParam<std::tuple<compare_f, int, int, cv::Size, double, double, cv::GCompileArgs>> {};
struct Merge3Test : public TestParams<std::tuple<cv::Size, cv::GCompileArgs>> {};
struct Merge4Test : public TestParams<std::tuple<cv::Size, cv::GCompileArgs>> {};
struct RemapTest : public TestParams<std::tuple<int,cv::Size,bool, cv::GCompileArgs>> {};
struct FlipTest : public TestParams<std::tuple<int, int, cv::Size,bool, cv::GCompileArgs>> {};
struct CropTest : public TestParams<std::tuple<int,cv::Rect,cv::Size,bool, cv::GCompileArgs>> {};
struct ConcatHorTest : public TestWithParam<std::tuple<int, cv::Size, cv::GCompileArgs>> {};
struct ConcatVertTest : public TestWithParam<std::tuple<int, cv::Size, cv::GCompileArgs>> {};
struct ConcatVertVecTest : public TestWithParam<std::tuple<int, cv::Size, cv::GCompileArgs>> {};
struct ConcatHorVecTest : public TestWithParam<std::tuple<int, cv::Size, cv::GCompileArgs>> {};
struct LUTTest : public TestParams<std::tuple<int, int, cv::Size,bool, cv::GCompileArgs>> {};
struct ConvertToTest : public TestParams<std::tuple<int, int, cv::Size, double, double, compare_f, cv::GCompileArgs>> {};
struct PhaseTest : public TestParams<std::tuple<int, cv::Size, bool, cv::GCompileArgs>> {};
struct SqrtTest : public TestParams<std::tuple<int, cv::Size, cv::GCompileArgs>> {};
struct NormalizeTest : public TestParams<std::tuple<compare_f,MatType,cv::Size,double,double,int,MatType,bool,cv::GCompileArgs>> {};
GAPI_TEST_FIXTURE(MathOpTest, initMatsRandU, FIXTURE_API(mathOp,bool,double,bool), 4,
opType, testWithScalar, scale, doReverseOp)
GAPI_TEST_FIXTURE(MulDoubleTest, initMatrixRandU, <>, 0)
GAPI_TEST_FIXTURE(DivTest, initMatrixRandU, <>, 0)
GAPI_TEST_FIXTURE(DivCTest, initMatrixRandU, <>, 0)
GAPI_TEST_FIXTURE(MeanTest, initMatrixRandU, <>, 0)
GAPI_TEST_FIXTURE(MaskTest, initMatrixRandU, <>, 0)
GAPI_TEST_FIXTURE(Polar2CartTest, initMatsRandU, <>, 0)
GAPI_TEST_FIXTURE(Cart2PolarTest, initMatsRandU, <>, 0)
GAPI_TEST_FIXTURE(CmpTest, initMatsRandU, FIXTURE_API(CmpTypes,bool), 2, opType, testWithScalar)
GAPI_TEST_FIXTURE(BitwiseTest, initMatsRandU, FIXTURE_API(bitwiseOp), 1, opType)
GAPI_TEST_FIXTURE(NotTest, initMatrixRandU, <>, 0)
GAPI_TEST_FIXTURE(SelectTest, initMatsRandU, <>, 0)
GAPI_TEST_FIXTURE(MinTest, initMatsRandU, <>, 0)
GAPI_TEST_FIXTURE(MaxTest, initMatsRandU, <>, 0)
GAPI_TEST_FIXTURE(AbsDiffTest, initMatsRandU, <>, 0)
GAPI_TEST_FIXTURE(AbsDiffCTest, initMatsRandU, <>, 0)
GAPI_TEST_FIXTURE(SumTest, initMatrixRandU, FIXTURE_API(compare_scalar_f), 1, cmpF)
GAPI_TEST_FIXTURE(AddWeightedTest, initMatsRandU, FIXTURE_API(compare_f), 1, cmpF)
GAPI_TEST_FIXTURE(NormTest, initMatrixRandU, FIXTURE_API(compare_scalar_f,NormTypes), 2,
cmpF, opType)
GAPI_TEST_FIXTURE(IntegralTest, initNothing, <>, 0)
GAPI_TEST_FIXTURE(ThresholdTest, initMatrixRandU, FIXTURE_API(int), 1, tt)
GAPI_TEST_FIXTURE(ThresholdOTTest, initMatrixRandU, FIXTURE_API(int), 1, tt)
GAPI_TEST_FIXTURE(InRangeTest, initMatrixRandU, <>, 0)
GAPI_TEST_FIXTURE(Split3Test, initMatrixRandU, <>, 0)
GAPI_TEST_FIXTURE(Split4Test, initMatrixRandU, <>, 0)
GAPI_TEST_FIXTURE(ResizeTest, initNothing, FIXTURE_API(compare_f,int,cv::Size), 3,
cmpF, interp, sz_out)
GAPI_TEST_FIXTURE(ResizeTestFxFy, initNothing, FIXTURE_API(compare_f,int,double,double), 4,
cmpF, interp, fx, fy)
GAPI_TEST_FIXTURE(Merge3Test, initMatsRandU, <>, 0)
GAPI_TEST_FIXTURE(Merge4Test, initMatsRandU, <>, 0)
GAPI_TEST_FIXTURE(RemapTest, initMatrixRandU, <>, 0)
GAPI_TEST_FIXTURE(FlipTest, initMatrixRandU, FIXTURE_API(int), 1, flipCode)
GAPI_TEST_FIXTURE(CropTest, initMatrixRandU, FIXTURE_API(cv::Rect), 1, rect_to)
GAPI_TEST_FIXTURE(ConcatHorTest, initNothing, <>, 0)
GAPI_TEST_FIXTURE(ConcatVertTest, initNothing, <>, 0)
GAPI_TEST_FIXTURE(ConcatVertVecTest, initNothing, <>, 0)
GAPI_TEST_FIXTURE(ConcatHorVecTest, initNothing, <>, 0)
GAPI_TEST_FIXTURE(LUTTest, initNothing, <>, 0)
GAPI_TEST_FIXTURE(ConvertToTest, initNothing, FIXTURE_API(compare_f, double, double), 3,
cmpF, alpha, beta)
GAPI_TEST_FIXTURE(PhaseTest, initMatsRandU, FIXTURE_API(bool), 1, angle_in_degrees)
GAPI_TEST_FIXTURE(SqrtTest, initMatrixRandU, <>, 0)
GAPI_TEST_FIXTURE(NormalizeTest, initNothing, FIXTURE_API(compare_f,double,double,int,MatType), 5,
cmpF, a, b, norm_type, ddepth)
} // opencv_test
#endif //OPENCV_GAPI_CORE_TESTS_HPP
File diff suppressed because it is too large Load Diff
@@ -2,7 +2,7 @@
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
//
// Copyright (C) 2018 Intel Corporation
// Copyright (C) 2018-2019 Intel Corporation
#ifndef OPENCV_GAPI_IMGPROC_TESTS_INL_HPP
@@ -61,7 +61,7 @@ TEST_P(Filter2DTest, AccuracyTest)
bool initOut = false;
cv::GCompileArgs compile_args;
std::tie(cmpF, type, kernSize, sz, borderType, dtype, initOut, compile_args) = GetParam();
initMatsRandN(type, sz, dtype, initOut);
initMatrixRandN(type, sz, dtype, initOut);
cv::Point anchor = {-1, -1};
double delta = 0;
@@ -97,7 +97,7 @@ TEST_P(BoxFilterTest, AccuracyTest)
bool initOut = false;
cv::GCompileArgs compile_args;
std::tie(cmpF, type, filterSize, sz, borderType, dtype, initOut, compile_args) = GetParam();
initMatsRandN(type, sz, dtype, initOut);
initMatrixRandN(type, sz, dtype, initOut);
cv::Point anchor = {-1, -1};
bool normalize = true;
@@ -133,7 +133,7 @@ TEST_P(SepFilterTest, AccuracyTest)
cv::Mat kernelY(kernSize, 1, CV_32F);
randu(kernelX, -1, 1);
randu(kernelY, -1, 1);
initMatsRandN(type, sz, dtype, initOut);
initMatrixRandN(type, sz, dtype, initOut);
cv::Point anchor = cv::Point(-1, -1);
@@ -163,7 +163,7 @@ TEST_P(BlurTest, AccuracyTest)
bool initOut = false;
cv::GCompileArgs compile_args;
std::tie(cmpF, type, filterSize, sz, borderType, initOut, compile_args) = GetParam();
initMatsRandN(type, sz, type, initOut);
initMatrixRandN(type, sz, type, initOut);
cv::Point anchor = {-1, -1};
@@ -193,7 +193,7 @@ TEST_P(GaussianBlurTest, AccuracyTest)
bool initOut = false;
cv::GCompileArgs compile_args;
std::tie(cmpF,type, kernSize, sz, initOut, compile_args) = GetParam();
initMatsRandN(type, sz, type, initOut);
initMatrixRandN(type, sz, type, initOut);
cv::Size kSize = cv::Size(kernSize, kernSize);
double sigmaX = rand();
@@ -224,7 +224,7 @@ TEST_P(MedianBlurTest, AccuracyTest)
bool initOut = false;
cv::GCompileArgs compile_args;
std::tie(cmpF, type, kernSize, sz, initOut, compile_args) = GetParam();
initMatsRandN(type, sz, type, initOut);
initMatrixRandN(type, sz, type, initOut);
// G-API code //////////////////////////////////////////////////////////////
cv::GMat in;
@@ -252,7 +252,7 @@ TEST_P(ErodeTest, AccuracyTest)
bool initOut = false;
cv::GCompileArgs compile_args;
std::tie(cmpF, type, kernSize, sz, kernType, initOut, compile_args) = GetParam();
initMatsRandN(type, sz, type, initOut);
initMatrixRandN(type, sz, type, initOut);
cv::Mat kernel = cv::getStructuringElement(kernType, cv::Size(kernSize, kernSize));
@@ -282,7 +282,7 @@ TEST_P(Erode3x3Test, AccuracyTest)
bool initOut = false;
cv::GCompileArgs compile_args;
std::tie(cmpF, type, sz, initOut, numIters, compile_args) = GetParam();
initMatsRandN(type, sz, type, initOut);
initMatrixRandN(type, sz, type, initOut);
cv::Mat kernel = cv::getStructuringElement(cv::MorphShapes::MORPH_RECT, cv::Size(3,3));
@@ -312,7 +312,7 @@ TEST_P(DilateTest, AccuracyTest)
bool initOut = false;
cv::GCompileArgs compile_args;
std::tie(cmpF, type, kernSize, sz, kernType, initOut, compile_args) = GetParam();
initMatsRandN(type, sz, type, initOut);
initMatrixRandN(type, sz, type, initOut);
cv::Mat kernel = cv::getStructuringElement(kernType, cv::Size(kernSize, kernSize));
@@ -342,7 +342,7 @@ TEST_P(Dilate3x3Test, AccuracyTest)
bool initOut = false;
cv::GCompileArgs compile_args;
std::tie(cmpF, type, sz, initOut, numIters, compile_args) = GetParam();
initMatsRandN(type, sz, type, initOut);
initMatrixRandN(type, sz, type, initOut);
cv::Mat kernel = cv::getStructuringElement(cv::MorphShapes::MORPH_RECT, cv::Size(3,3));
@@ -373,7 +373,7 @@ TEST_P(SobelTest, AccuracyTest)
bool initOut = false;
cv::GCompileArgs compile_args;
std::tie(cmpF, type, kernSize, sz, dtype, dx, dy, initOut, compile_args) = GetParam();
initMatsRandN(type, sz, dtype, initOut);
initMatrixRandN(type, sz, dtype, initOut);
// G-API code //////////////////////////////////////////////////////////////
cv::GMat in;
@@ -404,7 +404,7 @@ TEST_P(SobelXYTest, AccuracyTest)
cv::Mat out_mat_ocv2;
cv::Mat out_mat_gapi2;
initMatsRandN(type, sz, dtype);
initMatrixRandN(type, sz, dtype);
// G-API code //////////////////////////////////////////////////////////////
cv::GMat in;
@@ -441,7 +441,7 @@ TEST_P(EqHistTest, AccuracyTest)
bool initOut = false;
cv::GCompileArgs compile_args;
std::tie(cmpF, sz, initOut, compile_args) = GetParam();
initMatsRandN(CV_8UC1, sz, CV_8UC1, initOut);
initMatrixRandN(CV_8UC1, sz, CV_8UC1, initOut);
// G-API code //////////////////////////////////////////////////////////////
cv::GMat in;
@@ -471,7 +471,7 @@ TEST_P(CannyTest, AccuracyTest)
cv::GCompileArgs compile_args;
std::tie(cmpF, type, sz, thrLow, thrUp, apSize, l2gr, initOut, compile_args) = GetParam();
initMatsRandN(type, sz, CV_8UC1, initOut);
initMatrixRandN(type, sz, CV_8UC1, initOut);
// G-API code //////////////////////////////////////////////////////////////
cv::GMat in;
@@ -495,7 +495,7 @@ TEST_P(RGB2GrayTest, AccuracyTest)
auto param = GetParam();
auto compile_args = std::get<3>(param);
compare_f cmpF = std::get<0>(param);
initMatsRandN(CV_8UC3, std::get<1>(param), CV_8UC1, std::get<2>(param));
initMatrixRandN(CV_8UC3, std::get<1>(param), CV_8UC1, std::get<2>(param));
// G-API code //////////////////////////////////////////////////////////////
cv::GMat in;
@@ -519,7 +519,7 @@ TEST_P(BGR2GrayTest, AccuracyTest)
auto param = GetParam();
auto compile_args = std::get<3>(param);
compare_f cmpF = std::get<0>(param);
initMatsRandN(CV_8UC3, std::get<1>(param), CV_8UC1, std::get<2>(param));
initMatrixRandN(CV_8UC3, std::get<1>(param), CV_8UC1, std::get<2>(param));
// G-API code //////////////////////////////////////////////////////////////
cv::GMat in;
@@ -543,7 +543,7 @@ TEST_P(RGB2YUVTest, AccuracyTest)
auto param = GetParam();
auto compile_args = std::get<3>(param);
compare_f cmpF = std::get<0>(param);
initMatsRandN(CV_8UC3, std::get<1>(param), CV_8UC3, std::get<2>(param));
initMatrixRandN(CV_8UC3, std::get<1>(param), CV_8UC3, std::get<2>(param));
// G-API code //////////////////////////////////////////////////////////////
cv::GMat in;
@@ -567,7 +567,7 @@ TEST_P(YUV2RGBTest, AccuracyTest)
auto param = GetParam();
auto compile_args = std::get<3>(param);
compare_f cmpF = std::get<0>(param);
initMatsRandN(CV_8UC3, std::get<1>(param), CV_8UC3, std::get<2>(param));
initMatrixRandN(CV_8UC3, std::get<1>(param), CV_8UC3, std::get<2>(param));
// G-API code //////////////////////////////////////////////////////////////
@@ -594,7 +594,7 @@ TEST_P(NV12toRGBTest, AccuracyTest)
cv::GCompileArgs compile_args;
std::tie(cmpF, sz, compile_args) = GetParam();
initMatsRandN(CV_8UC1, sz, CV_8UC3);
initMatrixRandN(CV_8UC1, sz, CV_8UC3);
// G-API code //////////////////////////////////////////////////////////////
cv::GMat in_y;
@@ -625,7 +625,7 @@ TEST_P(NV12toBGRTest, AccuracyTest)
cv::GCompileArgs compile_args;
std::tie(cmpF, sz, compile_args) = GetParam();
initMatsRandN(CV_8UC1, sz, CV_8UC3);
initMatrixRandN(CV_8UC1, sz, CV_8UC3);
// G-API code //////////////////////////////////////////////////////////////
cv::GMat in_y;
@@ -654,7 +654,7 @@ TEST_P(RGB2LabTest, AccuracyTest)
auto param = GetParam();
auto compile_args = std::get<3>(param);
compare_f cmpF = std::get<0>(param);
initMatsRandN(CV_8UC3, std::get<1>(param), CV_8UC3, std::get<2>(param));
initMatrixRandN(CV_8UC3, std::get<1>(param), CV_8UC3, std::get<2>(param));
// G-API code //////////////////////////////////////////////////////////////
cv::GMat in;
@@ -678,7 +678,7 @@ TEST_P(BGR2LUVTest, AccuracyTest)
auto param = GetParam();
auto compile_args = std::get<3>(param);
compare_f cmpF = std::get<0>(param);
initMatsRandN(CV_8UC3, std::get<1>(param), CV_8UC3, std::get<2>(param));
initMatrixRandN(CV_8UC3, std::get<1>(param), CV_8UC3, std::get<2>(param));
// G-API code //////////////////////////////////////////////////////////////
cv::GMat in;
@@ -702,7 +702,7 @@ TEST_P(LUV2BGRTest, AccuracyTest)
auto param = GetParam();
auto compile_args = std::get<3>(param);
compare_f cmpF = std::get<0>(param);
initMatsRandN(CV_8UC3, std::get<1>(param), CV_8UC3, std::get<2>(param));
initMatrixRandN(CV_8UC3, std::get<1>(param), CV_8UC3, std::get<2>(param));
// G-API code //////////////////////////////////////////////////////////////
cv::GMat in;
@@ -726,7 +726,7 @@ TEST_P(BGR2YUVTest, AccuracyTest)
auto param = GetParam();
auto compile_args = std::get<3>(param);
compare_f cmpF = std::get<0>(param);
initMatsRandN(CV_8UC3, std::get<1>(param), CV_8UC3, std::get<2>(param));
initMatrixRandN(CV_8UC3, std::get<1>(param), CV_8UC3, std::get<2>(param));
// G-API code //////////////////////////////////////////////////////////////
cv::GMat in;
@@ -750,7 +750,7 @@ TEST_P(YUV2BGRTest, AccuracyTest)
auto param = GetParam();
auto compile_args = std::get<3>(param);
compare_f cmpF = std::get<0>(param);
initMatsRandN(CV_8UC3, std::get<1>(param), CV_8UC3, std::get<2>(param));
initMatrixRandN(CV_8UC3, std::get<1>(param), CV_8UC3, std::get<2>(param));
// G-API code //////////////////////////////////////////////////////////////
cv::GMat in;
@@ -774,7 +774,7 @@ TEST_P(RGB2HSVTest, AccuracyTest)
auto param = GetParam();
auto compile_args = std::get<3>(param);
compare_f cmpF = std::get<0>(param);
initMatsRandN(CV_8UC3, std::get<1>(param), CV_8UC3, std::get<2>(param));
initMatrixRandN(CV_8UC3, std::get<1>(param), CV_8UC3, std::get<2>(param));
// G-API code //////////////////////////////////////////////////////////////
cv::GMat in;
@@ -798,7 +798,7 @@ TEST_P(BayerGR2RGBTest, AccuracyTest)
auto param = GetParam();
auto compile_args = std::get<3>(param);
compare_f cmpF = std::get<0>(param);
initMatsRandN(CV_8UC1, std::get<1>(param), CV_8UC3, std::get<2>(param));
initMatrixRandN(CV_8UC1, std::get<1>(param), CV_8UC3, std::get<2>(param));
// G-API code //////////////////////////////////////////////////////////////
cv::GMat in;
@@ -822,7 +822,7 @@ TEST_P(RGB2YUV422Test, AccuracyTest)
auto param = GetParam();
auto compile_args = std::get<3>(param);
compare_f cmpF = std::get<0>(param);
initMatsRandN(CV_8UC3, std::get<1>(param), CV_8UC2, std::get<2>(param));
initMatrixRandN(CV_8UC3, std::get<1>(param), CV_8UC2, std::get<2>(param));
// G-API code //////////////////////////////////////////////////////////////
cv::GMat in;
+124 -13
View File
@@ -2,13 +2,20 @@
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
//
// Copyright (C) 2018 Intel Corporation
// Copyright (C) 2018-2019 Intel Corporation
#ifndef OPENCV_GAPI_TESTS_COMMON_HPP
#define OPENCV_GAPI_TESTS_COMMON_HPP
#include <iostream>
#include <tuple>
#include <type_traits>
#include <opencv2/ts.hpp>
#include <opencv2/gapi.hpp>
#include <opencv2/gapi/util/util.hpp>
#include "gapi_tests_helpers.hpp"
namespace
{
@@ -41,6 +48,15 @@ public:
return cv::Scalar(s1, s2, s3, s4);
}
void initOutMats(cv::Size sz_in, int dtype)
{
if (dtype != -1)
{
out_mat_gapi = cv::Mat(sz_in, dtype);
out_mat_ocv = cv::Mat(sz_in, dtype);
}
}
void initMatsRandU(int type, cv::Size sz_in, int dtype, bool createOutputMatrices = true)
{
in_mat1 = cv::Mat(sz_in, type);
@@ -50,10 +66,9 @@ public:
cv::randu(in_mat1, cv::Scalar::all(0), cv::Scalar::all(255));
cv::randu(in_mat2, cv::Scalar::all(0), cv::Scalar::all(255));
if (createOutputMatrices && dtype != -1)
if (createOutputMatrices)
{
out_mat_gapi = cv::Mat (sz_in, dtype);
out_mat_ocv = cv::Mat (sz_in, dtype);
initOutMats(sz_in, dtype);
}
}
@@ -62,28 +77,28 @@ public:
in_mat1 = cv::Mat(sz_in, type);
sc = initScalarRandU(100);
cv::randu(in_mat1, cv::Scalar::all(0), cv::Scalar::all(255));
if (createOutputMatrices && dtype != -1)
if (createOutputMatrices)
{
out_mat_gapi = cv::Mat (sz_in, dtype);
out_mat_ocv = cv::Mat (sz_in, dtype);
initOutMats(sz_in, dtype);
}
}
void initMatsRandN(int type, cv::Size sz_in, int dtype, bool createOutputMatrices = true)
void initMatrixRandN(int type, cv::Size sz_in, int dtype, bool createOutputMatrices = true)
{
in_mat1 = cv::Mat(sz_in, type);
in_mat1 = cv::Mat(sz_in, type);
cv::randn(in_mat1, cv::Scalar::all(127), cv::Scalar::all(40.f));
if (createOutputMatrices && dtype != -1)
if (createOutputMatrices)
{
out_mat_gapi = cv::Mat(sz_in, dtype);
out_mat_ocv = cv::Mat(sz_in, dtype);
initOutMats(sz_in, dtype);
}
}
// empty function intended to show that nothing is to be initialized via TestFunctional methods
void initNothing(int, cv::Size, int, bool = true) {}
static cv::Mat nonZeroPixels(const cv::Mat& mat)
{
int channels = mat.channels();
@@ -117,6 +132,100 @@ using compare_f = std::function<bool(const cv::Mat &a, const cv::Mat &b)>;
using compare_scalar_f = std::function<bool(const cv::Scalar &a, const cv::Scalar &b)>;
// Universal parameter wrapper for common (pre-defined) and specific (user-defined) parameters
template<typename ...SpecificParams>
struct Params
{
using gcomp_args_function_t = cv::GCompileArgs(*)();
// TODO: delete bool (createOutputMatrices) from common parameters
using common_params_t = std::tuple<int, cv::Size, int, bool, gcomp_args_function_t>;
using specific_params_t = std::tuple<SpecificParams...>;
using params_t = std::tuple<int, cv::Size, int, bool, gcomp_args_function_t, SpecificParams...>;
static constexpr const size_t common_params_size = std::tuple_size<common_params_t>::value;
static constexpr const size_t specific_params_size = std::tuple_size<specific_params_t>::value;
template<size_t I>
static const typename std::tuple_element<I, common_params_t>::type&
getCommon(const params_t& t)
{
static_assert(I < common_params_size, "Index out of range");
return std::get<I>(t);
}
template<size_t I>
static const typename std::tuple_element<I, specific_params_t>::type&
getSpecific(const params_t& t)
{
static_assert(specific_params_size > 0,
"Impossible to call this function: no specific parameters specified");
static_assert(I < specific_params_size, "Index out of range");
return std::get<common_params_size + I>(t);
}
};
// Base class for test fixtures
template<typename ...SpecificParams>
struct TestWithParamBase : TestFunctional,
TestWithParam<typename Params<SpecificParams...>::params_t>
{
using AllParams = Params<SpecificParams...>;
MatType type = getCommonParam<0>();
cv::Size sz = getCommonParam<1>();
MatType dtype = getCommonParam<2>();
bool createOutputMatrices = getCommonParam<3>();
TestWithParamBase()
{
if (dtype == SAME_TYPE) { dtype = type; }
}
// Get common (pre-defined) parameter value by index
template<size_t I>
inline auto getCommonParam() const
-> decltype(AllParams::template getCommon<I>(this->GetParam()))
{
return AllParams::template getCommon<I>(this->GetParam());
}
// Get specific (user-defined) parameter value by index
template<size_t I>
inline auto getSpecificParam() const
-> decltype(AllParams::template getSpecific<I>(this->GetParam()))
{
return AllParams::template getSpecific<I>(this->GetParam());
}
// Return G-API compile arguments specified for test fixture
inline cv::GCompileArgs getCompileArgs() const
{
return getCommonParam<4>()();
}
};
/**
* @private
* @brief Create G-API test fixture with TestWithParamBase base class
* @param Fixture test fixture name
* @param InitF callable that will initialize default available members (from TestFunctional)
* @param API base class API. Specifies types of user-defined parameters. If there are no such
* parameters, empty angle brackets ("<>") must be specified.
* @param Number number of user-defined parameters (corresponds to the number of types in API).
* if there are no such parameters, 0 must be specified.
* @param ... list of names of user-defined parameters. if there are no parameters, the list
* must be empty.
*/
#define GAPI_TEST_FIXTURE(Fixture, InitF, API, Number, ...) \
struct Fixture : public TestWithParamBase API { \
static_assert(Number == AllParams::specific_params_size, \
"Number of user-defined parameters doesn't match size of __VA_ARGS__"); \
__WRAP_VAARGS(DEFINE_SPECIFIC_PARAMS_##Number(__VA_ARGS__)) \
Fixture() { InitF(type, sz, dtype, createOutputMatrices); } \
};
// Wrapper for test fixture API. Use to specify multiple types.
// Example: FIXTURE_API(int, bool) expands to <int, bool>
#define FIXTURE_API(...) <__VA_ARGS__>
template<typename T>
struct Wrappable
@@ -341,3 +450,5 @@ namespace
return os << "compare_scalar_f";
}
}
#endif //OPENCV_GAPI_TESTS_COMMON_HPP
@@ -0,0 +1,73 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
//
// Copyright (C) 2019 Intel Corporation
#ifndef OPENCV_GAPI_TESTS_HELPERS_HPP
#define OPENCV_GAPI_TESTS_HELPERS_HPP
#include <tuple>
#include <limits>
namespace opencv_test
{
// out_type == in_type in matrices initialization if out_type is marked as SAME_TYPE
enum {
// TODO: why is it different from -1?
SAME_TYPE = std::numeric_limits<int>::max()
};
// Ensure correct __VA_ARGS__ expansion on Windows
#define __WRAP_VAARGS(x) x
#define __TUPLE_PARAM_TYPE(i) std::tuple_element<i, AllParams::specific_params_t>::type
// implementation of recursive in-class declaration and initialization of member variables
#define __DEFINE_PARAMS_IMPL1(index, param_name) \
__TUPLE_PARAM_TYPE(index) param_name = getSpecificParam<index>();
#define __DEFINE_PARAMS_IMPL2(index, param_name, ...) \
__TUPLE_PARAM_TYPE(index) param_name = getSpecificParam<index>(); \
__WRAP_VAARGS(__DEFINE_PARAMS_IMPL1(index+1, __VA_ARGS__))
#define __DEFINE_PARAMS_IMPL3(index, param_name, ...) \
__TUPLE_PARAM_TYPE(index) param_name = getSpecificParam<index>(); \
__WRAP_VAARGS(__DEFINE_PARAMS_IMPL2(index+1, __VA_ARGS__))
#define __DEFINE_PARAMS_IMPL4(index, param_name, ...) \
__TUPLE_PARAM_TYPE(index) param_name = getSpecificParam<index>(); \
__WRAP_VAARGS(__DEFINE_PARAMS_IMPL3(index+1, __VA_ARGS__))
#define __DEFINE_PARAMS_IMPL5(index, param_name, ...) \
__TUPLE_PARAM_TYPE(index) param_name = getSpecificParam<index>(); \
__WRAP_VAARGS(__DEFINE_PARAMS_IMPL4(index+1, __VA_ARGS__))
#define __DEFINE_PARAMS_IMPL6(index, param_name, ...) \
__TUPLE_PARAM_TYPE(index) param_name = getSpecificParam<index>(); \
__WRAP_VAARGS(__DEFINE_PARAMS_IMPL5(index+1, __VA_ARGS__))
// user interface to define member variables of specified names
#define DEFINE_SPECIFIC_PARAMS_0()
#define DEFINE_SPECIFIC_PARAMS_1(...) \
__WRAP_VAARGS(__DEFINE_PARAMS_IMPL1(0, __VA_ARGS__))
#define DEFINE_SPECIFIC_PARAMS_2(...) \
__WRAP_VAARGS(__DEFINE_PARAMS_IMPL2(0, __VA_ARGS__))
#define DEFINE_SPECIFIC_PARAMS_3(...) \
__WRAP_VAARGS(__DEFINE_PARAMS_IMPL3(0, __VA_ARGS__))
#define DEFINE_SPECIFIC_PARAMS_4(...) \
__WRAP_VAARGS(__DEFINE_PARAMS_IMPL4(0, __VA_ARGS__))
#define DEFINE_SPECIFIC_PARAMS_5(...) \
__WRAP_VAARGS(__DEFINE_PARAMS_IMPL5(0, __VA_ARGS__))
#define DEFINE_SPECIFIC_PARAMS_6(...) \
__WRAP_VAARGS(__DEFINE_PARAMS_IMPL6(0, __VA_ARGS__))
} // namespace opencv_test
#endif //OPENCV_GAPI_TESTS_HELPERS_HPP