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

Merge pull request #14945 from andrey-golubev:delete_bool

G-API: clean up accuracy tests (#14945)

* Delete createOutputMatrices flag

Update the way compile args function is created

Fix instantiation suffix print function

* Update comment (NB)

* Make printable comparison functions

* Use defines instead of objects for compile args

* Remove custom printers, use operator<< overload

* Remove SAME_TYPE and use -1 instead

* Delete createOutputMatrices flag in new tests

* Fix GetParam() printed values

* Update Resize tests: use CompareF object

* Address code review feedback

* Add default cases for operator<< overloads

* change throw to GAPI_Assert
This commit is contained in:
Andrey Golubev
2019-07-16 19:04:18 +03:00
committed by Alexander Alekhin
parent c11423df1e
commit c9bd43c0f6
15 changed files with 424 additions and 597 deletions
+138 -24
View File
@@ -132,15 +132,33 @@ 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)>;
// FIXME: re-use MatType. current problem: "special values" interpreted incorrectly (-1 is printed
// as 16FC512)
struct MatType2
{
public:
MatType2(int val = 0) : _value(val) {}
operator int() const { return _value; }
friend std::ostream& operator<<(std::ostream& os, const MatType2& t)
{
switch (t)
{
case -1: return os << "SAME_TYPE";
default: PrintTo(MatType(t), &os); return os;
}
}
private:
int _value;
};
// 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 common_params_t = std::tuple<MatType2, cv::Size, MatType2, 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...>;
using params_t = std::tuple<MatType2, cv::Size, MatType2, 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;
@@ -170,15 +188,9 @@ struct TestWithParamBase : TestFunctional,
{
using AllParams = Params<SpecificParams...>;
MatType type = getCommonParam<0>();
MatType2 type = getCommonParam<0>();
cv::Size sz = getCommonParam<1>();
MatType dtype = getCommonParam<2>();
bool createOutputMatrices = getCommonParam<3>();
TestWithParamBase()
{
if (dtype == SAME_TYPE) { dtype = type; }
}
MatType2 dtype = getCommonParam<2>();
// Get common (pre-defined) parameter value by index
template<size_t I>
@@ -199,7 +211,7 @@ struct TestWithParamBase : TestFunctional,
// Return G-API compile arguments specified for test fixture
inline cv::GCompileArgs getCompileArgs() const
{
return getCommonParam<4>()();
return getCommonParam<3>()();
}
};
@@ -220,13 +232,35 @@ struct TestWithParamBase : TestFunctional,
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); } \
Fixture() { InitF(type, sz, dtype); } \
};
// 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 T1, typename T2>
struct CompareF
{
using callable_t = std::function<bool(const T1& a, const T2& b)>;
CompareF(callable_t&& cmp, std::string&& cmp_name) :
_comparator(std::move(cmp)), _name(std::move(cmp_name)) {}
bool operator()(const T1& a, const T2& b) const
{
return _comparator(a, b);
}
friend std::ostream& operator<<(std::ostream& os, const CompareF<T1, T2>& obj)
{
return os << obj._name;
}
private:
callable_t _comparator;
std::string _name;
};
using CompareMats = CompareF<cv::Mat, cv::Mat>;
using CompareScalars = CompareF<cv::Scalar, cv::Scalar>;
template<typename T>
struct Wrappable
{
@@ -238,6 +272,14 @@ struct Wrappable
return t(a, b);
};
}
CompareMats to_compare_obj()
{
T t = *static_cast<T*const>(this);
std::stringstream ss;
ss << t;
return CompareMats(to_compare_f(), ss.str());
}
};
template<typename T>
@@ -251,6 +293,14 @@ struct WrappableScalar
return t(a, b);
};
}
CompareScalars to_compare_obj()
{
T t = *static_cast<T*const>(this);
std::stringstream ss;
ss << t;
return CompareScalars(to_compare_f(), ss.str());
}
};
@@ -270,7 +320,10 @@ public:
return true;
}
}
private:
friend std::ostream& operator<<(std::ostream& os, const AbsExact&)
{
return os << "AbsExact()";
}
};
class AbsTolerance : public Wrappable<AbsTolerance>
@@ -290,6 +343,10 @@ public:
return true;
}
}
friend std::ostream& operator<<(std::ostream& os, const AbsTolerance& obj)
{
return os << "AbsTolerance(" << std::to_string(obj._tol) << ")";
}
private:
double _tol;
};
@@ -318,6 +375,10 @@ public:
}
}
}
friend std::ostream& operator<<(std::ostream& os, const Tolerance_FloatRel_IntAbs& obj)
{
return os << "Tolerance_FloatRel_IntAbs(" << obj._tol << ", " << obj._tol8u << ")";
}
private:
double _tol;
double _tol8u;
@@ -347,6 +408,10 @@ public:
return true;
}
}
friend std::ostream& operator<<(std::ostream& os, const AbsSimilarPoints& obj)
{
return os << "AbsSimilarPoints(" << obj._tol << ", " << obj._percent << ")";
}
private:
double _tol;
double _percent;
@@ -379,6 +444,11 @@ public:
}
return true;
}
friend std::ostream& operator<<(std::ostream& os, const ToleranceFilter& obj)
{
return os << "ToleranceFilter(" << obj._tol << ", " << obj._tol8u << ", "
<< obj._inf_tol << ")";
}
private:
double _tol;
double _tol8u;
@@ -407,6 +477,10 @@ public:
}
return true;
}
friend std::ostream& operator<<(std::ostream& os, const ToleranceColor& obj)
{
return os << "ToleranceColor(" << obj._tol << ", " << obj._inf_tol << ")";
}
private:
double _tol;
double _inf_tol;
@@ -429,26 +503,66 @@ public:
return true;
}
}
friend std::ostream& operator<<(std::ostream& os, const AbsToleranceScalar& obj)
{
return os << "AbsToleranceScalar(" << std::to_string(obj._tol) << ")";
}
private:
double _tol;
};
} // namespace opencv_test
namespace
{
inline std::ostream& operator<<(std::ostream& os, const opencv_test::compare_f&)
{
return os << "compare_f";
}
inline std::ostream& operator<<(std::ostream& os, const opencv_test::compare_f&)
{
return os << "compare_f";
}
namespace
inline std::ostream& operator<<(std::ostream& os, const opencv_test::compare_scalar_f&)
{
inline std::ostream& operator<<(std::ostream& os, const opencv_test::compare_scalar_f&)
{
return os << "compare_scalar_f";
}
return os << "compare_scalar_f";
}
} // anonymous namespace
// Note: namespace must match the namespace of the type of the printed object
namespace cv
{
inline std::ostream& operator<<(std::ostream& os, CmpTypes op)
{
#define CASE(v) case CmpTypes::v: os << #v; break
switch (op)
{
CASE(CMP_EQ);
CASE(CMP_GT);
CASE(CMP_GE);
CASE(CMP_LT);
CASE(CMP_LE);
CASE(CMP_NE);
default: GAPI_Assert(false && "unknown CmpTypes value");
}
#undef CASE
return os;
}
inline std::ostream& operator<<(std::ostream& os, NormTypes op)
{
#define CASE(v) case NormTypes::v: os << #v; break
switch (op)
{
CASE(NORM_INF);
CASE(NORM_L1);
CASE(NORM_L2);
CASE(NORM_L2SQR);
CASE(NORM_HAMMING);
CASE(NORM_HAMMING2);
CASE(NORM_RELATIVE);
CASE(NORM_MINMAX);
default: GAPI_Assert(false && "unknown NormTypes value");
}
#undef CASE
return os;
}
} // namespace cv
#endif //OPENCV_GAPI_TESTS_COMMON_HPP