add part of opencv
This commit is contained in:
@@ -0,0 +1,500 @@
|
||||
// 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) 2018 Intel Corporation
|
||||
|
||||
|
||||
// FIXME: move out from Common
|
||||
|
||||
#include "../test_precomp.hpp"
|
||||
#include <opencv2/gapi/cpu/core.hpp>
|
||||
|
||||
#include <ade/util/algorithm.hpp>
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
namespace
|
||||
{
|
||||
G_TYPED_KERNEL(GCompoundDoubleAddC, <GMat(GMat, GScalar)>, "org.opencv.test.compound_double_addC")
|
||||
{
|
||||
static GMatDesc outMeta(GMatDesc in, GScalarDesc) { return in; }
|
||||
};
|
||||
|
||||
GAPI_COMPOUND_KERNEL(GCompoundDoubleAddCImpl, GCompoundDoubleAddC)
|
||||
{
|
||||
static GMat expand(cv::GMat in, cv::GScalar s)
|
||||
{
|
||||
return cv::gapi::addC(cv::gapi::addC(in, s), s);
|
||||
}
|
||||
};
|
||||
|
||||
G_TYPED_KERNEL(GCompoundAddC, <GMat(GMat, GScalar)>, "org.opencv.test.compound_addC")
|
||||
{
|
||||
static GMatDesc outMeta(GMatDesc in, GScalarDesc) { return in; }
|
||||
};
|
||||
|
||||
GAPI_COMPOUND_KERNEL(GCompoundAddCImpl, GCompoundAddC)
|
||||
{
|
||||
static GMat expand(cv::GMat in, cv::GScalar s)
|
||||
{
|
||||
return cv::gapi::addC(in, s);
|
||||
}
|
||||
};
|
||||
|
||||
using GMat3 = std::tuple<GMat,GMat,GMat>;
|
||||
using GMat2 = std::tuple<GMat,GMat>;
|
||||
|
||||
G_TYPED_KERNEL_M(GCompoundMergeWithSplit, <GMat3(GMat, GMat, GMat)>, "org.opencv.test.compound_merge_split")
|
||||
{
|
||||
static std::tuple<GMatDesc,GMatDesc,GMatDesc> outMeta(GMatDesc a, GMatDesc b, GMatDesc c)
|
||||
{
|
||||
return std::make_tuple(a, b, c);
|
||||
}
|
||||
};
|
||||
|
||||
GAPI_COMPOUND_KERNEL(GCompoundMergeWithSplitImpl, GCompoundMergeWithSplit)
|
||||
{
|
||||
static GMat3 expand(cv::GMat a, cv::GMat b, cv::GMat c)
|
||||
{
|
||||
return cv::gapi::split3(cv::gapi::merge3(a, b, c));
|
||||
}
|
||||
};
|
||||
|
||||
G_TYPED_KERNEL(GCompoundAddWithAddC, <GMat(GMat, GMat, GScalar)>, "org.opencv.test.compound_add_with_addc")
|
||||
{
|
||||
static GMatDesc outMeta(GMatDesc in, GMatDesc, GScalarDesc)
|
||||
{
|
||||
return in;
|
||||
}
|
||||
};
|
||||
|
||||
GAPI_COMPOUND_KERNEL(GCompoundAddWithAddCImpl, GCompoundAddWithAddC)
|
||||
{
|
||||
static GMat expand(cv::GMat in1, cv::GMat in2, cv::GScalar s)
|
||||
{
|
||||
return cv::gapi::addC(cv::gapi::add(in1, in2), s);
|
||||
}
|
||||
};
|
||||
|
||||
G_TYPED_KERNEL_M(GCompoundSplitWithAdd, <GMat2(GMat)>, "org.opencv.test.compound_split_with_add")
|
||||
{
|
||||
static std::tuple<GMatDesc, GMatDesc> outMeta(GMatDesc in)
|
||||
{
|
||||
const auto out_depth = in.depth;
|
||||
const auto out_desc = in.withType(out_depth, 1);
|
||||
return std::make_tuple(out_desc, out_desc);
|
||||
}
|
||||
};
|
||||
|
||||
GAPI_COMPOUND_KERNEL(GCompoundSplitWithAddImpl, GCompoundSplitWithAdd)
|
||||
{
|
||||
static GMat2 expand(cv::GMat in)
|
||||
{
|
||||
cv::GMat a, b, c;
|
||||
std::tie(a, b, c) = cv::gapi::split3(in);
|
||||
return std::make_tuple(cv::gapi::add(a, b), c);
|
||||
}
|
||||
};
|
||||
|
||||
G_TYPED_KERNEL_M(GCompoundParallelAddC, <GMat2(GMat, GScalar)>, "org.opencv.test.compound_parallel_addc")
|
||||
{
|
||||
static std::tuple<GMatDesc, GMatDesc> outMeta(GMatDesc in, GScalarDesc)
|
||||
{
|
||||
return std::make_tuple(in, in);
|
||||
}
|
||||
};
|
||||
|
||||
GAPI_COMPOUND_KERNEL(GCompoundParallelAddCImpl, GCompoundParallelAddC)
|
||||
{
|
||||
static GMat2 expand(cv::GMat in, cv::GScalar s)
|
||||
{
|
||||
return std::make_tuple(cv::gapi::addC(in, s), cv::gapi::addC(in, s));
|
||||
}
|
||||
};
|
||||
|
||||
GAPI_COMPOUND_KERNEL(GCompoundAddImpl, cv::gapi::core::GAdd)
|
||||
{
|
||||
static GMat expand(cv::GMat in1, cv::GMat in2, int)
|
||||
{
|
||||
return cv::gapi::sub(cv::gapi::sub(in1, in2), in2);
|
||||
}
|
||||
};
|
||||
|
||||
G_TYPED_KERNEL(GCompoundAddWithAddCWithDoubleAddC, <GMat(GMat, GMat, GScalar)>, "org.opencv.test.compound_add_with_addC_with_double_addC")
|
||||
{
|
||||
static GMatDesc outMeta(GMatDesc in, GMatDesc, GScalarDesc)
|
||||
{
|
||||
return in;
|
||||
}
|
||||
};
|
||||
|
||||
GAPI_COMPOUND_KERNEL(GCompoundAddWithAddCWithDoubleAddCImpl, GCompoundAddWithAddCWithDoubleAddC)
|
||||
{
|
||||
static GMat expand(cv::GMat in1, cv::GMat in2, cv::GScalar s)
|
||||
{
|
||||
return GCompoundDoubleAddC::on(GCompoundAddWithAddC::on(in1, in2, s), s);
|
||||
}
|
||||
};
|
||||
|
||||
using GDoubleArray = cv::GArray<double>;
|
||||
G_TYPED_KERNEL(GNegateArray, <GDoubleArray(GDoubleArray)>, "org.opencv.test.negate_array")
|
||||
{
|
||||
static GArrayDesc outMeta(const GArrayDesc&) { return empty_array_desc(); }
|
||||
};
|
||||
|
||||
GAPI_OCV_KERNEL(GNegateArrayImpl, GNegateArray)
|
||||
{
|
||||
static void run(const std::vector<double>& in, std::vector<double>& out)
|
||||
{
|
||||
ade::util::transform(in, std::back_inserter(out), std::negate<double>());
|
||||
}
|
||||
};
|
||||
|
||||
G_TYPED_KERNEL(GMaxInArray, <GScalar(GDoubleArray)>, "org.opencv.test.max_in_array")
|
||||
{
|
||||
static GScalarDesc outMeta(const GArrayDesc&) { return empty_scalar_desc(); }
|
||||
};
|
||||
|
||||
GAPI_OCV_KERNEL(GMaxInArrayImpl, GMaxInArray)
|
||||
{
|
||||
static void run(const std::vector<double>& in, cv::Scalar& out)
|
||||
{
|
||||
out = *std::max_element(in.begin(), in.end());
|
||||
}
|
||||
};
|
||||
|
||||
G_TYPED_KERNEL(GCompoundMaxInArray, <GScalar(GDoubleArray)>, "org.opencv.test.compound_max_in_array")
|
||||
{
|
||||
static GScalarDesc outMeta(const GArrayDesc&) { return empty_scalar_desc(); }
|
||||
};
|
||||
|
||||
GAPI_COMPOUND_KERNEL(GCompoundMaxInArrayImpl, GCompoundMaxInArray)
|
||||
{
|
||||
static GScalar expand(GDoubleArray in)
|
||||
{
|
||||
return GMaxInArray::on(in);
|
||||
}
|
||||
};
|
||||
|
||||
G_TYPED_KERNEL(GCompoundNegateArray, <GDoubleArray(GDoubleArray)>, "org.opencv.test.compound_negate_array")
|
||||
{
|
||||
static GArrayDesc outMeta(const GArrayDesc&) { return empty_array_desc(); }
|
||||
};
|
||||
|
||||
GAPI_COMPOUND_KERNEL(GCompoundNegateArrayImpl, GCompoundNegateArray)
|
||||
{
|
||||
static GDoubleArray expand(GDoubleArray in)
|
||||
{
|
||||
return GNegateArray::on(in);
|
||||
}
|
||||
};
|
||||
|
||||
G_TYPED_KERNEL(SetDiagKernel, <GMat(GMat, GDoubleArray)>, "org.opencv.test.empty_kernel")
|
||||
{
|
||||
static GMatDesc outMeta(GMatDesc in, GArrayDesc) { return in; }
|
||||
};
|
||||
|
||||
void setDiag(cv::Mat& in, const std::vector<double>& diag)
|
||||
{
|
||||
GAPI_Assert(in.rows == static_cast<int>(diag.size()));
|
||||
GAPI_Assert(in.cols == static_cast<int>(diag.size()));
|
||||
for (int i = 0; i < in.rows; ++i)
|
||||
{
|
||||
in.at<uchar>(i, i) = static_cast<uchar>(diag[i]);
|
||||
}
|
||||
}
|
||||
|
||||
GAPI_OCV_KERNEL(SetDiagKernelImpl, SetDiagKernel)
|
||||
{
|
||||
static void run(const cv::Mat& in, const std::vector<double>& v, cv::Mat& out)
|
||||
{
|
||||
in.copyTo(out);
|
||||
setDiag(out, v);
|
||||
}
|
||||
};
|
||||
|
||||
G_TYPED_KERNEL(GCompoundGMatGArrayGMat, <GMat(GMat, GDoubleArray, GMat)>, "org.opencv.test.compound_gmat_garray_gmat")
|
||||
{
|
||||
static GMatDesc outMeta(GMatDesc in, GArrayDesc, GMatDesc) { return in; }
|
||||
};
|
||||
|
||||
GAPI_COMPOUND_KERNEL(GCompoundGMatGArrayGMatImpl, GCompoundGMatGArrayGMat)
|
||||
{
|
||||
static GMat expand(GMat a, GDoubleArray b, GMat c)
|
||||
{
|
||||
return SetDiagKernel::on(cv::gapi::add(a, c), b);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
// FIXME avoid cv::combine that use custom and default kernels together
|
||||
TEST(GCompoundKernel, ReplaceDefaultKernel)
|
||||
{
|
||||
cv::GMat in1, in2;
|
||||
auto out = cv::gapi::add(in1, in2);
|
||||
const auto custom_pkg = cv::gapi::kernels<GCompoundAddImpl>();
|
||||
const auto full_pkg = cv::gapi::combine(cv::gapi::core::cpu::kernels(), custom_pkg);
|
||||
cv::GComputation comp(cv::GIn(in1, in2), cv::GOut(out));
|
||||
cv::Mat in_mat1 = cv::Mat::eye(3, 3, CV_8UC1),
|
||||
in_mat2 = cv::Mat::eye(3, 3, CV_8UC1),
|
||||
out_mat(3, 3, CV_8UC1),
|
||||
ref_mat(3, 3, CV_8UC1);
|
||||
|
||||
comp.apply(cv::gin(in_mat1, in_mat2), cv::gout(out_mat), cv::compile_args(full_pkg));
|
||||
ref_mat = in_mat1 - in_mat2 - in_mat2;
|
||||
|
||||
EXPECT_EQ(0, cv::countNonZero(out_mat != ref_mat));
|
||||
}
|
||||
|
||||
TEST(GCompoundKernel, DoubleAddC)
|
||||
{
|
||||
cv::GMat in1, in2;
|
||||
cv::GScalar s;
|
||||
auto add_res = cv::gapi::add(in1, in2);
|
||||
auto super = GCompoundDoubleAddC::on(add_res, s);
|
||||
auto out = cv::gapi::addC(super, s);
|
||||
|
||||
const auto custom_pkg = cv::gapi::kernels<GCompoundDoubleAddCImpl>();
|
||||
const auto full_pkg = cv::gapi::combine(custom_pkg, cv::gapi::core::cpu::kernels());
|
||||
cv::GComputation comp(cv::GIn(in1, in2, s), cv::GOut(out));
|
||||
|
||||
cv::Mat in_mat1 = cv::Mat::eye(3, 3, CV_8UC1),
|
||||
in_mat2 = cv::Mat::eye(3, 3, CV_8UC1),
|
||||
out_mat(3, 3, CV_8UC1),
|
||||
ref_mat(3, 3, CV_8UC1);
|
||||
|
||||
cv::Scalar scalar = 2;
|
||||
|
||||
comp.apply(cv::gin(in_mat1, in_mat2, scalar), cv::gout(out_mat), cv::compile_args(full_pkg));
|
||||
ref_mat = in_mat1 + in_mat2 + scalar + scalar + scalar;
|
||||
|
||||
EXPECT_EQ(0, cv::countNonZero(out_mat != ref_mat));
|
||||
}
|
||||
|
||||
TEST(GCompoundKernel, AddC)
|
||||
{
|
||||
cv::GMat in1, in2;
|
||||
cv::GScalar s;
|
||||
auto add_res = cv::gapi::add(in1, in2);
|
||||
auto super = GCompoundAddC::on(add_res, s);
|
||||
auto out = cv::gapi::addC(super, s);
|
||||
|
||||
const auto custom_pkg = cv::gapi::kernels<GCompoundAddCImpl>();
|
||||
const auto full_pkg = cv::gapi::combine(custom_pkg, cv::gapi::core::cpu::kernels());
|
||||
cv::GComputation comp(cv::GIn(in1, in2, s), cv::GOut(out));
|
||||
|
||||
cv::Mat in_mat1 = cv::Mat::eye(3, 3, CV_8UC1),
|
||||
in_mat2 = cv::Mat::eye(3, 3, CV_8UC1),
|
||||
out_mat(3, 3, CV_8UC1),
|
||||
ref_mat(3, 3, CV_8UC1);
|
||||
|
||||
cv::Scalar scalar = 2;
|
||||
|
||||
comp.apply(cv::gin(in_mat1, in_mat2, scalar), cv::gout(out_mat), cv::compile_args(full_pkg));
|
||||
ref_mat = in_mat1 + in_mat2 + scalar + scalar;
|
||||
|
||||
EXPECT_EQ(0, cv::countNonZero(out_mat != ref_mat));
|
||||
}
|
||||
|
||||
TEST(GCompoundKernel, MergeWithSplit)
|
||||
{
|
||||
cv::GMat in, a1, b1, c1,
|
||||
a2, b2, c2;
|
||||
|
||||
std::tie(a1, b1, c1) = cv::gapi::split3(in);
|
||||
std::tie(a2, b2, c2) = GCompoundMergeWithSplit::on(a1, b1, c1);
|
||||
auto out = cv::gapi::merge3(a2, b2, c2);
|
||||
|
||||
const auto custom_pkg = cv::gapi::kernels<GCompoundMergeWithSplitImpl>();
|
||||
const auto full_pkg = cv::gapi::combine(custom_pkg, cv::gapi::core::cpu::kernels());
|
||||
cv::GComputation comp(cv::GIn(in), cv::GOut(out));
|
||||
|
||||
cv::Mat in_mat = cv::Mat::eye(3, 3, CV_8UC3), out_mat, ref_mat;
|
||||
comp.apply(cv::gin(in_mat), cv::gout(out_mat), cv::compile_args(full_pkg));
|
||||
ref_mat = in_mat;
|
||||
|
||||
EXPECT_EQ(0, cv::countNonZero(out_mat != ref_mat));
|
||||
}
|
||||
|
||||
TEST(GCompoundKernel, AddWithAddC)
|
||||
{
|
||||
cv::GMat in1, in2;
|
||||
cv::GScalar s;
|
||||
auto out = GCompoundAddWithAddC::on(in1, in2, s);
|
||||
|
||||
const auto custom_pkg = cv::gapi::kernels<GCompoundAddWithAddCImpl>();
|
||||
const auto full_pkg = cv::gapi::combine(custom_pkg, cv::gapi::core::cpu::kernels());
|
||||
cv::GComputation comp(cv::GIn(in1, in2, s), cv::GOut(out));
|
||||
|
||||
cv::Mat in_mat1 = cv::Mat::eye(3, 3, CV_8UC1),
|
||||
in_mat2 = cv::Mat::eye(3, 3, CV_8UC1),
|
||||
out_mat(3, 3, CV_8UC1),
|
||||
ref_mat(3, 3, CV_8UC1);
|
||||
|
||||
cv::Scalar scalar = 2;
|
||||
|
||||
comp.apply(cv::gin(in_mat1, in_mat2, scalar), cv::gout(out_mat), cv::compile_args(full_pkg));
|
||||
ref_mat = in_mat1 + in_mat2 + scalar;
|
||||
|
||||
EXPECT_EQ(0, cv::countNonZero(out_mat != ref_mat));
|
||||
}
|
||||
|
||||
TEST(GCompoundKernel, SplitWithAdd)
|
||||
{
|
||||
cv::GMat in, out1, out2;
|
||||
std::tie(out1, out2) = GCompoundSplitWithAdd::on(in);
|
||||
|
||||
const auto custom_pkg = cv::gapi::kernels<GCompoundSplitWithAddImpl>();
|
||||
const auto full_pkg = cv::gapi::combine(custom_pkg, cv::gapi::core::cpu::kernels());
|
||||
cv::GComputation comp(cv::GIn(in), cv::GOut(out1, out2));
|
||||
|
||||
cv::Mat in_mat = cv::Mat::eye(3, 3, CV_8UC3),
|
||||
out_mat1(3, 3, CV_8UC1),
|
||||
out_mat2(3, 3, CV_8UC1),
|
||||
ref_mat1(3, 3, CV_8UC1),
|
||||
ref_mat2(3, 3, CV_8UC1);
|
||||
|
||||
comp.apply(cv::gin(in_mat), cv::gout(out_mat1, out_mat2), cv::compile_args(full_pkg));
|
||||
|
||||
std::vector<cv::Mat> channels(3);
|
||||
cv::split(in_mat, channels);
|
||||
|
||||
ref_mat1 = channels[0] + channels[1];
|
||||
ref_mat2 = channels[2];
|
||||
|
||||
EXPECT_EQ(0, cv::countNonZero(out_mat1 != ref_mat1));
|
||||
EXPECT_EQ(0, cv::countNonZero(out_mat2 != ref_mat2));
|
||||
}
|
||||
|
||||
TEST(GCompoundKernel, ParallelAddC)
|
||||
{
|
||||
cv::GMat in1, out1, out2;
|
||||
cv::GScalar in2;
|
||||
std::tie(out1, out2) = GCompoundParallelAddC::on(in1, in2);
|
||||
|
||||
const auto custom_pkg = cv::gapi::kernels<GCompoundParallelAddCImpl>();
|
||||
const auto full_pkg = cv::gapi::combine(custom_pkg, cv::gapi::core::cpu::kernels());
|
||||
cv::GComputation comp(cv::GIn(in1, in2), cv::GOut(out1, out2));
|
||||
|
||||
cv::Mat in_mat = cv::Mat::eye(3, 3, CV_8UC1),
|
||||
out_mat1(3, 3, CV_8UC1),
|
||||
out_mat2(3, 3, CV_8UC1),
|
||||
ref_mat1(3, 3, CV_8UC1),
|
||||
ref_mat2(3, 3, CV_8UC1);
|
||||
|
||||
cv::Scalar scalar = 2;
|
||||
|
||||
comp.apply(cv::gin(in_mat, scalar), cv::gout(out_mat1, out_mat2), cv::compile_args(full_pkg));
|
||||
|
||||
ref_mat1 = in_mat + scalar;
|
||||
ref_mat2 = in_mat + scalar;
|
||||
|
||||
EXPECT_EQ(0, cv::countNonZero(out_mat1 != ref_mat1));
|
||||
EXPECT_EQ(0, cv::countNonZero(out_mat2 != ref_mat2));
|
||||
}
|
||||
|
||||
TEST(GCompoundKernel, GCompundKernelAndDefaultUseOneData)
|
||||
{
|
||||
cv::GMat in1, in2;
|
||||
cv::GScalar s;
|
||||
auto out = cv::gapi::add(GCompoundAddWithAddC::on(in1, in2, s), cv::gapi::addC(in2, s));
|
||||
|
||||
const auto custom_pkg = cv::gapi::kernels<GCompoundAddWithAddCImpl>();
|
||||
const auto full_pkg = cv::gapi::combine(custom_pkg, cv::gapi::core::cpu::kernels());
|
||||
cv::GComputation comp(cv::GIn(in1, in2, s), cv::GOut(out));
|
||||
|
||||
cv::Mat in_mat1 = cv::Mat::eye(3, 3, CV_8UC1),
|
||||
in_mat2 = cv::Mat::eye(3, 3, CV_8UC1),
|
||||
out_mat(3, 3, CV_8UC1),
|
||||
ref_mat(3, 3, CV_8UC1);
|
||||
|
||||
cv::Scalar scalar = 2;
|
||||
|
||||
comp.apply(cv::gin(in_mat1, in_mat2, scalar), cv::gout(out_mat), cv::compile_args(full_pkg));
|
||||
ref_mat = in_mat1 + in_mat2 + scalar + in_mat2 + scalar;
|
||||
|
||||
EXPECT_EQ(0, cv::countNonZero(out_mat != ref_mat));
|
||||
}
|
||||
|
||||
TEST(GCompoundKernel, CompoundExpandedToCompound)
|
||||
{
|
||||
cv::GMat in1, in2;
|
||||
cv::GScalar s;
|
||||
auto out = GCompoundAddWithAddCWithDoubleAddC::on(in1, in2, s);
|
||||
|
||||
const auto custom_pkg = cv::gapi::kernels<GCompoundAddWithAddCWithDoubleAddCImpl,
|
||||
GCompoundAddWithAddCImpl,
|
||||
GCompoundDoubleAddCImpl>();
|
||||
|
||||
const auto full_pkg = cv::gapi::combine(custom_pkg, cv::gapi::core::cpu::kernels());
|
||||
cv::GComputation comp(cv::GIn(in1, in2, s), cv::GOut(out));
|
||||
|
||||
cv::Mat in_mat1 = cv::Mat::eye(3, 3, CV_8UC1),
|
||||
in_mat2 = cv::Mat::eye(3, 3, CV_8UC1),
|
||||
out_mat(3, 3, CV_8UC1),
|
||||
ref_mat(3, 3, CV_8UC1);
|
||||
|
||||
cv::Scalar scalar = 2;
|
||||
|
||||
comp.apply(cv::gin(in_mat1, in_mat2, scalar), cv::gout(out_mat), cv::compile_args(full_pkg));
|
||||
ref_mat = in_mat1 + in_mat2 + scalar + scalar + scalar;
|
||||
|
||||
EXPECT_EQ(0, cv::countNonZero(out_mat != ref_mat));
|
||||
}
|
||||
|
||||
TEST(GCompoundKernel, MaxInArray)
|
||||
{
|
||||
GDoubleArray in;
|
||||
auto out = GCompoundMaxInArray::on(in);
|
||||
const auto custom_pkg = cv::gapi::kernels<GCompoundMaxInArrayImpl, GMaxInArrayImpl>();
|
||||
const auto full_pkg = cv::gapi::combine(custom_pkg, cv::gapi::core::cpu::kernels());
|
||||
cv::GComputation comp(cv::GIn(in), cv::GOut(out));
|
||||
std::vector<double> v = { 1, 5, -2, 3, 10, 2};
|
||||
cv::Scalar out_scl;
|
||||
cv::Scalar ref_scl(*std::max_element(v.begin(), v.end()));
|
||||
|
||||
comp.apply(cv::gin(v), cv::gout(out_scl), cv::compile_args(full_pkg));
|
||||
|
||||
EXPECT_EQ(out_scl, ref_scl);
|
||||
}
|
||||
|
||||
TEST(GCompoundKernel, NegateArray)
|
||||
{
|
||||
GDoubleArray in;
|
||||
GDoubleArray out = GCompoundNegateArray::on(in);
|
||||
const auto custom_pkg = cv::gapi::kernels<GCompoundNegateArrayImpl, GNegateArrayImpl>();
|
||||
const auto full_pkg = cv::gapi::combine(custom_pkg, cv::gapi::core::cpu::kernels());
|
||||
cv::GComputation comp(cv::GIn(in), cv::GOut(out));
|
||||
std::vector<double> in_v = {1, 5, -2, -10, 3};
|
||||
std::vector<double> out_v;
|
||||
std::vector<double> ref_v;
|
||||
ade::util::transform(in_v, std::back_inserter(ref_v), std::negate<double>());
|
||||
|
||||
comp.apply(cv::gin(in_v), cv::gout(out_v), cv::compile_args(full_pkg));
|
||||
|
||||
EXPECT_EQ(out_v, ref_v);
|
||||
}
|
||||
|
||||
TEST(GCompoundKernel, RightGArrayHandle)
|
||||
{
|
||||
cv::GMat in[2];
|
||||
GDoubleArray a;
|
||||
cv::GMat out = GCompoundGMatGArrayGMat::on(in[0], a, in[1]);
|
||||
const auto custom_pkg = cv::gapi::kernels<GCompoundGMatGArrayGMatImpl, SetDiagKernelImpl>();
|
||||
const auto full_pkg = cv::gapi::combine(custom_pkg, cv::gapi::core::cpu::kernels());
|
||||
cv::GComputation comp(cv::GIn(in[0], a, in[1]), cv::GOut(out));
|
||||
std::vector<double> in_v(3, 1.0);
|
||||
cv::Mat in_mat1 = cv::Mat::eye(cv::Size(3, 3), CV_8UC1),
|
||||
in_mat2 = cv::Mat::eye(cv::Size(3, 3), CV_8UC1),
|
||||
out_mat;
|
||||
cv::Mat ref_mat= in_mat1 + in_mat2;
|
||||
setDiag(ref_mat, in_v);
|
||||
|
||||
comp.apply(cv::gin(in_mat1, in_v, in_mat2), cv::gout(out_mat), cv::compile_args(full_pkg));
|
||||
|
||||
EXPECT_EQ(0, cv::countNonZero(out_mat != ref_mat));
|
||||
|
||||
}
|
||||
} // opencv_test
|
||||
@@ -0,0 +1,9 @@
|
||||
// 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) 2018 Intel Corporation
|
||||
|
||||
|
||||
#include "../test_precomp.hpp"
|
||||
#include "gapi_core_tests_inl.hpp"
|
||||
146
Lib/opencv/sources/modules/gapi/test/common/gapi_core_tests.hpp
Normal file
146
Lib/opencv/sources/modules/gapi/test/common/gapi_core_tests.hpp
Normal file
@@ -0,0 +1,146 @@
|
||||
// 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) 2018-2019 Intel Corporation
|
||||
|
||||
|
||||
#ifndef OPENCV_GAPI_CORE_TESTS_HPP
|
||||
#define OPENCV_GAPI_CORE_TESTS_HPP
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "gapi_tests_common.hpp"
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
enum mathOp
|
||||
{
|
||||
ADD = 0,
|
||||
SUB = 1,
|
||||
MUL = 2,
|
||||
DIV = 3
|
||||
};
|
||||
|
||||
enum bitwiseOp
|
||||
{
|
||||
AND = 0,
|
||||
OR = 1,
|
||||
XOR = 2,
|
||||
NOT = 3
|
||||
};
|
||||
|
||||
// Note: namespace must match the namespace of the type of the printed object
|
||||
inline std::ostream& operator<<(std::ostream& os, mathOp op)
|
||||
{
|
||||
#define CASE(v) case mathOp::v: os << #v; break
|
||||
switch (op)
|
||||
{
|
||||
CASE(ADD);
|
||||
CASE(SUB);
|
||||
CASE(MUL);
|
||||
CASE(DIV);
|
||||
default: GAPI_Assert(false && "unknown mathOp value");
|
||||
}
|
||||
#undef CASE
|
||||
return os;
|
||||
}
|
||||
|
||||
// Note: namespace must match the namespace of the type of the printed object
|
||||
inline std::ostream& operator<<(std::ostream& os, bitwiseOp op)
|
||||
{
|
||||
#define CASE(v) case bitwiseOp::v: os << #v; break
|
||||
switch (op)
|
||||
{
|
||||
CASE(AND);
|
||||
CASE(OR);
|
||||
CASE(XOR);
|
||||
CASE(NOT);
|
||||
default: GAPI_Assert(false && "unknown bitwiseOp value");
|
||||
}
|
||||
#undef CASE
|
||||
return os;
|
||||
}
|
||||
|
||||
// Create new value-parameterized test fixture:
|
||||
// MathOpTest - fixture name
|
||||
// initMatsRandU - function that is used to initialize input/output data
|
||||
// FIXTURE_API(mathOp,bool,double,bool) - test-specific parameters (types)
|
||||
// 4 - number of test-specific parameters
|
||||
// opType, testWithScalar, scale, doReverseOp - test-spcific parameters (names)
|
||||
//
|
||||
// We get:
|
||||
// 1. Default parameters: int type, cv::Size sz, int dtype, getCompileArgs() function
|
||||
// - available in test body
|
||||
// 2. Input/output matrices will be initialized by initMatsRandU (in this fixture)
|
||||
// 3. Specific parameters: opType, testWithScalar, scale, doReverseOp of corresponding types
|
||||
// - created (and initialized) automatically
|
||||
// - available in test body
|
||||
// Note: all parameter _values_ (e.g. type CV_8UC3) are set via INSTANTIATE_TEST_CASE_P macro
|
||||
GAPI_TEST_FIXTURE(MathOpTest, initMatsRandU, FIXTURE_API(mathOp,bool,double,bool), 4,
|
||||
opType, testWithScalar, scale, doReverseOp)
|
||||
// No specific parameters for MulDoubleTest, so "fixture API" is empty - <>
|
||||
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(CompareScalars), 1, cmpF)
|
||||
GAPI_TEST_FIXTURE(AddWeightedTest, initMatsRandU, FIXTURE_API(CompareMats), 1, cmpF)
|
||||
GAPI_TEST_FIXTURE(NormTest, initMatrixRandU, FIXTURE_API(CompareScalars,NormTypes), 2,
|
||||
cmpF, opType)
|
||||
GAPI_TEST_FIXTURE(IntegralTest, initNothing, <>, 0)
|
||||
GAPI_TEST_FIXTURE(ThresholdTest, initMatrixRandU, FIXTURE_API(int, cv::Scalar), 2, tt, maxval)
|
||||
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(CompareMats,int,cv::Size), 3,
|
||||
cmpF, interp, sz_out)
|
||||
GAPI_TEST_FIXTURE(ResizePTest, initNothing, FIXTURE_API(CompareMats,int,cv::Size), 3,
|
||||
cmpF, interp, sz_out)
|
||||
GAPI_TEST_FIXTURE(ResizeTestFxFy, initNothing, FIXTURE_API(CompareMats,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(CopyTest, initMatrixRandU, <>, 0)
|
||||
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(CompareMats, 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(CompareMats,double,double,int,MatType2), 5,
|
||||
cmpF, a, b, norm_type, ddepth)
|
||||
struct BackendOutputAllocationTest : TestWithParamBase<>
|
||||
{
|
||||
BackendOutputAllocationTest()
|
||||
{
|
||||
in_mat1 = cv::Mat(sz, type);
|
||||
in_mat2 = cv::Mat(sz, type);
|
||||
cv::randu(in_mat1, cv::Scalar::all(1), cv::Scalar::all(15));
|
||||
cv::randu(in_mat2, cv::Scalar::all(1), cv::Scalar::all(15));
|
||||
}
|
||||
};
|
||||
// FIXME: move all tests from this fixture to the base class once all issues are resolved
|
||||
struct BackendOutputAllocationLargeSizeWithCorrectSubmatrixTest : BackendOutputAllocationTest {};
|
||||
GAPI_TEST_FIXTURE(ReInitOutTest, initNothing, <cv::Size>, 1, out_sz)
|
||||
} // opencv_test
|
||||
|
||||
#endif //OPENCV_GAPI_CORE_TESTS_HPP
|
||||
1543
Lib/opencv/sources/modules/gapi/test/common/gapi_core_tests_inl.hpp
Normal file
1543
Lib/opencv/sources/modules/gapi/test/common/gapi_core_tests_inl.hpp
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,9 @@
|
||||
// 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) 2018 Intel Corporation
|
||||
|
||||
|
||||
#include "../test_precomp.hpp"
|
||||
#include "gapi_imgproc_tests_inl.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) 2018-2019 Intel Corporation
|
||||
|
||||
|
||||
#ifndef OPENCV_GAPI_IMGPROC_TESTS_HPP
|
||||
#define OPENCV_GAPI_IMGPROC_TESTS_HPP
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "gapi_tests_common.hpp"
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
// Create new value-parameterized test fixture:
|
||||
// Filter2DTest - fixture name
|
||||
// initMatrixRandN - function that is used to initialize input/output data
|
||||
// FIXTURE_API(CompareMats,int,int) - test-specific parameters (types)
|
||||
// 3 - number of test-specific parameters
|
||||
// cmpF, kernSize, borderType - test-spcific parameters (names)
|
||||
//
|
||||
// We get:
|
||||
// 1. Default parameters: int type, cv::Size sz, int dtype, getCompileArgs() function
|
||||
// - available in test body
|
||||
// 2. Input/output matrices will be initialized by initMatrixRandN (in this fixture)
|
||||
// 3. Specific parameters: cmpF, kernSize, borderType of corresponding types
|
||||
// - created (and initialized) automatically
|
||||
// - available in test body
|
||||
// Note: all parameter _values_ (e.g. type CV_8UC3) are set via INSTANTIATE_TEST_CASE_P macro
|
||||
GAPI_TEST_FIXTURE(Filter2DTest, initMatrixRandN, FIXTURE_API(CompareMats,cv::Size,int), 3,
|
||||
cmpF, filterSize, borderType)
|
||||
GAPI_TEST_FIXTURE(BoxFilterTest, initMatrixRandN, FIXTURE_API(CompareMats,int,int), 3,
|
||||
cmpF, filterSize, borderType)
|
||||
GAPI_TEST_FIXTURE(SepFilterTest, initMatrixRandN, FIXTURE_API(CompareMats,int), 2, cmpF, kernSize)
|
||||
GAPI_TEST_FIXTURE(BlurTest, initMatrixRandN, FIXTURE_API(CompareMats,int,int), 3,
|
||||
cmpF, filterSize, borderType)
|
||||
GAPI_TEST_FIXTURE(GaussianBlurTest, initMatrixRandN, FIXTURE_API(CompareMats,int), 2, cmpF, kernSize)
|
||||
GAPI_TEST_FIXTURE(MedianBlurTest, initMatrixRandN, FIXTURE_API(CompareMats,int), 2, cmpF, kernSize)
|
||||
GAPI_TEST_FIXTURE(ErodeTest, initMatrixRandN, FIXTURE_API(CompareMats,int,int), 3,
|
||||
cmpF, kernSize, kernType)
|
||||
GAPI_TEST_FIXTURE(Erode3x3Test, initMatrixRandN, FIXTURE_API(CompareMats,int), 2,
|
||||
cmpF, numIters)
|
||||
GAPI_TEST_FIXTURE(DilateTest, initMatrixRandN, FIXTURE_API(CompareMats,int,int), 3,
|
||||
cmpF, kernSize, kernType)
|
||||
GAPI_TEST_FIXTURE(Dilate3x3Test, initMatrixRandN, FIXTURE_API(CompareMats,int), 2, cmpF, numIters)
|
||||
GAPI_TEST_FIXTURE(SobelTest, initMatrixRandN, FIXTURE_API(CompareMats,int,int,int), 4,
|
||||
cmpF, kernSize, dx, dy)
|
||||
GAPI_TEST_FIXTURE(SobelXYTest, initMatrixRandN, FIXTURE_API(CompareMats,int,int,int,int), 5,
|
||||
cmpF, kernSize, order, border_type, border_val)
|
||||
GAPI_TEST_FIXTURE(EqHistTest, initMatrixRandN, FIXTURE_API(CompareMats), 1, cmpF)
|
||||
GAPI_TEST_FIXTURE(CannyTest, initMatrixRandN, FIXTURE_API(CompareMats,double,double,int,bool), 5,
|
||||
cmpF, thrLow, thrUp, apSize, l2gr)
|
||||
GAPI_TEST_FIXTURE(RGB2GrayTest, initMatrixRandN, FIXTURE_API(CompareMats), 1, cmpF)
|
||||
GAPI_TEST_FIXTURE(BGR2GrayTest, initMatrixRandN, FIXTURE_API(CompareMats), 1, cmpF)
|
||||
GAPI_TEST_FIXTURE(RGB2YUVTest, initMatrixRandN, FIXTURE_API(CompareMats), 1, cmpF)
|
||||
GAPI_TEST_FIXTURE(YUV2RGBTest, initMatrixRandN, FIXTURE_API(CompareMats), 1, cmpF)
|
||||
GAPI_TEST_FIXTURE(NV12toRGBTest, initMatrixRandN, FIXTURE_API(CompareMats), 1, cmpF)
|
||||
GAPI_TEST_FIXTURE(NV12toBGRpTest, initMatrixRandN, FIXTURE_API(CompareMats), 1, cmpF)
|
||||
GAPI_TEST_FIXTURE(NV12toRGBpTest, initMatrixRandN, FIXTURE_API(CompareMats), 1, cmpF)
|
||||
GAPI_TEST_FIXTURE(NV12toBGRTest, initMatrixRandN, FIXTURE_API(CompareMats), 1, cmpF)
|
||||
GAPI_TEST_FIXTURE(RGB2LabTest, initMatrixRandN, FIXTURE_API(CompareMats), 1, cmpF)
|
||||
GAPI_TEST_FIXTURE(BGR2LUVTest, initMatrixRandN, FIXTURE_API(CompareMats), 1, cmpF)
|
||||
GAPI_TEST_FIXTURE(LUV2BGRTest, initMatrixRandN, FIXTURE_API(CompareMats), 1, cmpF)
|
||||
GAPI_TEST_FIXTURE(BGR2YUVTest, initMatrixRandN, FIXTURE_API(CompareMats), 1, cmpF)
|
||||
GAPI_TEST_FIXTURE(YUV2BGRTest, initMatrixRandN, FIXTURE_API(CompareMats), 1, cmpF)
|
||||
GAPI_TEST_FIXTURE(RGB2HSVTest, initMatrixRandN, FIXTURE_API(CompareMats), 1, cmpF)
|
||||
GAPI_TEST_FIXTURE(BayerGR2RGBTest, initMatrixRandN, FIXTURE_API(CompareMats), 1, cmpF)
|
||||
GAPI_TEST_FIXTURE(RGB2YUV422Test, initMatrixRandN, FIXTURE_API(CompareMats), 1, cmpF)
|
||||
} // opencv_test
|
||||
|
||||
#endif //OPENCV_GAPI_IMGPROC_TESTS_HPP
|
||||
@@ -0,0 +1,735 @@
|
||||
// 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) 2018-2019 Intel Corporation
|
||||
|
||||
|
||||
#ifndef OPENCV_GAPI_IMGPROC_TESTS_INL_HPP
|
||||
#define OPENCV_GAPI_IMGPROC_TESTS_INL_HPP
|
||||
|
||||
#include <opencv2/gapi/imgproc.hpp>
|
||||
#include "gapi_imgproc_tests.hpp"
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
|
||||
// FIXME avoid this code duplicate in perf tests
|
||||
namespace
|
||||
{
|
||||
void rgb2yuyv(const uchar* rgb_line, uchar* yuv422_line, int width)
|
||||
{
|
||||
CV_Assert(width % 2 == 0);
|
||||
|
||||
for (int i = 0; i < width; i += 2)
|
||||
{
|
||||
uchar r = rgb_line[i * 3 ];
|
||||
uchar g = rgb_line[i * 3 + 1];
|
||||
uchar b = rgb_line[i * 3 + 2];
|
||||
|
||||
yuv422_line[i * 2 ] = cv::saturate_cast<uchar>(-0.14713 * r - 0.28886 * g + 0.436 * b + 128.f); // U0
|
||||
yuv422_line[i * 2 + 1] = cv::saturate_cast<uchar>( 0.299 * r + 0.587 * g + 0.114 * b ); // Y0
|
||||
yuv422_line[i * 2 + 2] = cv::saturate_cast<uchar>( 0.615 * r - 0.51499 * g - 0.10001 * b + 128.f); // V0
|
||||
|
||||
r = rgb_line[i * 3 + 3];
|
||||
g = rgb_line[i * 3 + 4];
|
||||
b = rgb_line[i * 3 + 5];
|
||||
|
||||
yuv422_line[i * 2 + 3] = cv::saturate_cast<uchar>(0.299 * r + 0.587 * g + 0.114 * b); // Y1
|
||||
}
|
||||
}
|
||||
|
||||
void convertRGB2YUV422Ref(const cv::Mat& in, cv::Mat &out)
|
||||
{
|
||||
out.create(in.size(), CV_8UC2);
|
||||
|
||||
for (int i = 0; i < in.rows; ++i)
|
||||
{
|
||||
const uchar* in_line_p = in.ptr<uchar>(i);
|
||||
uchar* out_line_p = out.ptr<uchar>(i);
|
||||
rgb2yuyv(in_line_p, out_line_p, in.cols);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(Filter2DTest, AccuracyTest)
|
||||
{
|
||||
cv::Point anchor = {-1, -1};
|
||||
double delta = 0;
|
||||
|
||||
cv::Mat kernel = cv::Mat(filterSize, CV_32FC1);
|
||||
cv::Scalar kernMean, kernStddev;
|
||||
|
||||
const auto kernSize = filterSize.width * filterSize.height;
|
||||
const auto bigKernSize = 49;
|
||||
|
||||
if (kernSize < bigKernSize)
|
||||
{
|
||||
kernMean = cv::Scalar(0.3);
|
||||
kernStddev = cv::Scalar(0.5);
|
||||
}
|
||||
else
|
||||
{
|
||||
kernMean = cv::Scalar(0.008);
|
||||
kernStddev = cv::Scalar(0.008);
|
||||
}
|
||||
|
||||
randn(kernel, kernMean, kernStddev);
|
||||
|
||||
// G-API code //////////////////////////////////////////////////////////////
|
||||
cv::GMat in;
|
||||
auto out = cv::gapi::filter2D(in, dtype, kernel, anchor, delta, borderType);
|
||||
|
||||
cv::GComputation c(in, out);
|
||||
|
||||
c.apply(in_mat1, out_mat_gapi, getCompileArgs());
|
||||
// OpenCV code /////////////////////////////////////////////////////////////
|
||||
{
|
||||
cv::filter2D(in_mat1, out_mat_ocv, dtype, kernel, anchor, delta, borderType);
|
||||
}
|
||||
// Comparison //////////////////////////////////////////////////////////////
|
||||
{
|
||||
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
|
||||
EXPECT_EQ(out_mat_gapi.size(), sz);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(BoxFilterTest, AccuracyTest)
|
||||
{
|
||||
cv::Point anchor = {-1, -1};
|
||||
bool normalize = true;
|
||||
|
||||
// G-API code //////////////////////////////////////////////////////////////
|
||||
cv::GMat in;
|
||||
auto out = cv::gapi::boxFilter(in, dtype, cv::Size(filterSize, filterSize), anchor, normalize,
|
||||
borderType);
|
||||
|
||||
cv::GComputation c(in, out);
|
||||
c.apply(in_mat1, out_mat_gapi, getCompileArgs());
|
||||
// OpenCV code /////////////////////////////////////////////////////////////
|
||||
{
|
||||
cv::boxFilter(in_mat1, out_mat_ocv, dtype, cv::Size(filterSize, filterSize), anchor,
|
||||
normalize, borderType);
|
||||
}
|
||||
// Comparison //////////////////////////////////////////////////////////////
|
||||
{
|
||||
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
|
||||
EXPECT_EQ(out_mat_gapi.size(), sz);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(SepFilterTest, AccuracyTest)
|
||||
{
|
||||
cv::Mat kernelX(kernSize, 1, CV_32F);
|
||||
cv::Mat kernelY(kernSize, 1, CV_32F);
|
||||
randu(kernelX, -1, 1);
|
||||
randu(kernelY, -1, 1);
|
||||
|
||||
cv::Point anchor = cv::Point(-1, -1);
|
||||
|
||||
// G-API code //////////////////////////////////////////////////////////////
|
||||
cv::GMat in;
|
||||
auto out = cv::gapi::sepFilter(in, dtype, kernelX, kernelY, anchor, cv::Scalar() );
|
||||
|
||||
cv::GComputation c(in, out);
|
||||
c.apply(in_mat1, out_mat_gapi, getCompileArgs());
|
||||
// OpenCV code /////////////////////////////////////////////////////////////
|
||||
{
|
||||
cv::sepFilter2D(in_mat1, out_mat_ocv, dtype, kernelX, kernelY );
|
||||
}
|
||||
// Comparison //////////////////////////////////////////////////////////////
|
||||
{
|
||||
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
|
||||
EXPECT_EQ(out_mat_gapi.size(), sz);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(BlurTest, AccuracyTest)
|
||||
{
|
||||
cv::Point anchor = {-1, -1};
|
||||
|
||||
// G-API code //////////////////////////////////////////////////////////////
|
||||
cv::GMat in;
|
||||
auto out = cv::gapi::blur(in, cv::Size(filterSize, filterSize), anchor, borderType);
|
||||
|
||||
cv::GComputation c(in, out);
|
||||
c.apply(in_mat1, out_mat_gapi, getCompileArgs());
|
||||
// OpenCV code /////////////////////////////////////////////////////////////
|
||||
{
|
||||
cv::blur(in_mat1, out_mat_ocv, cv::Size(filterSize, filterSize), anchor, borderType);
|
||||
}
|
||||
// Comparison //////////////////////////////////////////////////////////////
|
||||
{
|
||||
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
|
||||
EXPECT_EQ(out_mat_gapi.size(), sz);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(GaussianBlurTest, AccuracyTest)
|
||||
{
|
||||
cv::Size kSize = cv::Size(kernSize, kernSize);
|
||||
double sigmaX = rand();
|
||||
|
||||
// G-API code //////////////////////////////////////////////////////////////
|
||||
cv::GMat in;
|
||||
auto out = cv::gapi::gaussianBlur(in, kSize, sigmaX);
|
||||
|
||||
cv::GComputation c(in, out);
|
||||
c.apply(in_mat1, out_mat_gapi, getCompileArgs());
|
||||
// OpenCV code /////////////////////////////////////////////////////////////
|
||||
{
|
||||
cv::GaussianBlur(in_mat1, out_mat_ocv, kSize, sigmaX);
|
||||
}
|
||||
// Comparison //////////////////////////////////////////////////////////////
|
||||
{
|
||||
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
|
||||
EXPECT_EQ(out_mat_gapi.size(), sz);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(MedianBlurTest, AccuracyTest)
|
||||
{
|
||||
// G-API code //////////////////////////////////////////////////////////////
|
||||
cv::GMat in;
|
||||
auto out = cv::gapi::medianBlur(in, kernSize);
|
||||
|
||||
cv::GComputation c(in, out);
|
||||
c.apply(in_mat1, out_mat_gapi, getCompileArgs());
|
||||
// OpenCV code /////////////////////////////////////////////////////////////
|
||||
{
|
||||
cv::medianBlur(in_mat1, out_mat_ocv, kernSize);
|
||||
}
|
||||
// Comparison //////////////////////////////////////////////////////////////
|
||||
{
|
||||
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
|
||||
EXPECT_EQ(out_mat_gapi.size(), sz);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(ErodeTest, AccuracyTest)
|
||||
{
|
||||
cv::Mat kernel = cv::getStructuringElement(kernType, cv::Size(kernSize, kernSize));
|
||||
|
||||
// G-API code //////////////////////////////////////////////////////////////
|
||||
cv::GMat in;
|
||||
auto out = cv::gapi::erode(in, kernel);
|
||||
|
||||
cv::GComputation c(in, out);
|
||||
c.apply(in_mat1, out_mat_gapi, getCompileArgs());
|
||||
// OpenCV code /////////////////////////////////////////////////////////////
|
||||
{
|
||||
cv::erode(in_mat1, out_mat_ocv, kernel);
|
||||
}
|
||||
// Comparison //////////////////////////////////////////////////////////////
|
||||
{
|
||||
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
|
||||
EXPECT_EQ(out_mat_gapi.size(), sz);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(Erode3x3Test, AccuracyTest)
|
||||
{
|
||||
cv::Mat kernel = cv::getStructuringElement(cv::MorphShapes::MORPH_RECT, cv::Size(3,3));
|
||||
|
||||
// G-API code //////////////////////////////////////////////////////////////
|
||||
cv::GMat in;
|
||||
auto out = cv::gapi::erode3x3(in, numIters);
|
||||
|
||||
cv::GComputation c(in, out);
|
||||
c.apply(in_mat1, out_mat_gapi, getCompileArgs());
|
||||
// OpenCV code /////////////////////////////////////////////////////////////
|
||||
{
|
||||
cv::erode(in_mat1, out_mat_ocv, kernel, cv::Point(-1, -1), numIters);
|
||||
}
|
||||
// Comparison //////////////////////////////////////////////////////////////
|
||||
{
|
||||
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
|
||||
EXPECT_EQ(out_mat_gapi.size(), sz);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(DilateTest, AccuracyTest)
|
||||
{
|
||||
cv::Mat kernel = cv::getStructuringElement(kernType, cv::Size(kernSize, kernSize));
|
||||
|
||||
// G-API code //////////////////////////////////////////////////////////////
|
||||
cv::GMat in;
|
||||
auto out = cv::gapi::dilate(in, kernel);
|
||||
|
||||
cv::GComputation c(in, out);
|
||||
c.apply(in_mat1, out_mat_gapi, getCompileArgs());
|
||||
// OpenCV code /////////////////////////////////////////////////////////////
|
||||
{
|
||||
cv::dilate(in_mat1, out_mat_ocv, kernel);
|
||||
}
|
||||
// Comparison //////////////////////////////////////////////////////////////
|
||||
{
|
||||
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
|
||||
EXPECT_EQ(out_mat_gapi.size(), sz);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(Dilate3x3Test, AccuracyTest)
|
||||
{
|
||||
cv::Mat kernel = cv::getStructuringElement(cv::MorphShapes::MORPH_RECT, cv::Size(3,3));
|
||||
|
||||
// G-API code //////////////////////////////////////////////////////////////
|
||||
cv::GMat in;
|
||||
auto out = cv::gapi::dilate3x3(in, numIters);
|
||||
|
||||
cv::GComputation c(in, out);
|
||||
c.apply(in_mat1, out_mat_gapi, getCompileArgs());
|
||||
// OpenCV code /////////////////////////////////////////////////////////////
|
||||
{
|
||||
cv::dilate(in_mat1, out_mat_ocv, kernel, cv::Point(-1,-1), numIters);
|
||||
}
|
||||
// Comparison //////////////////////////////////////////////////////////////
|
||||
{
|
||||
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
|
||||
EXPECT_EQ(out_mat_gapi.size(), sz);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(SobelTest, AccuracyTest)
|
||||
{
|
||||
// G-API code //////////////////////////////////////////////////////////////
|
||||
cv::GMat in;
|
||||
auto out = cv::gapi::Sobel(in, dtype, dx, dy, kernSize );
|
||||
|
||||
cv::GComputation c(in, out);
|
||||
c.apply(in_mat1, out_mat_gapi, getCompileArgs());
|
||||
// OpenCV code /////////////////////////////////////////////////////////////
|
||||
{
|
||||
cv::Sobel(in_mat1, out_mat_ocv, dtype, dx, dy, kernSize);
|
||||
}
|
||||
// Comparison //////////////////////////////////////////////////////////////
|
||||
{
|
||||
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
|
||||
EXPECT_EQ(out_mat_gapi.size(), sz);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(SobelXYTest, AccuracyTest)
|
||||
{
|
||||
cv::Mat out_mat_ocv2;
|
||||
cv::Mat out_mat_gapi2;
|
||||
|
||||
// G-API code //////////////////////////////////////////////////////////////
|
||||
cv::GMat in;
|
||||
auto out = cv::gapi::SobelXY(in, dtype, order, kernSize, 1, 0, border_type, border_val);
|
||||
|
||||
cv::GComputation c(cv::GIn(in), cv::GOut(std::get<0>(out), std::get<1>(out)));
|
||||
c.apply(cv::gin(in_mat1), cv::gout(out_mat_gapi, out_mat_gapi2), getCompileArgs());
|
||||
// OpenCV code /////////////////////////////////////////////////////////////
|
||||
{
|
||||
// workaround for cv::Sobel
|
||||
cv::Mat temp_in;
|
||||
if(border_type == cv::BORDER_CONSTANT)
|
||||
{
|
||||
int n_pixels = (kernSize - 1) / 2;
|
||||
cv::copyMakeBorder(in_mat1, temp_in, n_pixels, n_pixels, n_pixels, n_pixels, border_type, border_val);
|
||||
in_mat1 = temp_in(cv::Rect(n_pixels, n_pixels, in_mat1.cols, in_mat1.rows));
|
||||
}
|
||||
cv::Sobel(in_mat1, out_mat_ocv, dtype, order, 0, kernSize, 1, 0, border_type);
|
||||
cv::Sobel(in_mat1, out_mat_ocv2, dtype, 0, order, kernSize, 1, 0, border_type);
|
||||
}
|
||||
// Comparison //////////////////////////////////////////////////////////////
|
||||
{
|
||||
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
|
||||
EXPECT_TRUE(cmpF(out_mat_gapi2, out_mat_ocv2));
|
||||
EXPECT_EQ(out_mat_gapi.size(), sz);
|
||||
EXPECT_EQ(out_mat_gapi2.size(), sz);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(EqHistTest, AccuracyTest)
|
||||
{
|
||||
// G-API code //////////////////////////////////////////////////////////////
|
||||
cv::GMat in;
|
||||
auto out = cv::gapi::equalizeHist(in);
|
||||
|
||||
cv::GComputation c(in, out);
|
||||
c.apply(in_mat1, out_mat_gapi, getCompileArgs());
|
||||
// OpenCV code /////////////////////////////////////////////////////////////
|
||||
{
|
||||
cv::equalizeHist(in_mat1, out_mat_ocv);
|
||||
}
|
||||
// Comparison //////////////////////////////////////////////////////////////
|
||||
{
|
||||
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
|
||||
EXPECT_EQ(out_mat_gapi.size(), sz);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(CannyTest, AccuracyTest)
|
||||
{
|
||||
// G-API code //////////////////////////////////////////////////////////////
|
||||
cv::GMat in;
|
||||
auto out = cv::gapi::Canny(in, thrLow, thrUp, apSize, l2gr);
|
||||
|
||||
cv::GComputation c(in, out);
|
||||
c.apply(in_mat1, out_mat_gapi, getCompileArgs());
|
||||
// OpenCV code /////////////////////////////////////////////////////////////
|
||||
{
|
||||
cv::Canny(in_mat1, out_mat_ocv, thrLow, thrUp, apSize, l2gr);
|
||||
}
|
||||
// Comparison //////////////////////////////////////////////////////////////
|
||||
{
|
||||
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
|
||||
EXPECT_EQ(out_mat_gapi.size(), sz);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(RGB2GrayTest, AccuracyTest)
|
||||
{
|
||||
// G-API code //////////////////////////////////////////////////////////////
|
||||
cv::GMat in;
|
||||
auto out = cv::gapi::RGB2Gray(in);
|
||||
|
||||
cv::GComputation c(in, out);
|
||||
c.apply(in_mat1, out_mat_gapi, getCompileArgs());
|
||||
// OpenCV code /////////////////////////////////////////////////////////////
|
||||
{
|
||||
cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_RGB2GRAY);
|
||||
}
|
||||
// Comparison //////////////////////////////////////////////////////////////
|
||||
{
|
||||
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
|
||||
EXPECT_EQ(out_mat_gapi.size(), sz);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(BGR2GrayTest, AccuracyTest)
|
||||
{
|
||||
// G-API code //////////////////////////////////////////////////////////////
|
||||
cv::GMat in;
|
||||
auto out = cv::gapi::BGR2Gray(in);
|
||||
|
||||
cv::GComputation c(in, out);
|
||||
c.apply(in_mat1, out_mat_gapi, getCompileArgs());
|
||||
// OpenCV code /////////////////////////////////////////////////////////////
|
||||
{
|
||||
cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_BGR2GRAY);
|
||||
}
|
||||
// Comparison //////////////////////////////////////////////////////////////
|
||||
{
|
||||
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
|
||||
EXPECT_EQ(out_mat_gapi.size(), sz);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(RGB2YUVTest, AccuracyTest)
|
||||
{
|
||||
// G-API code //////////////////////////////////////////////////////////////
|
||||
cv::GMat in;
|
||||
auto out = cv::gapi::RGB2YUV(in);
|
||||
|
||||
cv::GComputation c(in, out);
|
||||
c.apply(in_mat1, out_mat_gapi, getCompileArgs());
|
||||
// OpenCV code /////////////////////////////////////////////////////////////
|
||||
{
|
||||
cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_RGB2YUV);
|
||||
}
|
||||
// Comparison //////////////////////////////////////////////////////////////
|
||||
{
|
||||
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
|
||||
EXPECT_EQ(out_mat_gapi.size(), sz);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(YUV2RGBTest, AccuracyTest)
|
||||
{
|
||||
// G-API code //////////////////////////////////////////////////////////////
|
||||
cv::GMat in;
|
||||
auto out = cv::gapi::YUV2RGB(in);
|
||||
|
||||
cv::GComputation c(in, out);
|
||||
c.apply(in_mat1, out_mat_gapi, getCompileArgs());
|
||||
// OpenCV code /////////////////////////////////////////////////////////////
|
||||
{
|
||||
cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_YUV2RGB);
|
||||
}
|
||||
// Comparison //////////////////////////////////////////////////////////////
|
||||
{
|
||||
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
|
||||
EXPECT_EQ(out_mat_gapi.size(), sz);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(NV12toRGBTest, AccuracyTest)
|
||||
{
|
||||
// G-API code //////////////////////////////////////////////////////////////
|
||||
cv::GMat in_y;
|
||||
cv::GMat in_uv;
|
||||
auto out = cv::gapi::NV12toRGB(in_y, in_uv);
|
||||
|
||||
// Additional mat for uv
|
||||
cv::Mat in_mat_uv(cv::Size(sz.width / 2, sz.height / 2), CV_8UC2);
|
||||
cv::randn(in_mat_uv, cv::Scalar::all(127), cv::Scalar::all(40.f));
|
||||
|
||||
cv::GComputation c(cv::GIn(in_y, in_uv), cv::GOut(out));
|
||||
c.apply(cv::gin(in_mat1, in_mat_uv), cv::gout(out_mat_gapi), getCompileArgs());
|
||||
// OpenCV code /////////////////////////////////////////////////////////////
|
||||
{
|
||||
cv::cvtColorTwoPlane(in_mat1, in_mat_uv, out_mat_ocv, cv::COLOR_YUV2RGB_NV12);
|
||||
}
|
||||
// Comparison //////////////////////////////////////////////////////////////
|
||||
{
|
||||
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
|
||||
EXPECT_EQ(out_mat_gapi.size(), sz);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(NV12toBGRTest, AccuracyTest)
|
||||
{
|
||||
// G-API code //////////////////////////////////////////////////////////////
|
||||
cv::GMat in_y;
|
||||
cv::GMat in_uv;
|
||||
auto out = cv::gapi::NV12toBGR(in_y, in_uv);
|
||||
|
||||
// Additional mat for uv
|
||||
cv::Mat in_mat_uv(cv::Size(sz.width / 2, sz.height / 2), CV_8UC2);
|
||||
cv::randn(in_mat_uv, cv::Scalar::all(127), cv::Scalar::all(40.f));
|
||||
|
||||
cv::GComputation c(cv::GIn(in_y, in_uv), cv::GOut(out));
|
||||
c.apply(cv::gin(in_mat1, in_mat_uv), cv::gout(out_mat_gapi), getCompileArgs());
|
||||
// OpenCV code /////////////////////////////////////////////////////////////
|
||||
{
|
||||
cv::cvtColorTwoPlane(in_mat1, in_mat_uv, out_mat_ocv, cv::COLOR_YUV2BGR_NV12);
|
||||
}
|
||||
// Comparison //////////////////////////////////////////////////////////////
|
||||
{
|
||||
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
|
||||
EXPECT_EQ(out_mat_gapi.size(), sz);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void toPlanar(const cv::Mat& in, cv::Mat& out)
|
||||
{
|
||||
GAPI_Assert(out.depth() == in.depth());
|
||||
GAPI_Assert(out.channels() == 1);
|
||||
GAPI_Assert(in.channels() == 3);
|
||||
GAPI_Assert(out.cols == in.cols);
|
||||
GAPI_Assert(out.rows == 3*in.rows);
|
||||
|
||||
std::vector<cv::Mat> outs(3);
|
||||
for (int i = 0; i < 3; i++) {
|
||||
outs[i] = out(cv::Rect(0, i*in.rows, in.cols, in.rows));
|
||||
}
|
||||
cv::split(in, outs);
|
||||
}
|
||||
|
||||
TEST_P(NV12toRGBpTest, AccuracyTest)
|
||||
{
|
||||
cv::Size sz_p = cv::Size(sz.width, sz.height * 3);
|
||||
// G-API code //////////////////////////////////////////////////////////////
|
||||
cv::GMat in_y;
|
||||
cv::GMat in_uv;
|
||||
auto out = cv::gapi::NV12toRGBp(in_y, in_uv);
|
||||
|
||||
// Additional mat for uv
|
||||
cv::Mat in_mat_uv(cv::Size(sz.width / 2, sz.height / 2), CV_8UC2);
|
||||
cv::randn(in_mat_uv, cv::Scalar::all(127), cv::Scalar::all(40.f));
|
||||
|
||||
cv::GComputation c(cv::GIn(in_y, in_uv), cv::GOut(out));
|
||||
cv::Mat out_mat_gapi_planar(cv::Size(sz.width, sz.height * 3), CV_8UC1);
|
||||
c.apply(cv::gin(in_mat1, in_mat_uv), cv::gout(out_mat_gapi_planar), getCompileArgs());
|
||||
// OpenCV code /////////////////////////////////////////////////////////////
|
||||
cv::Mat out_mat_ocv_planar(cv::Size(sz.width, sz.height * 3), CV_8UC1);
|
||||
{
|
||||
cv::cvtColorTwoPlane(in_mat1, in_mat_uv, out_mat_ocv, cv::COLOR_YUV2RGB_NV12);
|
||||
toPlanar(out_mat_ocv, out_mat_ocv_planar);
|
||||
}
|
||||
// Comparison //////////////////////////////////////////////////////////////
|
||||
{
|
||||
EXPECT_TRUE(cmpF(out_mat_gapi_planar, out_mat_ocv_planar));
|
||||
EXPECT_EQ(out_mat_gapi_planar.size(), sz_p);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TEST_P(NV12toBGRpTest, AccuracyTest)
|
||||
{
|
||||
cv::Size sz_p = cv::Size(sz.width, sz.height * 3);
|
||||
|
||||
// G-API code //////////////////////////////////////////////////////////////
|
||||
cv::GMat in_y;
|
||||
cv::GMat in_uv;
|
||||
auto out = cv::gapi::NV12toBGRp(in_y, in_uv);
|
||||
|
||||
// Additional mat for uv
|
||||
cv::Mat in_mat_uv(cv::Size(sz.width / 2, sz.height / 2), CV_8UC2);
|
||||
cv::randn(in_mat_uv, cv::Scalar::all(127), cv::Scalar::all(40.f));
|
||||
|
||||
cv::GComputation c(cv::GIn(in_y, in_uv), cv::GOut(out));
|
||||
cv::Mat out_mat_gapi_planar(cv::Size(sz.width, sz.height * 3), CV_8UC1);
|
||||
c.apply(cv::gin(in_mat1, in_mat_uv), cv::gout(out_mat_gapi_planar), getCompileArgs());
|
||||
// OpenCV code /////////////////////////////////////////////////////////////
|
||||
cv::Mat out_mat_ocv_planar(cv::Size(sz.width, sz.height * 3), CV_8UC1);
|
||||
{
|
||||
cv::cvtColorTwoPlane(in_mat1, in_mat_uv, out_mat_ocv, cv::COLOR_YUV2BGR_NV12);
|
||||
toPlanar(out_mat_ocv, out_mat_ocv_planar);
|
||||
}
|
||||
// Comparison //////////////////////////////////////////////////////////////
|
||||
{
|
||||
EXPECT_TRUE(cmpF(out_mat_gapi_planar, out_mat_ocv_planar));
|
||||
EXPECT_EQ(out_mat_gapi_planar.size(), sz_p);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(RGB2LabTest, AccuracyTest)
|
||||
{
|
||||
// G-API code //////////////////////////////////////////////////////////////
|
||||
cv::GMat in;
|
||||
auto out = cv::gapi::RGB2Lab(in);
|
||||
|
||||
cv::GComputation c(in, out);
|
||||
c.apply(in_mat1, out_mat_gapi, getCompileArgs());
|
||||
// OpenCV code /////////////////////////////////////////////////////////////
|
||||
{
|
||||
cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_RGB2Lab);
|
||||
}
|
||||
// Comparison //////////////////////////////////////////////////////////////
|
||||
{
|
||||
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
|
||||
EXPECT_EQ(out_mat_gapi.size(), sz);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(BGR2LUVTest, AccuracyTest)
|
||||
{
|
||||
// G-API code //////////////////////////////////////////////////////////////
|
||||
cv::GMat in;
|
||||
auto out = cv::gapi::BGR2LUV(in);
|
||||
|
||||
cv::GComputation c(in, out);
|
||||
c.apply(in_mat1, out_mat_gapi, getCompileArgs());
|
||||
// OpenCV code /////////////////////////////////////////////////////////////
|
||||
{
|
||||
cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_BGR2Luv);
|
||||
}
|
||||
// Comparison //////////////////////////////////////////////////////////////
|
||||
{
|
||||
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
|
||||
EXPECT_EQ(out_mat_gapi.size(), sz);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(LUV2BGRTest, AccuracyTest)
|
||||
{
|
||||
// G-API code //////////////////////////////////////////////////////////////
|
||||
cv::GMat in;
|
||||
auto out = cv::gapi::LUV2BGR(in);
|
||||
|
||||
cv::GComputation c(in, out);
|
||||
c.apply(in_mat1, out_mat_gapi, getCompileArgs());
|
||||
// OpenCV code /////////////////////////////////////////////////////////////
|
||||
{
|
||||
cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_Luv2BGR);
|
||||
}
|
||||
// Comparison //////////////////////////////////////////////////////////////
|
||||
{
|
||||
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
|
||||
EXPECT_EQ(out_mat_gapi.size(), sz);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(BGR2YUVTest, AccuracyTest)
|
||||
{
|
||||
// G-API code //////////////////////////////////////////////////////////////
|
||||
cv::GMat in;
|
||||
auto out = cv::gapi::BGR2YUV(in);
|
||||
|
||||
cv::GComputation c(in, out);
|
||||
c.apply(in_mat1, out_mat_gapi, getCompileArgs());
|
||||
// OpenCV code /////////////////////////////////////////////////////////////
|
||||
{
|
||||
cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_BGR2YUV);
|
||||
}
|
||||
// Comparison //////////////////////////////////////////////////////////////
|
||||
{
|
||||
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
|
||||
EXPECT_EQ(out_mat_gapi.size(), sz);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(YUV2BGRTest, AccuracyTest)
|
||||
{
|
||||
// G-API code //////////////////////////////////////////////////////////////
|
||||
cv::GMat in;
|
||||
auto out = cv::gapi::YUV2BGR(in);
|
||||
|
||||
cv::GComputation c(in, out);
|
||||
c.apply(in_mat1, out_mat_gapi, getCompileArgs());
|
||||
// OpenCV code /////////////////////////////////////////////////////////////
|
||||
{
|
||||
cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_YUV2BGR);
|
||||
}
|
||||
// Comparison //////////////////////////////////////////////////////////////
|
||||
{
|
||||
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
|
||||
EXPECT_EQ(out_mat_gapi.size(), sz);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(RGB2HSVTest, AccuracyTest)
|
||||
{
|
||||
// G-API code //////////////////////////////////////////////////////////////
|
||||
cv::GMat in;
|
||||
auto out = cv::gapi::RGB2HSV(in);
|
||||
|
||||
cv::GComputation c(in, out);
|
||||
c.apply(in_mat1, out_mat_gapi, getCompileArgs());
|
||||
// OpenCV code /////////////////////////////////////////////////////////////
|
||||
{
|
||||
cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_RGB2HSV);
|
||||
}
|
||||
// Comparison //////////////////////////////////////////////////////////////
|
||||
{
|
||||
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
|
||||
EXPECT_EQ(out_mat_gapi.size(), sz);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(BayerGR2RGBTest, AccuracyTest)
|
||||
{
|
||||
// G-API code //////////////////////////////////////////////////////////////
|
||||
cv::GMat in;
|
||||
auto out = cv::gapi::BayerGR2RGB(in);
|
||||
|
||||
cv::GComputation c(in, out);
|
||||
c.apply(in_mat1, out_mat_gapi, getCompileArgs());
|
||||
// OpenCV code /////////////////////////////////////////////////////////////
|
||||
{
|
||||
cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_BayerGR2RGB);
|
||||
}
|
||||
// Comparison //////////////////////////////////////////////////////////////
|
||||
{
|
||||
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
|
||||
EXPECT_EQ(out_mat_gapi.size(), sz);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(RGB2YUV422Test, AccuracyTest)
|
||||
{
|
||||
// G-API code //////////////////////////////////////////////////////////////
|
||||
cv::GMat in;
|
||||
auto out = cv::gapi::RGB2YUV422(in);
|
||||
|
||||
cv::GComputation c(in, out);
|
||||
c.apply(in_mat1, out_mat_gapi, getCompileArgs());
|
||||
// OpenCV code /////////////////////////////////////////////////////////////
|
||||
{
|
||||
convertRGB2YUV422Ref(in_mat1, out_mat_ocv);
|
||||
}
|
||||
// Comparison //////////////////////////////////////////////////////////////
|
||||
{
|
||||
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
|
||||
EXPECT_EQ(out_mat_gapi.size(), sz);
|
||||
}
|
||||
}
|
||||
|
||||
} // opencv_test
|
||||
|
||||
#endif //OPENCV_GAPI_IMGPROC_TESTS_INL_HPP
|
||||
@@ -0,0 +1,9 @@
|
||||
// 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) 2018 Intel Corporation
|
||||
|
||||
|
||||
#include "../test_precomp.hpp"
|
||||
#include "gapi_operators_tests_inl.hpp"
|
||||
@@ -0,0 +1,209 @@
|
||||
// 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) 2018 Intel Corporation
|
||||
|
||||
|
||||
#ifndef OPENCV_GAPI_OPERATOR_TESTS_COMMON_HPP
|
||||
#define OPENCV_GAPI_OPERATOR_TESTS_COMMON_HPP
|
||||
|
||||
#include "gapi_tests_common.hpp"
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
|
||||
struct g_api_ocv_pair_mat_scalar {
|
||||
using g_api_function_t = std::function<cv::GMat(cv::GMat,cv::GScalar)>;
|
||||
using ocv_function_t = std::function<void(cv::Mat const&, cv::Scalar, cv::Mat&)>;
|
||||
|
||||
std::string name;
|
||||
g_api_function_t g_api_function;
|
||||
ocv_function_t ocv_function;
|
||||
|
||||
|
||||
g_api_ocv_pair_mat_scalar(std::string const& n, g_api_function_t const& g, ocv_function_t const& o)
|
||||
: name(n), g_api_function(g), ocv_function(o) {}
|
||||
|
||||
g_api_ocv_pair_mat_scalar() = default;
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& o, const g_api_ocv_pair_mat_scalar& p)
|
||||
{
|
||||
return o<<p.name;
|
||||
}
|
||||
};
|
||||
|
||||
struct g_api_ocv_pair_mat_mat {
|
||||
using g_api_function_t = std::function<cv::GMat(cv::GMat,cv::GMat)>;
|
||||
using ocv_function_t = std::function<void(cv::Mat const&, cv::Mat const&, cv::Mat&)>;
|
||||
|
||||
std::string name;
|
||||
g_api_function_t g_api_function;
|
||||
ocv_function_t ocv_function;
|
||||
|
||||
|
||||
g_api_ocv_pair_mat_mat(std::string const& n, g_api_function_t const& g, ocv_function_t const& o)
|
||||
: name(n), g_api_function(g), ocv_function(o) {}
|
||||
|
||||
g_api_ocv_pair_mat_mat() = default;
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& o, const g_api_ocv_pair_mat_mat& p)
|
||||
{
|
||||
return o<<p.name;
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// FIXME: Please refactor this test to a template test (T,U) with enum (OP)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
namespace
|
||||
{
|
||||
|
||||
//declare test cases for matrix and scalar operators
|
||||
g_api_ocv_pair_mat_scalar opPlus = {std::string{"operator+"},
|
||||
[](cv::GMat in,cv::GScalar c){return in+c;},
|
||||
[](const cv::Mat& in, cv::Scalar c, cv::Mat& out){cv::add(in, c, out);}};
|
||||
g_api_ocv_pair_mat_scalar opPlusR = {std::string{"rev_operator+"},
|
||||
[](cv::GMat in,cv::GScalar c){return c+in;},
|
||||
[](const cv::Mat& in, cv::Scalar c, cv::Mat& out){cv::add(c, in, out);}};
|
||||
g_api_ocv_pair_mat_scalar opMinus = {std::string{"operator-"},
|
||||
[](cv::GMat in,cv::GScalar c){return in-c;},
|
||||
[](const cv::Mat& in, cv::Scalar c, cv::Mat& out){cv::subtract(in, c, out);}};
|
||||
g_api_ocv_pair_mat_scalar opMinusR = {std::string{"rev_operator-"},
|
||||
[](cv::GMat in,cv::GScalar c){return c-in;},
|
||||
[](const cv::Mat& in, cv::Scalar c, cv::Mat& out){cv::subtract(c, in, out);}};
|
||||
g_api_ocv_pair_mat_scalar opMul = {std::string{"operator*"},
|
||||
[](cv::GMat in,cv::GScalar c){return in*c;},
|
||||
[](const cv::Mat& in, cv::Scalar c, cv::Mat& out){cv::multiply(in, c, out);}};
|
||||
g_api_ocv_pair_mat_scalar opMulR = {std::string{"rev_operator*"},
|
||||
[](cv::GMat in,cv::GScalar c){return c*in;},
|
||||
[](const cv::Mat& in, cv::Scalar c, cv::Mat& out){cv::multiply(c, in, out);}};
|
||||
g_api_ocv_pair_mat_scalar opDiv = {std::string{"operator/"},
|
||||
[](cv::GMat in,cv::GScalar c){return in/c;},
|
||||
[](const cv::Mat& in, cv::Scalar c, cv::Mat& out){cv::divide(in, c, out);}};
|
||||
g_api_ocv_pair_mat_scalar opDivR = {std::string{"rev_operator/"},
|
||||
[](cv::GMat in,cv::GScalar c){return c/in;},
|
||||
[](const cv::Mat& in, cv::Scalar c, cv::Mat& out){cv::divide(c, in, out);}};
|
||||
|
||||
g_api_ocv_pair_mat_scalar opGT = {std::string{"operator>"},
|
||||
[](cv::GMat in,cv::GScalar c){return in>c;},
|
||||
[](const cv::Mat& in, cv::Scalar c, cv::Mat& out){cv::compare(in, c, out,cv::CMP_GT);}};
|
||||
g_api_ocv_pair_mat_scalar opLT = {std::string{"operator<"},
|
||||
[](cv::GMat in,cv::GScalar c){return in<c;},
|
||||
[](const cv::Mat& in, cv::Scalar c, cv::Mat& out){cv::compare(in, c, out,cv::CMP_LT);}};
|
||||
g_api_ocv_pair_mat_scalar opGE = {std::string{"operator>="},
|
||||
[](cv::GMat in,cv::GScalar c){return in>=c;},
|
||||
[](const cv::Mat& in, cv::Scalar c, cv::Mat& out){cv::compare(in, c, out,cv::CMP_GE);}};
|
||||
g_api_ocv_pair_mat_scalar opLE = {std::string{"operator<="},
|
||||
[](cv::GMat in,cv::GScalar c){return in<=c;},
|
||||
[](const cv::Mat& in, cv::Scalar c, cv::Mat& out){cv::compare(in, c, out,cv::CMP_LE);}};
|
||||
g_api_ocv_pair_mat_scalar opEQ = {std::string{"operator=="},
|
||||
[](cv::GMat in,cv::GScalar c){return in==c;},
|
||||
[](const cv::Mat& in, cv::Scalar c, cv::Mat& out){cv::compare(in, c, out,cv::CMP_EQ);}};
|
||||
g_api_ocv_pair_mat_scalar opNE = {std::string{"operator!="},
|
||||
[](cv::GMat in,cv::GScalar c){return in!=c;},
|
||||
[](const cv::Mat& in, cv::Scalar c, cv::Mat& out){cv::compare(in, c, out,cv::CMP_NE);}};
|
||||
g_api_ocv_pair_mat_scalar opGTR = {std::string{"rev_operator>"},
|
||||
[](cv::GMat in,cv::GScalar c){return c>in;},
|
||||
[](const cv::Mat& in, cv::Scalar c, cv::Mat& out){cv::compare(c, in, out,cv::CMP_GT);}};
|
||||
g_api_ocv_pair_mat_scalar opLTR = {std::string{"rev_operator<"},
|
||||
[](cv::GMat in,cv::GScalar c){return c<in;},
|
||||
[](const cv::Mat& in, cv::Scalar c, cv::Mat& out){cv::compare(c, in, out,cv::CMP_LT);}};
|
||||
g_api_ocv_pair_mat_scalar opGER = {std::string{"rev_operator>="},
|
||||
[](cv::GMat in,cv::GScalar c){return c>=in;},
|
||||
[](const cv::Mat& in, cv::Scalar c, cv::Mat& out){cv::compare(c, in, out,cv::CMP_GE);}};
|
||||
g_api_ocv_pair_mat_scalar opLER = {std::string{"rev_operator<="},
|
||||
[](cv::GMat in,cv::GScalar c){return c<=in;},
|
||||
[](const cv::Mat& in, cv::Scalar c, cv::Mat& out){cv::compare(c, in, out,cv::CMP_LE);}};
|
||||
g_api_ocv_pair_mat_scalar opEQR = {std::string{"rev_operator=="},
|
||||
[](cv::GMat in,cv::GScalar c){return c==in;},
|
||||
[](const cv::Mat& in, cv::Scalar c, cv::Mat& out){cv::compare(c, in, out,cv::CMP_EQ);}};
|
||||
g_api_ocv_pair_mat_scalar opNER = {std::string{"rev_operator!="},
|
||||
[](cv::GMat in,cv::GScalar c){return c!=in;},
|
||||
[](const cv::Mat& in, cv::Scalar c, cv::Mat& out){cv::compare(c, in, out,cv::CMP_NE);}};
|
||||
|
||||
g_api_ocv_pair_mat_scalar opAND = {std::string{"operator&"},
|
||||
[](cv::GMat in1,cv::GScalar in2){return in1&in2;},
|
||||
[](const cv::Mat& in1, const cv::Scalar& in2, cv::Mat& out){cv::bitwise_and(in1, in2, out);}};
|
||||
g_api_ocv_pair_mat_scalar opOR = {std::string{"operator|"},
|
||||
[](cv::GMat in1,cv::GScalar in2){return in1|in2;},
|
||||
[](const cv::Mat& in1, const cv::Scalar& in2, cv::Mat& out){cv::bitwise_or(in1, in2, out);}};
|
||||
g_api_ocv_pair_mat_scalar opXOR = {std::string{"operator^"},
|
||||
[](cv::GMat in1,cv::GScalar in2){return in1^in2;},
|
||||
[](const cv::Mat& in1, const cv::Scalar& in2, cv::Mat& out){cv::bitwise_xor(in1, in2, out);}};
|
||||
g_api_ocv_pair_mat_scalar opANDR = {std::string{"rev_operator&"},
|
||||
[](cv::GMat in1,cv::GScalar in2){return in2&in1;},
|
||||
[](const cv::Mat& in1, const cv::Scalar& in2, cv::Mat& out){cv::bitwise_and(in2, in1, out);}};
|
||||
g_api_ocv_pair_mat_scalar opORR = {std::string{"rev_operator|"},
|
||||
[](cv::GMat in1,cv::GScalar in2){return in2|in1;},
|
||||
[](const cv::Mat& in1, const cv::Scalar& in2, cv::Mat& out){cv::bitwise_or(in2, in1, out);}};
|
||||
g_api_ocv_pair_mat_scalar opXORR = {std::string{"rev_operator^"},
|
||||
[](cv::GMat in1,cv::GScalar in2){return in2^in1;},
|
||||
[](const cv::Mat& in1, const cv::Scalar& in2, cv::Mat& out){cv::bitwise_xor(in2, in1, out);}};
|
||||
|
||||
// declare test cases for matrix and matrix operators
|
||||
g_api_ocv_pair_mat_mat opPlusM = {std::string{"operator+"},
|
||||
[](cv::GMat in1,cv::GMat in2){return in1+in2;},
|
||||
[](const cv::Mat& in1, const cv::Mat& in2, cv::Mat& out){cv::add(in1, in2, out);}};
|
||||
g_api_ocv_pair_mat_mat opMinusM = {std::string{"operator-"},
|
||||
[](cv::GMat in,cv::GMat in2){return in-in2;},
|
||||
[](const cv::Mat& in, const cv::Mat& in2, cv::Mat& out){cv::subtract(in, in2, out);}};
|
||||
g_api_ocv_pair_mat_mat opDivM = {std::string{"operator/"},
|
||||
[](cv::GMat in,cv::GMat in2){return in/in2;},
|
||||
[](const cv::Mat& in, const cv::Mat& in2, cv::Mat& out){cv::divide(in, in2, out);}};
|
||||
g_api_ocv_pair_mat_mat opGreater = {std::string{"operator>"},
|
||||
[](cv::GMat in1,cv::GMat in2){return in1>in2;},
|
||||
[](const cv::Mat& in1, const cv::Mat& in2, cv::Mat& out){cv::compare(in1, in2, out, cv::CMP_GT);}};
|
||||
g_api_ocv_pair_mat_mat opGreaterEq = {std::string{"operator>="},
|
||||
[](cv::GMat in1,cv::GMat in2){return in1>=in2;},
|
||||
[](const cv::Mat& in1, const cv::Mat& in2, cv::Mat& out){cv::compare(in1, in2, out, cv::CMP_GE);}};
|
||||
g_api_ocv_pair_mat_mat opLess = {std::string{"operator<"},
|
||||
[](cv::GMat in1,cv::GMat in2){return in1<in2;},
|
||||
[](const cv::Mat& in1, const cv::Mat& in2, cv::Mat& out){cv::compare(in1, in2, out, cv::CMP_LT);}};
|
||||
g_api_ocv_pair_mat_mat opLessEq = {std::string{"operator<="},
|
||||
[](cv::GMat in1,cv::GMat in2){return in1<=in2;},
|
||||
[](const cv::Mat& in1, const cv::Mat& in2, cv::Mat& out){cv::compare(in1, in2, out, cv::CMP_LE);}};
|
||||
g_api_ocv_pair_mat_mat opEq = {std::string{"operator=="},
|
||||
[](cv::GMat in1,cv::GMat in2){return in1==in2;},
|
||||
[](const cv::Mat& in1, const cv::Mat& in2, cv::Mat& out){cv::compare(in1, in2, out, cv::CMP_EQ);}};
|
||||
g_api_ocv_pair_mat_mat opNotEq = {std::string{"operator!="},
|
||||
[](cv::GMat in1,cv::GMat in2){return in1!=in2;},
|
||||
[](const cv::Mat& in1, const cv::Mat& in2, cv::Mat& out){cv::compare(in1, in2, out, cv::CMP_NE);}};
|
||||
|
||||
g_api_ocv_pair_mat_mat opAnd = {std::string{"operator&"},
|
||||
[](cv::GMat in1,cv::GMat in2){return in1&in2;},
|
||||
[](const cv::Mat& in1, const cv::Mat& in2, cv::Mat& out){cv::bitwise_and(in1, in2, out);}};
|
||||
g_api_ocv_pair_mat_mat opOr = {std::string{"operator|"},
|
||||
[](cv::GMat in1,cv::GMat in2){return in1|in2;},
|
||||
[](const cv::Mat& in1, const cv::Mat& in2, cv::Mat& out){cv::bitwise_or(in1, in2, out);}};
|
||||
g_api_ocv_pair_mat_mat opXor = {std::string{"operator^"},
|
||||
[](cv::GMat in1,cv::GMat in2){return in1^in2;},
|
||||
[](const cv::Mat& in1, const cv::Mat& in2, cv::Mat& out){cv::bitwise_xor(in1, in2, out);}};
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
// Create new value-parameterized test fixture:
|
||||
// MathOperatorMatScalarTest - fixture name
|
||||
// initMatsRandU - function that is used to initialize input/output data
|
||||
// FIXTURE_API(CompareMats, g_api_ocv_pair_mat_scalar) - test-specific parameters (types)
|
||||
// 2 - number of test-specific parameters
|
||||
// cmpF, op - test-spcific parameters (names)
|
||||
//
|
||||
// We get:
|
||||
// 1. Default parameters: int type, cv::Size sz, int dtype, getCompileArgs() function
|
||||
// - available in test body
|
||||
// 2. Input/output matrices will be initialized by initMatsRandU (in this fixture)
|
||||
// 3. Specific parameters: cmpF, op of corresponding types
|
||||
// - created (and initialized) automatically
|
||||
// - available in test body
|
||||
// Note: all parameter _values_ (e.g. type CV_8UC3) are set via INSTANTIATE_TEST_CASE_P macro
|
||||
GAPI_TEST_FIXTURE(MathOperatorMatScalarTest, initMatsRandU,
|
||||
FIXTURE_API(CompareMats, g_api_ocv_pair_mat_scalar), 2, cmpF, op)
|
||||
GAPI_TEST_FIXTURE(MathOperatorMatMatTest, initMatsRandU,
|
||||
FIXTURE_API(CompareMats, g_api_ocv_pair_mat_mat), 2, cmpF, op)
|
||||
GAPI_TEST_FIXTURE(NotOperatorTest, initMatrixRandU, <>, 0)
|
||||
} // opencv_test
|
||||
|
||||
#endif // OPENCV_GAPI_OPERATOR_TESTS_COMMON_HPP
|
||||
@@ -0,0 +1,82 @@
|
||||
// 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) 2018 Intel Corporation
|
||||
|
||||
|
||||
#ifndef OPENCV_GAPI_OPERATOR_TESTS_INL_COMMON_HPP
|
||||
#define OPENCV_GAPI_OPERATOR_TESTS_INL_COMMON_HPP
|
||||
|
||||
#include "gapi_operators_tests.hpp"
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
TEST_P(MathOperatorMatScalarTest, OperatorAccuracyTest )
|
||||
{
|
||||
auto fun_gapi = op.g_api_function;
|
||||
auto fun_ocv = op.ocv_function ;
|
||||
|
||||
// G-API code & corresponding OpenCV code ////////////////////////////////
|
||||
|
||||
cv::GMat in1;
|
||||
cv::GScalar in2;
|
||||
auto out = fun_gapi(in1, in2);
|
||||
cv::GComputation c(GIn(in1, in2), GOut(out));
|
||||
|
||||
c.apply(gin(in_mat1, sc), gout(out_mat_gapi), getCompileArgs());
|
||||
|
||||
fun_ocv(in_mat1, sc, out_mat_ocv);
|
||||
|
||||
// Comparison //////////////////////////////////////////////////////////////
|
||||
{
|
||||
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
|
||||
EXPECT_EQ(out_mat_gapi.size(), sz);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(MathOperatorMatMatTest, OperatorAccuracyTest )
|
||||
{
|
||||
auto fun_gapi = op.g_api_function;
|
||||
auto fun_ocv = op.ocv_function ;
|
||||
|
||||
// G-API code & corresponding OpenCV code ////////////////////////////////
|
||||
|
||||
cv::GMat in1;
|
||||
cv::GMat in2;
|
||||
auto out = fun_gapi(in1, in2);
|
||||
cv::GComputation c(GIn(in1, in2), GOut(out));
|
||||
|
||||
c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), getCompileArgs());
|
||||
|
||||
fun_ocv(in_mat1, in_mat2, out_mat_ocv);
|
||||
|
||||
// Comparison //////////////////////////////////////////////////////////////
|
||||
{
|
||||
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
|
||||
EXPECT_EQ(out_mat_gapi.size(), sz);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(NotOperatorTest, OperatorAccuracyTest)
|
||||
{
|
||||
// G-API code //////////////////////////////////////////////////////////////
|
||||
cv::GMat in;
|
||||
auto out = ~in;
|
||||
cv::GComputation c(in, out);
|
||||
|
||||
c.apply(in_mat1, out_mat_gapi, getCompileArgs());
|
||||
|
||||
// OpenCV code /////////////////////////////////////////////////////////////
|
||||
{
|
||||
out_mat_ocv =~in_mat1;
|
||||
}
|
||||
// Comparison //////////////////////////////////////////////////////////////
|
||||
{
|
||||
EXPECT_EQ(0, cv::countNonZero(out_mat_ocv != out_mat_gapi));
|
||||
EXPECT_EQ(out_mat_gapi.size(), sz);
|
||||
}
|
||||
}
|
||||
} // opencv_test
|
||||
|
||||
#endif // OPENCV_GAPI_OPERATOR_TESTS_INL_COMMON_HPP
|
||||
@@ -0,0 +1,97 @@
|
||||
// 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
|
||||
|
||||
|
||||
#include "../test_precomp.hpp"
|
||||
#include "gapi_render_tests.hpp"
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
|
||||
cv::Scalar cvtBGRToYUVC(const cv::Scalar& bgr)
|
||||
{
|
||||
double y = bgr[2] * 0.299000 + bgr[1] * 0.587000 + bgr[0] * 0.114000;
|
||||
double u = bgr[2] * -0.168736 + bgr[1] * -0.331264 + bgr[0] * 0.500000 + 128;
|
||||
double v = bgr[2] * 0.500000 + bgr[1] * -0.418688 + bgr[0] * -0.081312 + 128;
|
||||
return {y, u, v};
|
||||
}
|
||||
|
||||
void drawMosaicRef(const cv::Mat& mat, const cv::Rect &rect, int cellSz)
|
||||
{
|
||||
cv::Rect mat_rect(0, 0, mat.cols, mat.rows);
|
||||
auto intersection = mat_rect & rect;
|
||||
|
||||
cv::Mat msc_roi = mat(intersection);
|
||||
|
||||
bool has_crop_x = false;
|
||||
bool has_crop_y = false;
|
||||
|
||||
int cols = msc_roi.cols;
|
||||
int rows = msc_roi.rows;
|
||||
|
||||
if (msc_roi.cols % cellSz != 0)
|
||||
{
|
||||
has_crop_x = true;
|
||||
cols -= msc_roi.cols % cellSz;
|
||||
}
|
||||
|
||||
if (msc_roi.rows % cellSz != 0)
|
||||
{
|
||||
has_crop_y = true;
|
||||
rows -= msc_roi.rows % cellSz;
|
||||
}
|
||||
|
||||
cv::Mat cell_roi;
|
||||
for(int i = 0; i < rows; i += cellSz )
|
||||
{
|
||||
for(int j = 0; j < cols; j += cellSz)
|
||||
{
|
||||
cell_roi = msc_roi(cv::Rect(j, i, cellSz, cellSz));
|
||||
cell_roi = cv::mean(cell_roi);
|
||||
}
|
||||
if (has_crop_x)
|
||||
{
|
||||
cell_roi = msc_roi(cv::Rect(cols, i, msc_roi.cols - cols, cellSz));
|
||||
cell_roi = cv::mean(cell_roi);
|
||||
}
|
||||
}
|
||||
|
||||
if (has_crop_y)
|
||||
{
|
||||
for(int j = 0; j < cols; j += cellSz)
|
||||
{
|
||||
cell_roi = msc_roi(cv::Rect(j, rows, cellSz, msc_roi.rows - rows));
|
||||
cell_roi = cv::mean(cell_roi);
|
||||
}
|
||||
if (has_crop_x)
|
||||
{
|
||||
cell_roi = msc_roi(cv::Rect(cols, rows, msc_roi.cols - cols, msc_roi.rows - rows));
|
||||
cell_roi = cv::mean(cell_roi);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void blendImageRef(cv::Mat& mat, const cv::Point& org, const cv::Mat& img, const cv::Mat& alpha)
|
||||
{
|
||||
auto roi = mat(cv::Rect(org, img.size()));
|
||||
cv::Mat img32f_w;
|
||||
cv::merge(std::vector<cv::Mat>(3, alpha), img32f_w);
|
||||
|
||||
cv::Mat roi32f_w(roi.size(), CV_32FC3, cv::Scalar::all(1.0));
|
||||
roi32f_w -= img32f_w;
|
||||
|
||||
cv::Mat img32f, roi32f;
|
||||
img.convertTo(img32f, CV_32F, 1.0/255);
|
||||
roi.convertTo(roi32f, CV_32F, 1.0/255);
|
||||
|
||||
cv::multiply(img32f, img32f_w, img32f);
|
||||
cv::multiply(roi32f, roi32f_w, roi32f);
|
||||
roi32f += img32f;
|
||||
|
||||
roi32f.convertTo(roi, CV_8U, 255.0);
|
||||
};
|
||||
|
||||
} // namespace opencv_test
|
||||
@@ -0,0 +1,145 @@
|
||||
// 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) 2018 Intel Corporation
|
||||
|
||||
|
||||
#ifndef OPENCV_GAPI_RENDER_TESTS_HPP
|
||||
#define OPENCV_GAPI_RENDER_TESTS_HPP
|
||||
|
||||
#include "gapi_tests_common.hpp"
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
|
||||
template<typename ...SpecificParams>
|
||||
struct RenderParams : public Params<SpecificParams...>
|
||||
{
|
||||
using common_params_t = std::tuple<cv::Size>;
|
||||
using specific_params_t = std::tuple<SpecificParams...>;
|
||||
using params_t = std::tuple<cv::Size, 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);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename ...SpecificParams>
|
||||
struct RenderTestBase : public TestWithParam<typename RenderParams<SpecificParams...>::params_t>
|
||||
{
|
||||
using AllParams = RenderParams<SpecificParams...>;
|
||||
|
||||
// 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());
|
||||
}
|
||||
|
||||
cv::Size sz_ = getCommonParam<0>();
|
||||
};
|
||||
|
||||
template <typename ...Args>
|
||||
class RenderBGRTestBase : public RenderTestBase<Args...>
|
||||
{
|
||||
protected:
|
||||
void Init(const cv::Size& sz)
|
||||
{
|
||||
MatType type = CV_8UC3;
|
||||
|
||||
ref_mat.create(sz, type);
|
||||
gapi_mat.create(sz, type);
|
||||
|
||||
cv::randu(ref_mat, cv::Scalar::all(0), cv::Scalar::all(255));
|
||||
ref_mat.copyTo(gapi_mat);
|
||||
}
|
||||
|
||||
cv::Mat gapi_mat, ref_mat;
|
||||
};
|
||||
|
||||
template <typename ...Args>
|
||||
class RenderNV12TestBase : public RenderTestBase<Args...>
|
||||
{
|
||||
protected:
|
||||
void Init(const cv::Size& sz)
|
||||
{
|
||||
auto create_rand_mats = [](const cv::Size& size, MatType type, cv::Mat& ref_mat, cv::Mat& gapi_mat) {
|
||||
ref_mat.create(size, type);
|
||||
cv::randu(ref_mat, cv::Scalar::all(0), cv::Scalar::all(255));
|
||||
ref_mat.copyTo(gapi_mat);
|
||||
};
|
||||
|
||||
create_rand_mats(sz, CV_8UC1, y_ref_mat , y_gapi_mat);
|
||||
create_rand_mats(sz / 2, CV_8UC2, uv_ref_mat , uv_gapi_mat);
|
||||
}
|
||||
|
||||
cv::Mat y_ref_mat, uv_ref_mat, y_gapi_mat, uv_gapi_mat;
|
||||
};
|
||||
|
||||
cv::Scalar cvtBGRToYUVC(const cv::Scalar& bgr);
|
||||
void drawMosaicRef(const cv::Mat& mat, const cv::Rect &rect, int cellSz);
|
||||
void blendImageRef(cv::Mat& mat,
|
||||
const cv::Point& org,
|
||||
const cv::Mat& img,
|
||||
const cv::Mat& alpha);
|
||||
|
||||
#define GAPI_RENDER_TEST_FIXTURE_NV12(Fixture, API, Number, ...) \
|
||||
struct Fixture : public RenderNV12TestBase API { \
|
||||
__WRAP_VAARGS(DEFINE_SPECIFIC_PARAMS_##Number(__VA_ARGS__)) \
|
||||
Fixture() { \
|
||||
Init(sz_); \
|
||||
}; \
|
||||
};
|
||||
|
||||
#define GAPI_RENDER_TEST_FIXTURE_BGR(Fixture, API, Number, ...) \
|
||||
struct Fixture : public RenderBGRTestBase API { \
|
||||
__WRAP_VAARGS(DEFINE_SPECIFIC_PARAMS_##Number(__VA_ARGS__)) \
|
||||
Fixture() { \
|
||||
Init(sz_); \
|
||||
}; \
|
||||
};
|
||||
|
||||
#define GET_VA_ARGS(...) __VA_ARGS__
|
||||
#define GAPI_RENDER_TEST_FIXTURES(Fixture, API, Number, ...) \
|
||||
GAPI_RENDER_TEST_FIXTURE_BGR(RenderBGR##Fixture, GET_VA_ARGS(API), Number, __VA_ARGS__) \
|
||||
GAPI_RENDER_TEST_FIXTURE_NV12(RenderNV12##Fixture, GET_VA_ARGS(API), Number, __VA_ARGS__) \
|
||||
|
||||
using Points = std::vector<cv::Point>;
|
||||
GAPI_RENDER_TEST_FIXTURES(TestTexts, FIXTURE_API(std::string, cv::Point, double, cv::Scalar), 4, text, org, fs, color)
|
||||
GAPI_RENDER_TEST_FIXTURES(TestRects, FIXTURE_API(cv::Rect, cv::Scalar, int), 3, rect, color, thick)
|
||||
GAPI_RENDER_TEST_FIXTURES(TestCircles, FIXTURE_API(cv::Point, int, cv::Scalar, int), 4, center, radius, color, thick)
|
||||
GAPI_RENDER_TEST_FIXTURES(TestLines, FIXTURE_API(cv::Point, cv::Point, cv::Scalar, int), 4, pt1, pt2, color, thick)
|
||||
GAPI_RENDER_TEST_FIXTURES(TestMosaics, FIXTURE_API(cv::Rect, int, int), 3, mos, cellsz, decim)
|
||||
GAPI_RENDER_TEST_FIXTURES(TestImages, FIXTURE_API(cv::Rect, cv::Scalar, double), 3, rect, color, transparency)
|
||||
GAPI_RENDER_TEST_FIXTURES(TestPolylines, FIXTURE_API(Points, cv::Scalar, int), 3, points, color, thick)
|
||||
|
||||
} // opencv_test
|
||||
|
||||
#endif //OPENCV_GAPI_RENDER_TESTS_HPP
|
||||
@@ -0,0 +1,627 @@
|
||||
// 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) 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"
|
||||
#include <opencv2/gapi/render/render.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
inline std::ostream& operator<<(std::ostream& o, const cv::GCompileArg& arg)
|
||||
{
|
||||
return o << (arg.tag.empty() ? "empty" : arg.tag);
|
||||
}
|
||||
|
||||
inline std::ostream& operator<<(std::ostream& o, const cv::gapi::wip::draw::Prim& p)
|
||||
{
|
||||
using namespace cv::gapi::wip::draw;
|
||||
switch (p.index())
|
||||
{
|
||||
case Prim::index_of<Rect>():
|
||||
o << "cv::gapi::draw::Rect";
|
||||
break;
|
||||
case Prim::index_of<Text>():
|
||||
o << "cv::gapi::draw::Text";
|
||||
break;
|
||||
case Prim::index_of<Circle>():
|
||||
o << "cv::gapi::draw::Circle";
|
||||
break;
|
||||
case Prim::index_of<Line>():
|
||||
o << "cv::gapi::draw::Line";
|
||||
break;
|
||||
case Prim::index_of<Mosaic>():
|
||||
o << "cv::gapi::draw::Mosaic";
|
||||
break;
|
||||
case Prim::index_of<Image>():
|
||||
o << "cv::gapi::draw::Image";
|
||||
break;
|
||||
case Prim::index_of<Poly>():
|
||||
o << "cv::gapi::draw::Poly";
|
||||
break;
|
||||
default: o << "Unrecognized primitive";
|
||||
}
|
||||
|
||||
return o;
|
||||
}
|
||||
}
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
|
||||
class TestFunctional
|
||||
{
|
||||
public:
|
||||
cv::Mat in_mat1;
|
||||
cv::Mat in_mat2;
|
||||
cv::Mat out_mat_gapi;
|
||||
cv::Mat out_mat_ocv;
|
||||
|
||||
cv::Scalar sc;
|
||||
|
||||
cv::Scalar initScalarRandU(unsigned upper)
|
||||
{
|
||||
auto& rng = cv::theRNG();
|
||||
double s1 = rng(upper); // FIXIT: RNG result is 'int', not double
|
||||
double s2 = rng(upper);
|
||||
double s3 = rng(upper);
|
||||
double s4 = rng(upper);
|
||||
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);
|
||||
in_mat2 = cv::Mat(sz_in, type);
|
||||
|
||||
sc = initScalarRandU(100);
|
||||
|
||||
// Details: https://github.com/opencv/opencv/pull/16083
|
||||
//if (CV_MAT_DEPTH(type) < CV_32F)
|
||||
if (1)
|
||||
{
|
||||
cv::randu(in_mat1, cv::Scalar::all(0), cv::Scalar::all(255));
|
||||
cv::randu(in_mat2, cv::Scalar::all(0), cv::Scalar::all(255));
|
||||
}
|
||||
else
|
||||
{
|
||||
const int fscale = 256; // avoid bits near ULP, generate stable test input
|
||||
Mat in_mat32s(in_mat1.size(), CV_MAKE_TYPE(CV_32S, CV_MAT_CN(type)));
|
||||
cv::randu(in_mat32s, cv::Scalar::all(0), cv::Scalar::all(255 * fscale));
|
||||
in_mat32s.convertTo(in_mat1, type, 1.0f / fscale, 0);
|
||||
|
||||
cv::randu(in_mat32s, cv::Scalar::all(0), cv::Scalar::all(255 * fscale));
|
||||
in_mat32s.convertTo(in_mat2, type, 1.0f / fscale, 0);
|
||||
}
|
||||
|
||||
if (createOutputMatrices)
|
||||
{
|
||||
initOutMats(sz_in, dtype);
|
||||
}
|
||||
}
|
||||
|
||||
void initMatrixRandU(int type, cv::Size sz_in, int dtype, bool createOutputMatrices = true)
|
||||
{
|
||||
in_mat1 = cv::Mat(sz_in, type);
|
||||
|
||||
sc = initScalarRandU(100);
|
||||
if (CV_MAT_DEPTH(type) < CV_32F)
|
||||
{
|
||||
cv::randu(in_mat1, cv::Scalar::all(0), cv::Scalar::all(255));
|
||||
}
|
||||
else
|
||||
{
|
||||
const int fscale = 256; // avoid bits near ULP, generate stable test input
|
||||
Mat in_mat32s(in_mat1.size(), CV_MAKE_TYPE(CV_32S, CV_MAT_CN(type)));
|
||||
cv::randu(in_mat32s, cv::Scalar::all(0), cv::Scalar::all(255 * fscale));
|
||||
in_mat32s.convertTo(in_mat1, type, 1.0f / fscale, 0);
|
||||
}
|
||||
|
||||
if (createOutputMatrices)
|
||||
{
|
||||
initOutMats(sz_in, dtype);
|
||||
}
|
||||
}
|
||||
|
||||
void initMatrixRandN(int type, cv::Size sz_in, int dtype, bool createOutputMatrices = true)
|
||||
{
|
||||
in_mat1 = cv::Mat(sz_in, type);
|
||||
cv::randn(in_mat1, cv::Scalar::all(127), cv::Scalar::all(40.f));
|
||||
|
||||
if (createOutputMatrices)
|
||||
{
|
||||
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();
|
||||
std::vector<cv::Mat> split(channels);
|
||||
cv::split(mat, split);
|
||||
cv::Mat result;
|
||||
for (int c=0; c < channels; c++)
|
||||
{
|
||||
if (c == 0)
|
||||
result = split[c] != 0;
|
||||
else
|
||||
result = result | (split[c] != 0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static int countNonZeroPixels(const cv::Mat& mat)
|
||||
{
|
||||
return cv::countNonZero( nonZeroPixels(mat) );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
template<class T>
|
||||
class TestParams: public TestFunctional, public TestWithParam<T>{};
|
||||
|
||||
template<class T>
|
||||
class TestPerfParams: public TestFunctional, public perf::TestBaseWithParam<T>{};
|
||||
|
||||
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(*)();
|
||||
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<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;
|
||||
|
||||
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...>;
|
||||
|
||||
MatType2 type = getCommonParam<0>();
|
||||
cv::Size sz = getCommonParam<1>();
|
||||
MatType2 dtype = getCommonParam<2>();
|
||||
|
||||
// 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<3>()();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @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); } \
|
||||
};
|
||||
|
||||
// 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
|
||||
{
|
||||
compare_f to_compare_f()
|
||||
{
|
||||
T t = *static_cast<T*const>(this);
|
||||
return [t](const cv::Mat &a, const cv::Mat &b)
|
||||
{
|
||||
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>
|
||||
struct WrappableScalar
|
||||
{
|
||||
compare_scalar_f to_compare_f()
|
||||
{
|
||||
T t = *static_cast<T*const>(this);
|
||||
return [t](const cv::Scalar &a, const cv::Scalar &b)
|
||||
{
|
||||
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());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class AbsExact : public Wrappable<AbsExact>
|
||||
{
|
||||
public:
|
||||
AbsExact() {}
|
||||
bool operator() (const cv::Mat& in1, const cv::Mat& in2) const
|
||||
{
|
||||
if (cv::norm(in1, in2, NORM_INF) != 0)
|
||||
{
|
||||
std::cout << "AbsExact error: G-API output and reference output matrixes are not bitexact equal." << std::endl;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
friend std::ostream& operator<<(std::ostream& os, const AbsExact&)
|
||||
{
|
||||
return os << "AbsExact()";
|
||||
}
|
||||
};
|
||||
|
||||
class AbsTolerance : public Wrappable<AbsTolerance>
|
||||
{
|
||||
public:
|
||||
AbsTolerance(double tol) : _tol(tol) {}
|
||||
bool operator() (const cv::Mat& in1, const cv::Mat& in2) const
|
||||
{
|
||||
if (cv::norm(in1, in2, NORM_INF) > _tol)
|
||||
{
|
||||
std::cout << "AbsTolerance error: Number of different pixels in " << std::endl;
|
||||
std::cout << "G-API output and reference output matrixes exceeds " << _tol << " pixels threshold." << std::endl;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
friend std::ostream& operator<<(std::ostream& os, const AbsTolerance& obj)
|
||||
{
|
||||
return os << "AbsTolerance(" << std::to_string(obj._tol) << ")";
|
||||
}
|
||||
private:
|
||||
double _tol;
|
||||
};
|
||||
|
||||
class Tolerance_FloatRel_IntAbs : public Wrappable<Tolerance_FloatRel_IntAbs>
|
||||
{
|
||||
public:
|
||||
Tolerance_FloatRel_IntAbs(double tol, double tol8u) : _tol(tol), _tol8u(tol8u) {}
|
||||
bool operator() (const cv::Mat& in1, const cv::Mat& in2) const
|
||||
{
|
||||
int depth = CV_MAT_DEPTH(in1.type());
|
||||
{
|
||||
double err = depth >= CV_32F ? cv::norm(in1, in2, NORM_L1 | NORM_RELATIVE)
|
||||
: cv::norm(in1, in2, NORM_INF);
|
||||
double tolerance = depth >= CV_32F ? _tol : _tol8u;
|
||||
if (err > tolerance)
|
||||
{
|
||||
std::cout << "Tolerance_FloatRel_IntAbs error: err=" << err
|
||||
<< " tolerance=" << tolerance
|
||||
<< " depth=" << cv::typeToString(depth) << std::endl;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
class AbsSimilarPoints : public Wrappable<AbsSimilarPoints>
|
||||
{
|
||||
public:
|
||||
AbsSimilarPoints(double tol, double percent) : _tol(tol), _percent(percent) {}
|
||||
bool operator() (const cv::Mat& in1, const cv::Mat& in2) const
|
||||
{
|
||||
Mat diff;
|
||||
cv::absdiff(in1, in2, diff);
|
||||
Mat err_mask = diff > _tol;
|
||||
int err_points = cv::countNonZero(err_mask.reshape(1));
|
||||
double max_err_points = _percent * std::max((size_t)1000, in1.total());
|
||||
if (err_points > max_err_points)
|
||||
{
|
||||
std::cout << "AbsSimilarPoints error: err_points=" << err_points
|
||||
<< " max_err_points=" << max_err_points << " (total=" << in1.total() << ")"
|
||||
<< " diff_tolerance=" << _tol << std::endl;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
friend std::ostream& operator<<(std::ostream& os, const AbsSimilarPoints& obj)
|
||||
{
|
||||
return os << "AbsSimilarPoints(" << obj._tol << ", " << obj._percent << ")";
|
||||
}
|
||||
private:
|
||||
double _tol;
|
||||
double _percent;
|
||||
};
|
||||
|
||||
|
||||
class ToleranceFilter : public Wrappable<ToleranceFilter>
|
||||
{
|
||||
public:
|
||||
ToleranceFilter(double tol, double tol8u, double inf_tol = 2.0) : _tol(tol), _tol8u(tol8u), _inf_tol(inf_tol) {}
|
||||
bool operator() (const cv::Mat& in1, const cv::Mat& in2) const
|
||||
{
|
||||
int depth = CV_MAT_DEPTH(in1.type());
|
||||
{
|
||||
double err_Inf = cv::norm(in1, in2, NORM_INF);
|
||||
if (err_Inf > _inf_tol)
|
||||
{
|
||||
std::cout << "ToleranceFilter error: err_Inf=" << err_Inf << " tolerance=" << _inf_tol << std::endl;
|
||||
return false;
|
||||
}
|
||||
double err = cv::norm(in1, in2, NORM_L2 | NORM_RELATIVE);
|
||||
double tolerance = depth >= CV_32F ? _tol : _tol8u;
|
||||
if (err > tolerance)
|
||||
{
|
||||
std::cout << "ToleranceFilter error: err=" << err << " tolerance=" << tolerance
|
||||
<< " depth=" << cv::depthToString(depth)
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
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;
|
||||
double _inf_tol;
|
||||
};
|
||||
|
||||
class ToleranceColor : public Wrappable<ToleranceColor>
|
||||
{
|
||||
public:
|
||||
ToleranceColor(double tol, double inf_tol = 2.0) : _tol(tol), _inf_tol(inf_tol) {}
|
||||
bool operator() (const cv::Mat& in1, const cv::Mat& in2) const
|
||||
{
|
||||
{
|
||||
double err_Inf = cv::norm(in1, in2, NORM_INF);
|
||||
if (err_Inf > _inf_tol)
|
||||
{
|
||||
std::cout << "ToleranceColor error: err_Inf=" << err_Inf << " tolerance=" << _inf_tol << std::endl;;
|
||||
return false;
|
||||
}
|
||||
double err = cv::norm(in1, in2, NORM_L1 | NORM_RELATIVE);
|
||||
if (err > _tol)
|
||||
{
|
||||
std::cout << "ToleranceColor error: err=" << err << " tolerance=" << _tol << std::endl;;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
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;
|
||||
};
|
||||
|
||||
class AbsToleranceScalar : public WrappableScalar<AbsToleranceScalar>
|
||||
{
|
||||
public:
|
||||
AbsToleranceScalar(double tol) : _tol(tol) {}
|
||||
bool operator() (const cv::Scalar& in1, const cv::Scalar& in2) const
|
||||
{
|
||||
double abs_err = std::abs(in1[0] - in2[0]) / std::max(1.0, std::abs(in2[0]));
|
||||
if (abs_err > _tol)
|
||||
{
|
||||
std::cout << "AbsToleranceScalar error: abs_err=" << abs_err << " tolerance=" << _tol << " in1[0]" << in1[0] << " in2[0]" << in2[0] << std::endl;;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
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_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
|
||||
@@ -0,0 +1,81 @@
|
||||
// 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
|
||||
{
|
||||
|
||||
// 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__))
|
||||
|
||||
#define __DEFINE_PARAMS_IMPL7(index, param_name, ...) \
|
||||
__TUPLE_PARAM_TYPE(index) param_name = getSpecificParam<index>(); \
|
||||
__WRAP_VAARGS(__DEFINE_PARAMS_IMPL6(index+1, __VA_ARGS__))
|
||||
|
||||
#define __DEFINE_PARAMS_IMPL8(index, param_name, ...) \
|
||||
__TUPLE_PARAM_TYPE(index) param_name = getSpecificParam<index>(); \
|
||||
__WRAP_VAARGS(__DEFINE_PARAMS_IMPL7(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__))
|
||||
|
||||
#define DEFINE_SPECIFIC_PARAMS_7(...) \
|
||||
__WRAP_VAARGS(__DEFINE_PARAMS_IMPL7(0, __VA_ARGS__))
|
||||
|
||||
#define DEFINE_SPECIFIC_PARAMS_8(...) \
|
||||
__WRAP_VAARGS(__DEFINE_PARAMS_IMPL8(0, __VA_ARGS__))
|
||||
} // namespace opencv_test
|
||||
|
||||
#endif //OPENCV_GAPI_TESTS_HELPERS_HPP
|
||||
Reference in New Issue
Block a user