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

Merge pull request #12608 from dmatveev:gapi

* G-API Initial code upload

* Update G-API code base to Sep-24-2018

* The majority of OpenCV buildbot problems was addressed

* Update G-API code base to 24-Sep-18 EOD

* G-API code base update 25-Sep-2018

* Linux warnings should be resolved
* Documentation build should become green
* Number of Windows warnings should be reduced

* Update G-API code base to 25-Sep-18 EOD

* ARMv7 build issue should be resolved
* ADE is bumped to latest version and should fix Clang builds for macOS/iOS
* Remaining Windows warnings should be resolved
* New Linux32 / ARMv7 warnings should be resolved

* G-API code base update 25-Sep-2018-EOD2

* Final Windows warnings should be resolved now

* G-API code base update 26-Sep-2018

* Fixed issues with precompiled headers in module and its tests
This commit is contained in:
Dmitry Matveev
2018-09-26 21:50:39 +03:00
committed by Alexander Alekhin
parent 852f061b26
commit 29e88e50ff
166 changed files with 35254 additions and 0 deletions
@@ -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::unite_policy::REPLACE);
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::unite_policy::KEEP);
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::unite_policy::KEEP);
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::unite_policy::KEEP);
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::unite_policy::KEEP);
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::unite_policy::KEEP);
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::unite_policy::KEEP);
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::unite_policy::KEEP);
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::unite_policy::KEEP);
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::unite_policy::KEEP);
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::unite_policy::KEEP);
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::unite_policy::KEEP);
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,8 @@
// 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 "gapi_core_tests_inl.hpp"
@@ -0,0 +1,151 @@
// 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_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
};
namespace
{
const char *MathOperations[] = {"ADD", "SUB", "MUL", "DIV"};
const char *BitwiseOperations[] = {"And", "Or", "Xor"};
const char *CompareOperations[] = {"CMP_EQ", "CMP_GT", "CMP_GE", "CMP_LT", "CMP_LE", "CMP_NE"};
//corresponds to OpenCV
const char *NormOperations[] = {"", "NORM_INF", "NORM_L1", "","NORM_L2"};
}
struct PrintMathOpCoreParams
{
template <class TestParams>
std::string operator()(const ::testing::TestParamInfo<TestParams>& info) const
{
std::stringstream ss;
cv::Size sz = std::get<4>(info.param);
ss<<MathOperations[std::get<0>(info.param)]
<<"_"<<std::get<1>(info.param)
<<"_"<<std::get<2>(info.param)
<<"_"<<(int)std::get<3>(info.param)
<<"_"<<sz.width
<<"x"<<sz.height
<<"_"<<(std::get<5>(info.param)+1)
<<"_"<<std::get<6>(info.param)
<<"_"<<std::get<7>(info.param);
return ss.str();
}
};
struct PrintCmpCoreParams
{
template <class TestParams>
std::string operator()(const ::testing::TestParamInfo<TestParams>& info) const
{
std::stringstream ss;
cv::Size sz = std::get<3>(info.param);
ss<<CompareOperations[std::get<0>(info.param)]
<<"_"<<std::get<1>(info.param)
<<"_"<<std::get<2>(info.param)
<<"_"<<sz.width
<<"x"<<sz.height
<<"_"<<std::get<4>(info.param);
return ss.str();
}
};
struct PrintBWCoreParams
{
template <class TestParams>
std::string operator()(const ::testing::TestParamInfo<TestParams>& info) const
{
std::stringstream ss;
cv::Size sz = std::get<2>(info.param);
ss<<BitwiseOperations[std::get<0>(info.param)]
<<"_"<<std::get<1>(info.param)
<<"_"<<sz.width
<<"x"<<sz.height
<<"_"<<std::get<3>(info.param);
return ss.str();
}
};
struct PrintNormCoreParams
{
template <class TestParams>
std::string operator()(const ::testing::TestParamInfo<TestParams>& info) const
{
std::stringstream ss;
cv::Size sz = std::get<2>(info.param);
ss<<NormOperations[std::get<0>(info.param)]
<<"_"<<std::get<1>(info.param)
<<"_"<<sz.width
<<"x"<<sz.height;
return ss.str();
}
};
struct MathOpTest : public TestParams<std::tuple<mathOp,bool,int,double,cv::Size,int,bool,bool,cv::GCompileArgs>>{};
struct MulDoubleTest : public TestParams<std::tuple<int,cv::Size,int,bool,cv::GCompileArgs>>{};
struct DivTest : public TestParams<std::tuple<int,cv::Size,int,bool, cv::GCompileArgs>>{};
struct DivCTest : public TestParams<std::tuple<int,cv::Size,int,bool, cv::GCompileArgs>>{};
struct MeanTest : public TestParams<std::tuple<int,cv::Size,bool, cv::GCompileArgs>> {};
struct MaskTest : public TestParams<std::tuple<int,cv::Size,bool, cv::GCompileArgs>> {};
struct Polar2CartTest : public TestParams<std::tuple<cv::Size,bool, cv::GCompileArgs>> {};
struct Cart2PolarTest : public TestParams<std::tuple<cv::Size,bool, cv::GCompileArgs>> {};
struct CmpTest : public TestParams<std::tuple<CmpTypes,bool,int,cv::Size,bool, cv::GCompileArgs>>{};
struct BitwiseTest : public TestParams<std::tuple<bitwiseOp,int,cv::Size,bool, cv::GCompileArgs>>{};
struct NotTest : public TestParams<std::tuple<int,cv::Size,bool, cv::GCompileArgs>> {};
struct SelectTest : public TestParams<std::tuple<int,cv::Size,bool, cv::GCompileArgs>> {};
struct MinTest : public TestParams<std::tuple<int,cv::Size,bool, cv::GCompileArgs>>{};
struct MaxTest : public TestParams<std::tuple<int,cv::Size,bool, cv::GCompileArgs>>{};
struct AbsDiffTest : public TestParams<std::tuple<int,cv::Size,bool, cv::GCompileArgs>>{};
struct AbsDiffCTest : public TestParams<std::tuple<int,cv::Size,bool, cv::GCompileArgs>> {};
struct SumTest : public TestParams<std::tuple<int, cv::Size,bool, cv::GCompileArgs>> {};
struct AddWeightedTest : public TestParams<std::tuple<int,cv::Size,int,bool, cv::GCompileArgs>>{};
struct NormTest : public TestParams<std::tuple<NormTypes,int,cv::Size, cv::GCompileArgs>>{};
struct IntegralTest : public TestWithParam<std::tuple<int,cv::Size, cv::GCompileArgs>> {};
struct ThresholdTest : public TestParams<std::tuple<int,cv::Size,int,bool, cv::GCompileArgs>> {};
struct ThresholdOTTest : public TestParams<std::tuple<int,cv::Size,int,bool, cv::GCompileArgs>> {};
struct InRangeTest : public TestParams<std::tuple<int,cv::Size,bool, cv::GCompileArgs>> {};
struct Split3Test : public TestParams<std::tuple<cv::Size, cv::GCompileArgs>> {};
struct Split4Test : public TestParams<std::tuple<cv::Size, cv::GCompileArgs>> {};
struct ResizeTest : public TestWithParam<std::tuple<int, int, cv::Size, cv::Size, double, cv::GCompileArgs>> {};
struct ResizeTestFxFy : public TestWithParam<std::tuple<int, int, cv::Size, double, double, double, cv::GCompileArgs>> {};
struct Merge3Test : public TestParams<std::tuple<cv::Size, cv::GCompileArgs>> {};
struct Merge4Test : public TestParams<std::tuple<cv::Size, cv::GCompileArgs>> {};
struct RemapTest : public TestParams<std::tuple<int,cv::Size,bool, cv::GCompileArgs>> {};
struct FlipTest : public TestParams<std::tuple<int, int, cv::Size,bool, cv::GCompileArgs>> {};
struct CropTest : public TestParams<std::tuple<int,cv::Rect,cv::Size,bool, cv::GCompileArgs>> {};
struct ConcatHorTest : public TestWithParam<std::tuple<int, cv::Size, cv::GCompileArgs>> {};
struct ConcatVertTest : public TestWithParam<std::tuple<int, cv::Size, cv::GCompileArgs>> {};
struct ConcatVertVecTest : public TestWithParam<std::tuple<int, cv::Size, cv::GCompileArgs>> {};
struct ConcatHorVecTest : public TestWithParam<std::tuple<int, cv::Size, cv::GCompileArgs>> {};
struct LUTTest : public TestParams<std::tuple<int, int, cv::Size,bool, cv::GCompileArgs>> {};
struct ConvertToTest : public TestParams<std::tuple<int, int, cv::Size, cv::GCompileArgs>> {};
} // opencv_test
#endif //OPENCV_GAPI_CORE_TESTS_HPP
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,8 @@
// 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 "gapi_imgproc_tests_inl.hpp"
@@ -0,0 +1,41 @@
// 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_IMGPROC_TESTS_HPP
#define OPENCV_GAPI_IMGPROC_TESTS_HPP
#include <iostream>
#include "gapi_tests_common.hpp"
namespace opencv_test
{
struct Filter2DTest : public TestParams <std::tuple<MatType,int,cv::Size,int,int,bool,cv::GCompileArgs>> {};
struct BoxFilterTest : public TestParams <std::tuple<MatType,int,cv::Size,int,int,double,bool,cv::GCompileArgs>> {};
struct SepFilterTest : public TestParams <std::tuple<MatType,int,cv::Size,int,bool,cv::GCompileArgs>> {};
struct BlurTest : public TestParams <std::tuple<MatType,int,cv::Size,int,double,bool,cv::GCompileArgs>> {};
struct GaussianBlurTest : public TestParams <std::tuple<MatType,int,cv::Size,bool,cv::GCompileArgs>> {};
struct MedianBlurTest : public TestParams <std::tuple<MatType,int,cv::Size,bool,cv::GCompileArgs>> {};
struct ErodeTest : public TestParams <std::tuple<MatType,int,cv::Size,int,bool,cv::GCompileArgs>> {};
struct Erode3x3Test : public TestParams <std::tuple<MatType,cv::Size,bool,int,cv::GCompileArgs>> {};
struct DilateTest : public TestParams <std::tuple<MatType,int,cv::Size,int,bool,cv::GCompileArgs>> {};
struct Dilate3x3Test : public TestParams <std::tuple<MatType,cv::Size,bool,int,cv::GCompileArgs>> {};
struct SobelTest : public TestParams <std::tuple<MatType,int,cv::Size,int,int,int,bool,cv::GCompileArgs>> {};
struct EqHistTest : public TestParams <std::tuple<cv::Size,bool, cv::GCompileArgs>> {};
struct CannyTest : public TestParams <std::tuple<MatType,cv::Size,double,double,int,bool,bool,cv::GCompileArgs>> {};
struct RGB2GrayTest : public TestParams<std::tuple<cv::Size,bool,cv::GCompileArgs>> {};
struct BGR2GrayTest : public TestParams<std::tuple<cv::Size,bool,cv::GCompileArgs>> {};
struct RGB2YUVTest : public TestParams<std::tuple<cv::Size,bool,cv::GCompileArgs>> {};
struct YUV2RGBTest : public TestParams<std::tuple<cv::Size,bool,cv::GCompileArgs>> {};
struct RGB2LabTest : public TestParams<std::tuple<cv::Size,bool,cv::GCompileArgs>> {};
struct BGR2LUVTest : public TestParams<std::tuple<cv::Size,bool,cv::GCompileArgs>> {};
struct LUV2BGRTest : public TestParams<std::tuple<cv::Size,bool,cv::GCompileArgs>> {};
struct BGR2YUVTest : public TestParams<std::tuple<cv::Size,bool,cv::GCompileArgs>> {};
struct YUV2BGRTest : public TestParams<std::tuple<cv::Size,bool,cv::GCompileArgs>> {};
} // opencv_test
#endif //OPENCV_GAPI_IMGPROC_TESTS_HPP
@@ -0,0 +1,751 @@
// 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_IMGPROC_TESTS_INL_HPP
#define OPENCV_GAPI_IMGPROC_TESTS_INL_HPP
#include "opencv2/gapi/imgproc.hpp"
#include "gapi_imgproc_tests.hpp"
namespace opencv_test
{
TEST_P(Filter2DTest, AccuracyTest)
{
MatType type = 0;
int kernSize = 0, borderType = 0, dtype = 0;
cv::Size sz;
bool initOut = false;
cv::GCompileArgs compile_args;
std::tie(type, kernSize, sz, borderType, dtype, initOut, compile_args) = GetParam();
initMatsRandN(type, sz, dtype, initOut);
cv::Point anchor = {-1, -1};
double delta = 0;
cv::Mat kernel = cv::Mat(kernSize, kernSize, CV_32FC1 );
cv::Scalar kernMean = cv::Scalar(1.0);
cv::Scalar kernStddev = cv::Scalar(2.0/3);
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, std::move(compile_args));
// OpenCV code /////////////////////////////////////////////////////////////
{
cv::filter2D(in_mat1, out_mat_ocv, dtype, kernel, anchor, delta, borderType);
}
// Comparison //////////////////////////////////////////////////////////////
{
// TODO: Control this choice with test's especial parameter
#if 1
// Allow some rounding error
if (CV_MAT_DEPTH(out_mat_gapi.type()) == CV_32F)
{
// 6 decimal digits is nearly best accuracy we can expect of FP32 arithmetic here
EXPECT_EQ(0, cv::countNonZero(cv::abs(out_mat_gapi - out_mat_ocv) > 1e-6*cv::abs(out_mat_ocv)));
}
else
{
// allow wrong rounding if result fractional part is nearly 0.5,
// assume there would be not more than 0.01% of such cases
EXPECT_LE(cv::countNonZero(out_mat_gapi != out_mat_ocv), 1e-4*out_mat_ocv.total());
}
#else
EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv));
#endif
EXPECT_EQ(out_mat_gapi.size(), sz);
}
}
TEST_P(BoxFilterTest, AccuracyTest)
{
MatType type = 0;
int filterSize = 0, borderType = 0, dtype = 0;
cv::Size sz;
double tolerance = 0.0;
bool initOut = false;
cv::GCompileArgs compile_args;
std::tie(type, filterSize, sz, borderType, dtype, tolerance, initOut, compile_args) = GetParam();
initMatsRandN(type, sz, dtype, initOut);
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, std::move(compile_args));
// OpenCV code /////////////////////////////////////////////////////////////
{
cv::boxFilter(in_mat1, out_mat_ocv, dtype, cv::Size(filterSize, filterSize), anchor, normalize, borderType);
}
// Comparison //////////////////////////////////////////////////////////////
{
// TODO: Control this choice with test's especial parameter
#if 1
// Allow some rounding error
if (CV_MAT_DEPTH(out_mat_gapi.type()) == CV_32F)
{
// 6 decimal digits is nearly best accuracy we can expect of FP32 arithmetic here
EXPECT_EQ(0, cv::countNonZero(cv::abs(out_mat_gapi - out_mat_ocv) > 1e-6*cv::abs(out_mat_ocv)));
}
else
{
// allow wrong rounding if result fractional part is nearly 0.5,
// assume there would be not more than 0.01% of such cases
EXPECT_LE(cv::countNonZero(out_mat_gapi != out_mat_ocv), 1e-4*out_mat_ocv.total());
}
#else
cv::Mat absDiff;
cv::absdiff(out_mat_gapi, out_mat_ocv, absDiff);
EXPECT_EQ(0, cv::countNonZero(absDiff > tolerance));
#endif
EXPECT_EQ(out_mat_gapi.size(), sz);
}
}
TEST_P(SepFilterTest, AccuracyTest)
{
MatType type = 0;
int kernSize = 0, dtype = 0;
cv::Size sz;
bool initOut = false;
cv::GCompileArgs compile_args;
std::tie(type, kernSize, sz, dtype, initOut, compile_args) = GetParam();
cv::Mat kernelX(kernSize, 1, CV_32F);
cv::Mat kernelY(kernSize, 1, CV_32F);
randu(kernelX, -1, 1);
randu(kernelY, -1, 1);
initMatsRandN(type, sz, dtype, initOut);
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, std::move(compile_args));
// OpenCV code /////////////////////////////////////////////////////////////
{
cv::sepFilter2D(in_mat1, out_mat_ocv, dtype, kernelX, kernelY );
}
// Comparison //////////////////////////////////////////////////////////////
{
// TODO: Control this choice with test's especial parameter
#if 1
// Expect some rounding error
EXPECT_LE(cv::countNonZero(cv::abs(out_mat_gapi - out_mat_ocv) > 1e-5 * cv::abs(out_mat_ocv)),
0.01 * out_mat_ocv.total());
#else
EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv));
#endif
EXPECT_EQ(out_mat_gapi.size(), sz);
}
}
TEST_P(BlurTest, AccuracyTest)
{
MatType type = 0;
int filterSize = 0, borderType = 0;
cv::Size sz;
double tolerance = 0.0;
bool initOut = false;
cv::GCompileArgs compile_args;
std::tie(type, filterSize, sz, borderType, tolerance, initOut, compile_args) = GetParam();
initMatsRandN(type, sz, type, initOut);
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, std::move(compile_args));
// OpenCV code /////////////////////////////////////////////////////////////
{
cv::blur(in_mat1, out_mat_ocv, cv::Size(filterSize, filterSize), anchor, borderType);
}
// Comparison //////////////////////////////////////////////////////////////
{
cv::Mat absDiff;
cv::absdiff(out_mat_gapi, out_mat_ocv, absDiff);
EXPECT_EQ(0, cv::countNonZero(absDiff > tolerance));
EXPECT_EQ(out_mat_gapi.size(), sz);
}
}
TEST_P(GaussianBlurTest, AccuracyTest)
{
MatType type = 0;
int kernSize = 0;
cv::Size sz;
bool initOut = false;
cv::GCompileArgs compile_args;
std::tie(type, kernSize, sz, initOut, compile_args) = GetParam();
initMatsRandN(type, sz, type, initOut);
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, std::move(compile_args));
// OpenCV code /////////////////////////////////////////////////////////////
{
cv::GaussianBlur(in_mat1, out_mat_ocv, kSize, sigmaX);
}
// Comparison //////////////////////////////////////////////////////////////
{
// TODO: Control this choice with test's especial parameter
#if 1
// Expect some rounding error
if (CV_MAT_DEPTH(out_mat_gapi.type()) == CV_32F ||
CV_MAT_DEPTH(out_mat_gapi.type()) == CV_64F)
{
// Note that 1e-6 is nearly best accuracy we can expect of FP32 arithetic
EXPECT_EQ(0, cv::countNonZero(cv::abs(out_mat_gapi - out_mat_ocv) >
1e-6*cv::abs(out_mat_ocv)));
}
else if (CV_MAT_DEPTH(out_mat_gapi.type()) == CV_8U)
{
// OpenCV uses 16-bits fixed-point for 8U data, so may produce wrong results
EXPECT_LE(cv::countNonZero(cv::abs(out_mat_gapi - out_mat_ocv) > 1),
0.05*out_mat_ocv.total());
EXPECT_LE(cv::countNonZero(cv::abs(out_mat_gapi - out_mat_ocv) > 2), 0);
}
else
{
EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv));
}
#else
EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv));
#endif
EXPECT_EQ(out_mat_gapi.size(), sz);
}
}
TEST_P(MedianBlurTest, AccuracyTest)
{
MatType type = 0;
int kernSize = 0;
cv::Size sz;
bool initOut = false;
cv::GCompileArgs compile_args;
std::tie(type, kernSize, sz, initOut, compile_args) = GetParam();
initMatsRandN(type, sz, type, initOut);
// 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, std::move(compile_args));
// OpenCV code /////////////////////////////////////////////////////////////
{
cv::medianBlur(in_mat1, out_mat_ocv, kernSize);
}
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), sz);
}
}
TEST_P(ErodeTest, AccuracyTest)
{
MatType type = 0;
int kernSize = 0, kernType = 0;
cv::Size sz;
bool initOut = false;
cv::GCompileArgs compile_args;
std::tie(type, kernSize, sz, kernType, initOut, compile_args) = GetParam();
initMatsRandN(type, sz, type, initOut);
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, std::move(compile_args));
// OpenCV code /////////////////////////////////////////////////////////////
{
cv::erode(in_mat1, out_mat_ocv, kernel);
}
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), sz);
}
}
TEST_P(Erode3x3Test, AccuracyTest)
{
MatType type = 0;
int numIters = 0;
cv::Size sz;
bool initOut = false;
cv::GCompileArgs compile_args;
std::tie(type, sz, initOut, numIters, compile_args) = GetParam();
initMatsRandN(type, sz, type, initOut);
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, std::move(compile_args));
// OpenCV code /////////////////////////////////////////////////////////////
{
cv::erode(in_mat1, out_mat_ocv, kernel, cv::Point(-1, -1), numIters);
}
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), sz);
}
}
TEST_P(DilateTest, AccuracyTest)
{
MatType type = 0;
int kernSize = 0, kernType = 0;
cv::Size sz;
bool initOut = false;
cv::GCompileArgs compile_args;
std::tie(type, kernSize, sz, kernType, initOut, compile_args) = GetParam();
initMatsRandN(type, sz, type, initOut);
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, std::move(compile_args));
// OpenCV code /////////////////////////////////////////////////////////////
{
cv::dilate(in_mat1, out_mat_ocv, kernel);
}
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), sz);
}
}
TEST_P(Dilate3x3Test, AccuracyTest)
{
MatType type = 0;
int numIters = 0;
cv::Size sz;
bool initOut = false;
cv::GCompileArgs compile_args;
std::tie(type, sz, initOut, numIters, compile_args) = GetParam();
initMatsRandN(type, sz, type, initOut);
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, std::move(compile_args));
// OpenCV code /////////////////////////////////////////////////////////////
{
cv::dilate(in_mat1, out_mat_ocv, kernel, cv::Point(-1,-1), numIters);
}
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), sz);
}
}
TEST_P(SobelTest, AccuracyTest)
{
MatType type = 0;
int kernSize = 0, dtype = 0, dx = 0, dy = 0;
cv::Size sz;
bool initOut = false;
cv::GCompileArgs compile_args;
std::tie(type, kernSize, sz, dtype, dx, dy, initOut, compile_args) = GetParam();
initMatsRandN(type, sz, dtype, initOut);
// 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, std::move(compile_args));
// OpenCV code /////////////////////////////////////////////////////////////
{
cv::Sobel(in_mat1, out_mat_ocv, dtype, dx, dy, kernSize);
}
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), sz);
}
}
TEST_P(EqHistTest, AccuracyTest)
{
cv::Size sz;
bool initOut = false;
cv::GCompileArgs compile_args;
std::tie(sz, initOut, compile_args) = GetParam();
initMatsRandN(CV_8UC1, sz, CV_8UC1, initOut);
// G-API code //////////////////////////////////////////////////////////////
cv::GMat in;
auto out = cv::gapi::equalizeHist(in);
cv::GComputation c(in, out);
c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
// OpenCV code /////////////////////////////////////////////////////////////
{
cv::equalizeHist(in_mat1, out_mat_ocv);
}
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), std::get<0>(GetParam()));
}
}
TEST_P(CannyTest, AccuracyTest)
{
MatType type;
int apSize = 0;
double thrLow = 0.0, thrUp = 0.0;
cv::Size sz;
bool l2gr = false, initOut = false;
cv::GCompileArgs compile_args;
std::tie(type, sz, thrLow, thrUp, apSize, l2gr, initOut, compile_args) = GetParam();
initMatsRandN(type, sz, CV_8UC1, initOut);
// 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, std::move(compile_args));
// OpenCV code /////////////////////////////////////////////////////////////
{
cv::Canny(in_mat1, out_mat_ocv, thrLow, thrUp, apSize, l2gr);
}
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), sz);
}
}
TEST_P(RGB2GrayTest, AccuracyTest)
{
auto param = GetParam();
auto compile_args = std::get<2>(param);
initMatsRandN(CV_8UC3, std::get<0>(param), CV_8UC1, std::get<1>(param));
// G-API code //////////////////////////////////////////////////////////////
cv::GMat in;
auto out = cv::gapi::RGB2Gray(in);
cv::GComputation c(in, out);
c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
// OpenCV code /////////////////////////////////////////////////////////////
{
cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_RGB2GRAY);
}
// Comparison //////////////////////////////////////////////////////////////
{
// TODO: control this choice with especial parameter of this test
#if 1
// allow faithful rounding if result's fractional part is nearly 0.5
// - assume not more than 0.1% of pixels may deviate this way
// - deviation must not exceed 1 unit anyway
EXPECT_LE(cv::countNonZero(out_mat_gapi - out_mat_ocv > 0), 0.001*out_mat_ocv.total());
EXPECT_LE(cv::countNonZero(out_mat_gapi - out_mat_ocv > 1), 0);
#else
// insist of bit-exact results
EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv));
#endif
EXPECT_EQ(out_mat_gapi.size(), std::get<0>(param));
}
}
TEST_P(BGR2GrayTest, AccuracyTest)
{
auto param = GetParam();
auto compile_args = std::get<2>(param);
initMatsRandN(CV_8UC3, std::get<0>(param), CV_8UC1, std::get<1>(param));
// G-API code //////////////////////////////////////////////////////////////
cv::GMat in;
auto out = cv::gapi::BGR2Gray(in);
cv::GComputation c(in, out);
c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
// OpenCV code /////////////////////////////////////////////////////////////
{
cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_BGR2GRAY);
}
// Comparison //////////////////////////////////////////////////////////////
{
// TODO: control this choice with especial parameter of this test
#if 1
// allow faithful rounding if result's fractional part is nearly 0.5
// - assume not more than 0.1% of pixels may deviate this way
// - deviation must not exceed 1 unit anyway
EXPECT_LE(cv::countNonZero(out_mat_gapi - out_mat_ocv > 0), 0.001*out_mat_ocv.total());
EXPECT_LE(cv::countNonZero(out_mat_gapi - out_mat_ocv > 1), 0);
#else
// insist of bit-exact results
EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv));
#endif
EXPECT_EQ(out_mat_gapi.size(), std::get<0>(param));
}
}
TEST_P(RGB2YUVTest, AccuracyTest)
{
auto param = GetParam();
auto compile_args = std::get<2>(param);
initMatsRandN(CV_8UC3, std::get<0>(param), CV_8UC3, std::get<1>(param));
// G-API code //////////////////////////////////////////////////////////////
cv::GMat in;
auto out = cv::gapi::RGB2YUV(in);
cv::GComputation c(in, out);
c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
// OpenCV code /////////////////////////////////////////////////////////////
{
cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_RGB2YUV);
}
// Comparison //////////////////////////////////////////////////////////////
{
// TODO: control this choice with especial parameter of this test
#if 1
// allow faithful rounding if result's fractional part is nearly 0.5
// - assume not more than 15% of pixels may deviate this way
// - deviation must not exceed 1 unit anyway
EXPECT_LE(cv::countNonZero(out_mat_gapi - out_mat_ocv > 0), 0.15*3*out_mat_ocv.total());
EXPECT_LE(cv::countNonZero(out_mat_gapi - out_mat_ocv > 1), 0);
#else
// insist of bit-exact results
EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv));
#endif
EXPECT_EQ(out_mat_gapi.size(), std::get<0>(param));
}
}
TEST_P(YUV2RGBTest, AccuracyTest)
{
auto param = GetParam();
auto compile_args = std::get<2>(param);
initMatsRandN(CV_8UC3, std::get<0>(param), CV_8UC3, std::get<1>(param));
// G-API code //////////////////////////////////////////////////////////////
cv::GMat in;
auto out = cv::gapi::YUV2RGB(in);
cv::GComputation c(in, out);
c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
// OpenCV code /////////////////////////////////////////////////////////////
{
cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_YUV2RGB);
}
// Comparison //////////////////////////////////////////////////////////////
{
// TODO: control this choice with especial parameter of this test
#if 1
// allow faithful rounding if result's fractional part is nearly 0.5
// - assume not more than 1% of pixels may deviate this way
// - deviation must not exceed 1 unit anyway
EXPECT_LE(cv::countNonZero(out_mat_gapi - out_mat_ocv > 0), 0.01*3*out_mat_ocv.total());
EXPECT_LE(cv::countNonZero(out_mat_gapi - out_mat_ocv > 1), 0);
#else
// insist of bit-exact results
EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv));
#endif
EXPECT_EQ(out_mat_gapi.size(), std::get<0>(param));
}
}
TEST_P(RGB2LabTest, AccuracyTest)
{
auto param = GetParam();
auto compile_args = std::get<2>(param);
initMatsRandN(CV_8UC3, std::get<0>(param), CV_8UC3, std::get<1>(param));
// G-API code //////////////////////////////////////////////////////////////
cv::GMat in;
auto out = cv::gapi::RGB2Lab(in);
cv::GComputation c(in, out);
c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
// OpenCV code /////////////////////////////////////////////////////////////
{
cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_RGB2Lab);
}
// Comparison //////////////////////////////////////////////////////////////
{
// TODO: control this choice with especial parameter of this test
#if 1
// allow faithful rounding, if result's fractional part is nearly 0.5
// - assume not more than 25% of pixels may deviate this way
// - not more than 1% of pixels may deviate by 1 unit
// - deviation must not exceed 2 units anyway
EXPECT_LE(cv::countNonZero(out_mat_gapi - out_mat_ocv > 0), 0.25*3*out_mat_ocv.total());
EXPECT_LE(cv::countNonZero(out_mat_gapi - out_mat_ocv > 1), 0.01*3*out_mat_ocv.total());
EXPECT_LE(cv::countNonZero(out_mat_gapi - out_mat_ocv > 2), 1e-5*3*out_mat_ocv.total());
#else
// insist on bit-exact results
EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv));
#endif
EXPECT_EQ(out_mat_gapi.size(), std::get<0>(param));
}
}
TEST_P(BGR2LUVTest, AccuracyTest)
{
auto param = GetParam();
auto compile_args = std::get<2>(param);
initMatsRandN(CV_8UC3, std::get<0>(param), CV_8UC3, std::get<1>(param));
// G-API code //////////////////////////////////////////////////////////////
cv::GMat in;
auto out = cv::gapi::BGR2LUV(in);
cv::GComputation c(in, out);
c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
// OpenCV code /////////////////////////////////////////////////////////////
{
cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_BGR2Luv);
}
// Comparison //////////////////////////////////////////////////////////////
{
// TODO: control this choice with especial parameter of this test
#if 1
// allow faithful rounding, if result's fractional part is nearly 0.5
// - assume not more than 25% of pixels may deviate this way
// - not more than 1% of pixels may deviate by 2+ units
// - not more than 0.01% pixels may deviate by 5+ units
EXPECT_LE(cv::countNonZero(out_mat_gapi - out_mat_ocv > 0), 0.25 * 3 * out_mat_ocv.total());
EXPECT_LE(cv::countNonZero(out_mat_gapi - out_mat_ocv > 1), 0.01 * 3 * out_mat_ocv.total());
EXPECT_LE(cv::countNonZero(out_mat_gapi - out_mat_ocv > 5), 0.0001 * 3 * out_mat_ocv.total());
#else
// insist on bit-exact results
EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv));
#endif
EXPECT_EQ(out_mat_gapi.size(), std::get<0>(param));
}
}
TEST_P(LUV2BGRTest, AccuracyTest)
{
auto param = GetParam();
auto compile_args = std::get<2>(param);
initMatsRandN(CV_8UC3, std::get<0>(param), CV_8UC3, std::get<1>(param));
// G-API code //////////////////////////////////////////////////////////////
cv::GMat in;
auto out = cv::gapi::LUV2BGR(in);
cv::GComputation c(in, out);
c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
// OpenCV code /////////////////////////////////////////////////////////////
{
cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_Luv2BGR);
}
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), std::get<0>(param));
}
}
TEST_P(BGR2YUVTest, AccuracyTest)
{
auto param = GetParam();
auto compile_args = std::get<2>(param);
initMatsRandN(CV_8UC3, std::get<0>(param), CV_8UC3, std::get<1>(param));
// G-API code //////////////////////////////////////////////////////////////
cv::GMat in;
auto out = cv::gapi::BGR2YUV(in);
cv::GComputation c(in, out);
c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
// OpenCV code /////////////////////////////////////////////////////////////
{
cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_BGR2YUV);
}
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), std::get<0>(param));
}
}
TEST_P(YUV2BGRTest, AccuracyTest)
{
auto param = GetParam();
auto compile_args = std::get<2>(param);
initMatsRandN(CV_8UC3, std::get<0>(param), CV_8UC3, std::get<1>(param));
// G-API code //////////////////////////////////////////////////////////////
cv::GMat in;
auto out = cv::gapi::YUV2BGR(in);
cv::GComputation c(in, out);
c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
// OpenCV code /////////////////////////////////////////////////////////////
{
cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_YUV2BGR);
}
// Comparison //////////////////////////////////////////////////////////////
{
// TODO: control this choice with especial parameter of this test
#if 1
// allow faithful rounding, if result's fractional part is nearly 0.5
// - assume not more than 25% of pixels may deviate this way
// - not more than 1% of pixels may deviate by 1 unit
// - deviation must not exceed 2 units anyway
EXPECT_LE(cv::countNonZero(out_mat_gapi - out_mat_ocv > 0), 0.25*3*out_mat_ocv.total());
EXPECT_LE(cv::countNonZero(out_mat_gapi - out_mat_ocv > 1), 0.01*3*out_mat_ocv.total());
EXPECT_LE(cv::countNonZero(out_mat_gapi - out_mat_ocv > 2), 1e-5*3*out_mat_ocv.total());
#else
// insist on bit-exact results
EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv));
#endif
EXPECT_EQ(out_mat_gapi.size(), std::get<0>(param));
}
}
} // opencv_test
#endif //OPENCV_GAPI_IMGPROC_TESTS_INL_HPP
@@ -0,0 +1,8 @@
// 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 "gapi_operators_tests_inl.hpp"
@@ -0,0 +1,192 @@
// 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 c){return in-c;},
[](const cv::Mat& in, const cv::Mat& c, cv::Mat& out){cv::subtract(in, c, out);}};
g_api_ocv_pair_mat_mat opDivM = {std::string{"operator/"},
[](cv::GMat in,cv::GMat c){return in/c;},
[](const cv::Mat& in, const cv::Mat& c, cv::Mat& out){cv::divide(in, c, 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
struct MathOperatorMatScalarTest : public TestParams<std::tuple<g_api_ocv_pair_mat_scalar,int,cv::Size,int,bool,cv::GCompileArgs>>{};
struct MathOperatorMatMatTest : public TestParams<std::tuple<g_api_ocv_pair_mat_mat,int,cv::Size,int,bool,cv::GCompileArgs>>{};
struct NotOperatorTest : public TestParams<std::tuple<int,cv::Size,bool,cv::GCompileArgs>> {};
} // opencv_test
#endif // OPENCV_GAPI_OPERATOR_TESTS_COMMON_HPP
@@ -0,0 +1,102 @@
// 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 )
{
g_api_ocv_pair_mat_scalar op;
int type = 0, dtype = 0;
cv::Size sz;
bool initOutMatr = false;
cv::GCompileArgs compile_args;
std::tie(op, type, sz, dtype, initOutMatr, compile_args) = GetParam();
initMatsRandU(type, sz, dtype, initOutMatr);
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), std::move(compile_args));
fun_ocv(in_mat1, sc, out_mat_ocv);
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), sz);
}
}
TEST_P(MathOperatorMatMatTest, OperatorAccuracyTest )
{
g_api_ocv_pair_mat_mat op;
int type = 0, dtype = 0;
cv::Size sz;
bool initOutMatr = false;
cv::GCompileArgs compile_args;
std::tie(op, type, sz, dtype, initOutMatr, compile_args) = GetParam();
initMatsRandU(type, sz, dtype, initOutMatr);
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), std::move(compile_args));
fun_ocv(in_mat1, in_mat2, out_mat_ocv);
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), sz);
}
}
TEST_P(NotOperatorTest, OperatorAccuracyTest)
{
cv::Size sz_in = std::get<1>(GetParam());
initMatrixRandU(std::get<0>(GetParam()), sz_in, std::get<0>(GetParam()), std::get<2>(GetParam()));
cv::GCompileArgs compile_args;
// G-API code //////////////////////////////////////////////////////////////
cv::GMat in;
auto out = ~in;
cv::GComputation c(in, out);
c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
// 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_in);
}
}
} // opencv_test
#endif // OPENCV_GAPI_OPERATOR_TESTS_INL_COMMON_HPP
@@ -0,0 +1,108 @@
// 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 <iostream>
#include "opencv2/ts.hpp"
#include "opencv2/gapi.hpp"
namespace
{
inline std::ostream& operator<<(std::ostream& o, const cv::GCompileArg& arg)
{
return o << (arg.tag.empty() ? "empty" : arg.tag);
}
}
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;
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);
auto& rng = cv::theRNG();
sc = cv::Scalar(rng(100),rng(100),rng(100),rng(100));
cv::randu(in_mat1, cv::Scalar::all(0), cv::Scalar::all(255));
cv::randu(in_mat2, cv::Scalar::all(0), cv::Scalar::all(255));
if (createOutputMatrices && dtype != -1)
{
out_mat_gapi = cv::Mat (sz_in, dtype);
out_mat_ocv = cv::Mat (sz_in, dtype);
}
}
void initMatrixRandU(int type, cv::Size sz_in, int dtype, bool createOutputMatrices = true)
{
in_mat1 = cv::Mat(sz_in, type);
auto& rng = cv::theRNG();
sc = cv::Scalar(rng(100),rng(100),rng(100),rng(100));
cv::randu(in_mat1, cv::Scalar::all(0), cv::Scalar::all(255));
if (createOutputMatrices && dtype != -1)
{
out_mat_gapi = cv::Mat (sz_in, dtype);
out_mat_ocv = cv::Mat (sz_in, dtype);
}
}
void initMatsRandN(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 && dtype != -1)
{
out_mat_gapi = cv::Mat(sz_in, dtype);
out_mat_ocv = cv::Mat(sz_in, dtype);
}
}
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>{};
}