Commit 75c567b6 authored by Andrey Golubev's avatar Andrey Golubev Committed by Alexander Alekhin

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
parent b95e93c2
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// It is subject to the license terms in the LICENSE file found in the top-level directory // 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. // 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_PERF_TESTS_INL_HPP #ifndef OPENCV_GAPI_IMGPROC_PERF_TESTS_INL_HPP
...@@ -68,7 +68,7 @@ PERF_TEST_P_(SepFilterPerfTest, TestPerformance) ...@@ -68,7 +68,7 @@ PERF_TEST_P_(SepFilterPerfTest, TestPerformance)
cv::Mat kernelY(kernSize, 1, CV_32F); cv::Mat kernelY(kernSize, 1, CV_32F);
randu(kernelX, -1, 1); randu(kernelX, -1, 1);
randu(kernelY, -1, 1); randu(kernelY, -1, 1);
initMatsRandN(type, sz, dtype, false); initMatrixRandN(type, sz, dtype, false);
cv::Point anchor = cv::Point(-1, -1); cv::Point anchor = cv::Point(-1, -1);
...@@ -110,7 +110,7 @@ PERF_TEST_P_(Filter2DPerfTest, TestPerformance) ...@@ -110,7 +110,7 @@ PERF_TEST_P_(Filter2DPerfTest, TestPerformance)
cv::GCompileArgs compile_args; cv::GCompileArgs compile_args;
std::tie(cmpF, type, kernSize, sz, borderType, dtype, compile_args) = GetParam(); std::tie(cmpF, type, kernSize, sz, borderType, dtype, compile_args) = GetParam();
initMatsRandN(type, sz, dtype, false); initMatrixRandN(type, sz, dtype, false);
cv::Point anchor = {-1, -1}; cv::Point anchor = {-1, -1};
double delta = 0; double delta = 0;
...@@ -160,7 +160,7 @@ PERF_TEST_P_(BoxFilterPerfTest, TestPerformance) ...@@ -160,7 +160,7 @@ PERF_TEST_P_(BoxFilterPerfTest, TestPerformance)
cv::GCompileArgs compile_args; cv::GCompileArgs compile_args;
std::tie(cmpF, type, filterSize, sz, borderType, dtype, compile_args) = GetParam(); std::tie(cmpF, type, filterSize, sz, borderType, dtype, compile_args) = GetParam();
initMatsRandN(type, sz, dtype, false); initMatrixRandN(type, sz, dtype, false);
cv::Point anchor = {-1, -1}; cv::Point anchor = {-1, -1};
bool normalize = true; bool normalize = true;
...@@ -204,7 +204,7 @@ PERF_TEST_P_(BlurPerfTest, TestPerformance) ...@@ -204,7 +204,7 @@ PERF_TEST_P_(BlurPerfTest, TestPerformance)
cv::GCompileArgs compile_args; cv::GCompileArgs compile_args;
std::tie(cmpF, type, filterSize, sz, borderType, compile_args) = GetParam(); std::tie(cmpF, type, filterSize, sz, borderType, compile_args) = GetParam();
initMatsRandN(type, sz, type, false); initMatrixRandN(type, sz, type, false);
cv::Point anchor = {-1, -1}; cv::Point anchor = {-1, -1};
...@@ -250,7 +250,7 @@ PERF_TEST_P_(GaussianBlurPerfTest, TestPerformance) ...@@ -250,7 +250,7 @@ PERF_TEST_P_(GaussianBlurPerfTest, TestPerformance)
cv::Size kSize = cv::Size(kernSize, kernSize); cv::Size kSize = cv::Size(kernSize, kernSize);
auto& rng = cv::theRNG(); auto& rng = cv::theRNG();
double sigmaX = rng(); double sigmaX = rng();
initMatsRandN(type, sz, type, false); initMatrixRandN(type, sz, type, false);
// OpenCV code /////////////////////////////////////////////////////////// // OpenCV code ///////////////////////////////////////////////////////////
cv::GaussianBlur(in_mat1, out_mat_ocv, kSize, sigmaX); cv::GaussianBlur(in_mat1, out_mat_ocv, kSize, sigmaX);
...@@ -289,7 +289,7 @@ PERF_TEST_P_(MedianBlurPerfTest, TestPerformance) ...@@ -289,7 +289,7 @@ PERF_TEST_P_(MedianBlurPerfTest, TestPerformance)
cv::GCompileArgs compile_args; cv::GCompileArgs compile_args;
std::tie(cmpF, type, kernSize, sz, compile_args) = GetParam(); std::tie(cmpF, type, kernSize, sz, compile_args) = GetParam();
initMatsRandN(type, sz, type, false); initMatrixRandN(type, sz, type, false);
// OpenCV code ///////////////////////////////////////////////////////////// // OpenCV code /////////////////////////////////////////////////////////////
{ {
...@@ -330,7 +330,7 @@ PERF_TEST_P_(ErodePerfTest, TestPerformance) ...@@ -330,7 +330,7 @@ PERF_TEST_P_(ErodePerfTest, TestPerformance)
cv::GCompileArgs compile_args; cv::GCompileArgs compile_args;
std::tie(cmpF, type, kernSize, sz, kernType, compile_args) = GetParam(); std::tie(cmpF, type, kernSize, sz, kernType, compile_args) = GetParam();
initMatsRandN(type, sz, type, false); initMatrixRandN(type, sz, type, false);
cv::Mat kernel = cv::getStructuringElement(kernType, cv::Size(kernSize, kernSize)); cv::Mat kernel = cv::getStructuringElement(kernType, cv::Size(kernSize, kernSize));
...@@ -373,7 +373,7 @@ PERF_TEST_P_(Erode3x3PerfTest, TestPerformance) ...@@ -373,7 +373,7 @@ PERF_TEST_P_(Erode3x3PerfTest, TestPerformance)
cv::GCompileArgs compile_args; cv::GCompileArgs compile_args;
std::tie(cmpF, type, sz, numIters, compile_args) = GetParam(); std::tie(cmpF, type, sz, numIters, compile_args) = GetParam();
initMatsRandN(type, sz, type, false); initMatrixRandN(type, sz, type, false);
cv::Mat kernel = cv::getStructuringElement(cv::MorphShapes::MORPH_RECT, cv::Size(3, 3)); cv::Mat kernel = cv::getStructuringElement(cv::MorphShapes::MORPH_RECT, cv::Size(3, 3));
...@@ -416,7 +416,7 @@ PERF_TEST_P_(DilatePerfTest, TestPerformance) ...@@ -416,7 +416,7 @@ PERF_TEST_P_(DilatePerfTest, TestPerformance)
cv::GCompileArgs compile_args; cv::GCompileArgs compile_args;
std::tie(cmpF, type, kernSize, sz, kernType, compile_args) = GetParam(); std::tie(cmpF, type, kernSize, sz, kernType, compile_args) = GetParam();
initMatsRandN(type, sz, type, false); initMatrixRandN(type, sz, type, false);
cv::Mat kernel = cv::getStructuringElement(kernType, cv::Size(kernSize, kernSize)); cv::Mat kernel = cv::getStructuringElement(kernType, cv::Size(kernSize, kernSize));
...@@ -459,7 +459,7 @@ PERF_TEST_P_(Dilate3x3PerfTest, TestPerformance) ...@@ -459,7 +459,7 @@ PERF_TEST_P_(Dilate3x3PerfTest, TestPerformance)
cv::GCompileArgs compile_args; cv::GCompileArgs compile_args;
std::tie(cmpF, type, sz, numIters, compile_args) = GetParam(); std::tie(cmpF, type, sz, numIters, compile_args) = GetParam();
initMatsRandN(type, sz, type, false); initMatrixRandN(type, sz, type, false);
cv::Mat kernel = cv::getStructuringElement(cv::MorphShapes::MORPH_RECT, cv::Size(3, 3)); cv::Mat kernel = cv::getStructuringElement(cv::MorphShapes::MORPH_RECT, cv::Size(3, 3));
...@@ -502,7 +502,7 @@ PERF_TEST_P_(SobelPerfTest, TestPerformance) ...@@ -502,7 +502,7 @@ PERF_TEST_P_(SobelPerfTest, TestPerformance)
cv::GCompileArgs compile_args; cv::GCompileArgs compile_args;
std::tie(cmpF, type, kernSize, sz, dtype, dx, dy, compile_args) = GetParam(); std::tie(cmpF, type, kernSize, sz, dtype, dx, dy, compile_args) = GetParam();
initMatsRandN(type, sz, dtype, false); initMatrixRandN(type, sz, dtype, false);
// OpenCV code ///////////////////////////////////////////////////////////// // OpenCV code /////////////////////////////////////////////////////////////
{ {
...@@ -545,7 +545,7 @@ PERF_TEST_P_(SobelXYPerfTest, TestPerformance) ...@@ -545,7 +545,7 @@ PERF_TEST_P_(SobelXYPerfTest, TestPerformance)
cv::Mat out_mat_ocv2; cv::Mat out_mat_ocv2;
cv::Mat out_mat_gapi2; cv::Mat out_mat_gapi2;
initMatsRandN(type, sz, dtype, false); initMatrixRandN(type, sz, dtype, false);
// OpenCV code ///////////////////////////////////////////////////////////// // OpenCV code /////////////////////////////////////////////////////////////
{ {
...@@ -590,7 +590,7 @@ PERF_TEST_P_(CannyPerfTest, TestPerformance) ...@@ -590,7 +590,7 @@ PERF_TEST_P_(CannyPerfTest, TestPerformance)
cv::GCompileArgs compile_args; cv::GCompileArgs compile_args;
std::tie(cmpF, type, sz, thrLow, thrUp, apSize, l2gr, compile_args) = GetParam(); std::tie(cmpF, type, sz, thrLow, thrUp, apSize, l2gr, compile_args) = GetParam();
initMatsRandN(type, sz, CV_8UC1, false); initMatrixRandN(type, sz, CV_8UC1, false);
// OpenCV code ///////////////////////////////////////////////////////////// // OpenCV code /////////////////////////////////////////////////////////////
{ {
...@@ -628,7 +628,7 @@ PERF_TEST_P_(EqHistPerfTest, TestPerformance) ...@@ -628,7 +628,7 @@ PERF_TEST_P_(EqHistPerfTest, TestPerformance)
Size sz = get<1>(GetParam()); Size sz = get<1>(GetParam());
cv::GCompileArgs compile_args = get<2>(GetParam()); cv::GCompileArgs compile_args = get<2>(GetParam());
initMatsRandN(CV_8UC1, sz, CV_8UC1, false); initMatrixRandN(CV_8UC1, sz, CV_8UC1, false);
// OpenCV code ///////////////////////////////////////////////////////////// // OpenCV code /////////////////////////////////////////////////////////////
{ {
...@@ -666,7 +666,7 @@ PERF_TEST_P_(RGB2GrayPerfTest, TestPerformance) ...@@ -666,7 +666,7 @@ PERF_TEST_P_(RGB2GrayPerfTest, TestPerformance)
Size sz = get<1>(GetParam()); Size sz = get<1>(GetParam());
cv::GCompileArgs compile_args = get<2>(GetParam()); cv::GCompileArgs compile_args = get<2>(GetParam());
initMatsRandN(CV_8UC3, sz, CV_8UC1, false); initMatrixRandN(CV_8UC3, sz, CV_8UC1, false);
// OpenCV code ///////////////////////////////////////////////////////////// // OpenCV code /////////////////////////////////////////////////////////////
{ {
...@@ -704,7 +704,7 @@ PERF_TEST_P_(BGR2GrayPerfTest, TestPerformance) ...@@ -704,7 +704,7 @@ PERF_TEST_P_(BGR2GrayPerfTest, TestPerformance)
Size sz = get<1>(GetParam()); Size sz = get<1>(GetParam());
cv::GCompileArgs compile_args = get<2>(GetParam()); cv::GCompileArgs compile_args = get<2>(GetParam());
initMatsRandN(CV_8UC3, sz, CV_8UC1, false); initMatrixRandN(CV_8UC3, sz, CV_8UC1, false);
// OpenCV code ///////////////////////////////////////////////////////////// // OpenCV code /////////////////////////////////////////////////////////////
{ {
...@@ -742,7 +742,7 @@ PERF_TEST_P_(RGB2YUVPerfTest, TestPerformance) ...@@ -742,7 +742,7 @@ PERF_TEST_P_(RGB2YUVPerfTest, TestPerformance)
Size sz = get<1>(GetParam()); Size sz = get<1>(GetParam());
cv::GCompileArgs compile_args = get<2>(GetParam()); cv::GCompileArgs compile_args = get<2>(GetParam());
initMatsRandN(CV_8UC3, sz, CV_8UC3, false); initMatrixRandN(CV_8UC3, sz, CV_8UC3, false);
// OpenCV code ///////////////////////////////////////////////////////////// // OpenCV code /////////////////////////////////////////////////////////////
{ {
...@@ -780,7 +780,7 @@ PERF_TEST_P_(YUV2RGBPerfTest, TestPerformance) ...@@ -780,7 +780,7 @@ PERF_TEST_P_(YUV2RGBPerfTest, TestPerformance)
Size sz = get<1>(GetParam()); Size sz = get<1>(GetParam());
cv::GCompileArgs compile_args = get<2>(GetParam()); cv::GCompileArgs compile_args = get<2>(GetParam());
initMatsRandN(CV_8UC3, sz, CV_8UC3, false); initMatrixRandN(CV_8UC3, sz, CV_8UC3, false);
// OpenCV code ///////////////////////////////////////////////////////////// // OpenCV code /////////////////////////////////////////////////////////////
{ {
...@@ -818,7 +818,7 @@ PERF_TEST_P_(RGB2LabPerfTest, TestPerformance) ...@@ -818,7 +818,7 @@ PERF_TEST_P_(RGB2LabPerfTest, TestPerformance)
Size sz = get<1>(GetParam()); Size sz = get<1>(GetParam());
cv::GCompileArgs compile_args = get<2>(GetParam()); cv::GCompileArgs compile_args = get<2>(GetParam());
initMatsRandN(CV_8UC3, sz, CV_8UC3, false); initMatrixRandN(CV_8UC3, sz, CV_8UC3, false);
// OpenCV code ///////////////////////////////////////////////////////////// // OpenCV code /////////////////////////////////////////////////////////////
{ {
...@@ -856,7 +856,7 @@ PERF_TEST_P_(BGR2LUVPerfTest, TestPerformance) ...@@ -856,7 +856,7 @@ PERF_TEST_P_(BGR2LUVPerfTest, TestPerformance)
Size sz = get<1>(GetParam()); Size sz = get<1>(GetParam());
cv::GCompileArgs compile_args = get<2>(GetParam()); cv::GCompileArgs compile_args = get<2>(GetParam());
initMatsRandN(CV_8UC3, sz, CV_8UC3, false); initMatrixRandN(CV_8UC3, sz, CV_8UC3, false);
// OpenCV code ///////////////////////////////////////////////////////////// // OpenCV code /////////////////////////////////////////////////////////////
{ {
...@@ -894,7 +894,7 @@ PERF_TEST_P_(LUV2BGRPerfTest, TestPerformance) ...@@ -894,7 +894,7 @@ PERF_TEST_P_(LUV2BGRPerfTest, TestPerformance)
Size sz = get<1>(GetParam()); Size sz = get<1>(GetParam());
cv::GCompileArgs compile_args = get<2>(GetParam()); cv::GCompileArgs compile_args = get<2>(GetParam());
initMatsRandN(CV_8UC3, sz, CV_8UC3, false); initMatrixRandN(CV_8UC3, sz, CV_8UC3, false);
// OpenCV code ///////////////////////////////////////////////////////////// // OpenCV code /////////////////////////////////////////////////////////////
{ {
...@@ -932,7 +932,7 @@ PERF_TEST_P_(BGR2YUVPerfTest, TestPerformance) ...@@ -932,7 +932,7 @@ PERF_TEST_P_(BGR2YUVPerfTest, TestPerformance)
Size sz = get<1>(GetParam()); Size sz = get<1>(GetParam());
cv::GCompileArgs compile_args = get<2>(GetParam()); cv::GCompileArgs compile_args = get<2>(GetParam());
initMatsRandN(CV_8UC3, sz, CV_8UC3, false); initMatrixRandN(CV_8UC3, sz, CV_8UC3, false);
cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_BGR2YUV); cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_BGR2YUV);
...@@ -962,7 +962,7 @@ PERF_TEST_P_(YUV2BGRPerfTest, TestPerformance) ...@@ -962,7 +962,7 @@ PERF_TEST_P_(YUV2BGRPerfTest, TestPerformance)
Size sz = get<1>(GetParam()); Size sz = get<1>(GetParam());
cv::GCompileArgs compile_args = get<2>(GetParam()); cv::GCompileArgs compile_args = get<2>(GetParam());
initMatsRandN(CV_8UC3, sz, CV_8UC3, false); initMatrixRandN(CV_8UC3, sz, CV_8UC3, false);
cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_YUV2BGR); cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_YUV2BGR);
...@@ -990,7 +990,7 @@ PERF_TEST_P_(BayerGR2RGBPerfTest, TestPerformance) ...@@ -990,7 +990,7 @@ PERF_TEST_P_(BayerGR2RGBPerfTest, TestPerformance)
Size sz = get<1>(GetParam()); Size sz = get<1>(GetParam());
cv::GCompileArgs compile_args = get<2>(GetParam()); cv::GCompileArgs compile_args = get<2>(GetParam());
initMatsRandN(CV_8UC1, sz, CV_8UC3, false); initMatrixRandN(CV_8UC1, sz, CV_8UC3, false);
cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_BayerGR2RGB); cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_BayerGR2RGB);
...@@ -1018,7 +1018,7 @@ PERF_TEST_P_(RGB2HSVPerfTest, TestPerformance) ...@@ -1018,7 +1018,7 @@ PERF_TEST_P_(RGB2HSVPerfTest, TestPerformance)
Size sz = get<1>(GetParam()); Size sz = get<1>(GetParam());
cv::GCompileArgs compile_args = get<2>(GetParam()); cv::GCompileArgs compile_args = get<2>(GetParam());
initMatsRandN(CV_8UC3, sz, CV_8UC3, false); initMatrixRandN(CV_8UC3, sz, CV_8UC3, false);
cv::cvtColor(in_mat1, in_mat1, cv::COLOR_BGR2RGB); cv::cvtColor(in_mat1, in_mat1, cv::COLOR_BGR2RGB);
cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_RGB2HSV); cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_RGB2HSV);
...@@ -1047,7 +1047,7 @@ PERF_TEST_P_(RGB2YUV422PerfTest, TestPerformance) ...@@ -1047,7 +1047,7 @@ PERF_TEST_P_(RGB2YUV422PerfTest, TestPerformance)
Size sz = get<1>(GetParam()); Size sz = get<1>(GetParam());
cv::GCompileArgs compile_args = get<2>(GetParam()); cv::GCompileArgs compile_args = get<2>(GetParam());
initMatsRandN(CV_8UC3, sz, CV_8UC2, false); initMatrixRandN(CV_8UC3, sz, CV_8UC2, false);
cv::cvtColor(in_mat1, in_mat1, cv::COLOR_BGR2RGB); cv::cvtColor(in_mat1, in_mat1, cv::COLOR_BGR2RGB);
convertRGB2YUV422Ref(in_mat1, out_mat_ocv); convertRGB2YUV422Ref(in_mat1, out_mat_ocv);
......
...@@ -2,13 +2,20 @@ ...@@ -2,13 +2,20 @@
// It is subject to the license terms in the LICENSE file found in the top-level directory // 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. // 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 <iostream>
#include <tuple>
#include <type_traits>
#include <opencv2/ts.hpp> #include <opencv2/ts.hpp>
#include <opencv2/gapi.hpp> #include <opencv2/gapi.hpp>
#include <opencv2/gapi/util/util.hpp>
#include "gapi_tests_helpers.hpp"
namespace namespace
{ {
...@@ -41,6 +48,15 @@ public: ...@@ -41,6 +48,15 @@ public:
return cv::Scalar(s1, s2, s3, s4); 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) void initMatsRandU(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);
...@@ -50,10 +66,9 @@ public: ...@@ -50,10 +66,9 @@ public:
cv::randu(in_mat1, cv::Scalar::all(0), cv::Scalar::all(255)); cv::randu(in_mat1, cv::Scalar::all(0), cv::Scalar::all(255));
cv::randu(in_mat2, 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); initOutMats(sz_in, dtype);
out_mat_ocv = cv::Mat (sz_in, dtype);
} }
} }
...@@ -62,28 +77,28 @@ public: ...@@ -62,28 +77,28 @@ public:
in_mat1 = cv::Mat(sz_in, type); in_mat1 = cv::Mat(sz_in, type);
sc = initScalarRandU(100); sc = initScalarRandU(100);
cv::randu(in_mat1, cv::Scalar::all(0), cv::Scalar::all(255)); 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); initOutMats(sz_in, dtype);
out_mat_ocv = cv::Mat (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)); 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); initOutMats(sz_in, dtype);
out_mat_ocv = cv::Mat(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) static cv::Mat nonZeroPixels(const cv::Mat& mat)
{ {
int channels = mat.channels(); int channels = mat.channels();
...@@ -117,6 +132,100 @@ using compare_f = std::function<bool(const cv::Mat &a, const cv::Mat &b)>; ...@@ -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)>; 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> template<typename T>
struct Wrappable struct Wrappable
...@@ -341,3 +450,5 @@ namespace ...@@ -341,3 +450,5 @@ namespace
return os << "compare_scalar_f"; return os << "compare_scalar_f";
} }
} }
#endif //OPENCV_GAPI_TESTS_COMMON_HPP
// 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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment