mirror of
https://github.com/opencv/opencv.git
synced 2026-07-31 00:03: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:
committed by
Alexander Alekhin
parent
852f061b26
commit
29e88e50ff
@@ -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>{};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,386 @@
|
||||
// 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 "../common/gapi_core_tests.hpp"
|
||||
#include "opencv2/gapi/cpu/core.hpp"
|
||||
|
||||
#define CORE_CPU cv::gapi::core::cpu::kernels()
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
|
||||
// FIXME: Wut? See MulTestCPU/MathOpTest below (duplicate?)
|
||||
INSTANTIATE_TEST_CASE_P(AddTestCPU, MathOpTest,
|
||||
Combine(Values(ADD, MUL),
|
||||
testing::Bool(),
|
||||
Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ),
|
||||
Values(1.0),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
Values( -1, CV_8U, CV_16U, CV_32F ),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(false),
|
||||
Values(cv::compile_args(CORE_CPU))),
|
||||
opencv_test::PrintMathOpCoreParams());
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(MulTestCPU, MathOpTest,
|
||||
Combine(Values(MUL),
|
||||
testing::Bool(),
|
||||
Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ),
|
||||
Values(1.0, 0.5, 2.0),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
Values( -1, CV_8U, CV_16U, CV_32F ),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(false),
|
||||
Values(cv::compile_args(CORE_CPU))),
|
||||
opencv_test::PrintMathOpCoreParams());
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(SubTestCPU, MathOpTest,
|
||||
Combine(Values(SUB),
|
||||
testing::Bool(),
|
||||
Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ),
|
||||
Values (1.0),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
Values( -1, CV_8U, CV_16U, CV_32F ),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
testing::Bool(),
|
||||
Values(cv::compile_args(CORE_CPU))),
|
||||
opencv_test::PrintMathOpCoreParams());
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(DivTestCPU, MathOpTest,
|
||||
Combine(Values(DIV),
|
||||
testing::Bool(),
|
||||
Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ),
|
||||
Values (1.0, 0.5, 2.0),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
Values( -1, CV_8U, CV_16U, CV_32F ),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
testing::Bool(),
|
||||
Values(cv::compile_args(CORE_CPU))),
|
||||
opencv_test::PrintMathOpCoreParams());
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(MulTestCPU, MulDoubleTest,
|
||||
Combine(Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
Values( -1, CV_8U, CV_16U, CV_32F ),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(CORE_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(DivTestCPU, DivTest,
|
||||
Combine(Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
Values( -1, CV_8U, CV_16U, CV_32F ),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(CORE_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(DivCTestCPU, DivCTest,
|
||||
Combine(Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
Values( -1, CV_8U, CV_16U, CV_32F ),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(CORE_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(MeanTestCPU, MeanTest,
|
||||
Combine(Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(CORE_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(MaskTestCPU, MaskTest,
|
||||
Combine(Values(CV_8UC1, CV_16UC1, CV_16SC1),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(CORE_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(SelectTestCPU, SelectTest,
|
||||
Combine(Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(CORE_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(Polar2CartCPU, Polar2CartTest,
|
||||
Combine(Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(CORE_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(Cart2PolarCPU, Cart2PolarTest,
|
||||
Combine(Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(CORE_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(CompareTestCPU, CmpTest,
|
||||
Combine(Values(CMP_EQ, CMP_GE, CMP_NE, CMP_GT, CMP_LT, CMP_LE),
|
||||
testing::Bool(),
|
||||
Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(CORE_CPU))),
|
||||
opencv_test::PrintCmpCoreParams());
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(BitwiseTestCPU, BitwiseTest,
|
||||
Combine(Values(AND, OR, XOR),
|
||||
Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(CORE_CPU))),
|
||||
opencv_test::PrintBWCoreParams());
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(BitwiseNotTestCPU, NotTest,
|
||||
Combine(Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(CORE_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(MinTestCPU, MinTest,
|
||||
Combine(Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(CORE_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(MaxTestCPU, MaxTest,
|
||||
Combine(Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(CORE_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(SumTestCPU, SumTest,
|
||||
Combine(Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(CORE_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(AbsDiffTestCPU, AbsDiffTest,
|
||||
Combine(Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(CORE_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(AbsDiffCTestCPU, AbsDiffCTest,
|
||||
Combine(Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(CORE_CPU))));
|
||||
|
||||
// FIXME: Comparison introduced by YL doesn't work with C3
|
||||
INSTANTIATE_TEST_CASE_P(AddWeightedTestCPU, AddWeightedTest,
|
||||
Combine(Values( CV_8UC1/*, CV_8UC3*/, CV_16UC1, CV_16SC1, CV_32FC1 ),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
Values( -1, CV_8U, CV_16U, CV_32F ),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(CORE_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(NormTestCPU, NormTest,
|
||||
Combine(Values(NORM_INF, NORM_L1, NORM_L2),
|
||||
Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
Values(cv::compile_args(CORE_CPU))),
|
||||
opencv_test::PrintNormCoreParams());
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(IntegralTestCPU, IntegralTest,
|
||||
Combine(Values( CV_8UC1, CV_16UC1, CV_16SC1, CV_32FC1 ),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
Values(cv::compile_args(CORE_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(ThresholdTestCPU, ThresholdTest,
|
||||
Combine(Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
Values(cv::THRESH_BINARY, cv::THRESH_BINARY_INV, cv::THRESH_TRUNC, cv::THRESH_TOZERO, cv::THRESH_TOZERO_INV),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(CORE_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(ThresholdTestCPU, ThresholdOTTest,
|
||||
Combine(Values(CV_8UC1),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
Values(cv::THRESH_OTSU, cv::THRESH_TRIANGLE),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(CORE_CPU))));
|
||||
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(InRangeTestCPU, InRangeTest,
|
||||
Combine(Values(CV_8UC1, CV_16UC1, CV_16SC1),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(CORE_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(Split3TestCPU, Split3Test,
|
||||
Combine(Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
Values(cv::compile_args(CORE_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(Split4TestCPU, Split4Test,
|
||||
Combine(Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
Values(cv::compile_args(CORE_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(ResizeTestCPU, ResizeTest,
|
||||
Combine(Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ),
|
||||
Values(cv::INTER_NEAREST, cv::INTER_LINEAR, cv::INTER_AREA),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
Values(cv::Size(64,64),
|
||||
cv::Size(30,30)),
|
||||
Values(0.0),
|
||||
Values(cv::compile_args(CORE_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(ResizeTestCPU, ResizeTestFxFy,
|
||||
Combine(Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ),
|
||||
Values(cv::INTER_NEAREST, cv::INTER_LINEAR, cv::INTER_AREA),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
Values(0.5, 0.1),
|
||||
Values(0.5, 0.1),
|
||||
Values(0.0),
|
||||
Values(cv::compile_args(CORE_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(Merge3TestCPU, Merge3Test,
|
||||
Combine(Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
Values(cv::compile_args(CORE_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(Merge4TestCPU, Merge4Test,
|
||||
Combine(Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
Values(cv::compile_args(CORE_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(RemapTestCPU, RemapTest,
|
||||
Combine(Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(CORE_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(FlipTestCPU, FlipTest,
|
||||
Combine(Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ),
|
||||
Values(0,1,-1),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(CORE_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(CropTestCPU, CropTest,
|
||||
Combine(Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ),
|
||||
Values(cv::Rect(10, 8, 20, 35), cv::Rect(4, 10, 37, 50)),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(CORE_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(LUTTestCPU, LUTTest,
|
||||
Combine(Values(CV_8UC1, CV_8UC3),
|
||||
Values(CV_8UC1),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(CORE_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(LUTTestCustomCPU, LUTTest,
|
||||
Combine(Values(CV_8UC3),
|
||||
Values(CV_8UC3),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(CORE_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(ConvertToCPU, ConvertToTest,
|
||||
Combine(Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ),
|
||||
Values(CV_8U, CV_16U, CV_16S, CV_32F),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
Values(cv::compile_args(CORE_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(ConcatHorTestCPU, ConcatHorTest,
|
||||
Combine(Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
Values(cv::compile_args(CORE_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(ConcatVertTestCPU, ConcatVertTest,
|
||||
Combine(Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
Values(cv::compile_args(CORE_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(ConcatVertVecTestCPU, ConcatVertVecTest,
|
||||
Combine(Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
Values(cv::compile_args(CORE_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(ConcatHorVecTestCPU, ConcatHorVecTest,
|
||||
Combine(Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
Values(cv::compile_args(CORE_CPU))));
|
||||
}
|
||||
@@ -0,0 +1,486 @@
|
||||
// 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 "../common/gapi_core_tests.hpp"
|
||||
#include "backends/fluid/gfluidcore.hpp"
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
|
||||
#define CORE_FLUID cv::gapi::core::fluid::kernels()
|
||||
|
||||
// FIXME: Windows accuracy problems after recent update!
|
||||
INSTANTIATE_TEST_CASE_P(MathOpTestFluid, MathOpTest,
|
||||
Combine(Values(ADD, SUB, DIV, MUL),
|
||||
testing::Bool(),
|
||||
Values(CV_8UC3, CV_8UC1, CV_16SC1, CV_32FC1),
|
||||
Values(1.0),
|
||||
Values(cv::Size(1920, 1080),
|
||||
cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
Values(-1, CV_8U, CV_32F),
|
||||
testing::Bool(),
|
||||
testing::Bool(),
|
||||
Values(cv::compile_args(CORE_FLUID))),
|
||||
opencv_test::PrintMathOpCoreParams());
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(MulSTestFluid, MulDoubleTest,
|
||||
Combine(Values(CV_8UC1, CV_16SC1, CV_32FC1),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
Values(-1), // FIXME: extend with more types
|
||||
testing::Bool(),
|
||||
Values(cv::compile_args(CORE_FLUID))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(DivCTestFluid, DivCTest,
|
||||
Combine(Values(CV_8UC1, CV_16SC1, CV_32FC1),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
Values(CV_8U, CV_32F),
|
||||
testing::Bool(),
|
||||
Values(cv::compile_args(CORE_FLUID))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(AbsDiffTestFluid, AbsDiffTest,
|
||||
Combine(Values(CV_8UC1, CV_16UC1, CV_16SC1),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
testing::Bool(),
|
||||
Values(cv::compile_args(CORE_FLUID))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(AbsDiffCTestFluid, AbsDiffCTest,
|
||||
Combine(Values(CV_8UC1, CV_16UC1, CV_16SC1),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
testing::Bool(),
|
||||
Values(cv::compile_args(CORE_FLUID))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(BitwiseTestFluid, BitwiseTest,
|
||||
Combine(Values(AND, OR, XOR),
|
||||
Values(CV_8UC3, CV_8UC1, CV_16UC1, CV_16SC1),
|
||||
Values(cv::Size(1920, 1080),
|
||||
cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
testing::Bool(),
|
||||
Values(cv::compile_args(CORE_FLUID))),
|
||||
opencv_test::PrintBWCoreParams());
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(BitwiseNotTestFluid, NotTest,
|
||||
Combine(Values(CV_8UC3, CV_8UC1, CV_16UC1, CV_16SC1),
|
||||
Values(cv::Size(1920, 1080),
|
||||
cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
testing::Bool(),
|
||||
Values(cv::compile_args(CORE_FLUID))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(MinTestFluid, MinTest,
|
||||
Combine(Values(CV_8UC3, CV_8UC1, CV_16UC1, CV_16SC1, CV_32FC1),
|
||||
Values(cv::Size(1920, 1080),
|
||||
cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
testing::Bool(),
|
||||
Values(cv::compile_args(CORE_FLUID))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(MaxTestFluid, MaxTest,
|
||||
Combine(Values(CV_8UC3, CV_8UC1, CV_16UC1, CV_16SC1, CV_32FC1),
|
||||
Values(cv::Size(1920, 1080),
|
||||
cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
testing::Bool(),
|
||||
Values(cv::compile_args(CORE_FLUID))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(CompareTestFluid, CmpTest,
|
||||
Combine(Values(CMP_EQ, CMP_GE, CMP_NE, CMP_GT, CMP_LT, CMP_LE),
|
||||
testing::Bool(),
|
||||
Values(CV_8UC3, CV_8UC1, CV_16SC1, CV_32FC1),
|
||||
Values(cv::Size(1920, 1080),
|
||||
cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
testing::Bool(),
|
||||
Values(cv::compile_args(CORE_FLUID))),
|
||||
opencv_test::PrintCmpCoreParams());
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(AddWeightedTestFluid, AddWeightedTest,
|
||||
Combine(Values(CV_8UC1, CV_16UC1, CV_16SC1),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
Values(-1, CV_8U, CV_32F),
|
||||
testing::Bool(),
|
||||
Values(cv::compile_args(CORE_FLUID))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(LUTTestFluid, LUTTest,
|
||||
Combine(Values(CV_8UC1, CV_8UC3),
|
||||
Values(CV_8UC1),
|
||||
Values(cv::Size(1920, 1080),
|
||||
cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
testing::Bool(),
|
||||
Values(cv::compile_args(CORE_FLUID))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(ConvertToFluid, ConvertToTest,
|
||||
Combine(Values(CV_8UC3, CV_8UC1, CV_16UC1, CV_32FC1),
|
||||
Values(CV_8U, CV_16U, CV_32F),
|
||||
Values(cv::Size(1920, 1080),
|
||||
cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
Values(cv::compile_args(CORE_FLUID))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(Split3TestFluid, Split3Test,
|
||||
Combine(Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
Values(cv::compile_args(CORE_FLUID))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(Split4TestFluid, Split4Test,
|
||||
Combine(Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
Values(cv::compile_args(CORE_FLUID))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(Merge3TestFluid, Merge3Test,
|
||||
Combine(Values(cv::Size(1920, 1080),
|
||||
cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
Values(cv::compile_args(CORE_FLUID))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(Merge4TestFluid, Merge4Test,
|
||||
Combine(Values(cv::Size(1920, 1080),
|
||||
cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
Values(cv::compile_args(CORE_FLUID))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(SelectTestFluid, SelectTest,
|
||||
Combine(Values(CV_8UC3, CV_8UC1, CV_16UC1, CV_16SC1),
|
||||
Values(cv::Size(1920, 1080),
|
||||
cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
testing::Bool(),
|
||||
Values(cv::compile_args(CORE_FLUID))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(Polar2CartFluid, Polar2CartTest,
|
||||
Combine(Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
testing::Bool(),
|
||||
Values(cv::compile_args(CORE_FLUID))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(Cart2PolarFluid, Cart2PolarTest,
|
||||
Combine(Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
testing::Bool(),
|
||||
Values(cv::compile_args(CORE_FLUID))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(ThresholdTestFluid, ThresholdTest,
|
||||
Combine(Values(CV_8UC3, CV_8UC1, CV_16UC1, CV_16SC1),
|
||||
Values(cv::Size(1920, 1080),
|
||||
cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
Values(cv::THRESH_BINARY, cv::THRESH_BINARY_INV,
|
||||
cv::THRESH_TRUNC,
|
||||
cv::THRESH_TOZERO, cv::THRESH_TOZERO_INV),
|
||||
testing::Bool(),
|
||||
Values(cv::compile_args(CORE_FLUID))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(InRangeTestFluid, InRangeTest,
|
||||
Combine(Values(CV_8UC3, CV_8UC1, CV_16UC1, CV_16SC1),
|
||||
Values(cv::Size(1920, 1080),
|
||||
cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
testing::Bool(),
|
||||
Values(cv::compile_args(CORE_FLUID))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(ResizeTestFluid, ResizeTest,
|
||||
Combine(Values(CV_8UC3/*CV_8UC1, CV_16UC1, CV_16SC1*/),
|
||||
Values(/*cv::INTER_NEAREST,*/ cv::INTER_LINEAR/*, cv::INTER_AREA*/),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128),
|
||||
cv::Size(64, 64),
|
||||
cv::Size(30, 30)),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128),
|
||||
cv::Size(64, 64),
|
||||
cv::Size(30, 30)),
|
||||
Values(0.0),
|
||||
Values(cv::compile_args(CORE_FLUID))));
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// FIXME: Clean-up test configurations which are enabled already
|
||||
#if 0
|
||||
INSTANTIATE_TEST_CASE_P(MathOpTestCPU, MathOpTest,
|
||||
Combine(Values(ADD, DIV, MUL),
|
||||
testing::Bool(),
|
||||
Values(CV_8UC1, CV_16SC1, CV_32FC1),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
Values(-1, CV_8U, CV_32F),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(false)),
|
||||
opencv_test::PrintMathOpCoreParams());
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(SubTestCPU, MathOpTest,
|
||||
Combine(Values(SUB),
|
||||
testing::Bool(),
|
||||
Values(CV_8UC1, CV_16SC1 , CV_32FC1),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
Values(-1, CV_8U, CV_32F),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
testing::Bool()),
|
||||
opencv_test::PrintMathOpCoreParams());
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(MulSTestCPU, MulSTest,
|
||||
Combine(Values(CV_8UC1, CV_16SC1, CV_32FC1),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
/*init output matrices or not*/ testing::Bool()));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(DivCTestCPU, DivCTest,
|
||||
Combine(Values(CV_8UC1, CV_16SC1, CV_32FC1),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
Values(CV_8U, CV_32F),
|
||||
/*init output matrices or not*/ testing::Bool()));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(MeanTestCPU, MeanTest,
|
||||
Combine(Values(CV_8UC1, CV_16UC1, CV_16SC1),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
/*init output matrices or not*/ testing::Bool()));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(SelectTestCPU, SelectTest,
|
||||
Combine(Values(CV_8UC1, CV_16UC1, CV_16SC1),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
/*init output matrices or not*/ testing::Bool()));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(Polar2CartCPU, Polar2CartTest,
|
||||
Combine(Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
/*init output matrices or not*/ testing::Bool()));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(Cart2PolarCPU, Cart2PolarTest,
|
||||
Combine(Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
/*init output matrices or not*/ testing::Bool()));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(CompareTestCPU, CmpTest,
|
||||
Combine(Values(CMP_EQ, CMP_GE, CMP_NE, CMP_GT, CMP_LT, CMP_LE),
|
||||
testing::Bool(),
|
||||
Values(CV_8UC1, CV_16SC1, CV_32FC1),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
/*init output matrices or not*/ testing::Bool()),
|
||||
opencv_test::PrintCmpCoreParams());
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(BitwiseTestCPU, BitwiseTest,
|
||||
Combine(Values(AND, OR, XOR),
|
||||
Values(CV_8UC1, CV_16UC1, CV_16SC1),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
/*init output matrices or not*/ testing::Bool()),
|
||||
opencv_test::PrintBWCoreParams());
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(BitwiseNotTestCPU, NotTest,
|
||||
Combine(Values(CV_8UC1, CV_16UC1, CV_16SC1),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
/*init output matrices or not*/ testing::Bool()));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(MinTestCPU, MinTest,
|
||||
Combine(Values(CV_8UC1, CV_16UC1, CV_16SC1),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
/*init output matrices or not*/ testing::Bool()));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(MaxTestCPU, MaxTest,
|
||||
Combine(Values(CV_8UC1, CV_16UC1, CV_16SC1),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
/*init output matrices or not*/ testing::Bool()));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(SumTestCPU, SumTest,
|
||||
Combine(Values(CV_8UC1, CV_16UC1, CV_16SC1),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
/*init output matrices or not*/ testing::Bool()));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(AbsDiffTestCPU, AbsDiffTest,
|
||||
Combine(Values(CV_8UC1, CV_16UC1, CV_16SC1),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
/*init output matrices or not*/ testing::Bool()));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(AbsDiffCTestCPU, AbsDiffCTest,
|
||||
Combine(Values(CV_8UC1, CV_16UC1, CV_16SC1),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
/*init output matrices or not*/ testing::Bool()));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(AddWeightedTestCPU, AddWeightedTest,
|
||||
Combine(Values(CV_8UC1, CV_16UC1, CV_16SC1),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
Values(-1, CV_8U, CV_32F),
|
||||
/*init output matrices or not*/ testing::Bool()));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(NormTestCPU, NormTest,
|
||||
Combine(Values(NORM_INF, NORM_L1, NORM_L2),
|
||||
Values(CV_8UC1, CV_16UC1, CV_16SC1),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128))),
|
||||
opencv_test::PrintNormCoreParams());
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(IntegralTestCPU, IntegralTest,
|
||||
Combine(Values(CV_8UC1, CV_16UC1, CV_16SC1),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(ThresholdTestCPU, ThresholdTest,
|
||||
Combine(Values(CV_8UC1, CV_16UC1, CV_16SC1),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
Values(cv::THRESH_BINARY, cv::THRESH_BINARY_INV, cv::THRESH_TRUNC, cv::THRESH_TOZERO, cv::THRESH_TOZERO_INV),
|
||||
/*init output matrices or not*/ testing::Bool()));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(ThresholdTestCPU, ThresholdOTTest,
|
||||
Combine(Values(CV_8UC1),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
Values(cv::THRESH_OTSU, cv::THRESH_TRIANGLE),
|
||||
/*init output matrices or not*/ testing::Bool()));
|
||||
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(InRangeTestCPU, InRangeTest,
|
||||
Combine(Values(CV_8UC1, CV_16UC1, CV_16SC1),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
/*init output matrices or not*/ testing::Bool()));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(Split3TestCPU, Split3Test,
|
||||
(Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(Split4TestCPU, Split4Test,
|
||||
(Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(Merge3TestCPU, Merge3Test,
|
||||
(Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(Merge4TestCPU, Merge4Test,
|
||||
(Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(RemapTestCPU, RemapTest,
|
||||
Combine(Values(CV_8UC1, CV_16UC1, CV_16SC1),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
/*init output matrices or not*/ testing::Bool()));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(FlipTestCPU, FlipTest,
|
||||
Combine(Values(CV_8UC1, CV_16UC1, CV_16SC1),
|
||||
Values(0,1,-1),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
/*init output matrices or not*/ testing::Bool()));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(CropTestCPU, CropTest,
|
||||
Combine(Values(CV_8UC1, CV_16UC1, CV_16SC1),
|
||||
Values(cv::Rect(10, 8, 20, 35), cv::Rect(4, 10, 37, 50)),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
/*init output matrices or not*/ testing::Bool()));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(LUTTestCPU, LUTTest,
|
||||
Combine(Values(CV_8UC1, CV_8UC3),
|
||||
Values(CV_8UC1),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
/*init output matrices or not*/ testing::Bool()));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(LUTTestCustomCPU, LUTTest,
|
||||
Combine(Values(CV_8UC3),
|
||||
Values(CV_8UC3),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
/*init output matrices or not*/ testing::Bool()));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(ConvertToCPU, ConvertToTest,
|
||||
Combine(Values(CV_8UC3, CV_8UC1, CV_16UC1, CV_32FC1),
|
||||
Values(CV_8U, CV_16U, CV_32F),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(ConcatHorTestCPU, ConcatHorTest,
|
||||
Combine(Values(CV_8UC1, CV_16UC1, CV_16SC1),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128))));
|
||||
INSTANTIATE_TEST_CASE_P(ConcatVertTestCPU, ConcatVertTest,
|
||||
Combine(Values(CV_8UC1, CV_16UC1, CV_16SC1),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128))));
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
#endif // 0
|
||||
|
||||
}
|
||||
@@ -0,0 +1,204 @@
|
||||
// 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 "../common/gapi_imgproc_tests.hpp"
|
||||
#include "opencv2/gapi/cpu/imgproc.hpp"
|
||||
|
||||
#define IMGPROC_CPU cv::gapi::imgproc::cpu::kernels()
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(Filter2DTestCPU, Filter2DTest,
|
||||
Combine(Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1),
|
||||
Values(3, 4, 5, 7),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
Values(cv::BORDER_DEFAULT),
|
||||
Values(-1, CV_32F),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(IMGPROC_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(BoxFilterTestCPU, BoxFilterTest,
|
||||
Combine(Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1),
|
||||
Values(3,5),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480)),
|
||||
Values(cv::BORDER_DEFAULT),
|
||||
Values(-1, CV_32F),
|
||||
Values(0.0),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(IMGPROC_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(SepFilterTestCPU_8U, SepFilterTest,
|
||||
Combine(Values(CV_8UC1, CV_8UC3),
|
||||
Values(3),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480)),
|
||||
Values(-1, CV_16S, CV_32F),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(IMGPROC_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(SepFilterTestCPU_other, SepFilterTest,
|
||||
Combine(Values(CV_16UC1, CV_16SC1, CV_32FC1),
|
||||
Values(3),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480)),
|
||||
Values(-1, CV_32F),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(IMGPROC_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(BlurTestCPU, BlurTest,
|
||||
Combine(Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1),
|
||||
Values(3,5),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480)),
|
||||
Values(cv::BORDER_DEFAULT),
|
||||
Values(0.0),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(IMGPROC_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(gaussBlurTestCPU, GaussianBlurTest,
|
||||
Combine(Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1),
|
||||
Values(3, 5),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480)),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(IMGPROC_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(MedianBlurTestCPU, MedianBlurTest,
|
||||
Combine(Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1),
|
||||
Values(3, 5),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480)),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(IMGPROC_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(ErodeTestCPU, ErodeTest,
|
||||
Combine(Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1),
|
||||
Values(3, 5),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480)),
|
||||
Values(cv::MorphShapes::MORPH_RECT,
|
||||
cv::MorphShapes::MORPH_CROSS,
|
||||
cv::MorphShapes::MORPH_ELLIPSE),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(IMGPROC_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(Erode3x3TestCPU, Erode3x3Test,
|
||||
Combine(Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480)),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(1,2,4),
|
||||
Values(cv::compile_args(IMGPROC_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(DilateTestCPU, DilateTest,
|
||||
Combine(Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1),
|
||||
Values(3, 5),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480)),
|
||||
Values(cv::MorphShapes::MORPH_RECT,
|
||||
cv::MorphShapes::MORPH_CROSS,
|
||||
cv::MorphShapes::MORPH_ELLIPSE),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(IMGPROC_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(Dilate3x3TestCPU, Dilate3x3Test,
|
||||
Combine(Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480)),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(1,2,4),
|
||||
Values(cv::compile_args(IMGPROC_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(SobelTestCPU, SobelTest,
|
||||
Combine(Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1),
|
||||
Values(3, 5),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480)),
|
||||
Values(-1, CV_32F),
|
||||
Values(0, 1),
|
||||
Values(1, 2),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(IMGPROC_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(EqHistTestCPU, EqHistTest,
|
||||
Combine(Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480)),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(IMGPROC_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(CannyTestCPU, CannyTest,
|
||||
Combine(Values(CV_8UC1, CV_8UC3),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480)),
|
||||
Values(3.0, 120.0),
|
||||
Values(125.0, 240.0),
|
||||
Values(3, 5),
|
||||
testing::Bool(),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(IMGPROC_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(RGB2GrayTestCPU, RGB2GrayTest,
|
||||
Combine(Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480)),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(IMGPROC_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(BGR2GrayTestCPU, BGR2GrayTest,
|
||||
Combine(Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480)),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(IMGPROC_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(RGB2YUVTestCPU, RGB2YUVTest,
|
||||
Combine(Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480)),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(IMGPROC_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(YUV2RGBTestCPU, YUV2RGBTest,
|
||||
Combine(Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480)),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(IMGPROC_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(RGB2LabTestCPU, RGB2LabTest,
|
||||
Combine(Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480)),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(IMGPROC_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(BGR2LUVTestCPU, BGR2LUVTest,
|
||||
Combine(Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480)),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(IMGPROC_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(LUV2BGRTestCPU, LUV2BGRTest,
|
||||
Combine(Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480)),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(IMGPROC_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(BGR2YUVTestCPU, BGR2YUVTest,
|
||||
Combine(Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480)),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(IMGPROC_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(YUV2BGRTestCPU, YUV2BGRTest,
|
||||
Combine(Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480)),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(IMGPROC_CPU))));
|
||||
|
||||
} // 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
|
||||
|
||||
|
||||
#include "../test_precomp.hpp"
|
||||
#include "../common/gapi_imgproc_tests.hpp"
|
||||
#include "backends/fluid/gfluidimgproc.hpp"
|
||||
|
||||
#define IMGPROC_FLUID cv::gapi::imgproc::fluid::kernels()
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(RGB2GrayTestFluid, RGB2GrayTest,
|
||||
Combine(Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480)),
|
||||
Values(true, false),
|
||||
Values(cv::compile_args(IMGPROC_FLUID))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(BGR2GrayTestFluid, BGR2GrayTest,
|
||||
Combine(Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480)),
|
||||
Values(true, false),
|
||||
Values(cv::compile_args(IMGPROC_FLUID))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(RGB2YUVTestFluid, RGB2YUVTest,
|
||||
Combine(Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480)),
|
||||
Values(true, false),
|
||||
Values(cv::compile_args(IMGPROC_FLUID))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(YUV2RGBTestFluid, YUV2RGBTest,
|
||||
Combine(Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480)),
|
||||
Values(true, false),
|
||||
Values(cv::compile_args(IMGPROC_FLUID))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(RGB2LabTestFluid, RGB2LabTest,
|
||||
Combine(Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480)),
|
||||
Values(true, false),
|
||||
Values(cv::compile_args(IMGPROC_FLUID))));
|
||||
|
||||
// FIXME: Not supported by Fluid yet (no kernel implemented)
|
||||
INSTANTIATE_TEST_CASE_P(BGR2LUVTestFluid, BGR2LUVTest,
|
||||
Combine(Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480)),
|
||||
Values(true, false),
|
||||
Values(cv::compile_args(IMGPROC_FLUID))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(blurTestFluid, BlurTest,
|
||||
Combine(Values(CV_8UC1, CV_16UC1, CV_16SC1),
|
||||
Values(3), // add kernel size=5 when implementation is ready
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480)),
|
||||
Values(cv::BORDER_DEFAULT),
|
||||
Values(0.0),
|
||||
Values(true, false),
|
||||
Values(cv::compile_args(IMGPROC_FLUID))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(gaussBlurTestFluid, GaussianBlurTest,
|
||||
Combine(Values(CV_8UC1, CV_16UC1, CV_16SC1),
|
||||
Values(3), // add kernel size=5 when implementation is ready
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480)),
|
||||
Values(true, false),
|
||||
Values(cv::compile_args(IMGPROC_FLUID))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(medianBlurTestFluid, MedianBlurTest,
|
||||
Combine(Values(CV_8UC1, CV_16UC1, CV_16SC1),
|
||||
Values(3), // add kernel size=5 when implementation is ready
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480)),
|
||||
Values(true, false),
|
||||
Values(cv::compile_args(IMGPROC_FLUID))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(erodeTestFluid, ErodeTest,
|
||||
Combine(Values(CV_8UC1, CV_16UC1, CV_16SC1),
|
||||
Values(3), // add kernel size=5 when implementation is ready
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480)),
|
||||
Values(cv::MorphShapes::MORPH_RECT,
|
||||
cv::MorphShapes::MORPH_CROSS,
|
||||
cv::MorphShapes::MORPH_ELLIPSE),
|
||||
Values(true, false),
|
||||
Values(cv::compile_args(IMGPROC_FLUID))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(dilateTestFluid, DilateTest,
|
||||
Combine(Values(CV_8UC1, CV_16UC1, CV_16SC1),
|
||||
Values(3), // add kernel size=5 when implementation is ready
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480)),
|
||||
Values(cv::MorphShapes::MORPH_RECT,
|
||||
cv::MorphShapes::MORPH_CROSS,
|
||||
cv::MorphShapes::MORPH_ELLIPSE),
|
||||
Values(true, false),
|
||||
Values(cv::compile_args(IMGPROC_FLUID))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(SobelTestFluid, SobelTest,
|
||||
Combine(Values(CV_8UC1, CV_16UC1, CV_16SC1),
|
||||
Values(3), // add kernel size=5 when implementation is ready
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480)),
|
||||
Values(-1, CV_32F),
|
||||
Values(0, 1),
|
||||
Values(1, 2),
|
||||
Values(true, false),
|
||||
Values(cv::compile_args(IMGPROC_FLUID))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(boxFilterTestFluid, BoxFilterTest,
|
||||
Combine(Values(CV_8UC1, CV_16UC1, CV_16SC1),
|
||||
Values(3), // add kernel size=5 when implementation is ready
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480)),
|
||||
Values(cv::BORDER_DEFAULT),
|
||||
Values(-1, CV_32F),
|
||||
Values(0.0),
|
||||
Values(true, false),
|
||||
Values(cv::compile_args(IMGPROC_FLUID))));
|
||||
|
||||
// FIXME: Tests are failing on Fluid backend (accuracy issue?)
|
||||
INSTANTIATE_TEST_CASE_P(sepFilterTestFluid, SepFilterTest,
|
||||
Combine(Values(CV_32FC1),
|
||||
Values(3), // add kernel size=5 when implementation is ready
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480)),
|
||||
Values(-1, CV_32F),
|
||||
Values(true, false),
|
||||
Values(cv::compile_args(IMGPROC_FLUID))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(filter2DTestFluid, Filter2DTest,
|
||||
Combine(Values(CV_8UC1, CV_16UC1, CV_16SC1),
|
||||
Values(3), // add kernel size=4,5,7 when implementation ready
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
Values(cv::BORDER_DEFAULT),
|
||||
Values(-1, CV_32F),
|
||||
Values(true, false),
|
||||
Values(cv::compile_args(IMGPROC_FLUID))));
|
||||
|
||||
} // opencv_test
|
||||
@@ -0,0 +1,67 @@
|
||||
// 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 "../common/gapi_operators_tests.hpp"
|
||||
#include "opencv2/gapi/cpu/core.hpp"
|
||||
|
||||
#define CORE_CPU cv::gapi::core::cpu::kernels()
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
// FIXME: CPU test runs are disabled since Fluid is an exclusive plugin now!
|
||||
INSTANTIATE_TEST_CASE_P(MathOperatorTestCPU, MathOperatorMatMatTest,
|
||||
Combine(Values( opPlusM, opMinusM, opDivM,
|
||||
opGreater, opLess, opGreaterEq, opLessEq, opEq, opNotEq),
|
||||
Values(CV_8UC1, CV_16SC1, CV_32FC1),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
Values(-1, CV_8U, CV_32F),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(CORE_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(MathOperatorTestCPU, MathOperatorMatScalarTest,
|
||||
Combine(Values( opPlus, opPlusR, opMinus, opMinusR, opMul, opMulR, opDiv, opDivR,
|
||||
opGT, opLT, opGE, opLE, opEQ, opNE,
|
||||
opGTR, opLTR, opGER, opLER, opEQR, opNER),
|
||||
Values(CV_8UC1, CV_16SC1, CV_32FC1),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
Values(-1, CV_8U, CV_32F),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(CORE_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(BitwiseOperatorTestCPU, MathOperatorMatMatTest,
|
||||
Combine(Values( opAnd, opOr, opXor ),
|
||||
Values(CV_8UC1, CV_16UC1, CV_16SC1),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
Values(-1),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(CORE_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(BitwiseOperatorTestCPU, MathOperatorMatScalarTest,
|
||||
Combine(Values( opAND, opOR, opXOR, opANDR, opORR, opXORR ),
|
||||
Values(CV_8UC1, CV_16UC1, CV_16SC1),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
Values(-1),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(CORE_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(BitwiseNotOperatorTestCPU, NotOperatorTest,
|
||||
Combine(Values(CV_8UC1, CV_16UC1, CV_16SC1),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(CORE_CPU))));
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
// 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 "../common/gapi_operators_tests.hpp"
|
||||
#include "opencv2/gapi/cpu/core.hpp"
|
||||
|
||||
#define CORE_FLUID cv::gapi::core::cpu::kernels()
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
INSTANTIATE_TEST_CASE_P(MathOperatorTestFluid, MathOperatorMatMatTest,
|
||||
Combine(Values( opPlusM, opMinusM, opDivM,
|
||||
opGreater, opLess, opGreaterEq, opLessEq, opEq, opNotEq),
|
||||
Values(CV_8UC1, CV_16SC1, CV_32FC1),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
Values(-1, CV_8U, CV_32F),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(CORE_FLUID))));
|
||||
|
||||
//FIXME: Some Mat/Scalar Fluid kernels are not there yet!
|
||||
INSTANTIATE_TEST_CASE_P(DISABLED_MathOperatorTestFluid, MathOperatorMatScalarTest,
|
||||
Combine(Values( opPlus, opPlusR, opMinus, opMinusR, opMul, opMulR, opDiv, opDivR,
|
||||
opGT, opLT, opGE, opLE, opEQ, opNE,
|
||||
opGTR, opLTR, opGER, opLER, opEQR, opNER),
|
||||
Values(CV_8UC1, CV_16SC1, CV_32FC1),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
Values(-1, CV_8U, CV_32F),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(CORE_FLUID))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(BitwiseOperatorTestFluid, MathOperatorMatMatTest,
|
||||
Combine(Values( opAnd, opOr, opXor ),
|
||||
Values(CV_8UC1, CV_16UC1, CV_16SC1),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
Values(-1),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(CORE_FLUID))));
|
||||
|
||||
//FIXME: Some Mat/Scalar Fluid kernels are not there yet!
|
||||
INSTANTIATE_TEST_CASE_P(DISABLED_BitwiseOperatorTestFluid, MathOperatorMatScalarTest,
|
||||
Combine(Values( opAND, opOR, opXOR, opANDR, opORR, opXORR ),
|
||||
Values(CV_8UC1, CV_16UC1, CV_16SC1),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
Values(-1),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(CORE_FLUID))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(BitwiseNotOperatorTestFluid, NotOperatorTest,
|
||||
Combine(Values(CV_8UC1, CV_16UC1, CV_16SC1),
|
||||
Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
/*init output matrices or not*/ testing::Bool(),
|
||||
Values(cv::compile_args(CORE_FLUID))));
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
// 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 <vector>
|
||||
#include <ade/util/algorithm.hpp>
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
|
||||
namespace ThisTest
|
||||
{
|
||||
using GPointArray = cv::GArray<cv::Point>;
|
||||
G_TYPED_KERNEL(GeneratePoints, <GPointArray(GMat)>, "test.array.out_const")
|
||||
{
|
||||
static GArrayDesc outMeta(const GMatDesc&) { return empty_array_desc(); }
|
||||
};
|
||||
G_TYPED_KERNEL(FindCorners, <GPointArray(GMat)>, "test.array.out")
|
||||
{
|
||||
static GArrayDesc outMeta(const GMatDesc&) { return empty_array_desc(); }
|
||||
};
|
||||
G_TYPED_KERNEL(CountCorners, <GScalar(GPointArray)>, "test.array.in")
|
||||
{
|
||||
static GScalarDesc outMeta(const GArrayDesc &) { return empty_scalar_desc(); }
|
||||
};
|
||||
} // namespace ThisTest
|
||||
|
||||
namespace
|
||||
{
|
||||
GAPI_OCV_KERNEL(OCVGeneratePoints, ThisTest::GeneratePoints)
|
||||
{
|
||||
static void run(cv::Mat, std::vector<cv::Point> &out)
|
||||
{
|
||||
for (int i = 0; i < 10; i++)
|
||||
out.emplace_back(i, i);
|
||||
}
|
||||
};
|
||||
|
||||
GAPI_OCV_KERNEL(OCVFindCorners, ThisTest::FindCorners)
|
||||
{
|
||||
static void run(cv::Mat in, std::vector<cv::Point> &out)
|
||||
{
|
||||
cv::goodFeaturesToTrack(in, out, 1024, 0.01, 3);
|
||||
}
|
||||
};
|
||||
|
||||
GAPI_OCV_KERNEL(OCVCountCorners, ThisTest::CountCorners)
|
||||
{
|
||||
static void run(const std::vector<cv::Point> &in, cv::Scalar &out)
|
||||
{
|
||||
out[0] = static_cast<double>(in.size());
|
||||
}
|
||||
};
|
||||
|
||||
cv::Mat cross(int w, int h)
|
||||
{
|
||||
cv::Mat mat = cv::Mat::eye(h, w, CV_8UC1)*255;
|
||||
cv::Mat yee;
|
||||
cv::flip(mat, yee, 0); // X-axis
|
||||
mat |= yee; // make an "X" matrix;
|
||||
return mat;
|
||||
}
|
||||
} // (anonymous namespace)
|
||||
|
||||
TEST(GArray, TestReturnValue)
|
||||
{
|
||||
// FIXME: Make .apply() able to take compile arguments
|
||||
cv::GComputationT<ThisTest::GPointArray(cv::GMat)> c(ThisTest::FindCorners::on);
|
||||
auto cc = c.compile(cv::GMatDesc{CV_8U,1,{32,32}},
|
||||
cv::compile_args(cv::gapi::kernels<OCVFindCorners>()));
|
||||
|
||||
// Prepare input matrix
|
||||
cv::Mat input = cross(32, 32);
|
||||
|
||||
std::vector<cv::Point> points;
|
||||
cc(input, points);
|
||||
|
||||
// OCV goodFeaturesToTrack should find 5 points here (with these settings)
|
||||
EXPECT_EQ(5u, points.size());
|
||||
EXPECT_TRUE(ade::util::find(points, cv::Point(16,16)) != points.end());
|
||||
EXPECT_TRUE(ade::util::find(points, cv::Point(30,30)) != points.end());
|
||||
EXPECT_TRUE(ade::util::find(points, cv::Point( 1,30)) != points.end());
|
||||
EXPECT_TRUE(ade::util::find(points, cv::Point(30, 1)) != points.end());
|
||||
EXPECT_TRUE(ade::util::find(points, cv::Point( 1, 1)) != points.end());
|
||||
}
|
||||
|
||||
TEST(GArray, TestInputArg)
|
||||
{
|
||||
cv::GComputationT<cv::GScalar(ThisTest::GPointArray)> c(ThisTest::CountCorners::on);
|
||||
auto cc = c.compile(cv::empty_array_desc(),
|
||||
cv::compile_args(cv::gapi::kernels<OCVCountCorners>()));
|
||||
|
||||
const std::vector<cv::Point> arr = {cv::Point(1,1), cv::Point(2,2)};
|
||||
cv::Scalar out;
|
||||
cc(arr, out);
|
||||
EXPECT_EQ(2, out[0]);
|
||||
}
|
||||
|
||||
TEST(GArray, TestPipeline)
|
||||
{
|
||||
cv::GComputationT<cv::GScalar(cv::GMat)> c([](cv::GMat in)
|
||||
{
|
||||
return ThisTest::CountCorners::on(ThisTest::FindCorners::on(in));
|
||||
});
|
||||
auto cc = c.compile(cv::GMatDesc{CV_8U,1,{32,32}},
|
||||
cv::compile_args(cv::gapi::kernels<OCVFindCorners, OCVCountCorners>()));
|
||||
|
||||
cv::Mat input = cross(32, 32);
|
||||
cv::Scalar out;
|
||||
cc(input, out);
|
||||
EXPECT_EQ(5, out[0]);
|
||||
}
|
||||
|
||||
TEST(GArray, NoAggregationBetweenRuns)
|
||||
{
|
||||
cv::GComputationT<cv::GScalar(cv::GMat)> c([](cv::GMat in)
|
||||
{
|
||||
return ThisTest::CountCorners::on(ThisTest::GeneratePoints::on(in));
|
||||
});
|
||||
auto cc = c.compile(cv::GMatDesc{CV_8U,1,{32,32}},
|
||||
cv::compile_args(cv::gapi::kernels<OCVGeneratePoints, OCVCountCorners>()));
|
||||
|
||||
cv::Mat input = cv::Mat::eye(32, 32, CV_8UC1);
|
||||
cv::Scalar out;
|
||||
|
||||
cc(input, out);
|
||||
EXPECT_EQ(10, out[0]);
|
||||
|
||||
// Last kernel in the graph counts number of elements in array, returned by the previous kernel
|
||||
// (in this test, this variable is constant).
|
||||
// After 10 executions, this number MUST remain the same - 1st kernel is adding new values on every
|
||||
// run, but it is graph's responsibility to reset internal object state.
|
||||
cv::Scalar out2;
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
cc(input, out2);
|
||||
}
|
||||
EXPECT_EQ(10, out2[0]);
|
||||
}
|
||||
|
||||
TEST(GArray, TestIntermediateOutput)
|
||||
{
|
||||
using Result = std::tuple<ThisTest::GPointArray, cv::GScalar>;
|
||||
cv::GComputationT<Result(cv::GMat)> c([](cv::GMat in)
|
||||
{
|
||||
auto corners = ThisTest::GeneratePoints::on(in);
|
||||
return std::make_tuple(corners, ThisTest::CountCorners::on(corners));
|
||||
});
|
||||
|
||||
cv::Mat in_mat = cv::Mat::eye(32, 32, CV_8UC1);
|
||||
std::vector<cv::Point> out_points;
|
||||
cv::Scalar out_count;
|
||||
|
||||
auto cc = c.compile(cv::descr_of(in_mat),
|
||||
cv::compile_args(cv::gapi::kernels<OCVGeneratePoints, OCVCountCorners>()));
|
||||
cc(in_mat, out_points, out_count);
|
||||
|
||||
EXPECT_EQ(10u, out_points.size());
|
||||
EXPECT_EQ(10, out_count[0]);
|
||||
}
|
||||
} // namespace opencv_test
|
||||
@@ -0,0 +1,124 @@
|
||||
// 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_mock_kernels.hpp"
|
||||
|
||||
#include "opencv2/gapi/fluid/gfluidkernel.hpp"
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
GAPI_OCV_KERNEL(OCVFoo, I::Foo)
|
||||
{
|
||||
static void run(const cv::Mat &in, cv::Mat &out)
|
||||
{
|
||||
out = in + 2;
|
||||
}
|
||||
};
|
||||
|
||||
GAPI_OCV_KERNEL(OCVBar, I::Bar)
|
||||
{
|
||||
static void run(const cv::Mat &a, const cv::Mat &b, cv::Mat &out)
|
||||
{
|
||||
out = 4*(a + b);
|
||||
}
|
||||
};
|
||||
|
||||
GAPI_FLUID_KERNEL(FFoo, I::Foo, false)
|
||||
{
|
||||
static const int Window = 1;
|
||||
|
||||
static void run(const cv::gapi::fluid::View &in,
|
||||
cv::gapi::fluid::Buffer &out)
|
||||
{
|
||||
const uint8_t* in_ptr = in.InLine<uint8_t>(0);
|
||||
uint8_t *out_ptr = out.OutLine<uint8_t>();
|
||||
for (int i = 0; i < in.length(); i++)
|
||||
{
|
||||
out_ptr[i] = in_ptr[i] + 3;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
GAPI_FLUID_KERNEL(FBar, I::Bar, false)
|
||||
{
|
||||
static const int Window = 1;
|
||||
|
||||
static void run(const cv::gapi::fluid::View &in1,
|
||||
const cv::gapi::fluid::View &in2,
|
||||
cv::gapi::fluid::Buffer &out)
|
||||
{
|
||||
const uint8_t* in1_ptr = in1.InLine<uint8_t>(0);
|
||||
const uint8_t* in2_ptr = in2.InLine<uint8_t>(0);
|
||||
uint8_t *out_ptr = out.OutLine<uint8_t>();
|
||||
for (int i = 0; i < in1.length(); i++)
|
||||
{
|
||||
out_ptr[i] = 3*(in1_ptr[i] + in2_ptr[i]);
|
||||
}
|
||||
}
|
||||
};
|
||||
} // anonymous namespace
|
||||
|
||||
struct GAPIHeteroTest: public ::testing::Test
|
||||
{
|
||||
cv::GComputation m_comp;
|
||||
cv::gapi::GKernelPackage m_ocv_kernels;
|
||||
cv::gapi::GKernelPackage m_fluid_kernels;
|
||||
cv::gapi::GKernelPackage m_hetero_kernels;
|
||||
|
||||
cv::Mat m_in_mat;
|
||||
cv::Mat m_out_mat;
|
||||
|
||||
GAPIHeteroTest();
|
||||
};
|
||||
|
||||
GAPIHeteroTest::GAPIHeteroTest()
|
||||
: m_comp([](){
|
||||
cv::GMat in;
|
||||
cv::GMat out = I::Bar::on(I::Foo::on(in),
|
||||
I::Foo::on(in));
|
||||
return cv::GComputation(in, out);
|
||||
})
|
||||
, m_ocv_kernels(cv::gapi::kernels<OCVFoo, OCVBar>())
|
||||
, m_fluid_kernels(cv::gapi::kernels<FFoo, FBar>())
|
||||
, m_hetero_kernels(cv::gapi::kernels<OCVFoo, FBar>())
|
||||
, m_in_mat(cv::Mat::eye(cv::Size(64, 64), CV_8UC1))
|
||||
{
|
||||
}
|
||||
|
||||
TEST_F(GAPIHeteroTest, TestOCV)
|
||||
{
|
||||
EXPECT_TRUE(cv::gapi::cpu::backend() == m_ocv_kernels.lookup<I::Foo>());
|
||||
EXPECT_TRUE(cv::gapi::cpu::backend() == m_ocv_kernels.lookup<I::Bar>());
|
||||
|
||||
cv::Mat ref = 4*(m_in_mat+2 + m_in_mat+2);
|
||||
EXPECT_NO_THROW(m_comp.apply(m_in_mat, m_out_mat, cv::compile_args(m_ocv_kernels)));
|
||||
EXPECT_EQ(0, cv::countNonZero(ref != m_out_mat));
|
||||
}
|
||||
|
||||
TEST_F(GAPIHeteroTest, TestFluid)
|
||||
{
|
||||
EXPECT_TRUE(cv::gapi::fluid::backend() == m_fluid_kernels.lookup<I::Foo>());
|
||||
EXPECT_TRUE(cv::gapi::fluid::backend() == m_fluid_kernels.lookup<I::Bar>());
|
||||
|
||||
cv::Mat ref = 3*(m_in_mat+3 + m_in_mat+3);
|
||||
EXPECT_NO_THROW(m_comp.apply(m_in_mat, m_out_mat, cv::compile_args(m_fluid_kernels)));
|
||||
EXPECT_EQ(0, cv::countNonZero(ref != m_out_mat));
|
||||
}
|
||||
|
||||
TEST_F(GAPIHeteroTest, TestBoth_ExpectFailure)
|
||||
{
|
||||
EXPECT_TRUE(cv::gapi::cpu::backend() == m_hetero_kernels.lookup<I::Foo>());
|
||||
EXPECT_TRUE(cv::gapi::fluid::backend() == m_hetero_kernels.lookup<I::Bar>());
|
||||
EXPECT_ANY_THROW(m_comp.apply(m_in_mat, m_out_mat, cv::compile_args(m_hetero_kernels)));
|
||||
}
|
||||
|
||||
|
||||
} // namespace opencv_test
|
||||
@@ -0,0 +1,202 @@
|
||||
// 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 "opencv2/gapi/cpu/gcpukernel.hpp"
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
G_TYPED_KERNEL(KTest, <cv::GScalar(cv::GScalar)>, "org.opencv.test.scalar_kernel") {
|
||||
static cv::GScalarDesc outMeta(cv::GScalarDesc in) { return in; }
|
||||
};
|
||||
GAPI_OCV_KERNEL(GOCVScalarTest, KTest)
|
||||
{
|
||||
static void run(const cv::Scalar &in, cv::Scalar &out) { out = in+cv::Scalar(1); }
|
||||
};
|
||||
}
|
||||
|
||||
TEST(GAPI_MetaDesc, MatDesc)
|
||||
{
|
||||
cv::Mat m1(240, 320, CV_8U);
|
||||
const auto desc1 = cv::descr_of(m1);
|
||||
EXPECT_EQ(CV_8U, desc1.depth);
|
||||
EXPECT_EQ(1, desc1.chan);
|
||||
EXPECT_EQ(320, desc1.size.width);
|
||||
EXPECT_EQ(240, desc1.size.height);
|
||||
|
||||
cv::Mat m2(480, 640, CV_8UC3);
|
||||
const auto desc2 = cv::descr_of(m2);
|
||||
EXPECT_EQ(CV_8U, desc2.depth);
|
||||
EXPECT_EQ(3, desc2.chan);
|
||||
EXPECT_EQ(640, desc2.size.width);
|
||||
EXPECT_EQ(480, desc2.size.height);
|
||||
}
|
||||
|
||||
TEST(GAPI_MetaDesc, Compare_Equal_MatDesc)
|
||||
{
|
||||
const auto desc1 = cv::GMatDesc{CV_8U, 1, {64, 64}};
|
||||
const auto desc2 = cv::GMatDesc{CV_8U, 1, {64, 64}};
|
||||
|
||||
EXPECT_TRUE(desc1 == desc2);
|
||||
}
|
||||
|
||||
TEST(GAPI_MetaDesc, Compare_Not_Equal_MatDesc)
|
||||
{
|
||||
const auto desc1 = cv::GMatDesc{CV_8U, 1, {64, 64}};
|
||||
const auto desc2 = cv::GMatDesc{CV_32F, 1, {64, 64}};
|
||||
|
||||
EXPECT_TRUE(desc1 != desc2);
|
||||
}
|
||||
|
||||
TEST(GAPI_MetaDesc, Compile_MatchMetaNumber_1)
|
||||
{
|
||||
cv::GMat in;
|
||||
cv::GComputation cc(in, in+in);
|
||||
|
||||
const auto desc1 = cv::GMatDesc{CV_8U,1,{64,64}};
|
||||
const auto desc2 = cv::GMatDesc{CV_32F,1,{128,128}};
|
||||
|
||||
EXPECT_NO_THROW(cc.compile(desc1));
|
||||
EXPECT_NO_THROW(cc.compile(desc2));
|
||||
|
||||
// FIXME: custom exception type?
|
||||
// It is worth checking if compilation fails with different number
|
||||
// of meta parameters
|
||||
EXPECT_THROW(cc.compile(desc1, desc1), std::logic_error);
|
||||
EXPECT_THROW(cc.compile(desc1, desc2, desc2), std::logic_error);
|
||||
}
|
||||
|
||||
TEST(GAPI_MetaDesc, Compile_MatchMetaNumber_2)
|
||||
{
|
||||
cv::GMat a, b;
|
||||
cv::GComputation cc(cv::GIn(a, b), cv::GOut(a+b));
|
||||
|
||||
const auto desc1 = cv::GMatDesc{CV_8U,1,{64,64}};
|
||||
EXPECT_NO_THROW(cc.compile(desc1, desc1));
|
||||
|
||||
const auto desc2 = cv::GMatDesc{CV_32F,1,{128,128}};
|
||||
EXPECT_NO_THROW(cc.compile(desc2, desc2));
|
||||
|
||||
// FIXME: custom exception type?
|
||||
EXPECT_THROW(cc.compile(desc1), std::logic_error);
|
||||
EXPECT_THROW(cc.compile(desc2), std::logic_error);
|
||||
EXPECT_THROW(cc.compile(desc2, desc2, desc2), std::logic_error);
|
||||
}
|
||||
|
||||
TEST(GAPI_MetaDesc, Compile_MatchMetaType_Mat)
|
||||
{
|
||||
cv::GMat in;
|
||||
cv::GComputation cc(in, in+in);
|
||||
|
||||
EXPECT_NO_THROW(cc.compile(cv::GMatDesc{CV_8U,1,{64,64}}));
|
||||
|
||||
// FIXME: custom exception type?
|
||||
EXPECT_THROW(cc.compile(cv::empty_scalar_desc()), std::logic_error);
|
||||
}
|
||||
|
||||
TEST(GAPI_MetaDesc, Compile_MatchMetaType_Scalar)
|
||||
{
|
||||
cv::GScalar in;
|
||||
cv::GComputation cc(cv::GIn(in), cv::GOut(KTest::on(in)));
|
||||
|
||||
const auto desc1 = cv::descr_of(cv::Scalar(128));
|
||||
const auto desc2 = cv::GMatDesc{CV_8U,1,{64,64}};
|
||||
const auto pkg = cv::gapi::kernels<GOCVScalarTest>();
|
||||
EXPECT_NO_THROW(cc.compile(desc1, cv::compile_args(pkg)));
|
||||
|
||||
// FIXME: custom exception type?
|
||||
EXPECT_THROW(cc.compile(desc2, cv::compile_args(pkg)), std::logic_error);
|
||||
}
|
||||
|
||||
TEST(GAPI_MetaDesc, Compile_MatchMetaType_Mixed)
|
||||
{
|
||||
cv::GMat a;
|
||||
cv::GScalar v;
|
||||
cv::GComputation cc(cv::GIn(a, v), cv::GOut(cv::gapi::addC(a, v)));
|
||||
|
||||
const auto desc1 = cv::GMatDesc{CV_8U,1,{64,64}};
|
||||
const auto desc2 = cv::descr_of(cv::Scalar(4));
|
||||
|
||||
EXPECT_NO_THROW(cc.compile(desc1, desc2));
|
||||
|
||||
// FIXME: custom exception type(s)?
|
||||
EXPECT_THROW(cc.compile(desc1), std::logic_error);
|
||||
EXPECT_THROW(cc.compile(desc2), std::logic_error);
|
||||
EXPECT_THROW(cc.compile(desc2, desc1), std::logic_error);
|
||||
EXPECT_THROW(cc.compile(desc1, desc1, desc1), std::logic_error);
|
||||
EXPECT_THROW(cc.compile(desc1, desc2, desc1), std::logic_error);
|
||||
}
|
||||
|
||||
TEST(GAPI_MetaDesc, Typed_Compile_MatchMetaNumber_1)
|
||||
{
|
||||
cv::GComputationT<cv::GMat(cv::GMat)> cc([](cv::GMat in)
|
||||
{
|
||||
return in+in;
|
||||
});
|
||||
|
||||
const auto desc1 = cv::GMatDesc{CV_8U,1,{64,64}};
|
||||
const auto desc2 = cv::GMatDesc{CV_32F,1,{128,128}};
|
||||
|
||||
EXPECT_NO_THROW(cc.compile(desc1));
|
||||
EXPECT_NO_THROW(cc.compile(desc2));
|
||||
}
|
||||
|
||||
TEST(GAPI_MetaDesc, Typed_Compile_MatchMetaNumber_2)
|
||||
{
|
||||
cv::GComputationT<cv::GMat(cv::GMat,cv::GMat)> cc([](cv::GMat a, cv::GMat b)
|
||||
{
|
||||
return a + b;
|
||||
});
|
||||
|
||||
const auto desc1 = cv::GMatDesc{CV_8U,1,{64,64}};
|
||||
EXPECT_NO_THROW(cc.compile(desc1, desc1));
|
||||
|
||||
const auto desc2 = cv::GMatDesc{CV_32F,1,{128,128}};
|
||||
EXPECT_NO_THROW(cc.compile(desc2, desc2));
|
||||
}
|
||||
|
||||
TEST(GAPI_MetaDesc, Typed_Compile_MatchMetaType_Mat)
|
||||
{
|
||||
cv::GComputationT<cv::GMat(cv::GMat)> cc([](cv::GMat in)
|
||||
{
|
||||
return in+in;
|
||||
});
|
||||
|
||||
EXPECT_NO_THROW(cc.compile(cv::GMatDesc{CV_8U,1,{64,64}}));
|
||||
}
|
||||
|
||||
TEST(GAPI_MetaDesc, Typed_Compile_MatchMetaType_Scalar)
|
||||
{
|
||||
cv::GComputationT<cv::GScalar(cv::GScalar)> cc([](cv::GScalar in)
|
||||
{
|
||||
return KTest::on(in);
|
||||
});
|
||||
|
||||
const auto desc1 = cv::descr_of(cv::Scalar(128));
|
||||
const auto pkg = cv::gapi::kernels<GOCVScalarTest>();
|
||||
// EXPECT_NO_THROW(cc.compile(desc1, cv::compile_args(pkg)));
|
||||
cc.compile(desc1, cv::compile_args(pkg));
|
||||
}
|
||||
|
||||
TEST(GAPI_MetaDesc, Typed_Compile_MatchMetaType_Mixed)
|
||||
{
|
||||
cv::GComputationT<cv::GMat(cv::GMat,cv::GScalar)> cc([](cv::GMat a, cv::GScalar v)
|
||||
{
|
||||
return cv::gapi::addC(a, v);
|
||||
});
|
||||
|
||||
const auto desc1 = cv::GMatDesc{CV_8U,1,{64,64}};
|
||||
const auto desc2 = cv::descr_of(cv::Scalar(4));
|
||||
|
||||
EXPECT_NO_THROW(cc.compile(desc1, desc2));
|
||||
}
|
||||
|
||||
} // namespace opencv_test
|
||||
@@ -0,0 +1,649 @@
|
||||
// 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_fluid_test_kernels.hpp"
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
|
||||
using namespace cv::gapi_test_kernels;
|
||||
|
||||
G_TYPED_KERNEL(TCopy, <GMat(GMat)>, "test.fluid.copy")
|
||||
{
|
||||
static GMatDesc outMeta(const cv::GMatDesc &in) {
|
||||
return in;
|
||||
}
|
||||
};
|
||||
|
||||
GAPI_FLUID_KERNEL(FCopy, TCopy, false)
|
||||
{
|
||||
static const int Window = 1;
|
||||
|
||||
static void run(const cv::gapi::fluid::View &in,
|
||||
cv::gapi::fluid::Buffer &out)
|
||||
{
|
||||
const uint8_t* in_row = in .InLine <uint8_t>(0);
|
||||
uint8_t* out_row = out.OutLine<uint8_t>();
|
||||
|
||||
for (int i = 0, w = in.length(); i < w; i++)
|
||||
{
|
||||
//std::cout << std::setw(4) << int(in_row[i]);
|
||||
out_row[i] = in_row[i];
|
||||
}
|
||||
//std::cout << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
GAPI_FLUID_KERNEL(FResizeNN, cv::gapi::core::GResize, false)
|
||||
{
|
||||
static const int Window = 1;
|
||||
static const auto Kind = GFluidKernel::Kind::Resize;
|
||||
|
||||
static void run(const cv::gapi::fluid::View& in, cv::Size /*sz*/, double /*fx*/, double /*fy*/, int /*interp*/,
|
||||
cv::gapi::fluid::Buffer& out)
|
||||
|
||||
{
|
||||
double vRatio = (double)in.meta().size.height / out.meta().size.height;
|
||||
auto y = out.y();
|
||||
auto inY = in.y();
|
||||
|
||||
auto sy = static_cast<int>(y * vRatio);
|
||||
int idx = sy - inY;
|
||||
|
||||
const auto src = in.InLine <unsigned char>(idx);
|
||||
auto dst = out.OutLine<unsigned char>();
|
||||
|
||||
double horRatio = (double)in.length() / out.length();
|
||||
|
||||
for (int x = 0; x < out.length(); x++)
|
||||
{
|
||||
auto inX = static_cast<int>(x * horRatio);
|
||||
dst[x] = src[inX];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace func
|
||||
{
|
||||
template <class Mapper>
|
||||
void initScratch(const cv::GMatDesc& in, cv::Size outSz, cv::gapi::fluid::Buffer &scratch)
|
||||
{
|
||||
CV_Assert(in.depth == CV_8U && in.chan == 1);
|
||||
|
||||
cv::Size scratch_size{static_cast<int>(outSz.width * sizeof(typename Mapper::Unit)), 1};
|
||||
|
||||
cv::GMatDesc desc;
|
||||
desc.chan = 1;
|
||||
desc.depth = CV_8UC1;
|
||||
desc.size = scratch_size;
|
||||
|
||||
cv::gapi::fluid::Buffer buffer(desc);
|
||||
scratch = std::move(buffer);
|
||||
|
||||
auto mapX = scratch.OutLine<typename Mapper::Unit>();
|
||||
double hRatio = (double)in.size.width / outSz.width;
|
||||
|
||||
for (int x = 0, w = outSz.width; x < w; x++)
|
||||
{
|
||||
mapX[x] = Mapper::map(hRatio, 0, in.size.width, x);
|
||||
}
|
||||
}
|
||||
|
||||
template <class Mapper>
|
||||
inline void calcRow(const cv::gapi::fluid::View& in, cv::gapi::fluid::Buffer& out, cv::gapi::fluid::Buffer &scratch)
|
||||
{
|
||||
double vRatio = (double)in.meta().size.height / out.meta().size.height;
|
||||
auto mapY = Mapper::map(vRatio, in.y(), in.meta().size.height, out.y());
|
||||
|
||||
const auto src0 = in.InLine <unsigned char>(mapY.s0);
|
||||
const auto src1 = in.InLine <unsigned char>(mapY.s1);
|
||||
|
||||
auto dst = out.OutLine<unsigned char>();
|
||||
auto mapX = scratch.OutLine<typename Mapper::Unit>();
|
||||
|
||||
for (int x = 0; x < out.length(); x++)
|
||||
{
|
||||
auto alpha0 = mapX[x].alpha0;
|
||||
auto alpha1 = mapX[x].alpha1;
|
||||
auto sx0 = mapX[x].s0;
|
||||
auto sx1 = mapX[x].s1;
|
||||
|
||||
int res0 = src0[sx0]*alpha0 + src0[sx1]*alpha1;
|
||||
int res1 = src1[sx0]*alpha0 + src1[sx1]*alpha1;
|
||||
|
||||
dst[x] = uchar(( ((mapY.alpha0 * (res0 >> 4)) >> 16) + ((mapY.alpha1 * (res1 >> 4)) >> 16) + 2)>>2);
|
||||
}
|
||||
}
|
||||
} // namespace func
|
||||
|
||||
constexpr static const int INTER_RESIZE_COEF_BITS = 11;
|
||||
constexpr static const int INTER_RESIZE_COEF_SCALE = 1 << INTER_RESIZE_COEF_BITS;
|
||||
|
||||
namespace linear
|
||||
{
|
||||
struct Mapper
|
||||
{
|
||||
struct Unit
|
||||
{
|
||||
short alpha0;
|
||||
short alpha1;
|
||||
int s0;
|
||||
int s1;
|
||||
};
|
||||
|
||||
static inline Unit map(double ratio, int start, int max, int outCoord)
|
||||
{
|
||||
auto f = static_cast<float>((outCoord + 0.5f) * ratio - 0.5f);
|
||||
int s = cvFloor(f);
|
||||
f -= s;
|
||||
|
||||
Unit u;
|
||||
|
||||
u.s0 = std::max(s - start, 0);
|
||||
u.s1 = ((f == 0.0) || s + 1 >= max) ? s - start : s - start + 1;
|
||||
|
||||
u.alpha0 = saturate_cast<short>((1.0f - f) * INTER_RESIZE_COEF_SCALE);
|
||||
u.alpha1 = saturate_cast<short>((f) * INTER_RESIZE_COEF_SCALE);
|
||||
|
||||
return u;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace linear
|
||||
|
||||
namespace areaUpscale
|
||||
{
|
||||
struct Mapper
|
||||
{
|
||||
struct Unit
|
||||
{
|
||||
short alpha0;
|
||||
short alpha1;
|
||||
int s0;
|
||||
int s1;
|
||||
};
|
||||
|
||||
static inline Unit map(double ratio, int start, int max, int outCoord)
|
||||
{
|
||||
int s = cvFloor(outCoord*ratio);
|
||||
float f = (float)((outCoord+1) - (s+1)/ratio);
|
||||
f = f <= 0 ? 0.f : f - cvFloor(f);
|
||||
|
||||
Unit u;
|
||||
|
||||
u.s0 = std::max(s - start, 0);
|
||||
u.s1 = ((f == 0.0) || s + 1 >= max) ? s - start : s - start + 1;
|
||||
|
||||
u.alpha0 = saturate_cast<short>((1.0f - f) * INTER_RESIZE_COEF_SCALE);
|
||||
u.alpha1 = saturate_cast<short>((f) * INTER_RESIZE_COEF_SCALE);
|
||||
|
||||
return u;
|
||||
}
|
||||
};
|
||||
} // namespace areaUpscale
|
||||
} // anonymous namespace
|
||||
|
||||
GAPI_FLUID_KERNEL(FResizeLinear, cv::gapi::core::GResize, true)
|
||||
{
|
||||
static const int Window = 1;
|
||||
static const auto Kind = GFluidKernel::Kind::Resize;
|
||||
|
||||
static void initScratch(const cv::GMatDesc& in,
|
||||
cv::Size outSz, double /*fx*/, double /*fy*/, int /*interp*/,
|
||||
cv::gapi::fluid::Buffer &scratch)
|
||||
{
|
||||
func::initScratch<linear::Mapper>(in, outSz, scratch);
|
||||
}
|
||||
|
||||
static void resetScratch(cv::gapi::fluid::Buffer& /*scratch*/)
|
||||
{}
|
||||
|
||||
static void run(const cv::gapi::fluid::View& in, cv::Size /*sz*/, double /*fx*/, double /*fy*/, int /*interp*/,
|
||||
cv::gapi::fluid::Buffer& out, cv::gapi::fluid::Buffer &scratch)
|
||||
|
||||
{
|
||||
func::calcRow<linear::Mapper>(in, out, scratch);
|
||||
}
|
||||
};
|
||||
|
||||
namespace
|
||||
{
|
||||
// FIXME
|
||||
// Move to some common place (to reuse/align with ResizeAgent)
|
||||
auto startInCoord = [](int outCoord, double ratio) {
|
||||
return static_cast<int>(outCoord * ratio + 1e-3);
|
||||
};
|
||||
auto endInCoord = [](int outCoord, double ratio) {
|
||||
return static_cast<int>(std::ceil((outCoord + 1) * ratio - 1e-3));
|
||||
};
|
||||
} // namespace
|
||||
|
||||
GAPI_FLUID_KERNEL(FResizeArea, cv::gapi::core::GResize, false)
|
||||
{
|
||||
static const int Window = 1;
|
||||
static const auto Kind = GFluidKernel::Kind::Resize;
|
||||
|
||||
static void run(const cv::gapi::fluid::View& in, cv::Size /*sz*/, double /*fx*/, double /*fy*/, int /*interp*/,
|
||||
cv::gapi::fluid::Buffer& out)
|
||||
|
||||
{
|
||||
auto y = out.y();
|
||||
double vRatio = (double)in.meta().size.height / out.meta().size.height;
|
||||
|
||||
int startY = startInCoord(y, vRatio);
|
||||
int endY = endInCoord (y, vRatio);
|
||||
|
||||
auto dst = out.OutLine<unsigned char>();
|
||||
|
||||
double hRatio = (double)in.length() / out.length();
|
||||
|
||||
for (int x = 0; x < out.length(); x++)
|
||||
{
|
||||
float res = 0.0;
|
||||
|
||||
int startX = startInCoord(x, hRatio);
|
||||
int endX = endInCoord (x, hRatio);
|
||||
|
||||
for (int inY = startY; inY < endY; inY++)
|
||||
{
|
||||
double startCoordY = inY / vRatio;
|
||||
double endCoordY = startCoordY + 1/vRatio;
|
||||
|
||||
if (startCoordY < y) startCoordY = y;
|
||||
if (endCoordY > y + 1) endCoordY = y + 1;
|
||||
|
||||
float fracY = static_cast<float>((inY == startY || inY == endY - 1) ? endCoordY - startCoordY : 1/vRatio);
|
||||
|
||||
const auto src = in.InLine <unsigned char>(inY - startY);
|
||||
|
||||
float rowSum = 0.0f;
|
||||
|
||||
for (int inX = startX; inX < endX; inX++)
|
||||
{
|
||||
double startCoordX = inX / hRatio;
|
||||
double endCoordX = startCoordX + 1/hRatio;
|
||||
|
||||
if (startCoordX < x) startCoordX = x;
|
||||
if (endCoordX > x + 1) endCoordX = x + 1;
|
||||
|
||||
float fracX = static_cast<float>((inX == startX || inX == endX - 1) ? endCoordX - startCoordX : 1/hRatio);
|
||||
|
||||
rowSum += src[inX] * fracX;
|
||||
}
|
||||
res += rowSum * fracY;
|
||||
}
|
||||
dst[x] = static_cast<unsigned char>(std::rint(res));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
GAPI_FLUID_KERNEL(FResizeAreaUpscale, cv::gapi::core::GResize, true)
|
||||
{
|
||||
static const int Window = 1;
|
||||
static const auto Kind = GFluidKernel::Kind::Resize;
|
||||
|
||||
static void initScratch(const cv::GMatDesc& in,
|
||||
cv::Size outSz, double /*fx*/, double /*fy*/, int /*interp*/,
|
||||
cv::gapi::fluid::Buffer &scratch)
|
||||
{
|
||||
func::initScratch<areaUpscale::Mapper>(in, outSz, scratch);
|
||||
}
|
||||
|
||||
static void resetScratch(cv::gapi::fluid::Buffer& /*scratch*/)
|
||||
{}
|
||||
|
||||
static void run(const cv::gapi::fluid::View& in, cv::Size /*sz*/, double /*fx*/, double /*fy*/, int /*interp*/,
|
||||
cv::gapi::fluid::Buffer& out, cv::gapi::fluid::Buffer &scratch)
|
||||
{
|
||||
func::calcRow<areaUpscale::Mapper>(in, out, scratch);
|
||||
}
|
||||
};
|
||||
|
||||
static auto fluidResizeTestPackage = [](int interpolation, cv::Size szIn, cv::Size szOut)
|
||||
{
|
||||
bool upscale = szIn.width < szOut.width || szIn.height < szOut.height;
|
||||
|
||||
cv::gapi::GKernelPackage pkg;
|
||||
switch (interpolation)
|
||||
{
|
||||
case cv::INTER_NEAREST: pkg = cv::gapi::kernels<FCopy, FResizeNN >(); break;
|
||||
case cv::INTER_LINEAR: pkg = cv::gapi::kernels<FCopy, FResizeLinear>(); break;
|
||||
case cv::INTER_AREA: pkg = upscale ? cv::gapi::kernels<FCopy, FResizeAreaUpscale>()
|
||||
: cv::gapi::kernels<FCopy, FResizeArea>(); break;
|
||||
default: CV_Assert(false);
|
||||
}
|
||||
return cv::gapi::combine(pkg, fluidTestPackage, cv::unite_policy::KEEP);
|
||||
};
|
||||
|
||||
struct ResizeTestFluid : public TestWithParam<std::tuple<int, int, cv::Size, std::tuple<cv::Size, cv::Rect>, double>> {};
|
||||
TEST_P(ResizeTestFluid, SanityTest)
|
||||
{
|
||||
int type = 0, interp = 0;
|
||||
cv::Size sz_in, sz_out;
|
||||
double tolerance = 0.0;
|
||||
cv::Rect outRoi;
|
||||
std::tuple<cv::Size, cv::Rect> outSizeAndRoi;
|
||||
std::tie(type, interp, sz_in, outSizeAndRoi, tolerance) = GetParam();
|
||||
std::tie(sz_out, outRoi) = outSizeAndRoi;
|
||||
if (outRoi == cv::Rect{}) outRoi = {0,0,sz_out.width,sz_out.height};
|
||||
if (outRoi.width == 0) outRoi.width = sz_out.width;
|
||||
double fx = 0, fy = 0;
|
||||
|
||||
cv::Mat in_mat1 (sz_in, type );
|
||||
cv::Scalar mean = cv::Scalar(127);
|
||||
cv::Scalar stddev = cv::Scalar(40.f);
|
||||
|
||||
cv::randn(in_mat1, mean, stddev);
|
||||
|
||||
cv::Mat out_mat = cv::Mat::zeros(sz_out, type);
|
||||
cv::Mat out_mat_ocv = cv::Mat::zeros(sz_out, type);
|
||||
|
||||
cv::GMat in;
|
||||
auto mid = TBlur3x3::on(in, cv::BORDER_REPLICATE, {});
|
||||
auto out = cv::gapi::resize(mid, sz_out, fx, fy, interp);
|
||||
|
||||
cv::GComputation c(in, out);
|
||||
c.apply(in_mat1, out_mat, cv::compile_args(GFluidOutputRois{{outRoi}}, fluidResizeTestPackage(interp, sz_in, sz_out)));
|
||||
|
||||
cv::Mat mid_mat;
|
||||
cv::blur(in_mat1, mid_mat, {3,3}, {-1,-1}, cv::BORDER_REPLICATE);
|
||||
cv::resize(mid_mat, out_mat_ocv, sz_out, fx, fy, interp);
|
||||
|
||||
cv::Mat absDiff;
|
||||
cv::absdiff(out_mat(outRoi), out_mat_ocv(outRoi), absDiff);
|
||||
EXPECT_EQ(0, cv::countNonZero(absDiff > tolerance));
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(ResizeTestCPU, ResizeTestFluid,
|
||||
Combine(Values(CV_8UC1),
|
||||
Values(cv::INTER_NEAREST, cv::INTER_LINEAR),
|
||||
Values(cv::Size(8, 7),
|
||||
cv::Size(8, 8),
|
||||
cv::Size(8, 64),
|
||||
cv::Size(8, 25),
|
||||
cv::Size(16, 8),
|
||||
cv::Size(16, 7)),
|
||||
Values(std::make_tuple(cv::Size(5, 4), cv::Rect{}),
|
||||
std::make_tuple(cv::Size(5, 4), cv::Rect{0, 0, 0, 2}),
|
||||
std::make_tuple(cv::Size(5, 4), cv::Rect{0, 1, 0, 2}),
|
||||
std::make_tuple(cv::Size(5, 4), cv::Rect{0, 2, 0, 2}),
|
||||
std::make_tuple(cv::Size(7, 7), cv::Rect{}),
|
||||
std::make_tuple(cv::Size(7, 7), cv::Rect{0, 0, 0, 3}),
|
||||
std::make_tuple(cv::Size(7, 7), cv::Rect{0, 2, 0, 2}),
|
||||
std::make_tuple(cv::Size(7, 7), cv::Rect{0, 4, 0, 3}),
|
||||
std::make_tuple(cv::Size(8, 4), cv::Rect{}),
|
||||
std::make_tuple(cv::Size(8, 4), cv::Rect{0, 0, 0, 3}),
|
||||
std::make_tuple(cv::Size(8, 4), cv::Rect{0, 1, 0, 2}),
|
||||
std::make_tuple(cv::Size(8, 4), cv::Rect{0, 3, 0, 1})),
|
||||
Values(0.0)));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(ResizeAreaTestCPU, ResizeTestFluid,
|
||||
Combine(Values(CV_8UC1),
|
||||
Values(cv::INTER_AREA),
|
||||
Values(cv::Size(8, 7),
|
||||
cv::Size(8, 8),
|
||||
cv::Size(8, 64),
|
||||
cv::Size(8, 25),
|
||||
cv::Size(16, 8),
|
||||
cv::Size(16, 7)),
|
||||
Values(std::make_tuple(cv::Size(5, 4), cv::Rect{}),
|
||||
std::make_tuple(cv::Size(5, 4), cv::Rect{0, 0, 0, 2}),
|
||||
std::make_tuple(cv::Size(5, 4), cv::Rect{0, 1, 0, 2}),
|
||||
std::make_tuple(cv::Size(5, 4), cv::Rect{0, 2, 0, 2}),
|
||||
std::make_tuple(cv::Size(7, 7), cv::Rect{}),
|
||||
std::make_tuple(cv::Size(7, 7), cv::Rect{0, 0, 0, 3}),
|
||||
std::make_tuple(cv::Size(7, 7), cv::Rect{0, 2, 0, 2}),
|
||||
std::make_tuple(cv::Size(7, 7), cv::Rect{0, 4, 0, 3}),
|
||||
std::make_tuple(cv::Size(8, 4), cv::Rect{}),
|
||||
std::make_tuple(cv::Size(8, 4), cv::Rect{0, 0, 0, 3}),
|
||||
std::make_tuple(cv::Size(8, 4), cv::Rect{0, 1, 0, 2}),
|
||||
std::make_tuple(cv::Size(8, 4), cv::Rect{0, 3, 0, 1})),
|
||||
// Actually this tolerance only for cases where OpenCV
|
||||
// uses ResizeAreaFast
|
||||
Values(1.0)));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(ResizeUpscaleTestCPU, ResizeTestFluid,
|
||||
Combine(Values(CV_8UC1),
|
||||
Values(cv::INTER_NEAREST, cv::INTER_LINEAR, cv::INTER_AREA),
|
||||
Values(cv::Size(1, 5),
|
||||
cv::Size(3, 5),
|
||||
cv::Size(7, 5),
|
||||
cv::Size(1, 7),
|
||||
cv::Size(3, 7),
|
||||
cv::Size(7, 7)),
|
||||
Values(std::make_tuple(cv::Size(8, 8), cv::Rect{0,0,8,2}),
|
||||
std::make_tuple(cv::Size(8, 8), cv::Rect{0,2,8,2}),
|
||||
std::make_tuple(cv::Size(8, 8), cv::Rect{0,4,8,2}),
|
||||
std::make_tuple(cv::Size(8, 8), cv::Rect{0,6,8,2}),
|
||||
std::make_tuple(cv::Size(8, 8), cv::Rect{0,0,8,8}),
|
||||
std::make_tuple(cv::Size(16, 8), cv::Rect{}),
|
||||
std::make_tuple(cv::Size(16, 64), cv::Rect{0, 0,16,16}),
|
||||
std::make_tuple(cv::Size(16, 64), cv::Rect{0,16,16,16}),
|
||||
std::make_tuple(cv::Size(16, 64), cv::Rect{0,32,16,16}),
|
||||
std::make_tuple(cv::Size(16, 64), cv::Rect{0,48,16,16}),
|
||||
std::make_tuple(cv::Size(16, 64), cv::Rect{0, 0,16,64}),
|
||||
std::make_tuple(cv::Size(16, 25), cv::Rect{0, 0,16, 7}),
|
||||
std::make_tuple(cv::Size(16, 25), cv::Rect{0, 7,16, 6}),
|
||||
std::make_tuple(cv::Size(16, 25), cv::Rect{0,13,16, 6}),
|
||||
std::make_tuple(cv::Size(16, 25), cv::Rect{0,19,16, 6}),
|
||||
std::make_tuple(cv::Size(16, 25), cv::Rect{0, 0,16, 7}),
|
||||
std::make_tuple(cv::Size(16, 25), cv::Rect{0, 7,16, 7}),
|
||||
std::make_tuple(cv::Size(16, 25), cv::Rect{0,14,16, 7}),
|
||||
std::make_tuple(cv::Size(16, 25), cv::Rect{0,21,16, 4}),
|
||||
std::make_tuple(cv::Size(16, 25), cv::Rect{0, 0,16,25}),
|
||||
std::make_tuple(cv::Size(16, 7), cv::Rect{}),
|
||||
std::make_tuple(cv::Size(16, 8), cv::Rect{})),
|
||||
Values(0.0)));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(ResizeUpscaleOneDimDownscaleAnother, ResizeTestFluid,
|
||||
Combine(Values(CV_8UC1),
|
||||
Values(cv::INTER_NEAREST, cv::INTER_LINEAR, cv::INTER_AREA),
|
||||
Values(cv::Size(6, 6),
|
||||
cv::Size(8, 7),
|
||||
cv::Size(8, 8),
|
||||
cv::Size(8, 10),
|
||||
cv::Size(10, 8),
|
||||
cv::Size(10, 7)),
|
||||
Values(std::make_tuple(cv::Size(11, 5), cv::Rect{}),
|
||||
std::make_tuple(cv::Size(11, 5), cv::Rect{0, 0, 0, 2}),
|
||||
std::make_tuple(cv::Size(11, 5), cv::Rect{0, 2, 0, 2}),
|
||||
std::make_tuple(cv::Size(11, 5), cv::Rect{0, 4, 0, 1}),
|
||||
std::make_tuple(cv::Size(12, 2), cv::Rect{}),
|
||||
std::make_tuple(cv::Size(12, 2), cv::Rect{0, 0, 0, 1}),
|
||||
std::make_tuple(cv::Size(12, 2), cv::Rect{0, 1, 0, 1}),
|
||||
std::make_tuple(cv::Size(23, 3), cv::Rect{}),
|
||||
std::make_tuple(cv::Size(23, 3), cv::Rect{0, 0, 0, 1}),
|
||||
std::make_tuple(cv::Size(23, 3), cv::Rect{0, 1, 0, 1}),
|
||||
std::make_tuple(cv::Size(23, 3), cv::Rect{0, 2, 0, 1}),
|
||||
std::make_tuple(cv::Size(3, 24), cv::Rect{}),
|
||||
std::make_tuple(cv::Size(3, 24), cv::Rect{0, 0, 0, 6}),
|
||||
std::make_tuple(cv::Size(3, 24), cv::Rect{0, 6, 0, 6}),
|
||||
std::make_tuple(cv::Size(3, 24), cv::Rect{0, 12, 0, 6}),
|
||||
std::make_tuple(cv::Size(3, 24), cv::Rect{0, 18, 0, 6}),
|
||||
std::make_tuple(cv::Size(5, 11), cv::Rect{}),
|
||||
std::make_tuple(cv::Size(5, 11), cv::Rect{0, 0, 0, 3}),
|
||||
std::make_tuple(cv::Size(5, 11), cv::Rect{0, 3, 0, 3}),
|
||||
std::make_tuple(cv::Size(5, 11), cv::Rect{0, 6, 0, 3}),
|
||||
std::make_tuple(cv::Size(5, 11), cv::Rect{0, 9, 0, 2})),
|
||||
Values(0.0)));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(Resize400_384TestCPU, ResizeTestFluid,
|
||||
Combine(Values(CV_8UC1),
|
||||
Values(cv::INTER_NEAREST, cv::INTER_LINEAR, cv::INTER_AREA),
|
||||
Values(cv::Size(128, 400)),
|
||||
Values(std::make_tuple(cv::Size(128, 384), cv::Rect{})),
|
||||
Values(0.0)));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(Resize220_400TestCPU, ResizeTestFluid,
|
||||
Combine(Values(CV_8UC1),
|
||||
Values(cv::INTER_LINEAR),
|
||||
Values(cv::Size(220, 220)),
|
||||
Values(std::make_tuple(cv::Size(400, 400), cv::Rect{})),
|
||||
Values(0.0)));
|
||||
|
||||
static auto cvBlur = [](const cv::Mat& in, cv::Mat& out, int kernelSize)
|
||||
{
|
||||
if (kernelSize == 1)
|
||||
{
|
||||
out = in;
|
||||
}
|
||||
else
|
||||
{
|
||||
cv::blur(in, out, {kernelSize, kernelSize});
|
||||
}
|
||||
};
|
||||
|
||||
using SizesWithRois = std::tuple<cv::Size, cv::Rect, cv::Size, cv::Rect>;
|
||||
struct ResizeAndAnotherReaderTest : public TestWithParam<std::tuple<int, int, bool, SizesWithRois>>{};
|
||||
TEST_P(ResizeAndAnotherReaderTest, SanityTest)
|
||||
{
|
||||
bool readFromInput = false;
|
||||
int interp = -1, kernelSize = -1;
|
||||
SizesWithRois sizesWithRois;
|
||||
std::tie(interp, kernelSize, readFromInput, sizesWithRois) = GetParam();
|
||||
|
||||
cv::Size sz, resizedSz;
|
||||
cv::Rect roi, resizedRoi;
|
||||
std::tie(sz, roi, resizedSz, resizedRoi) = sizesWithRois;
|
||||
|
||||
cv::Mat in_mat(sz, CV_8UC1);
|
||||
cv::Scalar mean = cv::Scalar(127);
|
||||
cv::Scalar stddev = cv::Scalar(40.f);
|
||||
cv::randn(in_mat, mean, stddev);
|
||||
|
||||
cv::Mat gapi_resize_out = cv::Mat::zeros(resizedSz, CV_8UC1);
|
||||
cv::Mat gapi_blur_out = cv::Mat::zeros(sz, CV_8UC1);
|
||||
|
||||
auto blur = kernelSize == 1 ? &TBlur1x1::on : kernelSize == 3 ? &TBlur3x3::on : &TBlur5x5::on;
|
||||
|
||||
cv::GMat in, resize_out, blur_out;
|
||||
|
||||
if (readFromInput)
|
||||
{
|
||||
resize_out = gapi::resize(in, resizedSz, 0, 0, interp);
|
||||
blur_out = blur(in, cv::BORDER_DEFAULT, {});
|
||||
}
|
||||
else
|
||||
{
|
||||
auto mid = TCopy::on(in);
|
||||
resize_out = gapi::resize(mid, resizedSz, 0, 0, interp);
|
||||
blur_out = blur(mid, cv::BORDER_DEFAULT, {});
|
||||
}
|
||||
|
||||
cv::GComputation c(GIn(in), GOut(resize_out, blur_out));
|
||||
c.apply(gin(in_mat), gout(gapi_resize_out, gapi_blur_out), cv::compile_args(GFluidOutputRois{{resizedRoi, roi}},
|
||||
fluidResizeTestPackage(interp, sz, resizedSz)));
|
||||
|
||||
cv::Mat ocv_resize_out = cv::Mat::zeros(resizedSz, CV_8UC1);
|
||||
cv::resize(in_mat, ocv_resize_out, resizedSz, 0, 0, interp);
|
||||
cv::Mat ocv_blur_out = cv::Mat::zeros(sz, CV_8UC1);
|
||||
cvBlur(in_mat, ocv_blur_out, kernelSize);
|
||||
|
||||
EXPECT_EQ(0, cv::countNonZero(gapi_resize_out(resizedRoi) != ocv_resize_out(resizedRoi)));
|
||||
EXPECT_EQ(0, cv::countNonZero(gapi_blur_out(roi) != ocv_blur_out(roi)));
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(ResizeTestCPU, ResizeAndAnotherReaderTest,
|
||||
Combine(Values(cv::INTER_NEAREST, cv::INTER_LINEAR),
|
||||
Values(1, 3, 5),
|
||||
testing::Bool(), // Read from input directly or place a copy node at start
|
||||
Values(std::make_tuple(cv::Size{8,8}, cv::Rect{0,0,8,8},
|
||||
cv::Size{4,4}, cv::Rect{0,0,4,4}),
|
||||
std::make_tuple(cv::Size{8,8}, cv::Rect{0,0,8,2},
|
||||
cv::Size{4,4}, cv::Rect{0,0,4,1}),
|
||||
std::make_tuple(cv::Size{8,8}, cv::Rect{0,2,8,4},
|
||||
cv::Size{4,4}, cv::Rect{0,1,4,2}),
|
||||
std::make_tuple(cv::Size{8,8}, cv::Rect{0,4,8,4},
|
||||
cv::Size{4,4}, cv::Rect{0,2,4,2}),
|
||||
std::make_tuple(cv::Size{64,64}, cv::Rect{0, 0,64,64},
|
||||
cv::Size{49,49}, cv::Rect{0, 0,49,49}),
|
||||
std::make_tuple(cv::Size{64,64}, cv::Rect{0, 0,64,15},
|
||||
cv::Size{49,49}, cv::Rect{0, 0,49,11}),
|
||||
std::make_tuple(cv::Size{64,64}, cv::Rect{0,11,64,23},
|
||||
cv::Size{49,49}, cv::Rect{0, 9,49,17}),
|
||||
std::make_tuple(cv::Size{64,64}, cv::Rect{0,50,64,14},
|
||||
cv::Size{49,49}, cv::Rect{0,39,49,10}))));
|
||||
|
||||
struct BlursAfterResizeTest : public TestWithParam<std::tuple<int, int, int, bool, std::tuple<cv::Size, cv::Size, cv::Rect>>>{};
|
||||
TEST_P(BlursAfterResizeTest, SanityTest)
|
||||
{
|
||||
bool readFromInput = false;
|
||||
int interp = -1, kernelSize1 = -1, kernelSize2 = -1;
|
||||
std::tuple<cv::Size, cv::Size, cv::Rect> sizesWithRoi;
|
||||
std::tie(interp, kernelSize1, kernelSize2, readFromInput, sizesWithRoi) = GetParam();
|
||||
|
||||
cv::Size inSz, outSz;
|
||||
cv::Rect outRoi;
|
||||
std::tie(inSz, outSz, outRoi) = sizesWithRoi;
|
||||
|
||||
cv::Mat in_mat(inSz, CV_8UC1);
|
||||
cv::Scalar mean = cv::Scalar(127);
|
||||
cv::Scalar stddev = cv::Scalar(40.f);
|
||||
cv::randn(in_mat, mean, stddev);
|
||||
cv::Mat gapi_out1 = cv::Mat::zeros(outSz, CV_8UC1);
|
||||
cv::Mat gapi_out2 = cv::Mat::zeros(outSz, CV_8UC1);
|
||||
|
||||
auto blur1 = kernelSize1 == 1 ? &TBlur1x1::on : kernelSize1 == 3 ? &TBlur3x3::on : &TBlur5x5::on;
|
||||
auto blur2 = kernelSize2 == 1 ? &TBlur1x1::on : kernelSize2 == 3 ? &TBlur3x3::on : &TBlur5x5::on;
|
||||
|
||||
cv::GMat in, out1, out2;
|
||||
if (readFromInput)
|
||||
{
|
||||
auto resized = gapi::resize(in, outSz, 0, 0, interp);
|
||||
out1 = blur1(resized, cv::BORDER_DEFAULT, {});
|
||||
out2 = blur2(resized, cv::BORDER_DEFAULT, {});
|
||||
}
|
||||
else
|
||||
{
|
||||
auto mid = TCopy::on(in);
|
||||
auto resized = gapi::resize(mid, outSz, 0, 0, interp);
|
||||
out1 = blur1(resized, cv::BORDER_DEFAULT, {});
|
||||
out2 = blur2(resized, cv::BORDER_DEFAULT, {});
|
||||
}
|
||||
|
||||
cv::GComputation c(GIn(in), GOut(out1, out2));
|
||||
c.apply(gin(in_mat), gout(gapi_out1, gapi_out2), cv::compile_args(GFluidOutputRois{{outRoi, outRoi}},
|
||||
fluidResizeTestPackage(interp, inSz, outSz)));
|
||||
|
||||
cv::Mat ocv_out1 = cv::Mat::zeros(outSz, CV_8UC1);
|
||||
cv::Mat ocv_out2 = cv::Mat::zeros(outSz, CV_8UC1);
|
||||
cv::Mat resized = cv::Mat::zeros(outSz, CV_8UC1);
|
||||
cv::resize(in_mat, resized, outSz, 0, 0, interp);
|
||||
cvBlur(resized, ocv_out1, kernelSize1);
|
||||
cvBlur(resized, ocv_out2, kernelSize2);
|
||||
|
||||
EXPECT_EQ(0, cv::countNonZero(gapi_out1(outRoi) != ocv_out1(outRoi)));
|
||||
EXPECT_EQ(0, cv::countNonZero(gapi_out2(outRoi) != ocv_out2(outRoi)));
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(ResizeTestCPU, BlursAfterResizeTest,
|
||||
Combine(Values(cv::INTER_NEAREST, cv::INTER_LINEAR),
|
||||
Values(1, 3, 5),
|
||||
Values(1, 3, 5),
|
||||
testing::Bool(), // Read from input directly or place a copy node at start
|
||||
Values(std::make_tuple(cv::Size{8,8},
|
||||
cv::Size{4,4}, cv::Rect{0,0,4,4}),
|
||||
std::make_tuple(cv::Size{8,8},
|
||||
cv::Size{4,4}, cv::Rect{0,0,4,1}),
|
||||
std::make_tuple(cv::Size{8,8},
|
||||
cv::Size{4,4}, cv::Rect{0,1,4,2}),
|
||||
std::make_tuple(cv::Size{8,8},
|
||||
cv::Size{4,4}, cv::Rect{0,2,4,2}),
|
||||
std::make_tuple(cv::Size{64,64},
|
||||
cv::Size{49,49}, cv::Rect{0, 0,49,49}),
|
||||
std::make_tuple(cv::Size{64,64},
|
||||
cv::Size{49,49}, cv::Rect{0, 0,49,11}),
|
||||
std::make_tuple(cv::Size{64,64},
|
||||
cv::Size{49,49}, cv::Rect{0, 9,49,17}),
|
||||
std::make_tuple(cv::Size{64,64},
|
||||
cv::Size{49,49}, cv::Rect{0,39,49,10}))));
|
||||
|
||||
} // namespace opencv_test
|
||||
@@ -0,0 +1,197 @@
|
||||
// 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_fluid_test_kernels.hpp"
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
|
||||
using namespace cv::gapi_test_kernels;
|
||||
|
||||
struct PartialComputation : public TestWithParam <std::tuple<cv::Rect>> {};
|
||||
TEST_P(PartialComputation, Test)
|
||||
{
|
||||
cv::Rect roi;
|
||||
std::tie(roi) = GetParam();
|
||||
|
||||
int borderType = BORDER_REPLICATE;
|
||||
int kernelSize = 3;
|
||||
cv::Point anchor = {-1, -1};
|
||||
|
||||
cv::GMat in;
|
||||
cv::GMat out = TBlur3x3::on(in, borderType, {});
|
||||
cv::GComputation c(cv::GIn(in), cv::GOut(out));
|
||||
|
||||
const auto sz = cv::Size(8, 10);
|
||||
cv::Mat in_mat(sz, CV_8UC1);
|
||||
cv::Scalar mean = cv::Scalar(127.0f);
|
||||
cv::Scalar stddev = cv::Scalar(40.f);
|
||||
cv::randn(in_mat, mean, stddev);
|
||||
|
||||
cv::Mat out_mat_gapi = cv::Mat::zeros(sz, CV_8UC1);
|
||||
cv::Mat out_mat_ocv = cv::Mat::zeros(sz, CV_8UC1);
|
||||
|
||||
// Run G-API
|
||||
auto cc = c.compile(cv::descr_of(in_mat), cv::compile_args(fluidTestPackage, GFluidOutputRois{{to_own(roi)}}));
|
||||
cc(cv::gin(in_mat), cv::gout(out_mat_gapi));
|
||||
|
||||
// Check with OpenCV
|
||||
if (roi == cv::Rect{}) roi = cv::Rect{0,0,sz.width,sz.height};
|
||||
cv::blur(in_mat(roi), out_mat_ocv(roi), {kernelSize, kernelSize}, anchor, borderType);
|
||||
|
||||
EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv));
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(Fluid, PartialComputation,
|
||||
Values(cv::Rect{}, cv::Rect{0,0,8,6}, cv::Rect{0,1,8,3},
|
||||
cv::Rect{0,2,8,3}, cv::Rect{0,3,8,5}, cv::Rect{0,4,8,6}));
|
||||
|
||||
struct PartialComputationAddC : public TestWithParam <std::tuple<cv::Rect>> {};
|
||||
TEST_P(PartialComputationAddC, Test)
|
||||
{
|
||||
cv::Rect roi;
|
||||
std::tie(roi) = GetParam();
|
||||
|
||||
cv::GMat in;
|
||||
cv::GMat out = TAddCSimple::on(in, 1);
|
||||
cv::GComputation c(cv::GIn(in), cv::GOut(out));
|
||||
|
||||
const auto sz = cv::Size(8, 10);
|
||||
cv::Mat in_mat(sz, CV_8UC1);
|
||||
cv::Scalar mean = cv::Scalar(127.0f);
|
||||
cv::Scalar stddev = cv::Scalar(40.f);
|
||||
cv::randn(in_mat, mean, stddev);
|
||||
|
||||
cv::Mat out_mat_gapi = cv::Mat::zeros(sz, CV_8UC1);
|
||||
cv::Mat out_mat_ocv = cv::Mat::zeros(sz, CV_8UC1);
|
||||
|
||||
// Run G-API
|
||||
auto cc = c.compile(cv::descr_of(in_mat), cv::compile_args(fluidTestPackage, GFluidOutputRois{{to_own(roi)}}));
|
||||
cc(cv::gin(in_mat), cv::gout(out_mat_gapi));
|
||||
|
||||
// Check with OpenCV
|
||||
if (roi == cv::Rect{}) roi = cv::Rect{0,0,sz.width,sz.height};
|
||||
out_mat_ocv(roi) = in_mat(roi) + 1;
|
||||
|
||||
EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv));
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(FluidRoi, PartialComputationAddC,
|
||||
Values(cv::Rect{}, cv::Rect{0,0,8,6}, cv::Rect{0,1,8,3},
|
||||
cv::Rect{0,2,8,3}, cv::Rect{0,3,8,5}, cv::Rect{0,4,8,6}));
|
||||
|
||||
struct SequenceOfBlursRoiTest : public TestWithParam <std::tuple<int, cv::Rect>> {};
|
||||
TEST_P(SequenceOfBlursRoiTest, Test)
|
||||
{
|
||||
cv::Size sz_in = { 320, 240 };
|
||||
|
||||
int borderType = 0;
|
||||
cv::Rect roi;
|
||||
std::tie(borderType, roi) = GetParam();
|
||||
cv::Mat in_mat(sz_in, CV_8UC1);
|
||||
cv::Scalar mean = cv::Scalar(127.0f);
|
||||
cv::Scalar stddev = cv::Scalar(40.f);
|
||||
|
||||
cv::randn(in_mat, mean, stddev);
|
||||
|
||||
cv::Point anchor = {-1, -1};
|
||||
cv::Scalar borderValue(0);
|
||||
|
||||
GMat in;
|
||||
auto mid = TBlur3x3::on(in, borderType, borderValue);
|
||||
auto out = TBlur5x5::on(mid, borderType, borderValue);
|
||||
|
||||
Mat out_mat_gapi = Mat::zeros(sz_in, CV_8UC1);
|
||||
|
||||
GComputation c(GIn(in), GOut(out));
|
||||
auto cc = c.compile(descr_of(in_mat), cv::compile_args(fluidTestPackage, GFluidOutputRois{{to_own(roi)}}));
|
||||
cc(gin(in_mat), gout(out_mat_gapi));
|
||||
|
||||
cv::Mat mid_mat_ocv = Mat::zeros(sz_in, CV_8UC1);
|
||||
cv::Mat out_mat_ocv = Mat::zeros(sz_in, CV_8UC1);
|
||||
|
||||
cv::blur(in_mat, mid_mat_ocv, {3,3}, anchor, borderType);
|
||||
|
||||
if (roi == cv::Rect{})
|
||||
{
|
||||
roi = cv::Rect{0, 0, sz_in.width, sz_in.height};
|
||||
}
|
||||
|
||||
cv::blur(mid_mat_ocv(roi), out_mat_ocv(roi), {5,5}, anchor, borderType);
|
||||
|
||||
EXPECT_EQ(0, countNonZero(out_mat_ocv != out_mat_gapi));
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(FluidRoi, SequenceOfBlursRoiTest,
|
||||
Combine(Values(BORDER_CONSTANT, BORDER_REPLICATE, BORDER_REFLECT_101),
|
||||
Values(cv::Rect{0,0,320,240}, cv::Rect{0,64,320,128}, cv::Rect{0,128,320,112})));
|
||||
|
||||
struct TwoBlursRoiTest : public TestWithParam <std::tuple<int, int, int, int, int, int, bool, cv::Rect>> {};
|
||||
TEST_P(TwoBlursRoiTest, Test)
|
||||
{
|
||||
cv::Size sz_in = { 320, 240 };
|
||||
|
||||
int kernelSize1 = 0, kernelSize2 = 0;
|
||||
int borderType1 = -1, borderType2 = -1;
|
||||
cv::Scalar borderValue1{}, borderValue2{};
|
||||
bool readFromInput = false;
|
||||
cv::Rect outRoi;
|
||||
std::tie(kernelSize1, borderType1, borderValue1, kernelSize2, borderType2, borderValue2, readFromInput, outRoi) = GetParam();
|
||||
cv::Mat in_mat(sz_in, CV_8UC1);
|
||||
cv::Scalar mean = cv::Scalar(127.0f);
|
||||
cv::Scalar stddev = cv::Scalar(40.f);
|
||||
|
||||
cv::randn(in_mat, mean, stddev);
|
||||
|
||||
cv::Point anchor = {-1, -1};
|
||||
|
||||
auto blur1 = kernelSize1 == 3 ? &TBlur3x3::on : TBlur5x5::on;
|
||||
auto blur2 = kernelSize2 == 3 ? &TBlur3x3::on : TBlur5x5::on;
|
||||
|
||||
GMat in, out1, out2;
|
||||
if (readFromInput)
|
||||
{
|
||||
out1 = blur1(in, borderType1, borderValue1);
|
||||
out2 = blur2(in, borderType2, borderValue2);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto mid = TAddCSimple::on(in, 0);
|
||||
out1 = blur1(mid, borderType1, borderValue1);
|
||||
out2 = blur2(mid, borderType2, borderValue2);
|
||||
}
|
||||
|
||||
Mat out_mat_gapi1 = Mat::zeros(sz_in, CV_8UC1);
|
||||
Mat out_mat_gapi2 = Mat::zeros(sz_in, CV_8UC1);
|
||||
|
||||
GComputation c(GIn(in), GOut(out1, out2));
|
||||
auto cc = c.compile(descr_of(in_mat), cv::compile_args(fluidTestPackage, GFluidOutputRois{{outRoi, outRoi}}));
|
||||
cc(gin(in_mat), gout(out_mat_gapi1, out_mat_gapi2));
|
||||
|
||||
cv::Mat out_mat_ocv1 = Mat::zeros(sz_in, CV_8UC1);
|
||||
cv::Mat out_mat_ocv2 = Mat::zeros(sz_in, CV_8UC1);
|
||||
|
||||
cv::blur(in_mat(outRoi), out_mat_ocv1(outRoi), {kernelSize1, kernelSize1}, anchor, borderType1);
|
||||
cv::blur(in_mat(outRoi), out_mat_ocv2(outRoi), {kernelSize2, kernelSize2}, anchor, borderType2);
|
||||
|
||||
EXPECT_EQ(0, countNonZero(out_mat_ocv1 != out_mat_gapi1));
|
||||
EXPECT_EQ(0, countNonZero(out_mat_ocv2 != out_mat_gapi2));
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(FluidRoi, TwoBlursRoiTest,
|
||||
Combine(Values(3, 5),
|
||||
Values(cv::BORDER_CONSTANT, cv::BORDER_REPLICATE, cv::BORDER_REFLECT_101),
|
||||
Values(0),
|
||||
Values(3, 5),
|
||||
Values(cv::BORDER_CONSTANT, cv::BORDER_REPLICATE, cv::BORDER_REFLECT_101),
|
||||
Values(0),
|
||||
testing::Bool(), // Read from input directly or place a copy node at start
|
||||
Values(cv::Rect{0,0,320,240}, cv::Rect{0,64,320,128}, cv::Rect{0,128,320,112})));
|
||||
|
||||
} // namespace opencv_test
|
||||
@@ -0,0 +1,710 @@
|
||||
// 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 "opencv2/gapi/core.hpp"
|
||||
|
||||
#include "opencv2/gapi/fluid/gfluidbuffer.hpp"
|
||||
#include "opencv2/gapi/fluid/gfluidkernel.hpp"
|
||||
|
||||
// FIXME: move these tests with priv() to internal suite
|
||||
#include "backends/fluid/gfluidbuffer_priv.hpp"
|
||||
|
||||
#include "gapi_fluid_test_kernels.hpp"
|
||||
#include "logger.hpp"
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
|
||||
using namespace cv::gapi_test_kernels;
|
||||
|
||||
namespace
|
||||
{
|
||||
void WriteFunction(uint8_t* row, int nr, int w) {
|
||||
for (int i = 0; i < w; i++)
|
||||
row[i] = static_cast<uint8_t>(nr+i);
|
||||
};
|
||||
void ReadFunction1x1(const uint8_t* row, int w) {
|
||||
for (int i = 0; i < w; i++)
|
||||
std::cout << std::setw(4) << static_cast<int>(row[i]) << " ";
|
||||
std::cout << "\n";
|
||||
};
|
||||
void ReadFunction3x3(const uint8_t* rows[3], int w) {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
for (int j = -1; j < w+1; j++) {
|
||||
std::cout << std::setw(4) << static_cast<int>(rows[i][j]) << " ";
|
||||
}
|
||||
std::cout << "\n";
|
||||
}
|
||||
std::cout << "\n";
|
||||
};
|
||||
}
|
||||
|
||||
TEST(FluidBuffer, InputTest)
|
||||
{
|
||||
const cv::Size buffer_size = {8,8};
|
||||
cv::Mat in_mat = cv::Mat::eye(buffer_size, CV_8U);
|
||||
|
||||
cv::gapi::fluid::Buffer buffer(in_mat, true);
|
||||
cv::gapi::fluid::View view = buffer.mkView(1, 0, {}, false);
|
||||
view.priv().reset(1);
|
||||
int this_y = 0;
|
||||
|
||||
while (this_y < buffer_size.height)
|
||||
{
|
||||
const uint8_t* rrow = view.InLine<uint8_t>(0);
|
||||
ReadFunction1x1(rrow, buffer_size.width);
|
||||
view.priv().readDone(1,1);
|
||||
|
||||
cv::Mat from_buffer(1, buffer_size.width, CV_8U, const_cast<uint8_t*>(rrow));
|
||||
EXPECT_EQ(0, cv::countNonZero(in_mat.row(this_y) != from_buffer));
|
||||
|
||||
this_y++;
|
||||
}
|
||||
}
|
||||
|
||||
TEST(FluidBuffer, CircularTest)
|
||||
{
|
||||
const cv::Size buffer_size = {8,16};
|
||||
|
||||
cv::gapi::fluid::Buffer buffer(cv::GMatDesc{CV_8U,1,buffer_size}, 3, 1, 0, 1,
|
||||
util::make_optional(cv::gapi::fluid::Border{cv::BORDER_CONSTANT, cv::gapi::own::Scalar(255)}));
|
||||
cv::gapi::fluid::View view = buffer.mkView(3, 1, {}, false);
|
||||
view.priv().reset(3);
|
||||
buffer.debug(std::cout);
|
||||
|
||||
const auto whole_line_is = [](const uint8_t *line, int len, int value)
|
||||
{
|
||||
return std::all_of(line, line+len, [&](const uint8_t v){return v == value;});
|
||||
};
|
||||
|
||||
// Store all read/written data in separate Mats to compare with
|
||||
cv::Mat written_data(buffer_size, CV_8U);
|
||||
|
||||
// Simulate write/read process
|
||||
int num_reads = 0, num_writes = 0;
|
||||
while (num_reads < buffer_size.height)
|
||||
{
|
||||
if (num_writes < buffer_size.height)
|
||||
{
|
||||
uint8_t* wrow = buffer.OutLine<uint8_t>();
|
||||
WriteFunction(wrow, num_writes, buffer_size.width);
|
||||
buffer.priv().writeDone();
|
||||
|
||||
cv::Mat(1, buffer_size.width, CV_8U, wrow)
|
||||
.copyTo(written_data.row(num_writes));
|
||||
num_writes++;
|
||||
}
|
||||
buffer.debug(std::cout);
|
||||
|
||||
if (view.ready())
|
||||
{
|
||||
view.priv().prepareToRead();
|
||||
const uint8_t* rrow[3] = {
|
||||
view.InLine<uint8_t>(-1),
|
||||
view.InLine<uint8_t>( 0),
|
||||
view.InLine<uint8_t>( 1),
|
||||
};
|
||||
ReadFunction3x3(rrow, buffer_size.width);
|
||||
view.priv().readDone(1,3);
|
||||
buffer.debug(std::cout);
|
||||
|
||||
// Check borders right here
|
||||
EXPECT_EQ(255u, rrow[0][-1]);
|
||||
EXPECT_EQ(255u, rrow[0][buffer_size.width]);
|
||||
if (num_reads == 0)
|
||||
{
|
||||
EXPECT_TRUE(whole_line_is(rrow[0]-1, buffer_size.width+2, 255u));
|
||||
}
|
||||
if (num_reads == buffer_size.height-1)
|
||||
{
|
||||
EXPECT_TRUE(whole_line_is(rrow[2]-1, buffer_size.width+2, 255u));
|
||||
}
|
||||
|
||||
// Check window (without borders)
|
||||
if (num_reads > 0 && num_reads < buffer_size.height-1)
|
||||
{
|
||||
// +1 everywhere since num_writes was just incremented above
|
||||
cv::Mat written_lastLine2 = written_data.row(num_writes - (2+1));
|
||||
cv::Mat written_lastLine1 = written_data.row(num_writes - (1+1));
|
||||
cv::Mat written_lastLine0 = written_data.row(num_writes - (0+1));
|
||||
|
||||
cv::Mat read_prevLine(1, buffer_size.width, CV_8U, const_cast<uint8_t*>(rrow[0]));
|
||||
cv::Mat read_thisLine(1, buffer_size.width, CV_8U, const_cast<uint8_t*>(rrow[1]));
|
||||
cv::Mat read_nextLine(1, buffer_size.width, CV_8U, const_cast<uint8_t*>(rrow[2]));
|
||||
|
||||
EXPECT_EQ(0, cv::countNonZero(written_lastLine2 != read_prevLine));
|
||||
EXPECT_EQ(0, cv::countNonZero(written_lastLine1 != read_thisLine));
|
||||
EXPECT_EQ(0, cv::countNonZero(written_lastLine0 != read_nextLine));
|
||||
}
|
||||
num_reads++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST(FluidBuffer, OutputTest)
|
||||
{
|
||||
const cv::Size buffer_size = {8,16};
|
||||
cv::Mat out_mat = cv::Mat(buffer_size, CV_8U);
|
||||
|
||||
cv::gapi::fluid::Buffer buffer(out_mat, false);
|
||||
int num_writes = 0;
|
||||
while (num_writes < buffer_size.height)
|
||||
{
|
||||
uint8_t* wrow = buffer.OutLine<uint8_t>();
|
||||
WriteFunction(wrow, num_writes, buffer_size.width);
|
||||
buffer.priv().writeDone();
|
||||
num_writes++;
|
||||
}
|
||||
|
||||
GAPI_LOG_INFO(NULL, "\n" << out_mat);
|
||||
|
||||
// Validity check
|
||||
for (int r = 0; r < buffer_size.height; r++)
|
||||
{
|
||||
for (int c = 0; c < buffer_size.width; c++)
|
||||
{
|
||||
EXPECT_EQ(r+c, out_mat.at<uint8_t>(r, c));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Fluid, AddC_WithScalar)
|
||||
{
|
||||
cv::GMat in;
|
||||
cv::GScalar s;
|
||||
|
||||
cv::GComputation c(cv::GIn(in, s), cv::GOut(TAddScalar::on(in, s)));
|
||||
cv::Mat in_mat = cv::Mat::eye(3, 3, CV_8UC1), out_mat(3, 3, CV_8UC1), ref_mat;
|
||||
cv::Scalar in_s(100);
|
||||
|
||||
auto cc = c.compile(cv::descr_of(in_mat), cv::descr_of(in_s), cv::compile_args(fluidTestPackage));
|
||||
|
||||
cc(cv::gin(in_mat, in_s), cv::gout(out_mat));
|
||||
ref_mat = in_mat + in_s;
|
||||
EXPECT_EQ(0, cv::countNonZero(out_mat != ref_mat));
|
||||
}
|
||||
|
||||
TEST(Fluid, Scalar_In_Middle_Graph)
|
||||
{
|
||||
cv::GMat in;
|
||||
cv::GScalar s;
|
||||
|
||||
cv::GComputation c(cv::GIn(in, s), cv::GOut(TAddScalar::on(TAddCSimple::on(in, 5), s)));
|
||||
cv::Mat in_mat = cv::Mat::eye(3, 3, CV_8UC1), out_mat(3, 3, CV_8UC1), ref_mat;
|
||||
cv::Scalar in_s(100);
|
||||
|
||||
auto cc = c.compile(cv::descr_of(in_mat), cv::descr_of(in_s), cv::compile_args(fluidTestPackage));
|
||||
|
||||
cc(cv::gin(in_mat, in_s), cv::gout(out_mat));
|
||||
ref_mat = (in_mat + 5) + in_s;
|
||||
EXPECT_EQ(0, cv::countNonZero(out_mat != ref_mat));
|
||||
}
|
||||
|
||||
TEST(Fluid, Add_Scalar_To_Mat)
|
||||
{
|
||||
cv::GMat in;
|
||||
cv::GScalar s;
|
||||
|
||||
cv::GComputation c(cv::GIn(s, in), cv::GOut(TAddScalarToMat::on(s, in)));
|
||||
cv::Mat in_mat = cv::Mat::eye(3, 3, CV_8UC1), out_mat(3, 3, CV_8UC1), ref_mat;
|
||||
cv::Scalar in_s(100);
|
||||
|
||||
auto cc = c.compile(cv::descr_of(in_s), cv::descr_of(in_mat), cv::compile_args(fluidTestPackage));
|
||||
|
||||
cc(cv::gin(in_s, in_mat), cv::gout(out_mat));
|
||||
ref_mat = in_mat + in_s;
|
||||
EXPECT_EQ(0, cv::countNonZero(out_mat != ref_mat));
|
||||
}
|
||||
|
||||
TEST(Fluid, Sum_2_Mats_And_Scalar)
|
||||
{
|
||||
cv::GMat a, b;
|
||||
cv::GScalar s;
|
||||
|
||||
cv::GComputation c(cv::GIn(a, s, b), cv::GOut(TSum2MatsAndScalar::on(a, s, b)));
|
||||
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;
|
||||
cv::Scalar in_s(100);
|
||||
|
||||
auto cc = c.compile(cv::descr_of(in_mat1), cv::descr_of(in_s), cv::descr_of(in_mat2), cv::compile_args(fluidTestPackage));
|
||||
|
||||
cc(cv::gin(in_mat1, in_s, in_mat2), cv::gout(out_mat));
|
||||
ref_mat = in_mat1 + in_mat2 + in_s;
|
||||
EXPECT_EQ(0, cv::countNonZero(out_mat != ref_mat));
|
||||
}
|
||||
|
||||
TEST(Fluid, Split3)
|
||||
{
|
||||
cv::GMat bgr;
|
||||
cv::GMat r,g,b;
|
||||
std::tie(b,g,r) = cv::gapi::split3(bgr);
|
||||
auto rr = TAddSimple::on(r, TId::on(b));
|
||||
auto rrr = TAddSimple::on(TId::on(rr), g);
|
||||
cv::GComputation c(bgr, TId::on(rrr));
|
||||
|
||||
cv::Size sz(5120, 5120);
|
||||
cv::Mat eye_1 = cv::Mat::eye(sz, CV_8UC1);
|
||||
std::vector<cv::Mat> eyes = {eye_1, eye_1, eye_1};
|
||||
cv::Mat in_mat;
|
||||
cv::merge(eyes, in_mat);
|
||||
cv::Mat out_mat(sz, CV_8UC1);
|
||||
|
||||
// G-API
|
||||
auto cc = c.compile(cv::descr_of(in_mat),
|
||||
cv::compile_args(fluidTestPackage));
|
||||
cc(in_mat, out_mat);
|
||||
|
||||
// OCV
|
||||
std::vector<cv::Mat> chans;
|
||||
cv::split(in_mat, chans);
|
||||
|
||||
// Compare
|
||||
EXPECT_EQ(0, cv::countNonZero(out_mat != (chans[2]*3)));
|
||||
}
|
||||
|
||||
TEST(Fluid, ScratchTest)
|
||||
{
|
||||
cv::GMat in;
|
||||
cv::GMat out = TPlusRow0::on(TPlusRow0::on(in));
|
||||
cv::GComputation c(in, out);
|
||||
|
||||
cv::Size sz(8, 8);
|
||||
cv::Mat in_mat = cv::Mat::eye(sz, CV_8UC1);
|
||||
cv::Mat out_mat(sz, CV_8UC1);
|
||||
|
||||
// OpenCV (reference)
|
||||
cv::Mat ref;
|
||||
{
|
||||
cv::Mat first_row = cv::Mat::zeros(1, sz.width, CV_8U);
|
||||
cv::Mat remaining = cv::repeat(in_mat.row(0), sz.height-1, 1);
|
||||
cv::Mat operand;
|
||||
cv::vconcat(first_row, 2*remaining, operand);
|
||||
ref = in_mat + operand;
|
||||
}
|
||||
GAPI_LOG_INFO(NULL, "\n" << ref);
|
||||
|
||||
// G-API
|
||||
auto cc = c.compile(cv::descr_of(in_mat),
|
||||
cv::compile_args(fluidTestPackage));
|
||||
cc(in_mat, out_mat);
|
||||
GAPI_LOG_INFO(NULL, "\n" << out_mat);
|
||||
EXPECT_EQ(0, cv::countNonZero(ref != out_mat));
|
||||
|
||||
cc(in_mat, out_mat);
|
||||
GAPI_LOG_INFO(NULL, "\n" << out_mat);
|
||||
EXPECT_EQ(0, cv::countNonZero(ref != out_mat));
|
||||
}
|
||||
|
||||
TEST(Fluid, MultipleOutRowsTest)
|
||||
{
|
||||
cv::GMat in;
|
||||
cv::GMat out = TAddCSimple::on(TAddCSimple::on(in, 1), 2);
|
||||
cv::GComputation c(in, out);
|
||||
|
||||
cv::Size sz(4, 4);
|
||||
cv::Mat in_mat = cv::Mat::eye(sz, CV_8UC1);
|
||||
cv::Mat out_mat(sz, CV_8UC1);
|
||||
|
||||
auto cc = c.compile(cv::descr_of(in_mat),
|
||||
cv::compile_args(fluidTestPackage));
|
||||
cc(in_mat, out_mat);
|
||||
|
||||
std::cout << out_mat << std::endl;
|
||||
|
||||
cv::Mat ocv_ref = in_mat + 1 + 2;
|
||||
EXPECT_EQ(0, cv::countNonZero(ocv_ref != out_mat));
|
||||
}
|
||||
|
||||
|
||||
TEST(Fluid, LPIWindow)
|
||||
{
|
||||
cv::GMat in;
|
||||
cv::GMat r,g,b;
|
||||
std::tie(r,g,b) = cv::gapi::split3(in);
|
||||
cv::GMat rr = TId7x7::on(r);
|
||||
cv::GMat tmp = TAddSimple::on(rr, g);
|
||||
cv::GMat out = TAddSimple::on(tmp, b);
|
||||
|
||||
cv::GComputation c(in, out);
|
||||
|
||||
cv::Size sz(8, 8);
|
||||
|
||||
cv::Mat eye_1 = cv::Mat::eye(sz, CV_8UC1);
|
||||
std::vector<cv::Mat> eyes = {eye_1, eye_1, eye_1};
|
||||
cv::Mat in_mat;
|
||||
cv::merge(eyes, in_mat);
|
||||
|
||||
cv::Mat out_mat(sz, CV_8U);
|
||||
auto cc = c.compile(cv::descr_of(in_mat), cv::compile_args(fluidTestPackage));
|
||||
cc(in_mat, out_mat);
|
||||
|
||||
//std::cout << out_mat << std::endl;
|
||||
|
||||
// OpenCV reference
|
||||
cv::Mat ocv_ref = eyes[0]+eyes[1]+eyes[2];
|
||||
|
||||
EXPECT_EQ(0, cv::countNonZero(ocv_ref != out_mat));
|
||||
}
|
||||
|
||||
TEST(Fluid, MultipleReaders_SameLatency)
|
||||
{
|
||||
// in -> AddC -> a -> AddC -> b -> Add -> out
|
||||
// '--> AddC -> c -'
|
||||
//
|
||||
// b and c have the same skew
|
||||
|
||||
cv::GMat in;
|
||||
cv::GMat a = TAddCSimple::on(in, 1); // FIXME - align naming (G, non-G)
|
||||
cv::GMat b = TAddCSimple::on(a, 2);
|
||||
cv::GMat c = TAddCSimple::on(a, 3);
|
||||
cv::GMat out = TAddSimple::on(b, c);
|
||||
cv::GComputation comp(in, out);
|
||||
|
||||
const auto sz = cv::Size(32, 32);
|
||||
cv::Mat in_mat = cv::Mat::eye(sz, CV_8UC1);
|
||||
cv::Mat out_mat_gapi(sz, CV_8UC1);
|
||||
cv::Mat out_mat_ocv (sz, CV_8UC1);
|
||||
|
||||
// Run G-API
|
||||
auto cc = comp.compile(cv::descr_of(in_mat), cv::compile_args(fluidTestPackage));
|
||||
cc(in_mat, out_mat_gapi);
|
||||
|
||||
// Check with OpenCV
|
||||
cv::Mat tmp = in_mat + 1;
|
||||
out_mat_ocv = (tmp+2) + (tmp+3);
|
||||
EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv));
|
||||
}
|
||||
|
||||
TEST(Fluid, MultipleReaders_DifferentLatency)
|
||||
{
|
||||
// in1 -> AddC -> a -> AddC -------------> b -> Add -> out
|
||||
// '--------------> Add --> c -'
|
||||
// '--> Id7x7-> d -'
|
||||
//
|
||||
// b and c have different skew (due to latency introduced by Id7x7)
|
||||
// a is ready by multiple views with different latency.
|
||||
|
||||
cv::GMat in;
|
||||
cv::GMat a = TAddCSimple::on(in, 1); // FIXME - align naming (G, non-G)
|
||||
cv::GMat b = TAddCSimple::on(a, 2);
|
||||
cv::GMat d = TId7x7::on(a);
|
||||
cv::GMat c = TAddSimple::on(a, d);
|
||||
cv::GMat out = TAddSimple::on(b, c);
|
||||
cv::GComputation comp(in, out);
|
||||
|
||||
const auto sz = cv::Size(32, 32);
|
||||
cv::Mat in_mat = cv::Mat::eye(sz, CV_8UC1);
|
||||
cv::Mat out_mat_gapi(sz, CV_8UC1);
|
||||
|
||||
// Run G-API
|
||||
auto cc = comp.compile(cv::descr_of(in_mat), cv::compile_args(fluidTestPackage));
|
||||
cc(in_mat, out_mat_gapi);
|
||||
|
||||
// Check with OpenCV
|
||||
cv::Mat ocv_a = in_mat + 1;
|
||||
cv::Mat ocv_b = ocv_a + 2;
|
||||
cv::Mat ocv_d = ocv_a;
|
||||
cv::Mat ocv_c = ocv_a + ocv_d;
|
||||
cv::Mat out_mat_ocv = ocv_b + ocv_c;
|
||||
EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv));
|
||||
}
|
||||
|
||||
TEST(Fluid, DISABLED_MultipleOutputs)
|
||||
{
|
||||
// in -> AddC -> a -> AddC ------------------> out1
|
||||
// `--> Id7x7 --> b --> AddC -> out2
|
||||
|
||||
cv::GMat in;
|
||||
cv::GMat a = TAddCSimple::on(in, 1);
|
||||
cv::GMat b = TId7x7::on(a);
|
||||
cv::GMat out1 = TAddCSimple::on(a, 2);
|
||||
cv::GMat out2 = TAddCSimple::on(b, 7);
|
||||
cv::GComputation comp(cv::GIn(in), cv::GOut(out1, out2));
|
||||
|
||||
const auto sz = cv::Size(32, 32);
|
||||
cv::Mat in_mat = cv::Mat::eye(sz, CV_8UC1);
|
||||
cv::Mat out_mat_gapi1(sz, CV_8UC1), out_mat_gapi2(sz, CV_8UC1);
|
||||
cv::Mat out_mat_ocv1(sz, CV_8UC1), out_mat_ocv2(sz, CV_8UC1);
|
||||
|
||||
// Run G-API
|
||||
auto cc = comp.compile(cv::descr_of(in_mat), cv::compile_args(fluidTestPackage));
|
||||
cc(cv::gin(in_mat), cv::gout(out_mat_gapi1, out_mat_gapi2));
|
||||
|
||||
// Check with OpenCV
|
||||
out_mat_ocv1 = in_mat + 1 + 2;
|
||||
out_mat_ocv2 = in_mat + 1 + 7;
|
||||
EXPECT_EQ(0, cv::countNonZero(out_mat_gapi1 != out_mat_ocv1));
|
||||
EXPECT_EQ(0, cv::countNonZero(out_mat_gapi2 != out_mat_ocv2));
|
||||
}
|
||||
|
||||
TEST(Fluid, EmptyOutputMatTest)
|
||||
{
|
||||
cv::GMat in;
|
||||
cv::GMat out = TAddCSimple::on(in, 2);
|
||||
cv::GComputation c(in, out);
|
||||
|
||||
cv::Mat in_mat = cv::Mat::eye(cv::Size(32, 24), CV_8UC1);
|
||||
cv::Mat out_mat;
|
||||
|
||||
auto cc = c.compile(cv::descr_of(in_mat), cv::compile_args(fluidTestPackage));
|
||||
|
||||
cc(in_mat, out_mat);
|
||||
EXPECT_EQ(CV_8UC1, out_mat.type());
|
||||
EXPECT_EQ(32, out_mat.cols);
|
||||
EXPECT_EQ(24, out_mat.rows);
|
||||
EXPECT_TRUE(out_mat.ptr() != nullptr);
|
||||
}
|
||||
|
||||
struct LPISequenceTest : public TestWithParam<int>{};
|
||||
TEST_P(LPISequenceTest, DISABLED_LPISequenceTest)
|
||||
{
|
||||
// in -> AddC -> a -> Blur (2lpi) -> out
|
||||
|
||||
int kernelSize = GetParam();
|
||||
cv::GMat in;
|
||||
cv::GMat a = TAddCSimple::on(in, 1);
|
||||
auto blur = kernelSize == 3 ? &TBlur3x3_2lpi::on : &TBlur5x5_2lpi::on;
|
||||
cv::GMat out = blur(a, cv::BORDER_CONSTANT, cv::Scalar(0));
|
||||
cv::GComputation comp(cv::GIn(in), cv::GOut(out));
|
||||
|
||||
const auto sz = cv::Size(8, 10);
|
||||
cv::Mat in_mat = cv::Mat::eye(sz, CV_8UC1);
|
||||
cv::Mat out_mat_gapi(sz, CV_8UC1);
|
||||
cv::Mat out_mat_ocv(sz, CV_8UC1);
|
||||
|
||||
// Run G-API
|
||||
auto cc = comp.compile(cv::descr_of(in_mat), cv::compile_args(fluidTestPackage));
|
||||
cc(cv::gin(in_mat), cv::gout(out_mat_gapi));
|
||||
|
||||
// Check with OpenCV
|
||||
cv::blur(in_mat + 1, out_mat_ocv, {kernelSize,kernelSize}, {-1,-1}, cv::BORDER_CONSTANT);
|
||||
EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv));
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(Fluid, LPISequenceTest,
|
||||
Values(3, 5));
|
||||
|
||||
struct InputImageBorderTest : public TestWithParam <std::tuple<int, int>> {};
|
||||
TEST_P(InputImageBorderTest, InputImageBorderTest)
|
||||
{
|
||||
cv::Size sz_in = { 320, 240 };
|
||||
|
||||
int ks = 0;
|
||||
int borderType = 0;
|
||||
std::tie(ks, borderType) = GetParam();
|
||||
cv::Mat in_mat1(sz_in, CV_8UC1);
|
||||
cv::Scalar mean = cv::Scalar(127.0f);
|
||||
cv::Scalar stddev = cv::Scalar(40.f);
|
||||
|
||||
cv::randn(in_mat1, mean, stddev);
|
||||
|
||||
cv::Size kernelSize = {ks, ks};
|
||||
cv::Point anchor = {-1, -1};
|
||||
cv::Scalar borderValue(0);
|
||||
|
||||
auto gblur = ks == 3 ? &TBlur3x3::on : &TBlur5x5::on;
|
||||
|
||||
GMat in;
|
||||
auto out = gblur(in, borderType, borderValue);
|
||||
|
||||
Mat out_mat_gapi = Mat::zeros(sz_in, CV_8UC1);
|
||||
|
||||
GComputation c(GIn(in), GOut(out));
|
||||
auto cc = c.compile(descr_of(in_mat1), cv::compile_args(fluidTestPackage));
|
||||
cc(gin(in_mat1), gout(out_mat_gapi));
|
||||
|
||||
cv::Mat out_mat_ocv = Mat::zeros(sz_in, CV_8UC1);
|
||||
cv::blur(in_mat1, out_mat_ocv, kernelSize, anchor, borderType);
|
||||
|
||||
EXPECT_EQ(0, countNonZero(out_mat_ocv != out_mat_gapi));
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(Fluid, InputImageBorderTest,
|
||||
Combine(Values(3, 5),
|
||||
Values(BORDER_CONSTANT, BORDER_REPLICATE, BORDER_REFLECT_101)));
|
||||
|
||||
struct SequenceOfBlursTest : public TestWithParam <std::tuple<int>> {};
|
||||
TEST_P(SequenceOfBlursTest, Test)
|
||||
{
|
||||
cv::Size sz_in = { 320, 240 };
|
||||
|
||||
int borderType = 0;;
|
||||
std::tie(borderType) = GetParam();
|
||||
cv::Mat in_mat(sz_in, CV_8UC1);
|
||||
cv::Scalar mean = cv::Scalar(127.0f);
|
||||
cv::Scalar stddev = cv::Scalar(40.f);
|
||||
|
||||
cv::randn(in_mat, mean, stddev);
|
||||
|
||||
cv::Point anchor = {-1, -1};
|
||||
cv::Scalar borderValue(0);
|
||||
|
||||
GMat in;
|
||||
auto mid = TBlur3x3::on(in, borderType, borderValue);
|
||||
auto out = TBlur5x5::on(mid, borderType, borderValue);
|
||||
|
||||
Mat out_mat_gapi = Mat::zeros(sz_in, CV_8UC1);
|
||||
|
||||
GComputation c(GIn(in), GOut(out));
|
||||
auto cc = c.compile(descr_of(in_mat), cv::compile_args(fluidTestPackage));
|
||||
cc(gin(in_mat), gout(out_mat_gapi));
|
||||
|
||||
cv::Mat mid_mat_ocv = Mat::zeros(sz_in, CV_8UC1);
|
||||
cv::Mat out_mat_ocv = Mat::zeros(sz_in, CV_8UC1);
|
||||
cv::blur(in_mat, mid_mat_ocv, {3,3}, anchor, borderType);
|
||||
cv::blur(mid_mat_ocv, out_mat_ocv, {5,5}, anchor, borderType);
|
||||
|
||||
EXPECT_EQ(0, countNonZero(out_mat_ocv != out_mat_gapi));
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(Fluid, SequenceOfBlursTest,
|
||||
Values(BORDER_CONSTANT, BORDER_REPLICATE, BORDER_REFLECT_101));
|
||||
|
||||
struct TwoBlursTest : public TestWithParam <std::tuple<int, int, int, int, int, int, bool>> {};
|
||||
TEST_P(TwoBlursTest, Test)
|
||||
{
|
||||
cv::Size sz_in = { 320, 240 };
|
||||
|
||||
int kernelSize1 = 0, kernelSize2 = 0;
|
||||
int borderType1 = -1, borderType2 = -1;
|
||||
cv::Scalar borderValue1{}, borderValue2{};
|
||||
bool readFromInput = false;
|
||||
std::tie(kernelSize1, borderType1, borderValue1, kernelSize2, borderType2, borderValue2, readFromInput) = GetParam();
|
||||
cv::Mat in_mat(sz_in, CV_8UC1);
|
||||
cv::Scalar mean = cv::Scalar(127.0f);
|
||||
cv::Scalar stddev = cv::Scalar(40.f);
|
||||
|
||||
cv::randn(in_mat, mean, stddev);
|
||||
|
||||
cv::Point anchor = {-1, -1};
|
||||
|
||||
auto blur1 = kernelSize1 == 3 ? &TBlur3x3::on : TBlur5x5::on;
|
||||
auto blur2 = kernelSize2 == 3 ? &TBlur3x3::on : TBlur5x5::on;
|
||||
|
||||
GMat in, out1, out2;
|
||||
if (readFromInput)
|
||||
{
|
||||
out1 = blur1(in, borderType1, borderValue1);
|
||||
out2 = blur2(in, borderType2, borderValue2);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto mid = TAddCSimple::on(in, 0);
|
||||
out1 = blur1(mid, borderType1, borderValue1);
|
||||
out2 = blur2(mid, borderType2, borderValue2);
|
||||
}
|
||||
|
||||
Mat out_mat_gapi1 = Mat::zeros(sz_in, CV_8UC1);
|
||||
Mat out_mat_gapi2 = Mat::zeros(sz_in, CV_8UC1);
|
||||
|
||||
GComputation c(GIn(in), GOut(out1, out2));
|
||||
auto cc = c.compile(descr_of(in_mat), cv::compile_args(fluidTestPackage));
|
||||
cc(gin(in_mat), gout(out_mat_gapi1, out_mat_gapi2));
|
||||
|
||||
cv::Mat out_mat_ocv1 = Mat::zeros(sz_in, CV_8UC1);
|
||||
cv::Mat out_mat_ocv2 = Mat::zeros(sz_in, CV_8UC1);
|
||||
cv::blur(in_mat, out_mat_ocv1, {kernelSize1, kernelSize1}, anchor, borderType1);
|
||||
cv::blur(in_mat, out_mat_ocv2, {kernelSize2, kernelSize2}, anchor, borderType2);
|
||||
|
||||
EXPECT_EQ(0, countNonZero(out_mat_ocv1 != out_mat_gapi1));
|
||||
EXPECT_EQ(0, countNonZero(out_mat_ocv2 != out_mat_gapi2));
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(Fluid, TwoBlursTest,
|
||||
Combine(Values(3, 5),
|
||||
Values(cv::BORDER_CONSTANT, cv::BORDER_REPLICATE, cv::BORDER_REFLECT_101),
|
||||
Values(0),
|
||||
Values(3, 5),
|
||||
Values(cv::BORDER_CONSTANT, cv::BORDER_REPLICATE, cv::BORDER_REFLECT_101),
|
||||
Values(0),
|
||||
testing::Bool())); // Read from input directly or place a copy node at start
|
||||
|
||||
struct TwoReadersTest : public TestWithParam <std::tuple<int, int, int, bool>> {};
|
||||
TEST_P(TwoReadersTest, Test)
|
||||
{
|
||||
cv::Size sz_in = { 320, 240 };
|
||||
|
||||
int kernelSize = 0;
|
||||
int borderType = -1;
|
||||
cv::Scalar borderValue;
|
||||
bool readFromInput = false;
|
||||
std::tie(kernelSize, borderType, borderValue, readFromInput) = GetParam();
|
||||
cv::Mat in_mat(sz_in, CV_8UC1);
|
||||
cv::Scalar mean = cv::Scalar(127.0f);
|
||||
cv::Scalar stddev = cv::Scalar(40.f);
|
||||
|
||||
cv::randn(in_mat, mean, stddev);
|
||||
|
||||
cv::Point anchor = {-1, -1};
|
||||
|
||||
auto blur = kernelSize == 3 ? &TBlur3x3::on : TBlur5x5::on;
|
||||
|
||||
GMat in, out1, out2;
|
||||
if (readFromInput)
|
||||
{
|
||||
out1 = TAddCSimple::on(in, 0);
|
||||
out2 = blur(in, borderType, borderValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto mid = TAddCSimple::on(in, 0);
|
||||
out1 = TAddCSimple::on(mid, 0);
|
||||
out2 = blur(mid, borderType, borderValue);
|
||||
}
|
||||
|
||||
Mat out_mat_gapi1 = Mat::zeros(sz_in, CV_8UC1);
|
||||
Mat out_mat_gapi2 = Mat::zeros(sz_in, CV_8UC1);
|
||||
|
||||
GComputation c(GIn(in), GOut(out1, out2));
|
||||
auto cc = c.compile(descr_of(in_mat), cv::compile_args(fluidTestPackage));
|
||||
cc(gin(in_mat), gout(out_mat_gapi1, out_mat_gapi2));
|
||||
|
||||
cv::Mat out_mat_ocv1 = Mat::zeros(sz_in, CV_8UC1);
|
||||
cv::Mat out_mat_ocv2 = Mat::zeros(sz_in, CV_8UC1);
|
||||
out_mat_ocv1 = in_mat;
|
||||
cv::blur(in_mat, out_mat_ocv2, {kernelSize, kernelSize}, anchor, borderType);
|
||||
|
||||
EXPECT_EQ(0, countNonZero(out_mat_ocv1 != out_mat_gapi1));
|
||||
EXPECT_EQ(0, countNonZero(out_mat_ocv2 != out_mat_gapi2));
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(Fluid, TwoReadersTest,
|
||||
Combine(Values(3, 5),
|
||||
Values(cv::BORDER_CONSTANT, cv::BORDER_REPLICATE, cv::BORDER_REFLECT_101),
|
||||
Values(0),
|
||||
testing::Bool())); // Read from input directly or place a copy node at start
|
||||
|
||||
TEST(FluidTwoIslands, SanityTest)
|
||||
{
|
||||
cv::Size sz_in{8,8};
|
||||
|
||||
GMat in1, in2;
|
||||
auto out1 = TAddScalar::on(in1, {0});
|
||||
auto out2 = TAddScalar::on(in2, {0});
|
||||
|
||||
cv::Mat in_mat1(sz_in, CV_8UC1);
|
||||
cv::Mat in_mat2(sz_in, CV_8UC1);
|
||||
cv::Scalar mean = cv::Scalar(127.0f);
|
||||
cv::Scalar stddev = cv::Scalar(40.f);
|
||||
|
||||
cv::randn(in_mat1, mean, stddev);
|
||||
cv::randn(in_mat2, mean, stddev);
|
||||
|
||||
Mat out_mat1 = Mat::zeros(sz_in, CV_8UC1);
|
||||
Mat out_mat2 = Mat::zeros(sz_in, CV_8UC1);
|
||||
|
||||
GComputation c(GIn(in1, in2), GOut(out1, out2));
|
||||
EXPECT_NO_THROW(c.apply(gin(in_mat1, in_mat2), gout(out_mat1, out_mat2), cv::compile_args(fluidTestPackage)));
|
||||
EXPECT_EQ(0, countNonZero(in_mat1 != out_mat1));
|
||||
EXPECT_EQ(0, countNonZero(in_mat2 != out_mat2));
|
||||
}
|
||||
|
||||
} // namespace opencv_test
|
||||
@@ -0,0 +1,434 @@
|
||||
// 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 <iomanip>
|
||||
#include "gapi_fluid_test_kernels.hpp"
|
||||
#include <opencv2/gapi/core.hpp>
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace gapi_test_kernels
|
||||
{
|
||||
|
||||
GAPI_FLUID_KERNEL(FAddSimple, TAddSimple, false)
|
||||
{
|
||||
static const int Window = 1;
|
||||
|
||||
static void run(const cv::gapi::fluid::View &a,
|
||||
const cv::gapi::fluid::View &b,
|
||||
cv::gapi::fluid::Buffer &o)
|
||||
{
|
||||
// std::cout << "AddSimple {{{\n";
|
||||
// std::cout << " a - "; a.debug(std::cout);
|
||||
// std::cout << " b - "; b.debug(std::cout);
|
||||
// std::cout << " o - "; o.debug(std::cout);
|
||||
|
||||
const uint8_t* in1 = a.InLine<uint8_t>(0);
|
||||
const uint8_t* in2 = b.InLine<uint8_t>(0);
|
||||
uint8_t* out = o.OutLine<uint8_t>();
|
||||
|
||||
// std::cout << "a: ";
|
||||
// for (int i = 0, w = a.length(); i < w; i++)
|
||||
// {
|
||||
// std::cout << std::setw(4) << int(in1[i]);
|
||||
// }
|
||||
// std::cout << "\n";
|
||||
|
||||
// std::cout << "b: ";
|
||||
// for (int i = 0, w = a.length(); i < w; i++)
|
||||
// {
|
||||
// std::cout << std::setw(4) << int(in2[i]);
|
||||
// }
|
||||
// std::cout << "\n";
|
||||
|
||||
for (int i = 0, w = a.length(); i < w; i++)
|
||||
{
|
||||
out[i] = in1[i] + in2[i];
|
||||
}
|
||||
|
||||
// std::cout << "}}} " << std::endl;;
|
||||
}
|
||||
};
|
||||
|
||||
GAPI_FLUID_KERNEL(FAddCSimple, TAddCSimple, false)
|
||||
{
|
||||
static const int Window = 1;
|
||||
static const int LPI = 2;
|
||||
|
||||
static void run(const cv::gapi::fluid::View &in,
|
||||
const int cval,
|
||||
cv::gapi::fluid::Buffer &out)
|
||||
{
|
||||
for (int l = 0, lpi = out.lpi(); l < lpi; l++)
|
||||
{
|
||||
const uint8_t* in_row = in .InLine <uint8_t>(l);
|
||||
uint8_t* out_row = out.OutLine<uint8_t>(l);
|
||||
//std::cout << "l=" << l << ": ";
|
||||
for (int i = 0, w = in.length(); i < w; i++)
|
||||
{
|
||||
//std::cout << std::setw(4) << int(in_row[i]);
|
||||
out_row[i] = static_cast<uint8_t>(in_row[i] + cval);
|
||||
}
|
||||
//std::cout << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
GAPI_FLUID_KERNEL(FAddScalar, TAddScalar, false)
|
||||
{
|
||||
static const int Window = 1;
|
||||
static const int LPI = 2;
|
||||
|
||||
static void run(const cv::gapi::fluid::View &in,
|
||||
const cv::Scalar &cval,
|
||||
cv::gapi::fluid::Buffer &out)
|
||||
{
|
||||
for (int l = 0, lpi = out.lpi(); l < lpi; l++)
|
||||
{
|
||||
const uint8_t* in_row = in .InLine <uint8_t>(l);
|
||||
uint8_t* out_row = out.OutLine<uint8_t>(l);
|
||||
std::cout << "l=" << l << ": ";
|
||||
for (int i = 0, w = in.length(); i < w; i++)
|
||||
{
|
||||
std::cout << std::setw(4) << int(in_row[i]);
|
||||
out_row[i] = static_cast<uint8_t>(in_row[i] + cval[0]);
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
GAPI_FLUID_KERNEL(FAddScalarToMat, TAddScalarToMat, false)
|
||||
{
|
||||
static const int Window = 1;
|
||||
static const int LPI = 2;
|
||||
|
||||
static void run(const cv::Scalar &cval,
|
||||
const cv::gapi::fluid::View &in,
|
||||
cv::gapi::fluid::Buffer &out)
|
||||
{
|
||||
for (int l = 0, lpi = out.lpi(); l < lpi; l++)
|
||||
{
|
||||
const uint8_t* in_row = in .InLine <uint8_t>(l);
|
||||
uint8_t* out_row = out.OutLine<uint8_t>(l);
|
||||
std::cout << "l=" << l << ": ";
|
||||
for (int i = 0, w = in.length(); i < w; i++)
|
||||
{
|
||||
std::cout << std::setw(4) << int(in_row[i]);
|
||||
out_row[i] = static_cast<uint8_t>(in_row[i] + cval[0]);
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template<int kernelSize, int lpi = 1>
|
||||
static void runBlur(const cv::gapi::fluid::View& src, cv::gapi::fluid::Buffer& dst)
|
||||
{
|
||||
const auto borderSize = (kernelSize - 1) / 2;
|
||||
const unsigned char* ins[kernelSize];
|
||||
|
||||
for (int l = 0; l < lpi; l++)
|
||||
{
|
||||
for (int i = 0; i < kernelSize; i++)
|
||||
{
|
||||
ins[i] = src.InLine<unsigned char>(i - borderSize + l);
|
||||
}
|
||||
|
||||
auto out = dst.OutLine<unsigned char>(l);
|
||||
const auto width = dst.length();
|
||||
|
||||
for (int w = 0; w < width; w++)
|
||||
{
|
||||
float res = 0.0f;
|
||||
for (int i = 0; i < kernelSize; i++)
|
||||
{
|
||||
for (int j = -borderSize; j < borderSize + 1; j++)
|
||||
{
|
||||
res += ins[i][w+j];
|
||||
}
|
||||
}
|
||||
out[w] = static_cast<unsigned char>(std::rint(res / (kernelSize * kernelSize)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GAPI_FLUID_KERNEL(FBlur1x1, TBlur1x1, false)
|
||||
{
|
||||
static const int Window = 1;
|
||||
|
||||
static void run(const cv::gapi::fluid::View &src, int /*borderType*/,
|
||||
cv::Scalar /*borderValue*/, cv::gapi::fluid::Buffer &dst)
|
||||
{
|
||||
runBlur<Window>(src, dst);
|
||||
}
|
||||
};
|
||||
|
||||
GAPI_FLUID_KERNEL(FBlur3x3, TBlur3x3, false)
|
||||
{
|
||||
static const int Window = 3;
|
||||
|
||||
static void run(const cv::gapi::fluid::View &src, int /*borderType*/,
|
||||
cv::Scalar /*borderValue*/, cv::gapi::fluid::Buffer &dst)
|
||||
{
|
||||
runBlur<Window>(src, dst);
|
||||
}
|
||||
|
||||
static cv::gapi::fluid::Border getBorder(const cv::GMatDesc &/*src*/, int borderType, cv::Scalar borderValue)
|
||||
{
|
||||
return { borderType, to_own(borderValue)};
|
||||
}
|
||||
};
|
||||
|
||||
GAPI_FLUID_KERNEL(FBlur5x5, TBlur5x5, false)
|
||||
{
|
||||
static const int Window = 5;
|
||||
|
||||
static void run(const cv::gapi::fluid::View &src, int /*borderType*/,
|
||||
cv::Scalar /*borderValue*/, cv::gapi::fluid::Buffer &dst)
|
||||
{
|
||||
runBlur<Window>(src, dst);
|
||||
}
|
||||
|
||||
static cv::gapi::fluid::Border getBorder(const cv::GMatDesc &/*src*/, int borderType, cv::Scalar borderValue)
|
||||
{
|
||||
return { borderType, to_own(borderValue)};
|
||||
}
|
||||
};
|
||||
|
||||
GAPI_FLUID_KERNEL(FBlur3x3_2lpi, TBlur3x3_2lpi, false)
|
||||
{
|
||||
static const int Window = 3;
|
||||
static const int LPI = 2;
|
||||
|
||||
static void run(const cv::gapi::fluid::View &src, int /*borderType*/,
|
||||
cv::Scalar /*borderValue*/, cv::gapi::fluid::Buffer &dst)
|
||||
{
|
||||
runBlur<Window, LPI>(src, dst);
|
||||
}
|
||||
|
||||
static cv::gapi::fluid::Border getBorder(const cv::GMatDesc &/*src*/, int borderType, cv::Scalar borderValue)
|
||||
{
|
||||
return { borderType, to_own(borderValue)};
|
||||
}
|
||||
};
|
||||
|
||||
GAPI_FLUID_KERNEL(FBlur5x5_2lpi, TBlur5x5_2lpi, false)
|
||||
{
|
||||
static const int Window = 5;
|
||||
static const int LPI = 2;
|
||||
|
||||
static void run(const cv::gapi::fluid::View &src, int /*borderType*/,
|
||||
cv::Scalar /*borderValue*/, cv::gapi::fluid::Buffer &dst)
|
||||
{
|
||||
runBlur<Window, LPI>(src, dst);
|
||||
}
|
||||
|
||||
static cv::gapi::fluid::Border getBorder(const cv::GMatDesc &/*src*/, int borderType, cv::Scalar borderValue)
|
||||
{
|
||||
return { borderType, to_own(borderValue )};
|
||||
}
|
||||
};
|
||||
|
||||
GAPI_FLUID_KERNEL(FIdentity, TId, false)
|
||||
{
|
||||
static const int Window = 3;
|
||||
|
||||
static void run(const cv::gapi::fluid::View &a,
|
||||
cv::gapi::fluid::Buffer &o)
|
||||
{
|
||||
const uint8_t* in[3] = {
|
||||
a.InLine<uint8_t>(-1),
|
||||
a.InLine<uint8_t>( 0),
|
||||
a.InLine<uint8_t>(+1)
|
||||
};
|
||||
uint8_t* out = o.OutLine<uint8_t>();
|
||||
|
||||
// ReadFunction3x3(in, a.length());
|
||||
for (int i = 0, w = a.length(); i < w; i++)
|
||||
{
|
||||
out[i] = in[1][i];
|
||||
}
|
||||
}
|
||||
|
||||
static gapi::fluid::Border getBorder(const cv::GMatDesc &)
|
||||
{
|
||||
return { cv::BORDER_REPLICATE, cv::gapi::own::Scalar{} };
|
||||
}
|
||||
};
|
||||
|
||||
GAPI_FLUID_KERNEL(FId7x7, TId7x7, false)
|
||||
{
|
||||
static const int Window = 7;
|
||||
static const int LPI = 2;
|
||||
|
||||
static void run(const cv::gapi::fluid::View &a,
|
||||
cv::gapi::fluid::Buffer &o)
|
||||
{
|
||||
for (int l = 0, lpi = o.lpi(); l < lpi; l++)
|
||||
{
|
||||
const uint8_t* in[Window] = {
|
||||
a.InLine<uint8_t>(-3 + l),
|
||||
a.InLine<uint8_t>(-2 + l),
|
||||
a.InLine<uint8_t>(-1 + l),
|
||||
a.InLine<uint8_t>( 0 + l),
|
||||
a.InLine<uint8_t>(+1 + l),
|
||||
a.InLine<uint8_t>(+2 + l),
|
||||
a.InLine<uint8_t>(+3 + l),
|
||||
};
|
||||
uint8_t* out = o.OutLine<uint8_t>(l);
|
||||
|
||||
// std::cout << "Id7x7 " << l << " of " << lpi << " {{{\n";
|
||||
// std::cout << " a - "; a.debug(std::cout);
|
||||
// std::cout << " o - "; o.debug(std::cout);
|
||||
// std::cout << "}}} " << std::endl;;
|
||||
|
||||
// // std::cout << "Id7x7 at " << a.y() << "/L" << l << " {{{" << std::endl;
|
||||
// for (int j = 0; j < Window; j++)
|
||||
// {
|
||||
// // std::cout << std::setw(2) << j-(Window-1)/2 << ": ";
|
||||
// for (int i = 0, w = a.length(); i < w; i++)
|
||||
// std::cout << std::setw(4) << int(in[j][i]);
|
||||
// std::cout << std::endl;
|
||||
// }
|
||||
// std::cout << "}}}" << std::endl;
|
||||
|
||||
for (int i = 0, w = a.length(); i < w; i++)
|
||||
out[i] = in[(Window-1)/2][i];
|
||||
}
|
||||
}
|
||||
|
||||
static cv::gapi::fluid::Border getBorder(const cv::GMatDesc&/* src*/)
|
||||
{
|
||||
return { cv::BORDER_REPLICATE, cv::gapi::own::Scalar{} };
|
||||
}
|
||||
};
|
||||
|
||||
GAPI_FLUID_KERNEL(FPlusRow0, TPlusRow0, true)
|
||||
{
|
||||
static const int Window = 1;
|
||||
|
||||
static void initScratch(const cv::GMatDesc &in,
|
||||
cv::gapi::fluid::Buffer &scratch)
|
||||
{
|
||||
cv::Size scratch_size{in.size.width, 1};
|
||||
cv::gapi::fluid::Buffer buffer(in.withSize(scratch_size));
|
||||
scratch = std::move(buffer);
|
||||
}
|
||||
|
||||
static void resetScratch(cv::gapi::fluid::Buffer &scratch)
|
||||
{
|
||||
// FIXME: only 1 line can be used!
|
||||
uint8_t* out_row = scratch.OutLine<uint8_t>();
|
||||
for (int i = 0, w = scratch.length(); i < w; i++)
|
||||
{
|
||||
out_row[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void run(const cv::gapi::fluid::View &in,
|
||||
cv::gapi::fluid::Buffer &out,
|
||||
cv::gapi::fluid::Buffer &scratch)
|
||||
{
|
||||
const uint8_t* in_row = in .InLine <uint8_t>(0);
|
||||
uint8_t* out_row = out .OutLine<uint8_t>();
|
||||
uint8_t* tmp_row = scratch.OutLine<uint8_t>();
|
||||
|
||||
if (in.y() == 0)
|
||||
{
|
||||
// Copy 1st row to scratch buffer
|
||||
for (int i = 0, w = in.length(); i < w; i++)
|
||||
{
|
||||
out_row[i] = in_row[i];
|
||||
tmp_row[i] = in_row[i];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Output is 1st row + in
|
||||
for (int i = 0, w = in.length(); i < w; i++)
|
||||
{
|
||||
out_row[i] = in_row[i] + tmp_row[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
GAPI_FLUID_KERNEL(FTestSplit3, cv::gapi::core::GSplit3, false)
|
||||
{
|
||||
static const int Window = 1;
|
||||
|
||||
static void run(const cv::gapi::fluid::View &in,
|
||||
cv::gapi::fluid::Buffer &o1,
|
||||
cv::gapi::fluid::Buffer &o2,
|
||||
cv::gapi::fluid::Buffer &o3)
|
||||
{
|
||||
// std::cout << "Split3 {{{\n";
|
||||
// std::cout << " a - "; in.debug(std::cout);
|
||||
// std::cout << " 1 - "; o1.debug(std::cout);
|
||||
// std::cout << " 2 - "; o2.debug(std::cout);
|
||||
// std::cout << " 3 - "; o3.debug(std::cout);
|
||||
// std::cout << "}}} " << std::endl;;
|
||||
|
||||
const uint8_t* in_rgb = in.InLine<uint8_t>(0);
|
||||
uint8_t* out_r = o1.OutLine<uint8_t>();
|
||||
uint8_t* out_g = o2.OutLine<uint8_t>();
|
||||
uint8_t* out_b = o3.OutLine<uint8_t>();
|
||||
|
||||
for (int i = 0, w = in.length(); i < w; i++)
|
||||
{
|
||||
out_r[i] = in_rgb[3*i];
|
||||
out_g[i] = in_rgb[3*i+1];
|
||||
out_b[i] = in_rgb[3*i+2];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
GAPI_FLUID_KERNEL(FSum2MatsAndScalar, TSum2MatsAndScalar, false)
|
||||
{
|
||||
static const int Window = 1;
|
||||
static const int LPI = 2;
|
||||
|
||||
static void run(const cv::gapi::fluid::View &a,
|
||||
const cv::Scalar &cval,
|
||||
const cv::gapi::fluid::View &b,
|
||||
cv::gapi::fluid::Buffer &out)
|
||||
{
|
||||
for (int l = 0, lpi = out.lpi(); l < lpi; l++)
|
||||
{
|
||||
const uint8_t* in_row1 = a .InLine <uint8_t>(l);
|
||||
const uint8_t* in_row2 = b .InLine <uint8_t>(l);
|
||||
uint8_t* out_row = out.OutLine<uint8_t>(l);
|
||||
std::cout << "l=" << l << ": ";
|
||||
for (int i = 0, w = a.length(); i < w; i++)
|
||||
{
|
||||
std::cout << std::setw(4) << int(in_row1[i]);
|
||||
std::cout << std::setw(4) << int(in_row2[i]);
|
||||
out_row[i] = static_cast<uint8_t>(in_row1[i] + in_row2[i] + cval[0]);
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
cv::gapi::GKernelPackage fluidTestPackage = cv::gapi::kernels
|
||||
<FAddSimple
|
||||
,FAddCSimple
|
||||
,FAddScalar
|
||||
,FAddScalarToMat
|
||||
,FBlur1x1
|
||||
,FBlur3x3
|
||||
,FBlur5x5
|
||||
,FBlur3x3_2lpi
|
||||
,FBlur5x5_2lpi
|
||||
,FIdentity
|
||||
,FId7x7
|
||||
,FPlusRow0
|
||||
,FSum2MatsAndScalar
|
||||
,FTestSplit3
|
||||
>();
|
||||
} // namespace gapi_test_kernels
|
||||
} // namespace cv
|
||||
@@ -0,0 +1,105 @@
|
||||
// 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 GAPI_FLUID_TEST_KERNELS_HPP
|
||||
#define GAPI_FLUID_TEST_KERNELS_HPP
|
||||
|
||||
#include "opencv2/gapi/fluid/gfluidkernel.hpp"
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace gapi_test_kernels
|
||||
{
|
||||
|
||||
G_TYPED_KERNEL(TAddSimple, <GMat(GMat, GMat)>, "test.fluid.add_simple") {
|
||||
static cv::GMatDesc outMeta(cv::GMatDesc a, cv::GMatDesc) {
|
||||
return a;
|
||||
}
|
||||
};
|
||||
|
||||
G_TYPED_KERNEL(TAddCSimple, <GMat(GMat,int)>, "test.fluid.addc_simple")
|
||||
{
|
||||
static GMatDesc outMeta(const cv::GMatDesc &in, int) {
|
||||
return in;
|
||||
}
|
||||
};
|
||||
|
||||
G_TYPED_KERNEL(TAddScalar, <GMat(GMat,GScalar)>, "test.fluid.addc_scalar")
|
||||
{
|
||||
static GMatDesc outMeta(const cv::GMatDesc &in, const cv::GScalarDesc&) {
|
||||
return in;
|
||||
}
|
||||
};
|
||||
|
||||
G_TYPED_KERNEL(TAddScalarToMat, <GMat(GScalar,GMat)>, "test.fluid.add_scalar_to_mat")
|
||||
{
|
||||
static GMatDesc outMeta(const cv::GScalarDesc&, const cv::GMatDesc &in) {
|
||||
return in;
|
||||
}
|
||||
};
|
||||
|
||||
G_TYPED_KERNEL(TBlur1x1, <GMat(GMat,int,Scalar)>, "org.opencv.imgproc.filters.blur1x1"){
|
||||
static GMatDesc outMeta(GMatDesc in, int, Scalar) {
|
||||
return in;
|
||||
}
|
||||
};
|
||||
|
||||
G_TYPED_KERNEL(TBlur3x3, <GMat(GMat,int,Scalar)>, "org.opencv.imgproc.filters.blur3x3"){
|
||||
static GMatDesc outMeta(GMatDesc in, int, Scalar) {
|
||||
return in;
|
||||
}
|
||||
};
|
||||
|
||||
G_TYPED_KERNEL(TBlur5x5, <GMat(GMat,int,Scalar)>, "org.opencv.imgproc.filters.blur5x5"){
|
||||
static GMatDesc outMeta(GMatDesc in, int, Scalar) {
|
||||
return in;
|
||||
}
|
||||
};
|
||||
|
||||
G_TYPED_KERNEL(TBlur3x3_2lpi, <GMat(GMat,int,Scalar)>, "org.opencv.imgproc.filters.blur3x3_2lpi"){
|
||||
static GMatDesc outMeta(GMatDesc in, int, Scalar) {
|
||||
return in;
|
||||
}
|
||||
};
|
||||
|
||||
G_TYPED_KERNEL(TBlur5x5_2lpi, <GMat(GMat,int,Scalar)>, "org.opencv.imgproc.filters.blur5x5_2lpi"){
|
||||
static GMatDesc outMeta(GMatDesc in, int, Scalar) {
|
||||
return in;
|
||||
}
|
||||
};
|
||||
|
||||
G_TYPED_KERNEL(TId, <GMat(GMat)>, "test.fluid.identity") {
|
||||
static cv::GMatDesc outMeta(cv::GMatDesc a) {
|
||||
return a;
|
||||
}
|
||||
};
|
||||
|
||||
G_TYPED_KERNEL(TId7x7, <GMat(GMat)>, "test.fluid.identity7x7") {
|
||||
static cv::GMatDesc outMeta(cv::GMatDesc a) {
|
||||
return a;
|
||||
}
|
||||
};
|
||||
|
||||
G_TYPED_KERNEL(TPlusRow0, <GMat(GMat)>, "test.fluid.plus_row0") {
|
||||
static cv::GMatDesc outMeta(cv::GMatDesc a) {
|
||||
return a;
|
||||
}
|
||||
};
|
||||
|
||||
G_TYPED_KERNEL(TSum2MatsAndScalar, <GMat(GMat,GScalar,GMat)>, "test.fluid.sum_2_mats_and_scalar")
|
||||
{
|
||||
static GMatDesc outMeta(const cv::GMatDesc &in, const cv::GScalarDesc&, const cv::GMatDesc&) {
|
||||
return in;
|
||||
}
|
||||
};
|
||||
|
||||
extern cv::gapi::GKernelPackage fluidTestPackage;
|
||||
|
||||
} // namespace gapi_test_kernels
|
||||
} // namespace cv
|
||||
|
||||
#endif // GAPI_FLUID_TEST_KERNELS_HPP
|
||||
@@ -0,0 +1,173 @@
|
||||
// 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"
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
static cv::GMat DemoCC(cv::GMat in, cv::GScalar scale)
|
||||
{
|
||||
return cv::gapi::medianBlur(in + in*scale, 3);
|
||||
}
|
||||
|
||||
struct GCompiledValidateMetaTyped: public ::testing::Test
|
||||
{
|
||||
cv::GComputationT<cv::GMat(cv::GMat,cv::GScalar)> m_cc;
|
||||
|
||||
GCompiledValidateMetaTyped() : m_cc(DemoCC)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
struct GCompiledValidateMetaUntyped: public ::testing::Test
|
||||
{
|
||||
cv::GMat in;
|
||||
cv::GScalar scale;
|
||||
cv::GComputation m_ucc;
|
||||
|
||||
GCompiledValidateMetaUntyped() : m_ucc(cv::GIn(in, scale),
|
||||
cv::GOut(DemoCC(in, scale)))
|
||||
{
|
||||
}
|
||||
};
|
||||
} // anonymous namespace
|
||||
|
||||
TEST_F(GCompiledValidateMetaTyped, ValidMeta)
|
||||
{
|
||||
cv::Mat in = cv::Mat::eye(cv::Size(128, 32), CV_8UC1);
|
||||
cv::Scalar sc(127);
|
||||
|
||||
auto f = m_cc.compile(cv::descr_of(in),
|
||||
cv::descr_of(sc));
|
||||
|
||||
// Correct operation when meta is exactly the same
|
||||
cv::Mat out;
|
||||
EXPECT_NO_THROW(f(in, sc, out));
|
||||
|
||||
// Correct operation on next invocation with same meta
|
||||
// taken from different input objects
|
||||
cv::Mat in2 = cv::Mat::zeros(cv::Size(128, 32), CV_8UC1);
|
||||
cv::Scalar sc2(64);
|
||||
cv::Mat out2;
|
||||
EXPECT_NO_THROW(f(in2, sc2, out2));
|
||||
}
|
||||
|
||||
TEST_F(GCompiledValidateMetaTyped, InvalidMeta)
|
||||
{
|
||||
auto f = m_cc.compile(cv::GMatDesc{CV_8U,1,cv::gapi::own::Size(64,32)},
|
||||
cv::empty_scalar_desc());
|
||||
|
||||
cv::Scalar sc(33);
|
||||
cv::Mat out;
|
||||
|
||||
// 3 channels intead 1
|
||||
cv::Mat in1 = cv::Mat::eye(cv::Size(64,32), CV_8UC3);
|
||||
EXPECT_THROW(f(in1, sc, out), std::logic_error);
|
||||
|
||||
// 32f intead 8u
|
||||
cv::Mat in2 = cv::Mat::eye(cv::Size(64,32), CV_32F);
|
||||
EXPECT_THROW(f(in2, sc, out), std::logic_error);
|
||||
|
||||
// 32x32 instead of 64x32
|
||||
cv::Mat in3 = cv::Mat::eye(cv::Size(32,32), CV_8UC1);
|
||||
EXPECT_THROW(f(in3, sc, out), std::logic_error);
|
||||
|
||||
// All is wrong
|
||||
cv::Mat in4 = cv::Mat::eye(cv::Size(128,64), CV_32FC3);
|
||||
EXPECT_THROW(f(in4, sc, out), std::logic_error);
|
||||
}
|
||||
|
||||
TEST_F(GCompiledValidateMetaUntyped, ValidMeta)
|
||||
{
|
||||
cv::Mat in1 = cv::Mat::eye(cv::Size(128, 32), CV_8UC1);
|
||||
cv::Scalar sc(127);
|
||||
|
||||
auto f = m_ucc.compile(cv::descr_of(in1),
|
||||
cv::descr_of(sc));
|
||||
|
||||
// Correct operation when meta is exactly the same
|
||||
cv::Mat out1;
|
||||
EXPECT_NO_THROW(f(cv::gin(in1, sc), cv::gout(out1)));
|
||||
|
||||
// Correct operation on next invocation with same meta
|
||||
// taken from different input objects
|
||||
cv::Mat in2 = cv::Mat::zeros(cv::Size(128, 32), CV_8UC1);
|
||||
cv::Scalar sc2(64);
|
||||
cv::Mat out2;
|
||||
EXPECT_NO_THROW(f(cv::gin(in2, sc2), cv::gout(out2)));
|
||||
}
|
||||
|
||||
TEST_F(GCompiledValidateMetaUntyped, InvalidMetaValues)
|
||||
{
|
||||
auto f = m_ucc.compile(cv::GMatDesc{CV_8U,1,cv::gapi::own::Size(64,32)},
|
||||
cv::empty_scalar_desc());
|
||||
|
||||
cv::Scalar sc(33);
|
||||
cv::Mat out;
|
||||
|
||||
// 3 channels intead 1
|
||||
cv::Mat in1 = cv::Mat::eye(cv::Size(64,32), CV_8UC3);
|
||||
EXPECT_THROW(f(cv::gin(in1, sc), cv::gout(out)), std::logic_error);
|
||||
|
||||
// 32f intead 8u
|
||||
cv::Mat in2 = cv::Mat::eye(cv::Size(64,32), CV_32F);
|
||||
EXPECT_THROW(f(cv::gin(in2, sc), cv::gout(out)), std::logic_error);
|
||||
|
||||
// 32x32 instead of 64x32
|
||||
cv::Mat in3 = cv::Mat::eye(cv::Size(32,32), CV_8UC1);
|
||||
EXPECT_THROW(f(cv::gin(in3, sc), cv::gout(out)), std::logic_error);
|
||||
|
||||
// All is wrong
|
||||
cv::Mat in4 = cv::Mat::eye(cv::Size(128,64), CV_32FC3);
|
||||
EXPECT_THROW(f(cv::gin(in4, sc), cv::gout(out)), std::logic_error);
|
||||
}
|
||||
|
||||
TEST_F(GCompiledValidateMetaUntyped, InvalidMetaShape)
|
||||
{
|
||||
auto f = m_ucc.compile(cv::GMatDesc{CV_8U,1,cv::gapi::own::Size(64,32)},
|
||||
cv::empty_scalar_desc());
|
||||
|
||||
cv::Mat in1 = cv::Mat::eye(cv::Size(64,32), CV_8UC1);
|
||||
cv::Scalar sc(33);
|
||||
cv::Mat out1;
|
||||
|
||||
// call as f(Mat,Mat) while f(Mat,Scalar) is expected
|
||||
EXPECT_THROW(f(cv::gin(in1, in1), cv::gout(out1)), std::logic_error);
|
||||
|
||||
// call as f(Scalar,Mat) while f(Mat,Scalar) is expected
|
||||
EXPECT_THROW(f(cv::gin(sc, in1), cv::gout(out1)), std::logic_error);
|
||||
|
||||
// call as f(Scalar,Scalar) while f(Mat,Scalar) is expected
|
||||
EXPECT_THROW(f(cv::gin(sc, sc), cv::gout(out1)), std::logic_error);
|
||||
}
|
||||
|
||||
TEST_F(GCompiledValidateMetaUntyped, InvalidMetaNumber)
|
||||
{
|
||||
auto f = m_ucc.compile(cv::GMatDesc{CV_8U,1,cv::Size(64,32)},
|
||||
cv::empty_scalar_desc());
|
||||
|
||||
cv::Mat in1 = cv::Mat::eye(cv::Size(64,32), CV_8UC1);
|
||||
cv::Scalar sc(33);
|
||||
cv::Mat out1, out2;
|
||||
|
||||
// call as f(Mat,Scalar,Scalar) while f(Mat,Scalar) is expected
|
||||
EXPECT_THROW(f(cv::gin(in1, sc, sc), cv::gout(out1)), std::logic_error);
|
||||
|
||||
// call as f(Scalar,Mat,Scalar) while f(Mat,Scalar) is expected
|
||||
EXPECT_THROW(f(cv::gin(sc, in1, sc), cv::gout(out1)), std::logic_error);
|
||||
|
||||
// call as f(Scalar) while f(Mat,Scalar) is expected
|
||||
EXPECT_THROW(f(cv::gin(sc), cv::gout(out1)), std::logic_error);
|
||||
|
||||
// call as f(Mat,Scalar,[out1],[out2]) while f(Mat,Scalar,[out]) is expected
|
||||
EXPECT_THROW(f(cv::gin(in1, sc), cv::gout(out1, out2)), std::logic_error);
|
||||
}
|
||||
|
||||
} // namespace opencv_test
|
||||
@@ -0,0 +1,68 @@
|
||||
// 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 "opencv2/gapi/cpu/gcpukernel.hpp"
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
G_TYPED_KERNEL(CustomResize, <cv::GMat(cv::GMat, cv::Size, double, double, int)>, "org.opencv.customk.resize")
|
||||
{
|
||||
static cv::GMatDesc outMeta(cv::GMatDesc in, cv::Size sz, double fx, double fy, int) {
|
||||
if (sz.width != 0 && sz.height != 0)
|
||||
{
|
||||
return in.withSize(to_own(sz));
|
||||
}
|
||||
else
|
||||
{
|
||||
GAPI_Assert(fx != 0. && fy != 0.);
|
||||
return in.withSize
|
||||
(cv::gapi::own::Size(static_cast<int>(std::round(in.size.width * fx)),
|
||||
static_cast<int>(std::round(in.size.height * fy))));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
GAPI_OCV_KERNEL(CustomResizeImpl, CustomResize)
|
||||
{
|
||||
static void run(const cv::Mat& in, cv::Size sz, double fx, double fy, int interp, cv::Mat &out)
|
||||
{
|
||||
cv::resize(in, out, sz, fx, fy, interp);
|
||||
}
|
||||
};
|
||||
|
||||
struct GComputationApplyTest: public ::testing::Test
|
||||
{
|
||||
cv::GMat in;
|
||||
cv::Mat in_mat;
|
||||
cv::Mat out_mat;
|
||||
cv::GComputation m_c;
|
||||
|
||||
GComputationApplyTest() : in_mat(300, 300, CV_8UC1),
|
||||
m_c(cv::GIn(in), cv::GOut(CustomResize::on(in, cv::Size(100, 100),
|
||||
0.0, 0.0, cv::INTER_LINEAR)))
|
||||
{
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
TEST_F(GComputationApplyTest, ThrowDontPassCustomKernel)
|
||||
{
|
||||
EXPECT_THROW(m_c.apply(in_mat, out_mat), std::logic_error);
|
||||
}
|
||||
|
||||
TEST_F(GComputationApplyTest, NoThrowPassCustomKernel)
|
||||
{
|
||||
const auto pkg = cv::gapi::kernels<CustomResizeImpl>();
|
||||
|
||||
ASSERT_NO_THROW(m_c.apply(in_mat, out_mat, cv::compile_args(pkg)));
|
||||
}
|
||||
|
||||
} // namespace opencv_test
|
||||
@@ -0,0 +1,202 @@
|
||||
// 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 "opencv2/gapi/cpu/gcpukernel.hpp"
|
||||
#include "gapi_mock_kernels.hpp"
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
G_TYPED_KERNEL(GClone, <GMat(GMat)>, "org.opencv.test.clone")
|
||||
{
|
||||
static GMatDesc outMeta(GMatDesc in) { return in; }
|
||||
|
||||
};
|
||||
|
||||
GAPI_OCV_KERNEL(GCloneImpl, GClone)
|
||||
{
|
||||
static void run(const cv::Mat& in, cv::Mat &out)
|
||||
{
|
||||
out = in.clone();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
TEST(KernelPackage, Create)
|
||||
{
|
||||
namespace J = Jupiter;
|
||||
auto pkg = cv::gapi::kernels<J::Foo, J::Bar, J::Baz>();
|
||||
EXPECT_EQ(3u, pkg.size());
|
||||
}
|
||||
|
||||
TEST(KernelPackage, Includes)
|
||||
{
|
||||
namespace J = Jupiter;
|
||||
auto pkg = cv::gapi::kernels<J::Foo, J::Bar, J::Baz>();
|
||||
EXPECT_TRUE (pkg.includes<J::Foo>());
|
||||
EXPECT_TRUE (pkg.includes<J::Bar>());
|
||||
EXPECT_TRUE (pkg.includes<J::Baz>());
|
||||
EXPECT_FALSE(pkg.includes<J::Qux>());
|
||||
}
|
||||
|
||||
TEST(KernelPackage, Include)
|
||||
{
|
||||
namespace J = Jupiter;
|
||||
auto pkg = cv::gapi::kernels<J::Foo, J::Bar, J::Baz>();
|
||||
EXPECT_FALSE(pkg.includes<J::Qux>());
|
||||
|
||||
pkg.include<J::Qux>();
|
||||
EXPECT_TRUE(pkg.includes<J::Qux>());
|
||||
}
|
||||
|
||||
TEST(KernelPackage, CreateHetero)
|
||||
{
|
||||
namespace J = Jupiter;
|
||||
namespace S = Saturn;
|
||||
auto pkg = cv::gapi::kernels<J::Foo, J::Bar, J::Baz, S::Qux>();
|
||||
EXPECT_EQ(4u, pkg.size());
|
||||
}
|
||||
|
||||
TEST(KernelPackage, IncludesHetero)
|
||||
{
|
||||
namespace J = Jupiter;
|
||||
namespace S = Saturn;
|
||||
auto pkg = cv::gapi::kernels<J::Foo, J::Bar, J::Baz, S::Qux>();
|
||||
EXPECT_TRUE (pkg.includes<J::Foo>());
|
||||
EXPECT_TRUE (pkg.includes<J::Bar>());
|
||||
EXPECT_TRUE (pkg.includes<J::Baz>());
|
||||
EXPECT_FALSE(pkg.includes<J::Qux>());
|
||||
EXPECT_TRUE (pkg.includes<S::Qux>());
|
||||
}
|
||||
|
||||
TEST(KernelPackage, IncludeHetero)
|
||||
{
|
||||
namespace J = Jupiter;
|
||||
namespace S = Saturn;
|
||||
auto pkg = cv::gapi::kernels<J::Foo, J::Bar, J::Baz>();
|
||||
EXPECT_FALSE(pkg.includes<J::Qux>());
|
||||
EXPECT_FALSE(pkg.includes<S::Qux>());
|
||||
|
||||
pkg.include<S::Qux>();
|
||||
EXPECT_FALSE(pkg.includes<J::Qux>());
|
||||
EXPECT_TRUE (pkg.includes<S::Qux>());
|
||||
}
|
||||
|
||||
TEST(KernelPackage, Unite_REPLACE_Full)
|
||||
{
|
||||
namespace J = Jupiter;
|
||||
namespace S = Saturn;
|
||||
auto j_pkg = cv::gapi::kernels<J::Foo, J::Bar, J::Baz>();
|
||||
auto s_pkg = cv::gapi::kernels<S::Foo, S::Bar, S::Baz>();
|
||||
auto u_pkg = cv::gapi::combine(j_pkg, s_pkg, cv::unite_policy::REPLACE);
|
||||
|
||||
EXPECT_EQ(3u, u_pkg.size());
|
||||
EXPECT_FALSE(u_pkg.includes<J::Foo>());
|
||||
EXPECT_FALSE(u_pkg.includes<J::Bar>());
|
||||
EXPECT_FALSE(u_pkg.includes<J::Baz>());
|
||||
EXPECT_TRUE (u_pkg.includes<S::Foo>());
|
||||
EXPECT_TRUE (u_pkg.includes<S::Bar>());
|
||||
EXPECT_TRUE (u_pkg.includes<S::Baz>());
|
||||
}
|
||||
|
||||
TEST(KernelPackage, Unite_REPLACE_Partial)
|
||||
{
|
||||
namespace J = Jupiter;
|
||||
namespace S = Saturn;
|
||||
auto j_pkg = cv::gapi::kernels<J::Foo, J::Bar>();
|
||||
auto s_pkg = cv::gapi::kernels<S::Bar>();
|
||||
auto u_pkg = cv::gapi::combine(j_pkg, s_pkg, cv::unite_policy::REPLACE);
|
||||
|
||||
EXPECT_EQ(2u, u_pkg.size());
|
||||
EXPECT_TRUE (u_pkg.includes<J::Foo>());
|
||||
EXPECT_FALSE(u_pkg.includes<J::Bar>());
|
||||
EXPECT_TRUE (u_pkg.includes<S::Bar>());
|
||||
}
|
||||
|
||||
TEST(KernelPackage, Unite_REPLACE_Append)
|
||||
{
|
||||
namespace J = Jupiter;
|
||||
namespace S = Saturn;
|
||||
auto j_pkg = cv::gapi::kernels<J::Foo, J::Bar>();
|
||||
auto s_pkg = cv::gapi::kernels<S::Qux>();
|
||||
auto u_pkg = cv::gapi::combine(j_pkg, s_pkg, cv::unite_policy::REPLACE);
|
||||
|
||||
EXPECT_EQ(3u, u_pkg.size());
|
||||
EXPECT_TRUE(u_pkg.includes<J::Foo>());
|
||||
EXPECT_TRUE(u_pkg.includes<J::Bar>());
|
||||
EXPECT_TRUE(u_pkg.includes<S::Qux>());
|
||||
}
|
||||
|
||||
TEST(KernelPackage, Unite_KEEP_AllDups)
|
||||
{
|
||||
namespace J = Jupiter;
|
||||
namespace S = Saturn;
|
||||
auto j_pkg = cv::gapi::kernels<J::Foo, J::Bar, J::Baz>();
|
||||
auto s_pkg = cv::gapi::kernels<S::Foo, S::Bar, S::Baz>();
|
||||
auto u_pkg = cv::gapi::combine(j_pkg ,s_pkg, cv::unite_policy::KEEP);
|
||||
|
||||
EXPECT_EQ(6u, u_pkg.size());
|
||||
EXPECT_TRUE(u_pkg.includes<J::Foo>());
|
||||
EXPECT_TRUE(u_pkg.includes<J::Bar>());
|
||||
EXPECT_TRUE(u_pkg.includes<J::Baz>());
|
||||
EXPECT_TRUE(u_pkg.includes<S::Foo>());
|
||||
EXPECT_TRUE(u_pkg.includes<S::Bar>());
|
||||
EXPECT_TRUE(u_pkg.includes<S::Baz>());
|
||||
}
|
||||
|
||||
TEST(KernelPackage, Unite_KEEP_Append_NoDups)
|
||||
{
|
||||
namespace J = Jupiter;
|
||||
namespace S = Saturn;
|
||||
auto j_pkg = cv::gapi::kernels<J::Foo, J::Bar>();
|
||||
auto s_pkg = cv::gapi::kernels<S::Qux>();
|
||||
auto u_pkg = cv::gapi::combine(j_pkg, s_pkg, cv::unite_policy::KEEP);
|
||||
|
||||
EXPECT_EQ(3u, u_pkg.size());
|
||||
EXPECT_TRUE(u_pkg.includes<J::Foo>());
|
||||
EXPECT_TRUE(u_pkg.includes<J::Bar>());
|
||||
EXPECT_TRUE(u_pkg.includes<S::Qux>());
|
||||
}
|
||||
|
||||
TEST(KernelPackage, TestWithEmptyLHS)
|
||||
{
|
||||
namespace J = Jupiter;
|
||||
auto lhs = cv::gapi::kernels<>();
|
||||
auto rhs = cv::gapi::kernels<J::Foo>();
|
||||
auto pkg = cv::gapi::combine(lhs, rhs, cv::unite_policy::KEEP);
|
||||
|
||||
EXPECT_EQ(1u, pkg.size());
|
||||
EXPECT_TRUE(pkg.includes<J::Foo>());
|
||||
}
|
||||
|
||||
TEST(KernelPackage, TestWithEmptyRHS)
|
||||
{
|
||||
namespace J = Jupiter;
|
||||
auto lhs = cv::gapi::kernels<J::Foo>();
|
||||
auto rhs = cv::gapi::kernels<>();
|
||||
auto pkg = cv::gapi::combine(lhs, rhs, cv::unite_policy::KEEP);
|
||||
|
||||
EXPECT_EQ(1u, pkg.size());
|
||||
EXPECT_TRUE(pkg.includes<J::Foo>());
|
||||
}
|
||||
|
||||
TEST(KernelPackage, Can_Use_Custom_Kernel)
|
||||
{
|
||||
cv::GMat in[2];
|
||||
auto out = GClone::on(cv::gapi::add(in[0], in[1]));
|
||||
const auto in_meta = cv::GMetaArg(cv::GMatDesc{CV_8U,1,cv::Size(32,32)});
|
||||
|
||||
auto pkg = cv::gapi::kernels<GCloneImpl>();
|
||||
|
||||
EXPECT_NO_THROW(cv::GComputation(cv::GIn(in[0], in[1]), cv::GOut(out)).
|
||||
compile({in_meta, in_meta}, cv::compile_args(pkg)));
|
||||
}
|
||||
|
||||
} // namespace opencv_test
|
||||
@@ -0,0 +1,123 @@
|
||||
// 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 "opencv2/gapi/cpu/gcpukernel.hpp"
|
||||
|
||||
#include "api/gbackend_priv.hpp" // directly instantiate GBackend::Priv
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
namespace {
|
||||
// FIXME: Currently every Kernel implementation in this test file has
|
||||
// its own backend() method and it is incorrect! API classes should
|
||||
// provide it out of the box.
|
||||
|
||||
namespace I
|
||||
{
|
||||
G_TYPED_KERNEL(Foo, <cv::GMat(cv::GMat)>, "test.kernels.foo")
|
||||
{
|
||||
static cv::GMatDesc outMeta(const cv::GMatDesc &in) { return in; }
|
||||
};
|
||||
|
||||
G_TYPED_KERNEL(Bar, <cv::GMat(cv::GMat,cv::GMat)>, "test.kernels.bar")
|
||||
{
|
||||
static cv::GMatDesc outMeta(const cv::GMatDesc &in, const cv::GMatDesc &) { return in; }
|
||||
};
|
||||
|
||||
G_TYPED_KERNEL(Baz, <cv::GScalar(cv::GMat)>, "test.kernels.baz")
|
||||
{
|
||||
static cv::GScalarDesc outMeta(const cv::GMatDesc &) { return cv::empty_scalar_desc(); }
|
||||
};
|
||||
|
||||
G_TYPED_KERNEL(Qux, <cv::GMat(cv::GMat, cv::GScalar)>, "test.kernels.qux")
|
||||
{
|
||||
static cv::GMatDesc outMeta(const cv::GMatDesc &in, const cv::GScalarDesc &) { return in; }
|
||||
};
|
||||
|
||||
G_TYPED_KERNEL(Quux, <cv::GMat(cv::GScalar, cv::GMat)>, "test.kernels.quux")
|
||||
{
|
||||
static cv::GMatDesc outMeta(const cv::GScalarDesc &, const cv::GMatDesc& in) { return in; }
|
||||
};
|
||||
}
|
||||
|
||||
// Kernel implementations for imaginary Jupiter device
|
||||
namespace Jupiter
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
static cv::gapi::GBackend backend(std::make_shared<cv::gapi::GBackend::Priv>());
|
||||
}
|
||||
|
||||
inline cv::gapi::GBackend backend() { return detail::backend; }
|
||||
|
||||
GAPI_OCV_KERNEL(Foo, I::Foo)
|
||||
{
|
||||
static void run(const cv::Mat &, cv::Mat &) { /*Do nothing*/ }
|
||||
static cv::gapi::GBackend backend() { return detail::backend; } // FIXME: Must be removed
|
||||
};
|
||||
GAPI_OCV_KERNEL(Bar, I::Bar)
|
||||
{
|
||||
static void run(const cv::Mat &, const cv::Mat &, cv::Mat &) { /*Do nothing*/ }
|
||||
static cv::gapi::GBackend backend() { return detail::backend; } // FIXME: Must be removed
|
||||
};
|
||||
GAPI_OCV_KERNEL(Baz, I::Baz)
|
||||
{
|
||||
static void run(const cv::Mat &, cv::Scalar &) { /*Do nothing*/ }
|
||||
static cv::gapi::GBackend backend() { return detail::backend; } // FIXME: Must be removed
|
||||
};
|
||||
GAPI_OCV_KERNEL(Qux, I::Qux)
|
||||
{
|
||||
static void run(const cv::Mat &, const cv::Scalar&, cv::Mat &) { /*Do nothing*/ }
|
||||
static cv::gapi::GBackend backend() { return detail::backend; } // FIXME: Must be removed
|
||||
};
|
||||
|
||||
GAPI_OCV_KERNEL(Quux, I::Quux)
|
||||
{
|
||||
static void run(const cv::Scalar&, const cv::Mat&, cv::Mat &) { /*Do nothing*/ }
|
||||
static cv::gapi::GBackend backend() { return detail::backend; } // FIXME: Must be removed
|
||||
};
|
||||
} // namespace Jupiter
|
||||
|
||||
// Kernel implementations for imaginary Saturn device
|
||||
namespace Saturn
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
static cv::gapi::GBackend backend(std::make_shared<cv::gapi::GBackend::Priv>());
|
||||
}
|
||||
|
||||
inline cv::gapi::GBackend backend() { return detail::backend; }
|
||||
|
||||
GAPI_OCV_KERNEL(Foo, I::Foo)
|
||||
{
|
||||
static void run(const cv::Mat &, cv::Mat &) { /*Do nothing*/ }
|
||||
static cv::gapi::GBackend backend() { return detail::backend; } // FIXME: Must be removed
|
||||
};
|
||||
GAPI_OCV_KERNEL(Bar, I::Bar)
|
||||
{
|
||||
static void run(const cv::Mat &, const cv::Mat &, cv::Mat &) { /*Do nothing*/ }
|
||||
static cv::gapi::GBackend backend() { return detail::backend; } // FIXME: Must be removed
|
||||
};
|
||||
GAPI_OCV_KERNEL(Baz, I::Baz)
|
||||
{
|
||||
static void run(const cv::Mat &, cv::Scalar &) { /*Do nothing*/ }
|
||||
static cv::gapi::GBackend backend() { return detail::backend; } // FIXME: Must be removed
|
||||
};
|
||||
GAPI_OCV_KERNEL(Qux, I::Qux)
|
||||
{
|
||||
static void run(const cv::Mat &, const cv::Scalar&, cv::Mat &) { /*Do nothing*/ }
|
||||
static cv::gapi::GBackend backend() { return detail::backend; } // FIXME: Must be removed
|
||||
};
|
||||
|
||||
GAPI_OCV_KERNEL(Quux, I::Quux)
|
||||
{
|
||||
static void run(const cv::Scalar&, const cv::Mat&, cv::Mat &) { /*Do nothing*/ }
|
||||
static cv::gapi::GBackend backend() { return detail::backend; } // FIXME: Must be removed
|
||||
};
|
||||
} // namespace Saturn
|
||||
} // anonymous namespace
|
||||
} // namespace opencv_test
|
||||
@@ -0,0 +1,301 @@
|
||||
// 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 <stdexcept>
|
||||
#include <ade/util/iota_range.hpp>
|
||||
#include "logger.hpp"
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
G_TYPED_KERNEL(GInvalidResize, <GMat(GMat,Size,double,double,int)>, "org.opencv.test.invalid_resize")
|
||||
{
|
||||
static GMatDesc outMeta(GMatDesc in, Size, double, double, int) { return in; }
|
||||
};
|
||||
|
||||
GAPI_OCV_KERNEL(GOCVInvalidResize, GInvalidResize)
|
||||
{
|
||||
static void run(const cv::Mat& in, cv::Size sz, double fx, double fy, int interp, cv::Mat &out)
|
||||
{
|
||||
cv::resize(in, out, sz, fx, fy, interp);
|
||||
}
|
||||
};
|
||||
|
||||
G_TYPED_KERNEL(GReallocatingCopy, <GMat(GMat)>, "org.opencv.test.reallocating_copy")
|
||||
{
|
||||
static GMatDesc outMeta(GMatDesc in) { return in; }
|
||||
};
|
||||
|
||||
GAPI_OCV_KERNEL(GOCVReallocatingCopy, GReallocatingCopy)
|
||||
{
|
||||
static void run(const cv::Mat& in, cv::Mat &out)
|
||||
{
|
||||
out = in.clone();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
TEST(GAPI_Pipeline, OverloadUnary_MatMat)
|
||||
{
|
||||
cv::GMat in;
|
||||
cv::GComputation comp(in, cv::gapi::bitwise_not(in));
|
||||
|
||||
cv::Mat in_mat = cv::Mat::eye(32, 32, CV_8UC1);
|
||||
cv::Mat ref_mat = ~in_mat;
|
||||
|
||||
cv::Mat out_mat;
|
||||
comp.apply(in_mat, out_mat);
|
||||
EXPECT_EQ(0, cv::countNonZero(out_mat != ref_mat));
|
||||
|
||||
out_mat = cv::Mat();
|
||||
auto cc = comp.compile(cv::descr_of(in_mat));
|
||||
cc(in_mat, out_mat);
|
||||
EXPECT_EQ(0, cv::countNonZero(out_mat != ref_mat));
|
||||
}
|
||||
|
||||
TEST(GAPI_Pipeline, OverloadUnary_MatScalar)
|
||||
{
|
||||
cv::GMat in;
|
||||
cv::GComputation comp(in, cv::gapi::sum(in));
|
||||
|
||||
cv::Mat in_mat = cv::Mat::eye(32, 32, CV_8UC1);
|
||||
cv::Scalar ref_scl = cv::sum(in_mat);
|
||||
|
||||
cv::Scalar out_scl;
|
||||
comp.apply(in_mat, out_scl);
|
||||
EXPECT_EQ(out_scl, ref_scl);
|
||||
|
||||
out_scl = cv::Scalar();
|
||||
auto cc = comp.compile(cv::descr_of(in_mat));
|
||||
cc(in_mat, out_scl);
|
||||
EXPECT_EQ(out_scl, ref_scl);
|
||||
}
|
||||
|
||||
TEST(GAPI_Pipeline, OverloadBinary_Mat)
|
||||
{
|
||||
cv::GMat a, b;
|
||||
cv::GComputation comp(a, b, cv::gapi::add(a, b));
|
||||
|
||||
cv::Mat in_mat = cv::Mat::eye(32, 32, CV_8UC1);
|
||||
cv::Mat ref_mat = (in_mat+in_mat);
|
||||
|
||||
cv::Mat out_mat;
|
||||
comp.apply(in_mat, in_mat, out_mat);
|
||||
EXPECT_EQ(0, cv::countNonZero(out_mat != ref_mat));
|
||||
|
||||
out_mat = cv::Mat();
|
||||
auto cc = comp.compile(cv::descr_of(in_mat), cv::descr_of(in_mat));
|
||||
cc(in_mat, in_mat, out_mat);
|
||||
EXPECT_EQ(0, cv::countNonZero(out_mat != ref_mat));
|
||||
}
|
||||
|
||||
TEST(GAPI_Pipeline, OverloadBinary_Scalar)
|
||||
{
|
||||
cv::GMat a, b;
|
||||
cv::GComputation comp(a, b, cv::gapi::sum(a + b));
|
||||
|
||||
cv::Mat in_mat = cv::Mat::eye(32, 32, CV_8UC1);
|
||||
cv::Scalar ref_scl = cv::sum(in_mat+in_mat);
|
||||
|
||||
cv::Scalar out_scl;
|
||||
comp.apply(in_mat, in_mat, out_scl);
|
||||
EXPECT_EQ(out_scl, ref_scl);
|
||||
|
||||
out_scl = cv::Scalar();
|
||||
auto cc = comp.compile(cv::descr_of(in_mat), cv::descr_of(in_mat));
|
||||
cc(in_mat, in_mat, out_scl);
|
||||
EXPECT_EQ(out_scl, ref_scl);
|
||||
}
|
||||
|
||||
TEST(GAPI_Pipeline, Sharpen)
|
||||
{
|
||||
const cv::Size sz_in (1280, 720);
|
||||
const cv::Size sz_out( 640, 480);
|
||||
cv::Mat in_mat (sz_in, CV_8UC3);
|
||||
in_mat = cv::Scalar(128, 33, 53);
|
||||
|
||||
cv::Mat out_mat(sz_out, CV_8UC3);
|
||||
cv::Mat out_mat_y;
|
||||
cv::Mat out_mat_ocv(sz_out, CV_8UC3);
|
||||
|
||||
float sharpen_coeffs[] = {
|
||||
0.0f, -1.f, 0.0f,
|
||||
-1.0f, 5.f, -1.0f,
|
||||
0.0f, -1.f, 0.0f
|
||||
};
|
||||
cv::Mat sharpen_kernel(3, 3, CV_32F, sharpen_coeffs);
|
||||
|
||||
// G-API code //////////////////////////////////////////////////////////////
|
||||
|
||||
cv::GMat in;
|
||||
auto vga = cv::gapi::resize(in, sz_out);
|
||||
auto yuv = cv::gapi::RGB2YUV(vga);
|
||||
auto yuv_p = cv::gapi::split3(yuv);
|
||||
auto y_sharp = cv::gapi::filter2D(std::get<0>(yuv_p), -1, sharpen_kernel);
|
||||
auto yuv_new = cv::gapi::merge3(y_sharp, std::get<1>(yuv_p), std::get<2>(yuv_p));
|
||||
auto out = cv::gapi::YUV2RGB(yuv_new);
|
||||
|
||||
cv::GComputation c(cv::GIn(in), cv::GOut(y_sharp, out));
|
||||
c.apply(cv::gin(in_mat), cv::gout(out_mat_y, out_mat));
|
||||
|
||||
// OpenCV code /////////////////////////////////////////////////////////////
|
||||
{
|
||||
cv::Mat smaller;
|
||||
cv::resize(in_mat, smaller, sz_out);
|
||||
|
||||
cv::Mat yuv_mat;
|
||||
cv::cvtColor(smaller, yuv_mat, cv::COLOR_RGB2YUV);
|
||||
std::vector<cv::Mat> yuv_planar(3);
|
||||
cv::split(yuv_mat, yuv_planar);
|
||||
cv::filter2D(yuv_planar[0], yuv_planar[0], -1, sharpen_kernel);
|
||||
cv::merge(yuv_planar, yuv_mat);
|
||||
cv::cvtColor(yuv_mat, out_mat_ocv, cv::COLOR_YUV2RGB);
|
||||
}
|
||||
|
||||
// Comparison //////////////////////////////////////////////////////////////
|
||||
{
|
||||
cv::Mat diff = out_mat_ocv != out_mat;
|
||||
std::vector<cv::Mat> diffBGR(3);
|
||||
cv::split(diff, diffBGR);
|
||||
EXPECT_EQ(0, cv::countNonZero(diffBGR[0]));
|
||||
EXPECT_EQ(0, cv::countNonZero(diffBGR[1]));
|
||||
EXPECT_EQ(0, cv::countNonZero(diffBGR[2]));
|
||||
}
|
||||
|
||||
// Metadata check /////////////////////////////////////////////////////////
|
||||
{
|
||||
auto cc = c.compile(cv::descr_of(in_mat));
|
||||
auto metas = cc.outMetas();
|
||||
ASSERT_EQ(2u, metas.size());
|
||||
|
||||
auto out_y_meta = cv::util::get<cv::GMatDesc>(metas[0]);
|
||||
auto out_meta = cv::util::get<cv::GMatDesc>(metas[1]);
|
||||
|
||||
// Y-output
|
||||
EXPECT_EQ(CV_8U, out_y_meta.depth);
|
||||
EXPECT_EQ(1, out_y_meta.chan);
|
||||
EXPECT_EQ(640, out_y_meta.size.width);
|
||||
EXPECT_EQ(480, out_y_meta.size.height);
|
||||
|
||||
// Final output
|
||||
EXPECT_EQ(CV_8U, out_meta.depth);
|
||||
EXPECT_EQ(3, out_meta.chan);
|
||||
EXPECT_EQ(640, out_meta.size.width);
|
||||
EXPECT_EQ(480, out_meta.size.height);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(GAPI_Pipeline, CustomRGB2YUV)
|
||||
{
|
||||
const cv::Size sz(1280, 720);
|
||||
|
||||
// BEWARE:
|
||||
//
|
||||
// std::vector<cv::Mat> out_mats_cv(3, cv::Mat(sz, CV_8U))
|
||||
//
|
||||
// creates a vector of 3 elements pointing to the same Mat!
|
||||
// FIXME: Make a G-API check for that
|
||||
const int INS = 3;
|
||||
std::vector<cv::Mat> in_mats(INS);
|
||||
for (auto i : ade::util::iota(INS))
|
||||
{
|
||||
in_mats[i].create(sz, CV_8U);
|
||||
cv::randu(in_mats[i], cv::Scalar::all(0), cv::Scalar::all(255));
|
||||
}
|
||||
|
||||
const int OUTS = 3;
|
||||
std::vector<cv::Mat> out_mats_cv(OUTS);
|
||||
std::vector<cv::Mat> out_mats_gapi(OUTS);
|
||||
for (auto i : ade::util::iota(OUTS))
|
||||
{
|
||||
out_mats_cv [i].create(sz, CV_8U);
|
||||
out_mats_gapi[i].create(sz, CV_8U);
|
||||
}
|
||||
|
||||
// G-API code //////////////////////////////////////////////////////////////
|
||||
{
|
||||
cv::GMat r, g, b;
|
||||
cv::GMat y = 0.299f*r + 0.587f*g + 0.114f*b;
|
||||
cv::GMat u = 0.492f*(b - y);
|
||||
cv::GMat v = 0.877f*(r - y);
|
||||
|
||||
cv::GComputation customCvt({r, g, b}, {y, u, v});
|
||||
customCvt.apply(in_mats, out_mats_gapi);
|
||||
}
|
||||
|
||||
// OpenCV code /////////////////////////////////////////////////////////////
|
||||
{
|
||||
cv::Mat r = in_mats[0], g = in_mats[1], b = in_mats[2];
|
||||
cv::Mat y = 0.299f*r + 0.587f*g + 0.114f*b;
|
||||
cv::Mat u = 0.492f*(b - y);
|
||||
cv::Mat v = 0.877f*(r - y);
|
||||
|
||||
out_mats_cv[0] = y;
|
||||
out_mats_cv[1] = u;
|
||||
out_mats_cv[2] = v;
|
||||
}
|
||||
|
||||
// Comparison //////////////////////////////////////////////////////////////
|
||||
{
|
||||
const auto diff = [](cv::Mat m1, cv::Mat m2, int t) {
|
||||
return cv::abs(m1-m2) > t;
|
||||
};
|
||||
|
||||
// FIXME: Not bit-accurate even now!
|
||||
cv::Mat
|
||||
diff_y = diff(out_mats_cv[0], out_mats_gapi[0], 2),
|
||||
diff_u = diff(out_mats_cv[1], out_mats_gapi[1], 2),
|
||||
diff_v = diff(out_mats_cv[2], out_mats_gapi[2], 2);
|
||||
|
||||
EXPECT_EQ(0, cv::countNonZero(diff_y));
|
||||
EXPECT_EQ(0, cv::countNonZero(diff_u));
|
||||
EXPECT_EQ(0, cv::countNonZero(diff_v));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(GAPI_Pipeline, PipelineWithInvalidKernel)
|
||||
{
|
||||
cv::GMat in, out;
|
||||
cv::Mat in_mat(500, 500, CV_8UC1), out_mat;
|
||||
out = GInvalidResize::on(in, cv::Size(300, 300), 0.0, 0.0, cv::INTER_LINEAR);
|
||||
|
||||
const auto pkg = cv::gapi::kernels<GOCVInvalidResize>();
|
||||
cv::GComputation comp(cv::GIn(in), cv::GOut(out));
|
||||
|
||||
EXPECT_THROW(comp.apply(in_mat, out_mat, cv::compile_args(pkg)), std::logic_error);
|
||||
}
|
||||
|
||||
TEST(GAPI_Pipeline, InvalidOutputComputation)
|
||||
{
|
||||
cv::GMat in1, out1, out2, out3;
|
||||
|
||||
std::tie(out1, out2, out2) = cv::gapi::split3(in1);
|
||||
cv::GComputation c({in1}, {out1, out2, out3});
|
||||
cv::Mat in_mat;
|
||||
cv::Mat out_mat1, out_mat2, out_mat3, out_mat4;
|
||||
std::vector<cv::Mat> u_outs = {out_mat1, out_mat2, out_mat3, out_mat4};
|
||||
std::vector<cv::Mat> u_ins = {in_mat};
|
||||
|
||||
EXPECT_THROW(c.apply(u_ins, u_outs), std::logic_error);
|
||||
}
|
||||
|
||||
TEST(GAPI_Pipeline, PipelineAllocatingKernel)
|
||||
{
|
||||
cv::GMat in, out;
|
||||
cv::Mat in_mat(500, 500, CV_8UC1), out_mat;
|
||||
out = GReallocatingCopy::on(in);
|
||||
|
||||
const auto pkg = cv::gapi::kernels<GOCVReallocatingCopy>();
|
||||
cv::GComputation comp(cv::GIn(in), cv::GOut(out));
|
||||
|
||||
EXPECT_THROW(comp.apply(in_mat, out_mat, cv::compile_args(pkg)), std::logic_error);
|
||||
}
|
||||
} // namespace opencv_test
|
||||
@@ -0,0 +1,116 @@
|
||||
// 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 <iostream>
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
|
||||
TEST(GAPI_Scalar, Argument)
|
||||
{
|
||||
cv::Size sz(2, 2);
|
||||
cv::Mat in_mat(sz, CV_8U);
|
||||
|
||||
cv::GComputationT<cv::GMat (cv::GMat, cv::GScalar)> mulS([](cv::GMat in, cv::GScalar c)
|
||||
{
|
||||
return in*c;
|
||||
});
|
||||
|
||||
cv::Mat out_mat(sz, CV_8U);
|
||||
mulS.apply(in_mat, cv::Scalar(2), out_mat);
|
||||
|
||||
cv::Mat reference = in_mat*2;
|
||||
EXPECT_EQ(0, cv::countNonZero(cv::abs(out_mat - reference)));
|
||||
}
|
||||
|
||||
TEST(GAPI_Scalar, ReturnValue)
|
||||
{
|
||||
const cv::Size sz(2, 2);
|
||||
cv::Mat in_mat(sz, CV_8U, cv::Scalar(1));
|
||||
|
||||
cv::GComputationT<cv::GScalar (cv::GMat)> sum_of_sum([](cv::GMat in)
|
||||
{
|
||||
return cv::gapi::sum(in + in);
|
||||
});
|
||||
|
||||
cv::Scalar out;
|
||||
sum_of_sum.apply(in_mat, out);
|
||||
|
||||
EXPECT_EQ(8, out[0]);
|
||||
}
|
||||
|
||||
TEST(GAPI_Scalar, TmpScalar)
|
||||
{
|
||||
const cv::Size sz(2, 2);
|
||||
cv::Mat in_mat(sz, CV_8U, cv::Scalar(1));
|
||||
|
||||
cv::GComputationT<cv::GMat (cv::GMat)> mul_by_sum([](cv::GMat in)
|
||||
{
|
||||
return in * cv::gapi::sum(in);
|
||||
});
|
||||
|
||||
cv::Mat out_mat(sz, CV_8U);
|
||||
mul_by_sum.apply(in_mat, out_mat);
|
||||
|
||||
cv::Mat reference = cv::Mat(sz, CV_8U, cv::Scalar(4));
|
||||
EXPECT_EQ(0, cv::countNonZero(cv::abs(out_mat - reference)));
|
||||
}
|
||||
|
||||
TEST(GAPI_ScalarWithValue, Simple_Arithmetic_Pipeline)
|
||||
{
|
||||
GMat in;
|
||||
GMat out = (in + 1) * 2;
|
||||
cv::GComputation comp(in, out);
|
||||
|
||||
cv::Mat in_mat = cv::Mat::eye(3, 3, CV_8UC1);
|
||||
cv::Mat ref_mat, out_mat;
|
||||
|
||||
ref_mat = (in_mat + 1) * 2;
|
||||
comp.apply(in_mat, out_mat);
|
||||
|
||||
EXPECT_EQ(0, cv::countNonZero(out_mat != ref_mat));
|
||||
}
|
||||
|
||||
TEST(GAPI_ScalarWithValue, GScalar_Initilization)
|
||||
{
|
||||
cv::Scalar sc(2);
|
||||
cv::GMat in;
|
||||
cv::GScalar s(sc);
|
||||
cv::GComputation comp(in, cv::gapi::mulC(in, s));
|
||||
|
||||
cv::Mat in_mat = cv::Mat::eye(3, 3, CV_8UC1);
|
||||
cv::Mat ref_mat, out_mat;
|
||||
cv::multiply(in_mat, sc, ref_mat, 1, CV_8UC1);
|
||||
comp.apply(cv::gin(in_mat), cv::gout(out_mat));
|
||||
|
||||
EXPECT_EQ(0, cv::countNonZero(out_mat != ref_mat));
|
||||
}
|
||||
|
||||
TEST(GAPI_ScalarWithValue, Constant_GScalar_In_Middle_Graph)
|
||||
{
|
||||
cv::Scalar sc(5);
|
||||
cv::GMat in1;
|
||||
cv::GScalar in2;
|
||||
cv::GScalar s(sc);
|
||||
|
||||
auto add_out = cv::gapi::addC(in1, in2);
|
||||
cv::GComputation comp(cv::GIn(in1, in2), cv::GOut(cv::gapi::mulC(add_out, s)));
|
||||
|
||||
cv::Mat in_mat = cv::Mat::eye(3, 3, CV_8UC1);
|
||||
cv::Scalar in_scalar(3);
|
||||
|
||||
cv::Mat ref_mat, out_mat, add_mat;
|
||||
cv::add(in_mat, in_scalar, add_mat);
|
||||
cv::multiply(add_mat, sc, ref_mat, 1, CV_8UC1);
|
||||
comp.apply(cv::gin(in_mat, in_scalar), cv::gout(out_mat));
|
||||
|
||||
EXPECT_EQ(0, cv::countNonZero(out_mat != ref_mat));
|
||||
}
|
||||
|
||||
} // namespace opencv_test
|
||||
@@ -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) 2018 Intel Corporation
|
||||
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
|
||||
TEST(GAPI, Mat_Create_NoLink)
|
||||
{
|
||||
cv::Mat m1;
|
||||
cv::Mat m2 = m1;
|
||||
m2.create(32, 32, CV_8U);
|
||||
|
||||
EXPECT_NE(m1.rows, m2.rows);
|
||||
EXPECT_NE(m1.cols, m2.cols);
|
||||
EXPECT_NE(m1.data, m2.data);
|
||||
}
|
||||
|
||||
TEST(GAPI, Mat_Recreate)
|
||||
{
|
||||
cv::Mat m1 = cv::Mat::zeros(480, 640, CV_8U);
|
||||
m1.at<uchar>(0, 0) = 128;
|
||||
cv::Mat m2 = m1;
|
||||
|
||||
EXPECT_EQ(m1.rows, m2.rows);
|
||||
EXPECT_EQ(m1.cols, m2.cols);
|
||||
EXPECT_EQ(m1.data, m2.data);
|
||||
EXPECT_EQ(m1.at<uchar>(0, 0), m2.at<uchar>(0, 0));
|
||||
|
||||
// Calling "create" with the same meta is NOOP - both m1 and m2 are the same
|
||||
m1.create(480, 640, CV_8U);
|
||||
EXPECT_EQ(m1.rows, m2.rows);
|
||||
EXPECT_EQ(m1.cols, m2.cols);
|
||||
EXPECT_EQ(m1.data, m2.data);
|
||||
EXPECT_EQ(m1.at<uchar>(0, 0), m2.at<uchar>(0, 0));
|
||||
|
||||
// Calling "create" on m2 with different meta doesn't update original m1
|
||||
// Now m1 and m2 are distinct
|
||||
m2.create(720, 1280, CV_8U);
|
||||
m2.at<uchar>(0, 0) = 64; // Initialize 0,0 element since m2 is a new buffer
|
||||
EXPECT_NE(m1.rows, m2.rows);
|
||||
EXPECT_NE(m1.cols, m2.cols);
|
||||
EXPECT_NE(m1.data, m2.data);
|
||||
EXPECT_NE(m1.at<uchar>(0, 0), m2.at<uchar>(0, 0));
|
||||
|
||||
// What if a Mat is created from handle?
|
||||
uchar data[] = {
|
||||
32, 0, 0,
|
||||
0, 0, 0,
|
||||
0, 0, 0
|
||||
};
|
||||
cv::Mat m3(3, 3, CV_8U, data);
|
||||
cv::Mat m4 = m3;
|
||||
EXPECT_EQ(m3.rows, m4.rows);
|
||||
EXPECT_EQ(m3.cols, m4.cols);
|
||||
EXPECT_EQ(m3.data, m4.data);
|
||||
EXPECT_EQ(data, m3.data);
|
||||
EXPECT_EQ(data, m4.data);
|
||||
EXPECT_EQ(m3.at<uchar>(0, 0), m4.at<uchar>(0, 0));
|
||||
|
||||
// cv::Mat::create must be NOOP if we don't change the meta,
|
||||
// even if the origianl mat is created from handle.
|
||||
m4.create(3, 3, CV_8U);
|
||||
EXPECT_EQ(m3.rows, m4.rows);
|
||||
EXPECT_EQ(m3.cols, m4.cols);
|
||||
EXPECT_EQ(m3.data, m4.data);
|
||||
EXPECT_EQ(data, m3.data);
|
||||
EXPECT_EQ(data, m4.data);
|
||||
EXPECT_EQ(m3.at<uchar>(0, 0), m4.at<uchar>(0, 0));
|
||||
}
|
||||
|
||||
TEST(GAPI, EmptyOutMat)
|
||||
{
|
||||
cv::Mat in_mat = cv::Mat(480, 640, CV_8U, cv::Scalar(64));
|
||||
|
||||
cv::GComputation cc([]()
|
||||
{
|
||||
cv::GMat in;
|
||||
cv::GMat out = in + in;
|
||||
return cv::GComputation(in, out);
|
||||
});
|
||||
|
||||
cv::Mat out;
|
||||
cc.apply(in_mat, out);
|
||||
|
||||
EXPECT_EQ(640, out.cols);
|
||||
EXPECT_EQ(480, out.rows);
|
||||
EXPECT_EQ(CV_8U, out.type());
|
||||
EXPECT_EQ(0, cv::countNonZero(out - (in_mat+in_mat)));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,185 @@
|
||||
// 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"
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
cv::Mat diff(cv::Mat m1, cv::Mat m2, int t)
|
||||
{
|
||||
return cv::abs(m1-m2) > t;
|
||||
}
|
||||
|
||||
int non_zero3(cv::Mat m3c)
|
||||
{
|
||||
std::vector<cv::Mat> mm(3);
|
||||
cv::split(m3c, mm);
|
||||
return ( cv::countNonZero(mm[0])
|
||||
+ cv::countNonZero(mm[1])
|
||||
+ cv::countNonZero(mm[2]));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(GAPI_Typed, UnaryOp)
|
||||
{
|
||||
// Initialization //////////////////////////////////////////////////////////
|
||||
const cv::Size sz(32, 32);
|
||||
cv::Mat
|
||||
in_mat (sz, CV_8UC3),
|
||||
out_mat_untyped(sz, CV_8UC3),
|
||||
out_mat_typed1 (sz, CV_8UC3),
|
||||
out_mat_typed2 (sz, CV_8UC3),
|
||||
out_mat_cv (sz, CV_8UC3);
|
||||
cv::randu(in_mat, cv::Scalar::all(0), cv::Scalar::all(255));
|
||||
|
||||
// Untyped G-API ///////////////////////////////////////////////////////////
|
||||
cv::GComputation cvtU([]()
|
||||
{
|
||||
cv::GMat in;
|
||||
cv::GMat out = cv::gapi::RGB2YUV(in);
|
||||
return cv::GComputation(in, out);
|
||||
});
|
||||
cvtU.apply(in_mat, out_mat_untyped);
|
||||
|
||||
// Typed G-API /////////////////////////////////////////////////////////////
|
||||
cv::GComputationT<cv::GMat (cv::GMat)> cvtT(cv::gapi::RGB2YUV);
|
||||
auto cvtTComp = cvtT.compile(cv::descr_of(in_mat));
|
||||
|
||||
cvtT.apply(in_mat, out_mat_typed1);
|
||||
cvtTComp(in_mat, out_mat_typed2);
|
||||
|
||||
// Plain OpenCV ////////////////////////////////////////////////////////////
|
||||
cv::cvtColor(in_mat, out_mat_cv, cv::COLOR_RGB2YUV);
|
||||
|
||||
// Comparison //////////////////////////////////////////////////////////////
|
||||
// FIXME: There must be OpenCV comparison test functions already available!
|
||||
cv::Mat
|
||||
diff_u = diff(out_mat_cv, out_mat_untyped, 0),
|
||||
diff_t = diff(out_mat_cv, out_mat_typed1, 0),
|
||||
diff_tc = diff(out_mat_cv, out_mat_typed2, 0);
|
||||
|
||||
EXPECT_EQ(0, non_zero3(diff_u));
|
||||
EXPECT_EQ(0, non_zero3(diff_t));
|
||||
EXPECT_EQ(0, non_zero3(diff_tc));
|
||||
}
|
||||
|
||||
TEST(GAPI_Typed, BinaryOp)
|
||||
{
|
||||
// Initialization //////////////////////////////////////////////////////////
|
||||
const cv::Size sz(32, 32);
|
||||
cv::Mat
|
||||
in_mat1 (sz, CV_8UC1),
|
||||
in_mat2 (sz, CV_8UC1),
|
||||
out_mat_untyped(sz, CV_8UC1),
|
||||
out_mat_typed1 (sz, CV_8UC1),
|
||||
out_mat_typed2 (sz, CV_8UC1),
|
||||
out_mat_cv (sz, CV_8UC1);
|
||||
cv::randu(in_mat1, cv::Scalar::all(0), cv::Scalar::all(255));
|
||||
cv::randu(in_mat2, cv::Scalar::all(0), cv::Scalar::all(255));
|
||||
|
||||
// Untyped G-API ///////////////////////////////////////////////////////////
|
||||
cv::GComputation cvtU([]()
|
||||
{
|
||||
cv::GMat in1, in2;
|
||||
cv::GMat out = cv::gapi::add(in1, in2);
|
||||
return cv::GComputation({in1, in2}, {out});
|
||||
});
|
||||
std::vector<cv::Mat> u_ins = {in_mat1, in_mat2};
|
||||
std::vector<cv::Mat> u_outs = {out_mat_untyped};
|
||||
cvtU.apply(u_ins, u_outs);
|
||||
|
||||
// Typed G-API /////////////////////////////////////////////////////////////
|
||||
cv::GComputationT<cv::GMat (cv::GMat, cv::GMat)> cvtT([](cv::GMat m1, cv::GMat m2)
|
||||
{
|
||||
return m1+m2;
|
||||
});
|
||||
auto cvtTC = cvtT.compile(cv::descr_of(in_mat1),
|
||||
cv::descr_of(in_mat2));
|
||||
|
||||
cvtT.apply(in_mat1, in_mat2, out_mat_typed1);
|
||||
cvtTC(in_mat1, in_mat2, out_mat_typed2);
|
||||
|
||||
// Plain OpenCV ////////////////////////////////////////////////////////////
|
||||
cv::add(in_mat1, in_mat2, out_mat_cv);
|
||||
|
||||
// Comparison //////////////////////////////////////////////////////////////
|
||||
// FIXME: There must be OpenCV comparison test functions already available!
|
||||
cv::Mat
|
||||
diff_u = diff(out_mat_cv, out_mat_untyped, 0),
|
||||
diff_t = diff(out_mat_cv, out_mat_typed1, 0),
|
||||
diff_tc = diff(out_mat_cv, out_mat_typed2, 0);
|
||||
|
||||
EXPECT_EQ(0, cv::countNonZero(diff_u));
|
||||
EXPECT_EQ(0, cv::countNonZero(diff_t));
|
||||
EXPECT_EQ(0, cv::countNonZero(diff_tc));
|
||||
}
|
||||
|
||||
|
||||
TEST(GAPI_Typed, MultipleOuts)
|
||||
{
|
||||
// Initialization //////////////////////////////////////////////////////////
|
||||
const cv::Size sz(32, 32);
|
||||
cv::Mat
|
||||
in_mat (sz, CV_8UC1),
|
||||
out_mat_unt1 (sz, CV_8UC1),
|
||||
out_mat_unt2 (sz, CV_8UC1),
|
||||
out_mat_typed1(sz, CV_8UC1),
|
||||
out_mat_typed2(sz, CV_8UC1),
|
||||
out_mat_comp1 (sz, CV_8UC1),
|
||||
out_mat_comp2 (sz, CV_8UC1),
|
||||
out_mat_cv1 (sz, CV_8UC1),
|
||||
out_mat_cv2 (sz, CV_8UC1);
|
||||
cv::randu(in_mat, cv::Scalar::all(0), cv::Scalar::all(255));
|
||||
|
||||
// Untyped G-API ///////////////////////////////////////////////////////////
|
||||
cv::GComputation cvtU([]()
|
||||
{
|
||||
cv::GMat in;
|
||||
cv::GMat out1 = in * 2.f;
|
||||
cv::GMat out2 = in * 4.f;
|
||||
return cv::GComputation({in}, {out1, out2});
|
||||
});
|
||||
std::vector<cv::Mat> u_ins = {in_mat};
|
||||
std::vector<cv::Mat> u_outs = {out_mat_unt1, out_mat_unt2};
|
||||
cvtU.apply(u_ins, u_outs);
|
||||
|
||||
// Typed G-API /////////////////////////////////////////////////////////////
|
||||
cv::GComputationT<std::tuple<cv::GMat, cv::GMat> (cv::GMat)> cvtT([](cv::GMat in)
|
||||
{
|
||||
return std::make_tuple(in*2.f, in*4.f);
|
||||
});
|
||||
auto cvtTC = cvtT.compile(cv::descr_of(in_mat));
|
||||
|
||||
cvtT.apply(in_mat, out_mat_typed1, out_mat_typed2);
|
||||
cvtTC(in_mat, out_mat_comp1, out_mat_comp2);
|
||||
|
||||
// Plain OpenCV ////////////////////////////////////////////////////////////
|
||||
out_mat_cv1 = in_mat * 2.f;
|
||||
out_mat_cv2 = in_mat * 4.f;
|
||||
|
||||
// Comparison //////////////////////////////////////////////////////////////
|
||||
// FIXME: There must be OpenCV comparison test functions already available!
|
||||
cv::Mat
|
||||
diff_u1 = diff(out_mat_cv1, out_mat_unt1, 0),
|
||||
diff_u2 = diff(out_mat_cv2, out_mat_unt2, 0),
|
||||
diff_t1 = diff(out_mat_cv1, out_mat_typed1, 0),
|
||||
diff_t2 = diff(out_mat_cv2, out_mat_typed2, 0),
|
||||
diff_c1 = diff(out_mat_cv1, out_mat_comp1, 0),
|
||||
diff_c2 = diff(out_mat_cv2, out_mat_comp2, 0);
|
||||
|
||||
EXPECT_EQ(0, cv::countNonZero(diff_u1));
|
||||
EXPECT_EQ(0, cv::countNonZero(diff_u2));
|
||||
EXPECT_EQ(0, cv::countNonZero(diff_t1));
|
||||
EXPECT_EQ(0, cv::countNonZero(diff_t2));
|
||||
EXPECT_EQ(0, cv::countNonZero(diff_c1));
|
||||
EXPECT_EQ(0, cv::countNonZero(diff_c2));
|
||||
}
|
||||
|
||||
} // opencv_test
|
||||
@@ -0,0 +1,43 @@
|
||||
// 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 <type_traits>
|
||||
|
||||
#include "opencv2/gapi/util/util.hpp"
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
|
||||
TEST(GAPIUtil, AllSatisfy)
|
||||
{
|
||||
static_assert(true == cv::detail::all_satisfy<std::is_integral, long, int, char>::value,
|
||||
"[long, int, char] are all integral types");
|
||||
static_assert(true == cv::detail::all_satisfy<std::is_integral, char>::value,
|
||||
"char is an integral type");
|
||||
|
||||
static_assert(false == cv::detail::all_satisfy<std::is_integral, float, int, char>::value,
|
||||
"[float, int, char] are NOT all integral types");
|
||||
static_assert(false == cv::detail::all_satisfy<std::is_integral, int, char, float>::value,
|
||||
"[int, char, float] are NOT all integral types");
|
||||
static_assert(false == cv::detail::all_satisfy<std::is_integral, float>::value,
|
||||
"float is not an integral types");
|
||||
}
|
||||
|
||||
TEST(GAPIUtil, AllButLast)
|
||||
{
|
||||
using test1 = cv::detail::all_but_last<long, int, float>::type;
|
||||
static_assert(true == cv::detail::all_satisfy<std::is_integral, test1>::value,
|
||||
"[long, int] are all integral types (float skipped)");
|
||||
|
||||
using test2 = cv::detail::all_but_last<int, float, char>::type;
|
||||
static_assert(false == cv::detail::all_satisfy<std::is_integral, test2>::value,
|
||||
"[int, float] are NOT all integral types");
|
||||
}
|
||||
|
||||
} // namespace opencv_test
|
||||
@@ -0,0 +1,86 @@
|
||||
// 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_mock_kernels.hpp"
|
||||
|
||||
#include "compiler/gmodel.hpp"
|
||||
#include "compiler/gcompiler.hpp"
|
||||
|
||||
namespace opencv_test {
|
||||
|
||||
namespace {
|
||||
|
||||
struct MockMeta
|
||||
{
|
||||
static const char* name() { return "MockMeta"; }
|
||||
};
|
||||
|
||||
class GMockBackendImpl final: public cv::gapi::GBackend::Priv
|
||||
{
|
||||
virtual void unpackKernel(ade::Graph &,
|
||||
const ade::NodeHandle &,
|
||||
const cv::GKernelImpl &) override
|
||||
{
|
||||
// Do nothing here
|
||||
}
|
||||
|
||||
virtual EPtr compile(const ade::Graph &,
|
||||
const cv::GCompileArgs &,
|
||||
const std::vector<ade::NodeHandle> &) const override
|
||||
{
|
||||
// Do nothing here as well
|
||||
return {};
|
||||
}
|
||||
|
||||
virtual void addBackendPasses(ade::ExecutionEngineSetupContext &ectx) override
|
||||
{
|
||||
ectx.addPass("transform", "set_mock_meta", [](ade::passes::PassContext &ctx) {
|
||||
ade::TypedGraph<MockMeta> me(ctx.graph);
|
||||
for (const auto &nh : me.nodes())
|
||||
{
|
||||
me.metadata(nh).set(MockMeta{});
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
static cv::gapi::GBackend mock_backend(std::make_shared<GMockBackendImpl>());
|
||||
|
||||
GAPI_OCV_KERNEL(MockFoo, I::Foo)
|
||||
{
|
||||
static void run(const cv::Mat &, cv::Mat &) { /*Do nothing*/ }
|
||||
static cv::gapi::GBackend backend() { return mock_backend; } // FIXME: Must be removed
|
||||
};
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
TEST(GBackend, CustomPassesExecuted)
|
||||
{
|
||||
cv::GMat in;
|
||||
cv::GMat out = I::Foo::on(in);
|
||||
cv::GComputation c(in, out);
|
||||
|
||||
// Prepare compilation parameters manually
|
||||
const auto in_meta = cv::GMetaArg(cv::GMatDesc{CV_8U,1,cv::Size(32,32)});
|
||||
const auto pkg = cv::gapi::kernels<MockFoo>();
|
||||
|
||||
// Directly instantiate G-API graph compiler and run partial compilation
|
||||
cv::gimpl::GCompiler compiler(c, {in_meta}, cv::compile_args(pkg));
|
||||
cv::gimpl::GCompiler::GPtr graph = compiler.generateGraph();
|
||||
compiler.runPasses(*graph);
|
||||
|
||||
// Inspect the graph and verify the metadata written by Mock backend
|
||||
ade::TypedGraph<MockMeta> me(*graph);
|
||||
EXPECT_LT(0u, static_cast<std::size_t>(me.nodes().size()));
|
||||
for (const auto &nh : me.nodes())
|
||||
{
|
||||
EXPECT_TRUE(me.metadata(nh).contains<MockMeta>());
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace opencv_test
|
||||
@@ -0,0 +1,83 @@
|
||||
// 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"
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
|
||||
// FIXME: avoid code duplication
|
||||
// The below graph and config is taken from ComplexIslands test suite
|
||||
TEST(GExecutor, SmokeTest)
|
||||
{
|
||||
cv::GMat in[2];
|
||||
cv::GMat tmp[4];
|
||||
cv::GScalar scl;
|
||||
cv::GMat out[2];
|
||||
|
||||
tmp[0] = cv::gapi::bitwise_not(cv::gapi::bitwise_not(in[0]));
|
||||
tmp[1] = cv::gapi::boxFilter(in[1], -1, cv::Size(3,3));
|
||||
tmp[2] = tmp[0] + tmp[1]; // FIXME: handle tmp[2] = tmp[0]+tmp[2] typo
|
||||
scl = cv::gapi::sum(tmp[1]);
|
||||
tmp[3] = cv::gapi::medianBlur(tmp[1], 3);
|
||||
out[0] = tmp[2] + scl;
|
||||
out[1] = cv::gapi::boxFilter(tmp[3], -1, cv::Size(3,3));
|
||||
|
||||
// isl0 #internal1
|
||||
// ........................... .........
|
||||
// (in1) -> NotNot ->(tmp0) --> Add ---------> (tmp2) --> AddC -------> (out1)
|
||||
// :.....................^...: :..^....:
|
||||
// : :
|
||||
// : :
|
||||
// #internal0 : :
|
||||
// .....................:......... :
|
||||
// (in2) -> Blur -> (tmp1) ----'--> Sum ----> (scl0) ----'
|
||||
// :..........:..................: isl1
|
||||
// : ..............................
|
||||
// `------------> Median -> (tmp3) --> Blur -------> (out2)
|
||||
// :............................:
|
||||
|
||||
cv::gapi::island("isl0", cv::GIn(in[0], tmp[1]), cv::GOut(tmp[2]));
|
||||
cv::gapi::island("isl1", cv::GIn(tmp[1]), cv::GOut(out[1]));
|
||||
|
||||
cv::Mat in_mat1 = cv::Mat::eye(32, 32, CV_8UC1);
|
||||
cv::Mat in_mat2 = cv::Mat::eye(32, 32, CV_8UC1);
|
||||
cv::Mat out_gapi[2];
|
||||
|
||||
// Run G-API:
|
||||
cv::GComputation(cv::GIn(in[0], in[1]), cv::GOut(out[0], out[1]))
|
||||
.apply(cv::gin(in_mat1, in_mat2), cv::gout(out_gapi[0], out_gapi[1]));
|
||||
|
||||
// Run OpenCV
|
||||
cv::Mat out_ocv[2];
|
||||
{
|
||||
cv::Mat ocv_tmp0;
|
||||
cv::Mat ocv_tmp1;
|
||||
cv::Mat ocv_tmp2;
|
||||
cv::Mat ocv_tmp3;
|
||||
cv::Scalar ocv_scl;
|
||||
|
||||
ocv_tmp0 = in_mat1; // skip !(!)
|
||||
cv::boxFilter(in_mat2, ocv_tmp1, -1, cv::Size(3,3));
|
||||
ocv_tmp2 = ocv_tmp0 + ocv_tmp1;
|
||||
ocv_scl = cv::sum(ocv_tmp1);
|
||||
cv::medianBlur(ocv_tmp1, ocv_tmp3, 3);
|
||||
out_ocv[0] = ocv_tmp2 + ocv_scl;
|
||||
cv::boxFilter(ocv_tmp3, out_ocv[1], -1, cv::Size(3,3));
|
||||
}
|
||||
|
||||
EXPECT_EQ(0, cv::countNonZero(out_gapi[0] != out_ocv[0]));
|
||||
EXPECT_EQ(0, cv::countNonZero(out_gapi[1] != out_ocv[1]));
|
||||
|
||||
// FIXME: check that GIslandModel has more than 1 island (e.g. fusion
|
||||
// with breakdown worked)
|
||||
}
|
||||
|
||||
// FIXME: Add explicit tests on GMat/GScalar/GArray<T> being connectors
|
||||
// between executed islands
|
||||
|
||||
} // namespace opencv_test
|
||||
@@ -0,0 +1,100 @@
|
||||
// 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"
|
||||
|
||||
namespace opencv_test {
|
||||
// Tests on T/Kind matching ////////////////////////////////////////////////////
|
||||
// {{
|
||||
|
||||
template<class T, cv::detail::ArgKind Exp>
|
||||
struct Expected
|
||||
{
|
||||
using type = T;
|
||||
static const constexpr cv::detail::ArgKind kind = Exp;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct GArgKind: public ::testing::Test
|
||||
{
|
||||
using Type = typename T::type;
|
||||
const cv::detail::ArgKind Kind = T::kind;
|
||||
};
|
||||
|
||||
// The reason here is to _manually_ list types and their kinds
|
||||
// (and NOT reuse cv::detail::ArgKind::Traits<>, since it is a subject of testing)
|
||||
using GArg_Test_Types = ::testing::Types
|
||||
<
|
||||
// G-API types
|
||||
Expected<cv::GMat, cv::detail::ArgKind::GMAT>
|
||||
, Expected<cv::GScalar, cv::detail::ArgKind::GSCALAR>
|
||||
, Expected<cv::GArray<int>, cv::detail::ArgKind::GARRAY>
|
||||
, Expected<cv::GArray<float>, cv::detail::ArgKind::GARRAY>
|
||||
, Expected<cv::GArray<cv::Point>, cv::detail::ArgKind::GARRAY>
|
||||
, Expected<cv::GArray<cv::Rect>, cv::detail::ArgKind::GARRAY>
|
||||
|
||||
// Built-in types
|
||||
, Expected<int, cv::detail::ArgKind::OPAQUE>
|
||||
, Expected<float, cv::detail::ArgKind::OPAQUE>
|
||||
, Expected<int*, cv::detail::ArgKind::OPAQUE>
|
||||
, Expected<cv::Point, cv::detail::ArgKind::OPAQUE>
|
||||
, Expected<std::string, cv::detail::ArgKind::OPAQUE>
|
||||
, Expected<cv::Mat, cv::detail::ArgKind::OPAQUE>
|
||||
, Expected<std::vector<int>, cv::detail::ArgKind::OPAQUE>
|
||||
, Expected<std::vector<cv::Point>, cv::detail::ArgKind::OPAQUE>
|
||||
>;
|
||||
|
||||
TYPED_TEST_CASE(GArgKind, GArg_Test_Types);
|
||||
|
||||
TYPED_TEST(GArgKind, LocalVar)
|
||||
{
|
||||
typename TestFixture::Type val{};
|
||||
cv::GArg arg(val);
|
||||
EXPECT_EQ(TestFixture::Kind, arg.kind);
|
||||
}
|
||||
|
||||
TYPED_TEST(GArgKind, ConstLocalVar)
|
||||
{
|
||||
const typename TestFixture::Type val{};
|
||||
cv::GArg arg(val);
|
||||
EXPECT_EQ(TestFixture::Kind, arg.kind);
|
||||
}
|
||||
|
||||
TYPED_TEST(GArgKind, RValue)
|
||||
{
|
||||
cv::GArg arg = cv::GArg(typename TestFixture::Type());
|
||||
EXPECT_EQ(TestFixture::Kind, arg.kind);
|
||||
}
|
||||
|
||||
// }}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TEST(GArg, HasWrap)
|
||||
{
|
||||
static_assert(!cv::detail::has_custom_wrap<cv::GMat>::value,
|
||||
"GMat has no custom marshalling logic");
|
||||
static_assert(!cv::detail::has_custom_wrap<cv::GScalar>::value,
|
||||
"GScalar has no custom marshalling logic");
|
||||
|
||||
static_assert(cv::detail::has_custom_wrap<cv::GArray<int> >::value,
|
||||
"GArray<int> has custom marshalling logic");
|
||||
static_assert(cv::detail::has_custom_wrap<cv::GArray<std::string> >::value,
|
||||
"GArray<int> has custom marshalling logic");
|
||||
}
|
||||
|
||||
TEST(GArg, GArrayU)
|
||||
{
|
||||
// Placing a GArray<T> into GArg automatically strips it to GArrayU
|
||||
cv::GArg arg1 = cv::GArg(cv::GArray<int>());
|
||||
EXPECT_NO_THROW(arg1.get<cv::detail::GArrayU>());
|
||||
|
||||
cv::GArg arg2 = cv::GArg(cv::GArray<cv::Point>());
|
||||
EXPECT_NO_THROW(arg2.get<cv::detail::GArrayU>());
|
||||
}
|
||||
|
||||
|
||||
} // namespace opencv_test
|
||||
@@ -0,0 +1,136 @@
|
||||
// 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 "api/gcomputation_priv.hpp"
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
|
||||
TEST(GMetaArg, Traits_Is_Positive)
|
||||
{
|
||||
using namespace cv::detail;
|
||||
|
||||
static_assert(is_meta_descr<cv::GScalarDesc>::value,
|
||||
"GScalarDesc is a meta description type");
|
||||
|
||||
static_assert(is_meta_descr<cv::GMatDesc>::value,
|
||||
"GMatDesc is a meta description type");
|
||||
}
|
||||
|
||||
TEST(GMetaArg, Traits_Is_Negative)
|
||||
{
|
||||
using namespace cv::detail;
|
||||
|
||||
static_assert(!is_meta_descr<cv::GCompileArgs>::value,
|
||||
"GCompileArgs is NOT a meta description type");
|
||||
|
||||
static_assert(!is_meta_descr<int>::value,
|
||||
"int is NOT a meta description type");
|
||||
|
||||
static_assert(!is_meta_descr<std::string>::value,
|
||||
"str::string is NOT a meta description type");
|
||||
}
|
||||
|
||||
TEST(GMetaArg, Traits_Are_EntireList_Positive)
|
||||
{
|
||||
using namespace cv::detail;
|
||||
|
||||
static_assert(are_meta_descrs<cv::GScalarDesc>::value,
|
||||
"GScalarDesc is a meta description type");
|
||||
|
||||
static_assert(are_meta_descrs<cv::GMatDesc>::value,
|
||||
"GMatDesc is a meta description type");
|
||||
|
||||
static_assert(are_meta_descrs<cv::GMatDesc, cv::GScalarDesc>::value,
|
||||
"Both GMatDesc and GScalarDesc are meta types");
|
||||
}
|
||||
|
||||
TEST(GMetaArg, Traits_Are_EntireList_Negative)
|
||||
{
|
||||
using namespace cv::detail;
|
||||
|
||||
static_assert(!are_meta_descrs<cv::GCompileArgs>::value,
|
||||
"GCompileArgs is NOT among meta types");
|
||||
|
||||
static_assert(!are_meta_descrs<int, std::string>::value,
|
||||
"Both int and std::string is NOT among meta types");
|
||||
|
||||
static_assert(!are_meta_descrs<cv::GMatDesc, cv::GScalarDesc, int>::value,
|
||||
"List of type is not valid for meta as there\'s int");
|
||||
|
||||
static_assert(!are_meta_descrs<cv::GMatDesc, cv::GScalarDesc, cv::GCompileArgs>::value,
|
||||
"List of type is not valid for meta as there\'s GCompileArgs");
|
||||
}
|
||||
|
||||
TEST(GMetaArg, Traits_Are_ButLast_Positive)
|
||||
{
|
||||
using namespace cv::detail;
|
||||
|
||||
static_assert(are_meta_descrs_but_last<cv::GScalarDesc, int>::value,
|
||||
"List is valid (int is ommitted)");
|
||||
|
||||
static_assert(are_meta_descrs_but_last<cv::GMatDesc, cv::GScalarDesc, cv::GCompileArgs>::value,
|
||||
"List is valid (GCompileArgs are omitted)");
|
||||
}
|
||||
|
||||
TEST(GMetaArg, Traits_Are_ButLast_Negative)
|
||||
{
|
||||
using namespace cv::detail;
|
||||
|
||||
static_assert(!are_meta_descrs_but_last<int, std::string>::value,
|
||||
"Both int is NOT among meta types (std::string is omitted)");
|
||||
|
||||
static_assert(!are_meta_descrs_but_last<cv::GMatDesc, cv::GScalarDesc, int, int>::value,
|
||||
"List of type is not valid for meta as there\'s two ints");
|
||||
|
||||
static_assert(!are_meta_descrs_but_last<cv::GMatDesc, cv::GScalarDesc, cv::GCompileArgs, float>::value,
|
||||
"List of type is not valid for meta as there\'s GCompileArgs");
|
||||
}
|
||||
|
||||
TEST(GMetaArg, Can_Get_Metas_From_Input_Run_Args)
|
||||
{
|
||||
cv::Mat m(3, 3, CV_8UC3);
|
||||
cv::Scalar s;
|
||||
std::vector<int> v;
|
||||
|
||||
GMatDesc m_desc;
|
||||
GMetaArgs meta_args = descr_of(cv::gin(m, s, v));
|
||||
|
||||
EXPECT_EQ(meta_args.size(), 3u);
|
||||
EXPECT_NO_THROW(m_desc = util::get<cv::GMatDesc>(meta_args[0]));
|
||||
EXPECT_NO_THROW(util::get<cv::GScalarDesc>(meta_args[1]));
|
||||
EXPECT_NO_THROW(util::get<cv::GArrayDesc>(meta_args[2]));
|
||||
|
||||
EXPECT_EQ(CV_8U, m_desc.depth);
|
||||
EXPECT_EQ(3, m_desc.chan);
|
||||
EXPECT_EQ(cv::gapi::own::Size(3, 3), m_desc.size);
|
||||
}
|
||||
|
||||
TEST(GMetaArg, Can_Get_Metas_From_Output_Run_Args)
|
||||
{
|
||||
cv::Mat m(3, 3, CV_8UC3);
|
||||
cv::Scalar s;
|
||||
std::vector<int> v;
|
||||
|
||||
GMatDesc m_desc;
|
||||
GRunArgsP out_run_args = cv::gout(m, s, v);
|
||||
GMetaArg m_meta = descr_of(out_run_args[0]);
|
||||
GMetaArg s_meta = descr_of(out_run_args[1]);
|
||||
GMetaArg v_meta = descr_of(out_run_args[2]);
|
||||
|
||||
EXPECT_NO_THROW(m_desc = util::get<cv::GMatDesc>(m_meta));
|
||||
EXPECT_NO_THROW(util::get<cv::GScalarDesc>(s_meta));
|
||||
EXPECT_NO_THROW(util::get<cv::GArrayDesc>(v_meta));
|
||||
|
||||
EXPECT_EQ(CV_8U, m_desc.depth);
|
||||
EXPECT_EQ(3, m_desc.chan);
|
||||
EXPECT_EQ(cv::Size(3, 3), m_desc.size);
|
||||
}
|
||||
|
||||
} // namespace opencv_test
|
||||
@@ -0,0 +1,364 @@
|
||||
// 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 <ade/util/zip_range.hpp> // util::indexed
|
||||
|
||||
#include "opencv2/gapi/gkernel.hpp"
|
||||
#include "compiler/gmodelbuilder.hpp"
|
||||
#include "compiler/gmodel.hpp" // RcDesc, GModel::init
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
|
||||
namespace test
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
cv::GMat unaryOp(cv::GMat m)
|
||||
{
|
||||
return cv::GCall(cv::GKernel{"gapi.test.unaryop", nullptr, { GShape::GMAT } }).pass(m).yield(0);
|
||||
}
|
||||
|
||||
cv::GMat binaryOp(cv::GMat m1, cv::GMat m2)
|
||||
{
|
||||
return cv::GCall(cv::GKernel{"gapi.test.binaryOp", nullptr, { GShape::GMAT } }).pass(m1, m2).yield(0);
|
||||
}
|
||||
|
||||
std::vector<ade::NodeHandle> collectOperations(const cv::gimpl::GModel::Graph& gr)
|
||||
{
|
||||
std::vector<ade::NodeHandle> ops;
|
||||
for (const auto& nh : gr.nodes())
|
||||
{
|
||||
if (gr.metadata(nh).get<cv::gimpl::NodeType>().t == cv::gimpl::NodeType::OP)
|
||||
ops.push_back(nh);
|
||||
}
|
||||
return ops;
|
||||
}
|
||||
|
||||
ade::NodeHandle inputOf(cv::gimpl::GModel::Graph& gm, ade::NodeHandle nh, std::size_t port)
|
||||
{
|
||||
for (const auto& eh : nh->inEdges())
|
||||
{
|
||||
if (gm.metadata(eh).get<cv::gimpl::Input>().port == port)
|
||||
{
|
||||
return eh->srcNode();
|
||||
}
|
||||
}
|
||||
util::throw_error(std::logic_error("port " + std::to_string(port) + " not found"));
|
||||
}
|
||||
}
|
||||
}// namespace opencv_test::test
|
||||
|
||||
TEST(GModelBuilder, Unroll_TestUnary)
|
||||
{
|
||||
cv::GMat in;
|
||||
cv::GMat out = test::unaryOp(in);
|
||||
|
||||
auto unrolled = cv::gimpl::unrollExpr(cv::GIn(in).m_args, cv::GOut(out).m_args);
|
||||
|
||||
EXPECT_EQ(1u, unrolled.all_ops.size()); // There is one operation
|
||||
EXPECT_EQ(2u, unrolled.all_data.size()); // And two data objects (in, out)
|
||||
|
||||
// TODO check what the operation is, and so on, and so on
|
||||
}
|
||||
|
||||
TEST(GModelBuilder, Unroll_TestUnaryOfUnary)
|
||||
{
|
||||
cv::GMat in;
|
||||
cv::GMat out = test::unaryOp(test::unaryOp(in));
|
||||
|
||||
auto unrolled = cv::gimpl::unrollExpr(cv::GIn(in).m_args, cv::GOut(out).m_args);
|
||||
|
||||
EXPECT_EQ(2u, unrolled.all_ops.size()); // There're two operations
|
||||
EXPECT_EQ(3u, unrolled.all_data.size()); // And three data objects (in, out)
|
||||
|
||||
// TODO check what the operation is, and so on, and so on
|
||||
}
|
||||
|
||||
TEST(GModelBuilder, Unroll_Not_All_Protocol_Inputs_Are_Reached)
|
||||
{
|
||||
cv::GMat in1, in2; // in1 -> unaryOp() -> u_op1 -> unaryOp() -> out
|
||||
auto u_op1 = test::unaryOp(in1); // in2 -> unaryOp() -> u_op2
|
||||
auto u_op2 = test::unaryOp(in2);
|
||||
auto out = test::unaryOp(u_op1);
|
||||
|
||||
EXPECT_THROW(cv::gimpl::unrollExpr(cv::GIn(in1, in2).m_args, cv::GOut(out).m_args), std::logic_error);
|
||||
}
|
||||
|
||||
TEST(GModelBuilder, Unroll_Parallel_Path)
|
||||
{
|
||||
cv::GMat in1, in2; // in1 -> unaryOp() -> out1
|
||||
auto out1 = test::unaryOp(in1); // in2 -> unaryOp() -> out2
|
||||
auto out2 = test::unaryOp(in2);
|
||||
|
||||
auto unrolled = cv::gimpl::unrollExpr(cv::GIn(in1, in2).m_args, cv::GOut(out1, out2).m_args);
|
||||
|
||||
EXPECT_EQ(unrolled.all_ops.size(), 2u);
|
||||
EXPECT_EQ(unrolled.all_data.size(), 4u);
|
||||
}
|
||||
|
||||
TEST(GModelBuilder, Unroll_WithBranch)
|
||||
{
|
||||
// in -> unaryOp() -> tmp -->unaryOp() -> out1
|
||||
// `---->unaryOp() -> out2
|
||||
|
||||
GMat in;
|
||||
auto tmp = test::unaryOp(in);
|
||||
auto out1 = test::unaryOp(tmp);
|
||||
auto out2 = test::unaryOp(tmp);
|
||||
|
||||
auto unrolled = cv::gimpl::unrollExpr(cv::GIn(in).m_args, cv::GOut(out1, out2).m_args);
|
||||
|
||||
EXPECT_EQ(unrolled.all_ops.size(), 3u);
|
||||
EXPECT_EQ(unrolled.all_data.size(), 4u);
|
||||
}
|
||||
|
||||
TEST(GModelBuilder, Build_Unary)
|
||||
{
|
||||
cv::GMat in;
|
||||
cv::GMat out = test::unaryOp(in);
|
||||
|
||||
ade::Graph g;
|
||||
cv::gimpl::GModel::Graph gm(g);
|
||||
cv::gimpl::GModel::init(gm);
|
||||
cv::gimpl::GModelBuilder(g).put(cv::GIn(in).m_args, cv::GOut(out).m_args);
|
||||
|
||||
EXPECT_EQ(3u, static_cast<std::size_t>(g.nodes().size())); // Generated graph should have three nodes
|
||||
|
||||
// TODO: Check what the nodes are
|
||||
}
|
||||
|
||||
TEST(GModelBuilder, Constant_GScalar)
|
||||
{
|
||||
// in -> addC()-----(GMat)---->mulC()-----(GMat)---->unaryOp()----out
|
||||
// ^ ^
|
||||
// | |
|
||||
// 3-------` c_s-------'
|
||||
|
||||
cv::GMat in;
|
||||
cv::GScalar c_s = 5;
|
||||
auto out = test::unaryOp((in + 3) * c_s); // 3 converted to GScalar
|
||||
|
||||
ade::Graph g;
|
||||
cv::gimpl::GModel::Graph gm(g);
|
||||
cv::gimpl::GModel::init(gm);
|
||||
auto proto_slots = cv::gimpl::GModelBuilder(g).put(cv::GIn(in).m_args, cv::GOut(out).m_args);
|
||||
cv::gimpl::Protocol p;
|
||||
std::tie(p.inputs, p.outputs, p.in_nhs, p.out_nhs) = proto_slots;
|
||||
|
||||
auto in_nh = p.in_nhs.front();
|
||||
auto addC_nh = in_nh->outNodes().front();
|
||||
auto mulC_nh = addC_nh->outNodes().front()->outNodes().front();
|
||||
|
||||
ASSERT_TRUE(gm.metadata(addC_nh).get<cv::gimpl::NodeType>().t == cv::gimpl::NodeType::OP);
|
||||
ASSERT_TRUE(gm.metadata(mulC_nh).get<cv::gimpl::NodeType>().t == cv::gimpl::NodeType::OP);
|
||||
|
||||
auto s_3 = test::inputOf(gm, addC_nh, 1);
|
||||
auto s_5 = test::inputOf(gm, mulC_nh, 1);
|
||||
|
||||
EXPECT_EQ(9u, static_cast<std::size_t>(g.nodes().size())); // 6 data nodes (1 -input, 1 output, 2 constant, 2 temp) and 3 op nodes
|
||||
EXPECT_EQ(2u, static_cast<std::size_t>(addC_nh->inNodes().size())); // in and 3
|
||||
EXPECT_EQ(2u, static_cast<std::size_t>(mulC_nh->inNodes().size())); // addC output and c_s
|
||||
EXPECT_EQ(3, (util::get<cv::gapi::own::Scalar>(gm.metadata(s_3).get<cv::gimpl::ConstValue>().arg))[0]);
|
||||
EXPECT_EQ(5, (util::get<cv::gapi::own::Scalar>(gm.metadata(s_5).get<cv::gimpl::ConstValue>().arg))[0]);
|
||||
}
|
||||
|
||||
TEST(GModelBuilder, Check_Multiple_Outputs)
|
||||
{
|
||||
// ------------------------------> r
|
||||
// '
|
||||
// ' -----------> i_out1
|
||||
// ' '
|
||||
// in ----> split3() ---> g ---> integral()
|
||||
// ' '
|
||||
// ' -----------> i_out2
|
||||
// '
|
||||
// '---------> b ---> unaryOp() ---> u_out
|
||||
|
||||
cv::GMat in, r, g, b, i_out1, i_out2, u_out;
|
||||
std::tie(r, g, b) = cv::gapi::split3(in);
|
||||
std::tie(i_out1, i_out2) = cv::gapi::integral(g, 1, 1);
|
||||
u_out = test::unaryOp(b);
|
||||
|
||||
ade::Graph gr;
|
||||
cv::gimpl::GModel::Graph gm(gr);
|
||||
cv::gimpl::GModel::init(gm);
|
||||
auto proto_slots = cv::gimpl::GModelBuilder(gr).put(cv::GIn(in).m_args, cv::GOut(r, i_out1, i_out2, u_out).m_args);
|
||||
cv::gimpl::Protocol p;
|
||||
std::tie(p.inputs, p.outputs, p.in_nhs, p.out_nhs) = proto_slots;
|
||||
|
||||
EXPECT_EQ(4u, static_cast<std::size_t>(p.out_nhs.size()));
|
||||
EXPECT_EQ(0u, gm.metadata(p.out_nhs[0]->inEdges().front()).get<cv::gimpl::Output>().port);
|
||||
EXPECT_EQ(0u, gm.metadata(p.out_nhs[1]->inEdges().front()).get<cv::gimpl::Output>().port);
|
||||
EXPECT_EQ(1u, gm.metadata(p.out_nhs[2]->inEdges().front()).get<cv::gimpl::Output>().port);
|
||||
EXPECT_EQ(0u, gm.metadata(p.out_nhs[3]->inEdges().front()).get<cv::gimpl::Output>().port);
|
||||
for (const auto& it : ade::util::indexed(p.out_nhs))
|
||||
{
|
||||
const auto& out_nh = ade::util::value(it);
|
||||
|
||||
EXPECT_EQ(cv::gimpl::NodeType::DATA, gm.metadata(out_nh).get<cv::gimpl::NodeType>().t);
|
||||
EXPECT_EQ(GShape::GMAT, gm.metadata(out_nh).get<cv::gimpl::Data>().shape);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(GModelBuilder, Unused_Outputs)
|
||||
{
|
||||
cv::GMat in;
|
||||
auto yuv_p = cv::gapi::split3(in);
|
||||
|
||||
ade::Graph g;
|
||||
cv::gimpl::GModel::Graph gm(g);
|
||||
cv::gimpl::GModel::init(gm);
|
||||
cv::gimpl::GModelBuilder(g).put(cv::GIn(in).m_args, cv::GOut(std::get<0>(yuv_p)).m_args);
|
||||
|
||||
EXPECT_EQ(5u, static_cast<std::size_t>(g.nodes().size())); // 1 input, 1 operation, 3 outputs
|
||||
}
|
||||
|
||||
TEST(GModelBuilder, Work_With_One_Channel_From_Split3)
|
||||
{
|
||||
cv::GMat in, y, u, v;
|
||||
std::tie(y, u, v) = cv::gapi::split3(in);
|
||||
auto y_blur = cv::gapi::gaussianBlur(y, cv::Size(3, 3), 1);
|
||||
|
||||
ade::Graph g;
|
||||
cv::gimpl::GModel::Graph gm(g);
|
||||
cv::gimpl::GModel::init(gm);
|
||||
cv::gimpl::GModelBuilder(g).put(cv::GIn(in).m_args, cv::GOut(y_blur).m_args);
|
||||
|
||||
EXPECT_EQ(7u, static_cast<std::size_t>(g.nodes().size())); // 1 input, 2 operation, 3 nodes from split3, 1 output
|
||||
}
|
||||
|
||||
TEST(GModelBuilder, Add_Nodes_To_Unused_Nodes)
|
||||
{
|
||||
cv::GMat in, y, u, v;
|
||||
std::tie(y, u, v) = cv::gapi::split3(in);
|
||||
auto y_blur = cv::gapi::gaussianBlur(y, cv::Size(3, 3), 1);
|
||||
// unused nodes
|
||||
auto u_blur = cv::gapi::gaussianBlur(y, cv::Size(3, 3), 1);
|
||||
auto v_blur = cv::gapi::gaussianBlur(y, cv::Size(3, 3), 1);
|
||||
|
||||
ade::Graph g;
|
||||
cv::gimpl::GModel::Graph gm(g);
|
||||
cv::gimpl::GModel::init(gm);
|
||||
cv::gimpl::GModelBuilder(g).put(cv::GIn(in).m_args, cv::GOut(y_blur).m_args);
|
||||
|
||||
EXPECT_EQ(7u, static_cast<std::size_t>(g.nodes().size())); // 1 input, 2 operation, 3 nodes from split3, 1 output
|
||||
}
|
||||
|
||||
TEST(GModelBuilder, Unlisted_Inputs)
|
||||
{
|
||||
// in1 -> binaryOp() -> out
|
||||
// ^
|
||||
// |
|
||||
// in2 ----'
|
||||
|
||||
cv::GMat in1, in2;
|
||||
auto out = test::binaryOp(in1, in2);
|
||||
|
||||
ade::Graph g;
|
||||
cv::gimpl::GModel::Graph gm(g);
|
||||
cv::gimpl::GModel::init(gm);
|
||||
// add required 2 inputs but pass 1
|
||||
EXPECT_THROW(cv::gimpl::GModelBuilder(g).put(cv::GIn(in1).m_args, cv::GOut(out).m_args), std::logic_error);
|
||||
}
|
||||
|
||||
TEST(GModelBuilder, Unroll_No_Link_Between_In_And_Out)
|
||||
{
|
||||
// in -> unaryOp() -> u_op
|
||||
// other -> unaryOp() -> out
|
||||
|
||||
cv::GMat in, other;
|
||||
auto u_op = test::unaryOp(in);
|
||||
auto out = test::unaryOp(other);
|
||||
|
||||
EXPECT_THROW(cv::gimpl::unrollExpr(cv::GIn(in).m_args, cv::GOut(out).m_args), std::logic_error);
|
||||
}
|
||||
|
||||
|
||||
TEST(GModel_builder, Check_Binary_Op)
|
||||
{
|
||||
// in1 -> binaryOp() -> out
|
||||
// ^
|
||||
// |
|
||||
// in2 -----'
|
||||
|
||||
cv::GMat in1, in2;
|
||||
auto out = test::binaryOp(in1, in2);
|
||||
|
||||
ade::Graph g;
|
||||
cv::gimpl::GModel::Graph gm(g);
|
||||
cv::gimpl::GModel::init(gm);
|
||||
auto proto_slots = cv::gimpl::GModelBuilder(g).put(cv::GIn(in1, in2).m_args, cv::GOut(out).m_args);
|
||||
|
||||
cv::gimpl::Protocol p;
|
||||
std::tie(p.inputs, p.outputs, p.in_nhs, p.out_nhs) = proto_slots;
|
||||
auto ops = test::collectOperations(g);
|
||||
|
||||
EXPECT_EQ(1u, ops.size());
|
||||
EXPECT_EQ("gapi.test.binaryOp", gm.metadata(ops.front()).get<cv::gimpl::Op>().k.name);
|
||||
EXPECT_EQ(2u, static_cast<std::size_t>(ops.front()->inEdges().size()));
|
||||
EXPECT_EQ(1u, static_cast<std::size_t>(ops.front()->outEdges().size()));
|
||||
EXPECT_EQ(1u, static_cast<std::size_t>(ops.front()->outNodes().size()));
|
||||
}
|
||||
|
||||
TEST(GModelBuilder, Add_Operation_With_Two_Out_One_Time)
|
||||
{
|
||||
// in -> integral() --> out_b1 -> unaryOp() -> out1
|
||||
// |
|
||||
// '-------> out_b2 -> unaryOp() -> out2
|
||||
|
||||
cv::GMat in, out_b1, out_b2;
|
||||
std::tie(out_b1, out_b2) = cv::gapi::integral(in, 1, 1);
|
||||
auto out1 = test::unaryOp(out_b1);
|
||||
auto out2 = test::unaryOp(out_b1);
|
||||
|
||||
ade::Graph g;
|
||||
cv::gimpl::GModel::Graph gm(g);
|
||||
cv::gimpl::GModel::init(gm);
|
||||
auto proto_slots = cv::gimpl::GModelBuilder(g).put(cv::GIn(in).m_args, cv::GOut(out1, out2).m_args);
|
||||
|
||||
auto ops = test::collectOperations(gm);
|
||||
|
||||
cv::gimpl::Protocol p;
|
||||
std::tie(p.inputs, p.outputs, p.in_nhs, p.out_nhs) = proto_slots;
|
||||
auto integral_nh = p.in_nhs.front()->outNodes().front();
|
||||
|
||||
EXPECT_EQ(3u, ops.size());
|
||||
EXPECT_EQ("org.opencv.core.matrixop.integral", gm.metadata(integral_nh).get<cv::gimpl::Op>().k.name);
|
||||
EXPECT_EQ(1u, static_cast<std::size_t>(integral_nh->inEdges().size()));
|
||||
EXPECT_EQ(2u, static_cast<std::size_t>(integral_nh->outEdges().size()));
|
||||
EXPECT_EQ(2u, static_cast<std::size_t>(integral_nh->outNodes().size()));
|
||||
}
|
||||
TEST(GModelBuilder, Add_Operation_With_One_Out_One_Time)
|
||||
{
|
||||
// in1 -> binaryOp() -> b_out -> unaryOp() -> out1
|
||||
// ^ |
|
||||
// | |
|
||||
// in2 ------- '----> unaryOp() -> out2
|
||||
|
||||
cv::GMat in1, in2;
|
||||
auto b_out = test::binaryOp(in1, in2);
|
||||
auto out1 = test::unaryOp(b_out);
|
||||
auto out2 = test::unaryOp(b_out);
|
||||
|
||||
ade::Graph g;
|
||||
cv::gimpl::GModel::Graph gm(g);
|
||||
cv::gimpl::GModel::init(gm);
|
||||
auto proto_slots = cv::gimpl::GModelBuilder(g).put(cv::GIn(in1, in2).m_args, cv::GOut(out1, out2).m_args);
|
||||
cv::gimpl::Protocol p;
|
||||
std::tie(p.inputs, p.outputs, p.in_nhs, p.out_nhs) = proto_slots;
|
||||
cv::gimpl::GModel::Graph gr(g);
|
||||
auto binaryOp_nh = p.in_nhs.front()->outNodes().front();
|
||||
|
||||
EXPECT_EQ(2u, static_cast<std::size_t>(binaryOp_nh->inEdges().size()));
|
||||
EXPECT_EQ(1u, static_cast<std::size_t>(binaryOp_nh->outEdges().size()));
|
||||
EXPECT_EQ(8u, static_cast<std::size_t>(g.nodes().size()));
|
||||
}
|
||||
} // namespace opencv_test
|
||||
@@ -0,0 +1,527 @@
|
||||
// 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 "compiler/transactions.hpp"
|
||||
|
||||
#include "gapi_mock_kernels.hpp"
|
||||
|
||||
#include "compiler/gmodel.hpp"
|
||||
#include "compiler/gislandmodel.hpp"
|
||||
#include "compiler/gcompiler.hpp"
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
|
||||
TEST(IslandFusion, TwoOps_OneIsland)
|
||||
{
|
||||
namespace J = Jupiter; // see mock_kernels.cpp
|
||||
|
||||
// Define a computation:
|
||||
//
|
||||
// (in) -> J::Foo1 -> (tmp0) -> J::Foo2 -> (out)
|
||||
// : :
|
||||
// : "island0" :
|
||||
// :<----------------------------->:
|
||||
|
||||
cv::GMat in;
|
||||
cv::GMat tmp0 = I::Foo::on(in);
|
||||
cv::GMat out = I::Foo::on(tmp0);
|
||||
cv::GComputation cc(in, out);
|
||||
|
||||
// Prepare compilation parameters manually
|
||||
const auto in_meta = cv::GMetaArg(cv::GMatDesc{CV_8U,1,cv::gapi::own::Size(32,32)});
|
||||
const auto pkg = cv::gapi::kernels<J::Foo>();
|
||||
|
||||
// Directly instantiate G-API graph compiler and run partial compilation
|
||||
cv::gimpl::GCompiler compiler(cc, {in_meta}, cv::compile_args(pkg));
|
||||
cv::gimpl::GCompiler::GPtr graph = compiler.generateGraph();
|
||||
compiler.runPasses(*graph);
|
||||
|
||||
// Inspect the graph and verify the islands configuration
|
||||
cv::gimpl::GModel::ConstGraph gm(*graph);
|
||||
|
||||
auto in_nh = cv::gimpl::GModel::dataNodeOf(gm, in);
|
||||
auto tmp_nh = cv::gimpl::GModel::dataNodeOf(gm, tmp0);
|
||||
auto out_nh = cv::gimpl::GModel::dataNodeOf(gm, out);
|
||||
|
||||
// in/out mats shouldn't be assigned to any Island
|
||||
EXPECT_FALSE(gm.metadata(in_nh ).contains<cv::gimpl::Island>());
|
||||
EXPECT_FALSE(gm.metadata(out_nh).contains<cv::gimpl::Island>());
|
||||
|
||||
// Since tmp is surrounded by two J kernels, tmp should be assigned
|
||||
// to island J
|
||||
EXPECT_TRUE(gm.metadata(tmp_nh).contains<cv::gimpl::Island>());
|
||||
}
|
||||
|
||||
TEST(IslandFusion, TwoOps_TwoIslands)
|
||||
{
|
||||
namespace J = Jupiter; // see mock_kernels.cpp
|
||||
namespace S = Saturn; // see mock_kernels.cpp
|
||||
|
||||
// Define a computation:
|
||||
//
|
||||
// (in) -> J::Foo --> (tmp0) -> S::Bar --> (out)
|
||||
// : : -> :
|
||||
// : : : :
|
||||
// :<-------->: :<-------->:
|
||||
|
||||
cv::GMat in;
|
||||
cv::GMat tmp0 = I::Foo::on(in);
|
||||
cv::GMat out = I::Bar::on(tmp0, tmp0);
|
||||
cv::GComputation cc(in, out);
|
||||
|
||||
// Prepare compilation parameters manually
|
||||
const auto in_meta = cv::GMetaArg(cv::GMatDesc{CV_8U,1,cv::gapi::own::Size(32,32)});
|
||||
const auto pkg = cv::gapi::kernels<J::Foo, S::Bar>();
|
||||
|
||||
// Directly instantiate G-API graph compiler and run partial compilation
|
||||
cv::gimpl::GCompiler compiler(cc, {in_meta}, cv::compile_args(pkg));
|
||||
cv::gimpl::GCompiler::GPtr graph = compiler.generateGraph();
|
||||
compiler.runPasses(*graph);
|
||||
|
||||
// Inspect the graph and verify the islands configuration
|
||||
cv::gimpl::GModel::ConstGraph gm(*graph);
|
||||
|
||||
auto in_nh = cv::gimpl::GModel::dataNodeOf(gm, in);
|
||||
auto tmp_nh = cv::gimpl::GModel::dataNodeOf(gm, tmp0);
|
||||
auto out_nh = cv::gimpl::GModel::dataNodeOf(gm, out);
|
||||
|
||||
// in/tmp/out mats shouldn't be assigned to any Island
|
||||
EXPECT_FALSE(gm.metadata(in_nh ).contains<cv::gimpl::Island>());
|
||||
EXPECT_FALSE(gm.metadata(out_nh).contains<cv::gimpl::Island>());
|
||||
EXPECT_FALSE(gm.metadata(tmp_nh).contains<cv::gimpl::Island>());
|
||||
|
||||
auto isl_model = gm.metadata().get<cv::gimpl::IslandModel>().model;
|
||||
cv::gimpl::GIslandModel::ConstGraph gim(*isl_model);
|
||||
|
||||
// There should be two islands in the GIslandModel
|
||||
const auto is_island = [&](ade::NodeHandle nh) {
|
||||
return (cv::gimpl::NodeKind::ISLAND
|
||||
== gim.metadata(nh).get<cv::gimpl::NodeKind>().k);
|
||||
};
|
||||
const std::size_t num_isl = std::count_if(gim.nodes().begin(),
|
||||
gim.nodes().end(),
|
||||
is_island);
|
||||
EXPECT_EQ(2u, num_isl);
|
||||
|
||||
auto isl_foo_nh = cv::gimpl::GIslandModel::producerOf(gim, tmp_nh);
|
||||
auto isl_bar_nh = cv::gimpl::GIslandModel::producerOf(gim, out_nh);
|
||||
ASSERT_NE(nullptr, isl_foo_nh);
|
||||
ASSERT_NE(nullptr, isl_bar_nh);
|
||||
|
||||
// Islands should be different
|
||||
auto isl_foo_obj = gim.metadata(isl_foo_nh).get<cv::gimpl::FusedIsland>().object;
|
||||
auto isl_bar_obj = gim.metadata(isl_bar_nh).get<cv::gimpl::FusedIsland>().object;
|
||||
EXPECT_FALSE(isl_foo_obj == isl_bar_obj);
|
||||
}
|
||||
|
||||
TEST(IslandFusion, ConsumerHasTwoInputs)
|
||||
{
|
||||
namespace J = Jupiter; // see mock_kernels.cpp
|
||||
|
||||
// Define a computation: island
|
||||
// ............................
|
||||
// (in0) ->:J::Foo -> (tmp) -> S::Bar :--> (out)
|
||||
// :....................^.....:
|
||||
// |
|
||||
// (in1) -----------------------`
|
||||
//
|
||||
|
||||
// Check that island is build correctly, when consumer has two inputs
|
||||
|
||||
GMat in[2];
|
||||
GMat tmp = I::Foo::on(in[0]);
|
||||
GMat out = I::Bar::on(tmp, in[1]);
|
||||
|
||||
cv::GComputation cc(cv::GIn(in[0], in[1]), cv::GOut(out));
|
||||
|
||||
// Prepare compilation parameters manually
|
||||
cv::GMetaArgs in_metas = {GMetaArg(cv::GMatDesc{CV_8U,1,cv::gapi::own::Size(32,32)}),
|
||||
GMetaArg(cv::GMatDesc{CV_8U,1,cv::gapi::own::Size(32,32)})};
|
||||
const auto pkg = cv::gapi::kernels<J::Foo, J::Bar>();
|
||||
|
||||
// Directly instantiate G-API graph compiler and run partial compilation
|
||||
cv::gimpl::GCompiler compiler(cc, std::move(in_metas), cv::compile_args(pkg));
|
||||
cv::gimpl::GCompiler::GPtr graph = compiler.generateGraph();
|
||||
compiler.runPasses(*graph);
|
||||
|
||||
cv::gimpl::GModel::ConstGraph gm(*graph);
|
||||
|
||||
auto in0_nh = cv::gimpl::GModel::dataNodeOf(gm, in[0]);
|
||||
auto in1_nh = cv::gimpl::GModel::dataNodeOf(gm, in[1]);
|
||||
auto tmp_nh = cv::gimpl::GModel::dataNodeOf(gm, tmp);
|
||||
auto out_nh = cv::gimpl::GModel::dataNodeOf(gm, out);
|
||||
|
||||
EXPECT_FALSE(gm.metadata(in0_nh ).contains<cv::gimpl::Island>());
|
||||
EXPECT_FALSE(gm.metadata(in1_nh ).contains<cv::gimpl::Island>());
|
||||
EXPECT_FALSE(gm.metadata(out_nh).contains<cv::gimpl::Island>());
|
||||
EXPECT_TRUE(gm.metadata(tmp_nh).contains<cv::gimpl::Island>());
|
||||
|
||||
auto isl_model = gm.metadata().get<cv::gimpl::IslandModel>().model;
|
||||
cv::gimpl::GIslandModel::ConstGraph gim(*isl_model);
|
||||
|
||||
const auto is_island = [&](ade::NodeHandle nh) {
|
||||
return (cv::gimpl::NodeKind::ISLAND
|
||||
== gim.metadata(nh).get<cv::gimpl::NodeKind>().k);
|
||||
};
|
||||
const std::size_t num_isl = std::count_if(gim.nodes().begin(),
|
||||
gim.nodes().end(),
|
||||
is_island);
|
||||
EXPECT_EQ(1u, num_isl);
|
||||
|
||||
auto isl_nh = cv::gimpl::GIslandModel::producerOf(gim, out_nh);
|
||||
auto isl_obj = gim.metadata(isl_nh).get<cv::gimpl::FusedIsland>().object;
|
||||
|
||||
EXPECT_TRUE(ade::util::contains(isl_obj->contents(), tmp_nh));
|
||||
|
||||
EXPECT_EQ(2u, static_cast<std::size_t>(isl_nh->inNodes().size()));
|
||||
EXPECT_EQ(1u, static_cast<std::size_t>(isl_nh->outNodes().size()));
|
||||
}
|
||||
|
||||
TEST(IslandFusion, DataNodeUsedDifferentBackend)
|
||||
{
|
||||
// Define a computation:
|
||||
//
|
||||
// internal isl isl0
|
||||
// ...........................
|
||||
// (in1) -> :J::Foo--> (tmp) -> J::Foo: --> (out0)
|
||||
// :............|............:
|
||||
// | ........
|
||||
// `---->:S::Baz: --> (out1)
|
||||
// :......:
|
||||
|
||||
// Check that the node was not dropped out of the island
|
||||
// because it is used by the kernel from another backend
|
||||
|
||||
namespace J = Jupiter;
|
||||
namespace S = Saturn;
|
||||
|
||||
cv::GMat in, tmp, out0;
|
||||
cv::GScalar out1;
|
||||
tmp = I::Foo::on(in);
|
||||
out0 = I::Foo::on(tmp);
|
||||
out1 = I::Baz::on(tmp);
|
||||
|
||||
cv::GComputation cc(cv::GIn(in), cv::GOut(out0, out1));
|
||||
|
||||
// Prepare compilation parameters manually
|
||||
const auto in_meta = cv::GMetaArg(cv::GMatDesc{CV_8U,1,cv::gapi::own::Size(32,32)});
|
||||
const auto pkg = cv::gapi::kernels<J::Foo, S::Baz>();
|
||||
|
||||
// Directly instantiate G-API graph compiler and run partial compilation
|
||||
cv::gimpl::GCompiler compiler(cc, {in_meta}, cv::compile_args(pkg));
|
||||
cv::gimpl::GCompiler::GPtr graph = compiler.generateGraph();
|
||||
compiler.runPasses(*graph);
|
||||
|
||||
// Inspect the graph and verify the islands configuration
|
||||
cv::gimpl::GModel::ConstGraph gm(*graph);
|
||||
|
||||
auto in_nh = cv::gimpl::GModel::dataNodeOf(gm, in);
|
||||
auto tmp_nh = cv::gimpl::GModel::dataNodeOf(gm, tmp);
|
||||
auto out0_nh = cv::gimpl::GModel::dataNodeOf(gm, out0);
|
||||
auto out1_nh = cv::gimpl::GModel::dataNodeOf(gm, out1);
|
||||
|
||||
EXPECT_TRUE(gm.metadata(tmp_nh).contains<cv::gimpl::Island>());
|
||||
|
||||
auto isl_model = gm.metadata().get<cv::gimpl::IslandModel>().model;
|
||||
cv::gimpl::GIslandModel::ConstGraph gim(*isl_model);
|
||||
|
||||
auto isl_nh = cv::gimpl::GIslandModel::producerOf(gim, tmp_nh);
|
||||
auto isl_obj = gim.metadata(isl_nh).get<cv::gimpl::FusedIsland>().object;
|
||||
|
||||
EXPECT_TRUE(ade::util::contains(isl_obj->contents(), tmp_nh));
|
||||
|
||||
EXPECT_EQ(2u, static_cast<std::size_t>(isl_nh->outNodes().size()));
|
||||
EXPECT_EQ(7u, static_cast<std::size_t>(gm.nodes().size()));
|
||||
EXPECT_EQ(6u, static_cast<std::size_t>(gim.nodes().size()));
|
||||
}
|
||||
|
||||
TEST(IslandFusion, LoopBetweenDifferentBackends)
|
||||
{
|
||||
// Define a computation:
|
||||
//
|
||||
//
|
||||
// .............................
|
||||
// (in) -> :J::Baz -> (tmp0) -> J::Quux: -> (out0)
|
||||
// | :............|..........^....
|
||||
// | ........ | | ........
|
||||
// `---->:S::Foo: `----------|-------->:S::Qux:-> (out1)
|
||||
// :....|.: | :....^.:
|
||||
// | | |
|
||||
// `-------------- (tmp1) -----------`
|
||||
|
||||
// Kernels S::Foo and S::Qux cannot merge, because there will be a cycle between islands
|
||||
|
||||
namespace J = Jupiter;
|
||||
namespace S = Saturn;
|
||||
|
||||
cv::GScalar tmp0;
|
||||
cv::GMat in, tmp1, out0, out1;
|
||||
|
||||
tmp0 = I::Baz::on(in);
|
||||
tmp1 = I::Foo::on(in);
|
||||
out1 = I::Qux::on(tmp1, tmp0);
|
||||
out0 = I::Quux::on(tmp0, tmp1);
|
||||
|
||||
cv::GComputation cc(cv::GIn(in), cv::GOut(out1, out0));
|
||||
|
||||
// Prepare compilation parameters manually
|
||||
const auto in_meta = cv::GMetaArg(cv::GMatDesc{CV_8U,1,cv::gapi::own::Size(32,32)});
|
||||
const auto pkg = cv::gapi::kernels<J::Baz, J::Quux, S::Foo, S::Qux>();
|
||||
|
||||
// Directly instantiate G-API graph compiler and run partial compilation
|
||||
cv::gimpl::GCompiler compiler(cc, {in_meta}, cv::compile_args(pkg));
|
||||
cv::gimpl::GCompiler::GPtr graph = compiler.generateGraph();
|
||||
compiler.runPasses(*graph);
|
||||
|
||||
cv::gimpl::GModel::ConstGraph gm(*graph);
|
||||
auto isl_model = gm.metadata().get<cv::gimpl::IslandModel>().model;
|
||||
cv::gimpl::GIslandModel::ConstGraph gim(*isl_model);
|
||||
|
||||
auto in_nh = cv::gimpl::GModel::dataNodeOf(gm, in);
|
||||
auto tmp0_nh = cv::gimpl::GModel::dataNodeOf(gm, tmp0);
|
||||
auto tmp1_nh = cv::gimpl::GModel::dataNodeOf(gm, tmp1);
|
||||
auto out0_nh = cv::gimpl::GModel::dataNodeOf(gm, out0);
|
||||
auto out1_nh = cv::gimpl::GModel::dataNodeOf(gm, out1);
|
||||
|
||||
EXPECT_FALSE(gm.metadata(in_nh ).contains<cv::gimpl::Island>());
|
||||
EXPECT_FALSE(gm.metadata(out0_nh).contains<cv::gimpl::Island>());
|
||||
EXPECT_FALSE(gm.metadata(out1_nh).contains<cv::gimpl::Island>());
|
||||
// The node does not belong to the island so as not to form a cycle
|
||||
EXPECT_FALSE(gm.metadata(tmp1_nh).contains<cv::gimpl::Island>());
|
||||
|
||||
EXPECT_TRUE(gm.metadata(tmp0_nh).contains<cv::gimpl::Island>());
|
||||
|
||||
// There should be three islands in the GIslandModel
|
||||
const auto is_island = [&](ade::NodeHandle nh) {
|
||||
return (cv::gimpl::NodeKind::ISLAND
|
||||
== gim.metadata(nh).get<cv::gimpl::NodeKind>().k);
|
||||
};
|
||||
const std::size_t num_isl = std::count_if(gim.nodes().begin(),
|
||||
gim.nodes().end(),
|
||||
is_island);
|
||||
EXPECT_EQ(3u, num_isl);
|
||||
}
|
||||
|
||||
TEST(IslandsFusion, PartionOverlapUserIsland)
|
||||
{
|
||||
// Define a computation:
|
||||
//
|
||||
// internal isl isl0
|
||||
// ........ ........
|
||||
// (in0) -> :J::Foo:--> (tmp) ->:S::Bar: --> (out)
|
||||
// :......: :......:
|
||||
// ^
|
||||
// |
|
||||
// (in1) --------------------------`
|
||||
|
||||
// Check that internal islands does't overlap user island
|
||||
|
||||
namespace J = Jupiter;
|
||||
namespace S = Saturn;
|
||||
|
||||
GMat in[2];
|
||||
GMat tmp = I::Foo::on(in[0]);
|
||||
GMat out = I::Bar::on(tmp, in[1]);
|
||||
|
||||
cv::gapi::island("isl0", cv::GIn(tmp, in[1]), cv::GOut(out));
|
||||
cv::GComputation cc(cv::GIn(in[0], in[1]), cv::GOut(out));
|
||||
|
||||
// Prepare compilation parameters manually
|
||||
cv::GMetaArgs in_metas = {GMetaArg(cv::GMatDesc{CV_8U,1,cv::gapi::own::Size(32,32)}),
|
||||
GMetaArg(cv::GMatDesc{CV_8U,1,cv::gapi::own::Size(32,32)})};
|
||||
const auto pkg = cv::gapi::kernels<J::Foo, J::Bar>();
|
||||
|
||||
// Directly instantiate G-API graph compiler and run partial compilation
|
||||
cv::gimpl::GCompiler compiler(cc, std::move(in_metas), cv::compile_args(pkg));
|
||||
cv::gimpl::GCompiler::GPtr graph = compiler.generateGraph();
|
||||
compiler.runPasses(*graph);
|
||||
|
||||
cv::gimpl::GModel::ConstGraph gm(*graph);
|
||||
auto isl_model = gm.metadata().get<cv::gimpl::IslandModel>().model;
|
||||
cv::gimpl::GIslandModel::ConstGraph gim(*isl_model);
|
||||
|
||||
auto in0_nh = cv::gimpl::GModel::dataNodeOf(gm, in[0]);
|
||||
auto in1_nh = cv::gimpl::GModel::dataNodeOf(gm, in[1]);
|
||||
auto tmp_nh = cv::gimpl::GModel::dataNodeOf(gm, tmp);
|
||||
auto out_nh = cv::gimpl::GModel::dataNodeOf(gm, out);
|
||||
|
||||
auto foo_nh = cv::gimpl::GIslandModel::producerOf(gim, tmp_nh);
|
||||
auto foo_obj = gim.metadata(foo_nh).get<cv::gimpl::FusedIsland>().object;
|
||||
|
||||
auto bar_nh = cv::gimpl::GIslandModel::producerOf(gim, out_nh);
|
||||
auto bar_obj = gim.metadata(bar_nh).get<cv::gimpl::FusedIsland>().object;
|
||||
|
||||
EXPECT_FALSE(gm.metadata(in0_nh ).contains<cv::gimpl::Island>());
|
||||
EXPECT_FALSE(gm.metadata(in1_nh ).contains<cv::gimpl::Island>());
|
||||
EXPECT_FALSE(gm.metadata(out_nh).contains<cv::gimpl::Island>());
|
||||
EXPECT_FALSE(gm.metadata(tmp_nh).contains<cv::gimpl::Island>());
|
||||
EXPECT_FALSE(foo_obj->is_user_specified());
|
||||
EXPECT_TRUE(bar_obj->is_user_specified());
|
||||
}
|
||||
|
||||
TEST(IslandsFusion, DISABLED_IslandContainsDifferentBackends)
|
||||
{
|
||||
// Define a computation:
|
||||
//
|
||||
// isl0
|
||||
// ............................
|
||||
// (in0) -> :J::Foo:--> (tmp) -> S::Bar: --> (out)
|
||||
// :..........................:
|
||||
// ^
|
||||
// |
|
||||
// (in1) --------------------------`
|
||||
|
||||
// Try create island contains different backends
|
||||
|
||||
namespace J = Jupiter;
|
||||
namespace S = Saturn;
|
||||
|
||||
GMat in[2];
|
||||
GMat tmp = I::Foo::on(in[0]);
|
||||
GMat out = I::Bar::on(tmp, in[1]);
|
||||
|
||||
cv::gapi::island("isl0", cv::GIn(in[0], in[1]), cv::GOut(out));
|
||||
cv::GComputation cc(cv::GIn(in[0], in[1]), cv::GOut(out));
|
||||
|
||||
// Prepare compilation parameters manually
|
||||
cv::GMetaArgs in_metas = {GMetaArg(cv::GMatDesc{CV_8U,1,cv::gapi::own::Size(32,32)}),
|
||||
GMetaArg(cv::GMatDesc{CV_8U,1,cv::gapi::own::Size(32,32)})};
|
||||
const auto pkg = cv::gapi::kernels<J::Foo, S::Bar>();
|
||||
|
||||
// Directly instantiate G-API graph compiler and run partial compilation
|
||||
cv::gimpl::GCompiler compiler(cc, std::move(in_metas), cv::compile_args(pkg));
|
||||
cv::gimpl::GCompiler::GPtr graph = compiler.generateGraph();
|
||||
EXPECT_ANY_THROW(compiler.runPasses(*graph));
|
||||
}
|
||||
|
||||
TEST(IslandFusion, WithLoop)
|
||||
{
|
||||
namespace J = Jupiter; // see mock_kernels.cpp
|
||||
|
||||
// Define a computation:
|
||||
//
|
||||
// (in) -> J::Foo --> (tmp0) -> J::Foo --> (tmp1) -> J::Qux -> (out)
|
||||
// : ^
|
||||
// '--> J::Baz --> (scl0) --'
|
||||
//
|
||||
// The whole thing should be merged to a single island
|
||||
// There's a cycle warning if Foo/Foo/Qux are merged first
|
||||
// Then this island both produces data for Baz and consumes data
|
||||
// from Baz. This is a cycle and it should be avoided by the merging code.
|
||||
//
|
||||
cv::GMat in;
|
||||
cv::GMat tmp0 = I::Foo::on(in);
|
||||
cv::GMat tmp1 = I::Foo::on(tmp0);
|
||||
cv::GScalar scl0 = I::Baz::on(tmp0);
|
||||
cv::GMat out = I::Qux::on(tmp1, scl0);
|
||||
cv::GComputation cc(in, out);
|
||||
|
||||
// Prepare compilation parameters manually
|
||||
const auto in_meta = cv::GMetaArg(cv::GMatDesc{CV_8U,1,cv::gapi::own::Size(32,32)});
|
||||
const auto pkg = cv::gapi::kernels<J::Foo, J::Baz, J::Qux>();
|
||||
|
||||
// Directly instantiate G-API graph compiler and run partial compilation
|
||||
cv::gimpl::GCompiler compiler(cc, {in_meta}, cv::compile_args(pkg));
|
||||
cv::gimpl::GCompiler::GPtr graph = compiler.generateGraph();
|
||||
compiler.runPasses(*graph);
|
||||
|
||||
// Inspect the graph and verify the islands configuration
|
||||
cv::gimpl::GModel::ConstGraph gm(*graph);
|
||||
|
||||
auto in_nh = cv::gimpl::GModel::dataNodeOf(gm, in);
|
||||
auto tmp0_nh = cv::gimpl::GModel::dataNodeOf(gm, tmp0);
|
||||
auto tmp1_nh = cv::gimpl::GModel::dataNodeOf(gm, tmp1);
|
||||
auto scl0_nh = cv::gimpl::GModel::dataNodeOf(gm, scl0);
|
||||
auto out_nh = cv::gimpl::GModel::dataNodeOf(gm, out);
|
||||
|
||||
// in/out mats shouldn't be assigned to any Island
|
||||
EXPECT_FALSE(gm.metadata(in_nh ).contains<cv::gimpl::Island>());
|
||||
EXPECT_FALSE(gm.metadata(out_nh).contains<cv::gimpl::Island>());
|
||||
|
||||
// tmp0/tmp1/scl should be assigned to island
|
||||
EXPECT_TRUE(gm.metadata(tmp0_nh).contains<cv::gimpl::Island>());
|
||||
EXPECT_TRUE(gm.metadata(tmp1_nh).contains<cv::gimpl::Island>());
|
||||
EXPECT_TRUE(gm.metadata(scl0_nh).contains<cv::gimpl::Island>());
|
||||
|
||||
// Check that there's a single island object and it contains all
|
||||
// that data object handles
|
||||
|
||||
cv::gimpl::GModel::ConstGraph cg(*graph);
|
||||
auto isl_model = cg.metadata().get<cv::gimpl::IslandModel>().model;
|
||||
cv::gimpl::GIslandModel::ConstGraph gim(*isl_model);
|
||||
|
||||
const auto is_island = [&](ade::NodeHandle nh) {
|
||||
return (cv::gimpl::NodeKind::ISLAND
|
||||
== gim.metadata(nh).get<cv::gimpl::NodeKind>().k);
|
||||
};
|
||||
const std::size_t num_isl = std::count_if(gim.nodes().begin(),
|
||||
gim.nodes().end(),
|
||||
is_island);
|
||||
EXPECT_EQ(1u, num_isl);
|
||||
|
||||
auto isl_nh = cv::gimpl::GIslandModel::producerOf(gim, out_nh);
|
||||
auto isl_obj = gim.metadata(isl_nh).get<cv::gimpl::FusedIsland>().object;
|
||||
EXPECT_TRUE(ade::util::contains(isl_obj->contents(), tmp0_nh));
|
||||
EXPECT_TRUE(ade::util::contains(isl_obj->contents(), tmp1_nh));
|
||||
EXPECT_TRUE(ade::util::contains(isl_obj->contents(), scl0_nh));
|
||||
}
|
||||
|
||||
TEST(IslandFusion, Regression_ShouldFuseAll)
|
||||
{
|
||||
// Initially the merge procedure didn't work as expected and
|
||||
// stopped fusion even if it could be continued (e.g. full
|
||||
// GModel graph could be fused into a single GIsland node).
|
||||
// Example of this is custom RGB 2 YUV pipeline as shown below:
|
||||
|
||||
cv::GMat r, g, b;
|
||||
cv::GMat y = 0.299f*r + 0.587f*g + 0.114f*b;
|
||||
cv::GMat u = 0.492f*(b - y);
|
||||
cv::GMat v = 0.877f*(r - y);
|
||||
|
||||
cv::GComputation customCvt({r, g, b}, {y, u, v});
|
||||
|
||||
const auto in_meta = cv::GMetaArg(cv::GMatDesc{CV_8U,1,cv::Size(32,32)});
|
||||
|
||||
// Directly instantiate G-API graph compiler and run partial compilation
|
||||
cv::gimpl::GCompiler compiler(customCvt, {in_meta,in_meta,in_meta}, cv::compile_args());
|
||||
cv::gimpl::GCompiler::GPtr graph = compiler.generateGraph();
|
||||
compiler.runPasses(*graph);
|
||||
|
||||
cv::gimpl::GModel::ConstGraph cg(*graph);
|
||||
auto isl_model = cg.metadata().get<cv::gimpl::IslandModel>().model;
|
||||
cv::gimpl::GIslandModel::ConstGraph gim(*isl_model);
|
||||
|
||||
std::vector<ade::NodeHandle> data_nhs;
|
||||
std::vector<ade::NodeHandle> isl_nhs;
|
||||
for (auto &&nh : gim.nodes())
|
||||
{
|
||||
if (gim.metadata(nh).contains<cv::gimpl::FusedIsland>())
|
||||
isl_nhs.push_back(std::move(nh));
|
||||
else if (gim.metadata(nh).contains<cv::gimpl::DataSlot>())
|
||||
data_nhs.push_back(std::move(nh));
|
||||
else FAIL() << "GIslandModel node with unexpected metadata type";
|
||||
}
|
||||
|
||||
EXPECT_EQ(6u, data_nhs.size()); // 3 input nodes + 3 output nodes
|
||||
EXPECT_EQ(1u, isl_nhs.size()); // 1 island
|
||||
}
|
||||
|
||||
// FIXME: add more tests on mixed (hetero) graphs
|
||||
// ADE-222, ADE-223
|
||||
|
||||
// FIXME: add test on combination of user-specified island
|
||||
// which should be heterogeneous (based on kernel availability)
|
||||
// but as we don't support this, compilation should fail
|
||||
|
||||
// FIXME: add tests on automatic inferred islands which are
|
||||
// connected via 1) gmat 2) gscalar 3) garray,
|
||||
// check the case with executor
|
||||
// check the case when this 1/2/3 interim object is also gcomputation output
|
||||
|
||||
} // namespace opencv_test
|
||||
@@ -0,0 +1,653 @@
|
||||
// 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 "compiler/gmodel.hpp"
|
||||
#include "compiler/gcompiled_priv.hpp"
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Tests on a plain graph
|
||||
//
|
||||
// (in) -> Blur1 -> (tmp0) -> Blur2 -> (tmp1) -> Blur3 -> (tmp2) -> Blur4 -> (out)
|
||||
//
|
||||
namespace
|
||||
{
|
||||
struct PlainIslandsFixture
|
||||
{
|
||||
cv::GMat in;
|
||||
cv::GMat tmp[3];
|
||||
cv::GMat out;
|
||||
|
||||
PlainIslandsFixture()
|
||||
{
|
||||
tmp[0] = cv::gapi::boxFilter(in, -1, cv::Size(3,3));
|
||||
tmp[1] = cv::gapi::boxFilter(tmp[0], -1, cv::Size(3,3));
|
||||
tmp[2] = cv::gapi::boxFilter(tmp[1], -1, cv::Size(3,3));
|
||||
out = cv::gapi::boxFilter(tmp[2], -1, cv::Size(3,3));
|
||||
}
|
||||
};
|
||||
|
||||
struct Islands: public ::testing::Test, public PlainIslandsFixture {};
|
||||
|
||||
using GIntArray = GArray<int>;
|
||||
|
||||
G_TYPED_KERNEL(CreateMatWithDiag, <GMat(GIntArray)>, "test.array.create_mat_with_diag")
|
||||
{
|
||||
static GMatDesc outMeta(const GArrayDesc&) { return cv::GMatDesc{CV_32S, 1,{3, 3}}; }
|
||||
};
|
||||
|
||||
GAPI_OCV_KERNEL(CreateMatWithDiagImpl, CreateMatWithDiag)
|
||||
{
|
||||
static void run(const std::vector<int> &in, cv::Mat& out)
|
||||
{
|
||||
auto size = static_cast<int>(in.size());
|
||||
out = Mat::zeros(size, size, CV_32SC1);
|
||||
for(int i = 0; i < out.rows; i++)
|
||||
{
|
||||
auto* row = out.ptr<int>(i);
|
||||
row[i] = in[i];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
G_TYPED_KERNEL(Mat2Array, <GIntArray(GMat)>, "test.array.mat2array")
|
||||
{
|
||||
static GArrayDesc outMeta(const GMatDesc&) { return empty_array_desc(); }
|
||||
};
|
||||
|
||||
GAPI_OCV_KERNEL(Mat2ArrayImpl, Mat2Array)
|
||||
{
|
||||
static void run(const cv::Mat& in, std::vector<int> &out)
|
||||
{
|
||||
GAPI_Assert(in.depth() == CV_32S && in.isContinuous());
|
||||
out.reserve(in.cols * in.rows);
|
||||
out.assign((int*)in.datastart, (int*)in.dataend);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
TEST_F(Islands, SmokeTest)
|
||||
{
|
||||
// (in) -> Blur1 -> (tmp0) -> Blur2 -> (tmp1) -> Blur3 -> (tmp2) -> Blur4 -> (out)
|
||||
// : "test" :
|
||||
// :<------------------------->:
|
||||
cv::gapi::island("test", cv::GIn(tmp[0]), cv::GOut(tmp[2]));
|
||||
auto cc = cv::GComputation(in, out).compile(cv::GMatDesc{CV_8U,1,{640,480}});
|
||||
|
||||
const auto &gm = cc.priv().model();
|
||||
const auto tmp0_nh = cv::gimpl::GModel::dataNodeOf(gm, tmp[0]);
|
||||
const auto tmp1_nh = cv::gimpl::GModel::dataNodeOf(gm, tmp[1]);
|
||||
const auto tmp2_nh = cv::gimpl::GModel::dataNodeOf(gm, tmp[2]);
|
||||
|
||||
// tmp1 and tmp3 is not a part of any island
|
||||
EXPECT_FALSE(gm.metadata(tmp0_nh).contains<cv::gimpl::Island>());
|
||||
EXPECT_FALSE(gm.metadata(tmp2_nh).contains<cv::gimpl::Island>());
|
||||
|
||||
// tmp2 is part of "test" island
|
||||
EXPECT_TRUE(gm.metadata(tmp1_nh).contains<cv::gimpl::Island>());
|
||||
EXPECT_EQ("test", gm.metadata(tmp1_nh).get<cv::gimpl::Island>().island);
|
||||
}
|
||||
|
||||
TEST_F(Islands, TwoIslands)
|
||||
{
|
||||
// (in) -> Blur1 -> (tmp0) -> Blur2 -> (tmp1) -> Blur3 -> (tmp2) -> Blur4 -> (out)
|
||||
// : "test1" : : "test2" :
|
||||
// :<---------------------------->: :<--------------------------------->
|
||||
EXPECT_NO_THROW(cv::gapi::island("test1", cv::GIn(in), cv::GOut(tmp[1])));
|
||||
EXPECT_NO_THROW(cv::gapi::island("test2", cv::GIn(tmp[1]), cv::GOut(out)));
|
||||
|
||||
auto cc = cv::GComputation(in, out).compile(cv::GMatDesc{CV_8U,1,{640,480}});
|
||||
const auto &gm = cc.priv().model();
|
||||
const auto in_nh = cv::gimpl::GModel::dataNodeOf(gm, in);
|
||||
const auto tmp0_nh = cv::gimpl::GModel::dataNodeOf(gm, tmp[0]);
|
||||
const auto tmp1_nh = cv::gimpl::GModel::dataNodeOf(gm, tmp[1]);
|
||||
const auto tmp2_nh = cv::gimpl::GModel::dataNodeOf(gm, tmp[2]);
|
||||
const auto out_nh = cv::gimpl::GModel::dataNodeOf(gm, out);
|
||||
|
||||
// Only tmp0 and tmp2 should be listed in islands.
|
||||
EXPECT_TRUE (gm.metadata(tmp0_nh).contains<cv::gimpl::Island>());
|
||||
EXPECT_TRUE (gm.metadata(tmp2_nh).contains<cv::gimpl::Island>());
|
||||
EXPECT_FALSE(gm.metadata(in_nh) .contains<cv::gimpl::Island>());
|
||||
EXPECT_FALSE(gm.metadata(tmp1_nh).contains<cv::gimpl::Island>());
|
||||
EXPECT_FALSE(gm.metadata(out_nh) .contains<cv::gimpl::Island>());
|
||||
|
||||
EXPECT_EQ("test1", gm.metadata(tmp0_nh).get<cv::gimpl::Island>().island);
|
||||
EXPECT_EQ("test2", gm.metadata(tmp2_nh).get<cv::gimpl::Island>().island);
|
||||
}
|
||||
|
||||
// FIXME: Disabled since currently merge procedure merges two into one
|
||||
// succesfully
|
||||
TEST_F(Islands, DISABLED_Two_Islands_With_Same_Name_Should_Fail)
|
||||
{
|
||||
// (in) -> Blur1 -> (tmp0) -> Blur2 -> (tmp1) -> Blur3 -> (tmp2) -> Blur4 -> (out)
|
||||
// : "test1" : : "test1" :
|
||||
// :<---------------------------->: :<--------------------------------->
|
||||
|
||||
EXPECT_NO_THROW(cv::gapi::island("test1", cv::GIn(in), cv::GOut(tmp[1])));
|
||||
EXPECT_NO_THROW(cv::gapi::island("test1", cv::GIn(tmp[1]), cv::GOut(out)));
|
||||
|
||||
EXPECT_ANY_THROW(cv::GComputation(in, out).compile(cv::GMatDesc{CV_8U,1,{640,480}}));
|
||||
}
|
||||
|
||||
|
||||
// (in) -> Blur1 -> (tmp0) -> Blur2 -> (tmp1) -> Blur3 -> (tmp2) -> Blur4 -> (out)
|
||||
// : "test1": : :
|
||||
// :<----------------:----------->: :
|
||||
// : :
|
||||
// : "test2" :
|
||||
// :<------------------------->:
|
||||
TEST_F(Islands, OverlappingIslands1)
|
||||
{
|
||||
EXPECT_NO_THROW (cv::gapi::island("test1", cv::GIn(in), cv::GOut(tmp[1])));
|
||||
EXPECT_ANY_THROW(cv::gapi::island("test2", cv::GIn(tmp[0]), cv::GOut(tmp[2])));
|
||||
}
|
||||
|
||||
TEST_F(Islands, OverlappingIslands2)
|
||||
{
|
||||
EXPECT_NO_THROW (cv::gapi::island("test2", cv::GIn(tmp[0]), cv::GOut(tmp[2])));
|
||||
EXPECT_ANY_THROW(cv::gapi::island("test1", cv::GIn(in), cv::GOut(tmp[1])));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Tests on a complex graph
|
||||
//
|
||||
// (in0) -> Not -> (tmp0) --> Add ---------> (tmp2) --> AddC -------> (out0)
|
||||
// ^ ^
|
||||
// (in1) -> Blur -> (tmp1) ----'--> Sum ----> (scl0) ----'
|
||||
// :
|
||||
// `------------> Median -> (tmp3) --> Blur -------> (out1)
|
||||
//
|
||||
namespace
|
||||
{
|
||||
struct ComplexIslandsFixture
|
||||
{
|
||||
cv::GMat in[2];
|
||||
cv::GMat tmp[4];
|
||||
cv::GScalar scl;
|
||||
cv::GMat out[2];
|
||||
|
||||
ComplexIslandsFixture()
|
||||
{
|
||||
tmp[0] = cv::gapi::bitwise_not(in[0]);
|
||||
tmp[1] = cv::gapi::boxFilter(in[1], -1, cv::Size(3,3));
|
||||
tmp[2] = tmp[0] + tmp[1]; // FIXME: handle tmp[2] = tmp[0]+tmp[2] typo
|
||||
scl = cv::gapi::sum(tmp[1]);
|
||||
tmp[3] = cv::gapi::medianBlur(tmp[1], 3);
|
||||
out[0] = tmp[2] + scl;
|
||||
out[1] = cv::gapi::boxFilter(tmp[3], -1, cv::Size(3,3));
|
||||
}
|
||||
};
|
||||
|
||||
struct ComplexIslands: public ::testing::Test, public ComplexIslandsFixture {};
|
||||
} // namespace
|
||||
|
||||
TEST_F(ComplexIslands, SmokeTest)
|
||||
{
|
||||
// isl0 #internal1
|
||||
// ........................... ........
|
||||
// (in0) -> Not -> (tmp0) --> Add ---------> (tmp2) --> AddC -------> (out0)
|
||||
// :............ ........^...: :.^....:
|
||||
// ... : :
|
||||
// (in1) -> Blur -> (tmp1) ----'--> Sum ----> (scl0) ----'
|
||||
// : isl1
|
||||
// : ..............................
|
||||
// `------------> Median -> (tmp3) --> Blur -------> (out1)
|
||||
// :............................:
|
||||
|
||||
cv::gapi::island("isl0", cv::GIn(in[0], tmp[1]), cv::GOut(tmp[2]));
|
||||
cv::gapi::island("isl1", cv::GIn(tmp[1]), cv::GOut(out[1]));
|
||||
auto cc = cv::GComputation(cv::GIn(in[0], in[1]), cv::GOut(out[0], out[1]))
|
||||
.compile(cv::GMatDesc{CV_8U,1,{640,480}},
|
||||
cv::GMatDesc{CV_8U,1,{640,480}});
|
||||
const auto &gm = cc.priv().model();
|
||||
const auto in0_nh = cv::gimpl::GModel::dataNodeOf(gm, in[0]);
|
||||
const auto in1_nh = cv::gimpl::GModel::dataNodeOf(gm, in[1]);
|
||||
const auto tmp0_nh = cv::gimpl::GModel::dataNodeOf(gm, tmp[0]);
|
||||
const auto tmp1_nh = cv::gimpl::GModel::dataNodeOf(gm, tmp[1]);
|
||||
const auto tmp2_nh = cv::gimpl::GModel::dataNodeOf(gm, tmp[2]);
|
||||
const auto tmp3_nh = cv::gimpl::GModel::dataNodeOf(gm, tmp[3]);
|
||||
const auto scl_nh = cv::gimpl::GModel::dataNodeOf(gm, scl);
|
||||
const auto out0_nh = cv::gimpl::GModel::dataNodeOf(gm, out[0]);
|
||||
const auto out1_nh = cv::gimpl::GModel::dataNodeOf(gm, out[1]);
|
||||
|
||||
// tmp0, tmp3 are in islands, others are not
|
||||
EXPECT_TRUE(gm.metadata(tmp0_nh) .contains<cv::gimpl::Island>()); // isl0
|
||||
EXPECT_TRUE(gm.metadata(tmp3_nh) .contains<cv::gimpl::Island>()); // isl1
|
||||
EXPECT_FALSE(gm.metadata(in0_nh) .contains<cv::gimpl::Island>()); // (input is never fused)
|
||||
EXPECT_FALSE(gm.metadata(in1_nh) .contains<cv::gimpl::Island>()); // (input is never fused)
|
||||
EXPECT_TRUE (gm.metadata(tmp1_nh).contains<cv::gimpl::Island>()); // <internal island>
|
||||
EXPECT_FALSE(gm.metadata(tmp2_nh).contains<cv::gimpl::Island>()); // #not fused as cycle-causing#
|
||||
EXPECT_FALSE(gm.metadata(scl_nh) .contains<cv::gimpl::Island>()); // #not fused as cycle-causing#
|
||||
EXPECT_FALSE(gm.metadata(out0_nh).contains<cv::gimpl::Island>()); // (output is never fused)
|
||||
EXPECT_FALSE(gm.metadata(out1_nh).contains<cv::gimpl::Island>()); // (output is never fused)
|
||||
|
||||
EXPECT_EQ("isl0", gm.metadata(tmp0_nh).get<cv::gimpl::Island>().island);
|
||||
EXPECT_EQ("isl1", gm.metadata(tmp3_nh).get<cv::gimpl::Island>().island);
|
||||
|
||||
EXPECT_NE("isl0", gm.metadata(tmp1_nh).get<cv::gimpl::Island>().island);
|
||||
EXPECT_NE("isl1", gm.metadata(tmp1_nh).get<cv::gimpl::Island>().island);
|
||||
|
||||
// FIXME: Add a test with same graph for Fusion and check GIslandModel
|
||||
}
|
||||
|
||||
TEST_F(ComplexIslands, DistinictIslandsWithSameName)
|
||||
{
|
||||
// isl0
|
||||
// ...........................
|
||||
// (in0) -> Not -> (tmp0) --> Add ---------> (tmp2) --> AddC -------> (out0)
|
||||
// :............ ........^...: ^
|
||||
// ... : :
|
||||
// (in1) -> Blur -> (tmp1) ----'--> Sum ----> (scl0) ----'
|
||||
// : isl0
|
||||
// : ..............................
|
||||
// `------------> Median -> (tmp3) --> Blur -------> (out1)
|
||||
// :............................:
|
||||
|
||||
cv::gapi::island("isl0", cv::GIn(in[0], tmp[1]), cv::GOut(tmp[2]));
|
||||
cv::gapi::island("isl0", cv::GIn(tmp[1]), cv::GOut(out[1]));
|
||||
|
||||
auto cc = cv::GComputation(cv::GIn(in[0], in[1]), cv::GOut(out[0], out[1]));
|
||||
|
||||
EXPECT_ANY_THROW(cc.compile(cv::GMatDesc{CV_8U,1,{640,480}},
|
||||
cv::GMatDesc{CV_8U,1,{640,480}}));
|
||||
}
|
||||
|
||||
TEST_F(ComplexIslands, FullGraph)
|
||||
{
|
||||
cv::gapi::island("isl0", cv::GIn(in[0], in[1]), cv::GOut(out[0], out[1]));
|
||||
auto cc = cv::GComputation(cv::GIn(in[0], in[1]), cv::GOut(out[0], out[1]))
|
||||
.compile(cv::GMatDesc{CV_8U,1,{640,480}},
|
||||
cv::GMatDesc{CV_8U,1,{640,480}});
|
||||
const auto &gm = cc.priv().model();
|
||||
std::vector<ade::NodeHandle> handles_inside = {
|
||||
cv::gimpl::GModel::dataNodeOf(gm, tmp[0]),
|
||||
cv::gimpl::GModel::dataNodeOf(gm, tmp[1]),
|
||||
cv::gimpl::GModel::dataNodeOf(gm, tmp[2]),
|
||||
cv::gimpl::GModel::dataNodeOf(gm, tmp[3]),
|
||||
cv::gimpl::GModel::dataNodeOf(gm, scl),
|
||||
};
|
||||
std::vector<ade::NodeHandle> handles_outside = {
|
||||
cv::gimpl::GModel::dataNodeOf(gm, in[0]),
|
||||
cv::gimpl::GModel::dataNodeOf(gm, in[1]),
|
||||
cv::gimpl::GModel::dataNodeOf(gm, out[0]),
|
||||
cv::gimpl::GModel::dataNodeOf(gm, out[1]),
|
||||
};
|
||||
|
||||
for (auto nh_inside : handles_inside)
|
||||
{
|
||||
EXPECT_EQ("isl0", gm.metadata(nh_inside).get<cv::gimpl::Island>().island);
|
||||
}
|
||||
for (auto nh_outside : handles_outside)
|
||||
{
|
||||
EXPECT_FALSE(gm.metadata(nh_outside).contains<cv::gimpl::Island>());
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(ComplexIslands, ViaScalar)
|
||||
{
|
||||
//
|
||||
// .........................................#internal0.
|
||||
// (in0) -> Not -> (tmp0) --> Add ---------> (tmp2) --> AddC -------> (out0)
|
||||
// :....................^.........................^...:
|
||||
// : :
|
||||
// .....................:.........(isl0). :
|
||||
// (in1) -> Blur -> (tmp1) ----'--> Sum ----> (scl0) ----'
|
||||
// :..........:.........................:
|
||||
// :
|
||||
// : ..................#internal1.
|
||||
// `------------> Median -> (tmp3) --> Blur -------> (out1)
|
||||
// :...........................:
|
||||
|
||||
cv::gapi::island("isl0", cv::GIn(in[1]), cv::GOut(scl));
|
||||
auto cc = cv::GComputation(cv::GIn(in[0], in[1]), cv::GOut(out[0], out[1]))
|
||||
.compile(cv::GMatDesc{CV_8U,1,{640,480}},
|
||||
cv::GMatDesc{CV_8U,1,{640,480}});
|
||||
const auto &gm = cc.priv().model();
|
||||
|
||||
const auto tmp0_nh = cv::gimpl::GModel::dataNodeOf(gm, tmp[0]);
|
||||
const auto tmp1_nh = cv::gimpl::GModel::dataNodeOf(gm, tmp[1]);
|
||||
const auto tmp2_nh = cv::gimpl::GModel::dataNodeOf(gm, tmp[2]);
|
||||
const auto tmp3_nh = cv::gimpl::GModel::dataNodeOf(gm, tmp[3]);
|
||||
|
||||
EXPECT_NE("isl0", gm.metadata(tmp0_nh).get<cv::gimpl::Island>().island); // <internal>
|
||||
EXPECT_EQ("isl0", gm.metadata(tmp1_nh).get<cv::gimpl::Island>().island); // isl0
|
||||
EXPECT_NE("isl0", gm.metadata(tmp2_nh).get<cv::gimpl::Island>().island); // <internal>
|
||||
EXPECT_NE("isl0", gm.metadata(tmp3_nh).get<cv::gimpl::Island>().island); // <internal>
|
||||
|
||||
std::vector<ade::NodeHandle> handles_outside = {
|
||||
cv::gimpl::GModel::dataNodeOf(gm, in[0]),
|
||||
cv::gimpl::GModel::dataNodeOf(gm, in[1]),
|
||||
cv::gimpl::GModel::dataNodeOf(gm, scl),
|
||||
cv::gimpl::GModel::dataNodeOf(gm, out[0]),
|
||||
cv::gimpl::GModel::dataNodeOf(gm, out[1]),
|
||||
};
|
||||
for (auto nh_outside : handles_outside)
|
||||
{
|
||||
EXPECT_FALSE(gm.metadata(nh_outside).contains<cv::gimpl::Island>());
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(ComplexIslands, BorderDataIsland)
|
||||
{
|
||||
// .................................(isl0)..
|
||||
// : :
|
||||
// (in0) -> Not -> (tmp0) --> Add ---------> (tmp2) --> AddC -------> (out0)
|
||||
// : ^ : ^
|
||||
// : : : :
|
||||
// (in1) -> Blur -> (tmp1) ----'--> Sum ----> (scl0) ----'
|
||||
// :...........:...........................:
|
||||
// : : :
|
||||
// : : :.........................................(isl1)..
|
||||
// : `------------> Median -> (tmp3) --> Blur -------> (out1)
|
||||
// : :
|
||||
// :......................................................:
|
||||
|
||||
cv::gapi::island("isl0", cv::GIn(in[0], in[1]), cv::GOut(tmp[2], scl));
|
||||
cv::gapi::island("isl1", cv::GIn(tmp[1]), cv::GOut(out[1]));
|
||||
|
||||
auto cc = cv::GComputation(cv::GIn(in[0], in[1]), cv::GOut(out[0], out[1]))
|
||||
.compile(cv::GMatDesc{CV_8U,1,{640,480}},
|
||||
cv::GMatDesc{CV_8U,1,{640,480}});
|
||||
const auto &gm = cc.priv().model();
|
||||
const auto in0_nh = cv::gimpl::GModel::dataNodeOf(gm, in[0]);
|
||||
const auto in1_nh = cv::gimpl::GModel::dataNodeOf(gm, in[1]);
|
||||
const auto tmp0_nh = cv::gimpl::GModel::dataNodeOf(gm, tmp[0]);
|
||||
const auto tmp1_nh = cv::gimpl::GModel::dataNodeOf(gm, tmp[1]);
|
||||
const auto tmp2_nh = cv::gimpl::GModel::dataNodeOf(gm, tmp[2]);
|
||||
const auto tmp3_nh = cv::gimpl::GModel::dataNodeOf(gm, tmp[3]);
|
||||
const auto scl_nh = cv::gimpl::GModel::dataNodeOf(gm, scl);
|
||||
const auto out0_nh = cv::gimpl::GModel::dataNodeOf(gm, out[0]);
|
||||
const auto out1_nh = cv::gimpl::GModel::dataNodeOf(gm, out[1]);
|
||||
|
||||
// Check handles inside isl0
|
||||
EXPECT_EQ("isl0", gm.metadata(tmp0_nh).get<cv::gimpl::Island>().island);
|
||||
EXPECT_EQ("isl0", gm.metadata(tmp1_nh).get<cv::gimpl::Island>().island);
|
||||
// ^^^ Important - tmp1 is assigned to isl0, not isl1
|
||||
|
||||
// Check handles inside isl1
|
||||
EXPECT_EQ("isl1", gm.metadata(tmp3_nh).get<cv::gimpl::Island>().island);
|
||||
|
||||
// Check outside handles
|
||||
EXPECT_FALSE(gm.metadata(in0_nh) .contains<cv::gimpl::Island>());
|
||||
EXPECT_FALSE(gm.metadata(in1_nh) .contains<cv::gimpl::Island>());
|
||||
EXPECT_FALSE(gm.metadata(tmp2_nh).contains<cv::gimpl::Island>());
|
||||
EXPECT_FALSE(gm.metadata(scl_nh) .contains<cv::gimpl::Island>());
|
||||
EXPECT_FALSE(gm.metadata(out0_nh).contains<cv::gimpl::Island>());
|
||||
EXPECT_FALSE(gm.metadata(out1_nh).contains<cv::gimpl::Island>());
|
||||
}
|
||||
|
||||
|
||||
TEST_F(ComplexIslands, IncompleteSpec)
|
||||
{
|
||||
// isl0
|
||||
// ...........................
|
||||
// (in0) -> Not -> (tmp0) --> Add ---------> (tmp2) --> AddC -------> (out0)
|
||||
// :...........xxx.......^...: ^
|
||||
// : :
|
||||
// (in1) -> Blur -> (tmp1) ----'--> Sum ----> (scl0) ----'
|
||||
// :
|
||||
// :
|
||||
// `------------> Median -> (tmp3) --> Blur -------> (out1)
|
||||
//
|
||||
|
||||
// tmp1 is missing in the below spec
|
||||
EXPECT_ANY_THROW(cv::gapi::island("isl0", cv::GIn(in[0]), cv::GOut(tmp[2])));
|
||||
|
||||
// empty range
|
||||
EXPECT_ANY_THROW(cv::gapi::island("isl1", cv::GIn(tmp[2]), cv::GOut(tmp[2])));
|
||||
}
|
||||
|
||||
TEST_F(ComplexIslands, InputOperationFromDifferentIslands)
|
||||
{
|
||||
// isl1
|
||||
// ........................... ........
|
||||
// (in0)--> Not -> (tmp0) --> Add :--------> (tmp2)-->: AddC : -------> (out0)
|
||||
// :......................^..: : ^ :
|
||||
// isl0 : : : :
|
||||
// .......................:....................... : :
|
||||
// (in1) :-> Blur -> (tmp1) ----'--> Sum ----> (scl0) ----- :
|
||||
// :....................................................:
|
||||
// isl0 :
|
||||
// `------------> Median -> (tmp3) --> Blur -------> (out1)
|
||||
//
|
||||
|
||||
cv::gapi::island("isl0", cv::GIn(in[1], tmp[2]), cv::GOut(out[0]));
|
||||
cv::gapi::island("isl1", cv::GIn(in[0], tmp[1]), cv::GOut(tmp[2]));
|
||||
auto cc = cv::GComputation(cv::GIn(in[0], in[1]), cv::GOut(out[0], out[1]))
|
||||
.compile(cv::GMatDesc{CV_8U,1,{640,480}},
|
||||
cv::GMatDesc{CV_8U,1,{640,480}});
|
||||
|
||||
const auto &gm = cc.priv().model();
|
||||
const auto tmp0_nh = cv::gimpl::GModel::dataNodeOf(gm, tmp[0]);
|
||||
const auto tmp1_nh = cv::gimpl::GModel::dataNodeOf(gm, tmp[1]);
|
||||
const auto tmp2_nh = cv::gimpl::GModel::dataNodeOf(gm, tmp[2]);
|
||||
|
||||
EXPECT_EQ("isl1", gm.metadata(tmp0_nh).get<cv::gimpl::Island>().island);
|
||||
EXPECT_EQ("isl0", gm.metadata(tmp1_nh).get<cv::gimpl::Island>().island);
|
||||
EXPECT_FALSE(gm.metadata(tmp2_nh).contains<cv::gimpl::Island>());
|
||||
}
|
||||
|
||||
TEST_F(ComplexIslands, NoWayBetweenNodes)
|
||||
{
|
||||
// (in0) -> Not -> (tmp0) --> Add ---------> (tmp2) --> AddC -------> (out0)
|
||||
// ^ ^
|
||||
// (in1) -> Blur -> (tmp1) ----'--> Sum ----> (scl0) ----'
|
||||
// :
|
||||
// `------------> Median -> (tmp3) --> Blur -------> (out1)
|
||||
|
||||
EXPECT_ANY_THROW(cv::gapi::island("isl0", cv::GIn(in[1]), cv::GOut(tmp[0])));
|
||||
}
|
||||
|
||||
TEST_F(ComplexIslands, IslandsContainUnusedPart)
|
||||
{
|
||||
// Unused part of the graph
|
||||
// x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
|
||||
// x x
|
||||
// x(in0) -> Not -> (tmp0) --> Add ---------> (tmp2)---> AddC ---------> (out0) x
|
||||
// x ^ ^ x
|
||||
// x x x x x x x x x x x x x x x | x x | x
|
||||
// | x | x
|
||||
// ...... | x | x
|
||||
// (in1) -> :Blur:----------> (tmp1) x-----> Sum ------> (scl0) x
|
||||
// ...... : x x x x x x x x x x x x x x x x x x x x x x x x
|
||||
// isl0
|
||||
// :
|
||||
// `------------> Median -> (tmp3) --> Blur -------> (out1)
|
||||
|
||||
cv::gapi::island("isl0", cv::GIn(in[1]), cv::GOut(scl));
|
||||
auto cc = cv::GComputation(cv::GIn(in[1]), cv::GOut(out[1]))
|
||||
.compile(cv::GMatDesc{CV_8U,1,{640,480}});
|
||||
|
||||
const auto &gm = cc.priv().model();
|
||||
const auto tmp1_nh = cv::gimpl::GModel::dataNodeOf(gm, tmp[1]);
|
||||
|
||||
//The output 0 is not specified in the graph
|
||||
//means that there will not be a node scl, so that tmp1 will not assign to the island
|
||||
// FIXME Check that blur assigned to island using the function producerOf
|
||||
// After merge islands fusion
|
||||
EXPECT_FALSE(gm.metadata(tmp1_nh) .contains<cv::gimpl::Island>());
|
||||
}
|
||||
|
||||
TEST_F(ComplexIslands, FullGraphInTwoIslands)
|
||||
{
|
||||
// isl0
|
||||
// ..................................................
|
||||
// (in0) -> :Not -> (tmp0) --> Add ---------> (tmp2) --> AddC: -------> (out0)
|
||||
// ...................^.... ^ :
|
||||
// ............... | : : :
|
||||
// (in1) -> :Blur-> (tmp1):----'-->:Sum ----> (scl0) ----' :
|
||||
// ........ | : ...........................
|
||||
// isl1 : | :............................................
|
||||
// : `------------> Median -> (tmp3) --> Blur ------->:(out1)
|
||||
// ....................................................
|
||||
|
||||
cv::gapi::island("isl0", cv::GIn(in[0], tmp[1]), cv::GOut(out[0]));
|
||||
cv::gapi::island("isl1", cv::GIn(in[1]), cv::GOut(out[1]));
|
||||
auto cc = cv::GComputation(cv::GIn(in[0], in[1]), cv::GOut(out[0], out[1]))
|
||||
.compile(cv::GMatDesc{CV_8U,1,{640,480}},
|
||||
cv::GMatDesc{CV_8U,1,{640,480}});
|
||||
|
||||
const auto &gm = cc.priv().model();
|
||||
const auto in0_nh = cv::gimpl::GModel::dataNodeOf(gm, in[0]);
|
||||
const auto in1_nh = cv::gimpl::GModel::dataNodeOf(gm, in[1]);
|
||||
const auto tmp0_nh = cv::gimpl::GModel::dataNodeOf(gm, tmp[0]);
|
||||
const auto tmp1_nh = cv::gimpl::GModel::dataNodeOf(gm, tmp[1]);
|
||||
const auto tmp2_nh = cv::gimpl::GModel::dataNodeOf(gm, tmp[2]);
|
||||
const auto tmp3_nh = cv::gimpl::GModel::dataNodeOf(gm, tmp[3]);
|
||||
const auto scl_nh = cv::gimpl::GModel::dataNodeOf(gm, scl);
|
||||
const auto out0_nh = cv::gimpl::GModel::dataNodeOf(gm, out[0]);
|
||||
const auto out1_nh = cv::gimpl::GModel::dataNodeOf(gm, out[1]);
|
||||
|
||||
// Check handles inside isl0
|
||||
EXPECT_EQ("isl0", gm.metadata(tmp0_nh).get<cv::gimpl::Island>().island);
|
||||
EXPECT_EQ("isl0", gm.metadata(tmp2_nh).get<cv::gimpl::Island>().island);
|
||||
EXPECT_EQ("isl0", gm.metadata(scl_nh).get<cv::gimpl::Island>().island);
|
||||
|
||||
// Check handles inside isl1
|
||||
EXPECT_EQ("isl1", gm.metadata(tmp1_nh).get<cv::gimpl::Island>().island);
|
||||
EXPECT_EQ("isl1", gm.metadata(tmp3_nh).get<cv::gimpl::Island>().island);
|
||||
|
||||
// Check outside handles
|
||||
EXPECT_FALSE(gm.metadata(in0_nh) .contains<cv::gimpl::Island>());
|
||||
EXPECT_FALSE(gm.metadata(in1_nh) .contains<cv::gimpl::Island>());
|
||||
EXPECT_FALSE(gm.metadata(out0_nh).contains<cv::gimpl::Island>());
|
||||
EXPECT_FALSE(gm.metadata(out1_nh).contains<cv::gimpl::Island>());
|
||||
}
|
||||
|
||||
TEST_F(ComplexIslands, OnlyOperationsAssignedToIslands)
|
||||
{
|
||||
cv::gapi::island("isl0", cv::GIn(in[1]), cv::GOut(tmp[1]));
|
||||
cv::gapi::island("isl1", cv::GIn(tmp[1]), cv::GOut(scl));
|
||||
cv::gapi::island("isl2", cv::GIn(scl, tmp[2]), cv::GOut(out[0]));
|
||||
cv::gapi::island("isl3", cv::GIn(in[0]), cv::GOut(tmp[0]));
|
||||
cv::gapi::island("isl4", cv::GIn(tmp[0], tmp[1]), cv::GOut(tmp[2]));
|
||||
cv::gapi::island("isl5", cv::GIn(tmp[1]), cv::GOut(tmp[3]));
|
||||
cv::gapi::island("isl6", cv::GIn(tmp[3]), cv::GOut(out[1]));
|
||||
|
||||
auto cc = cv::GComputation(cv::GIn(in[0], in[1]), cv::GOut(out[0], out[1]))
|
||||
.compile(cv::GMatDesc{CV_8U,1,{640,480}},
|
||||
cv::GMatDesc{CV_8U,1,{640,480}});
|
||||
|
||||
const auto &gm = cc.priv().model();
|
||||
//FIXME: Check that operation handles are really assigned to isl0..isl6
|
||||
const auto in0_nh = cv::gimpl::GModel::dataNodeOf(gm, in[0]);
|
||||
const auto in1_nh = cv::gimpl::GModel::dataNodeOf(gm, in[1]);
|
||||
const auto tmp0_nh = cv::gimpl::GModel::dataNodeOf(gm, tmp[0]);
|
||||
const auto tmp1_nh = cv::gimpl::GModel::dataNodeOf(gm, tmp[1]);
|
||||
const auto tmp2_nh = cv::gimpl::GModel::dataNodeOf(gm, tmp[2]);
|
||||
const auto tmp3_nh = cv::gimpl::GModel::dataNodeOf(gm, tmp[3]);
|
||||
const auto scl_nh = cv::gimpl::GModel::dataNodeOf(gm, scl);
|
||||
const auto out0_nh = cv::gimpl::GModel::dataNodeOf(gm, out[0]);
|
||||
const auto out1_nh = cv::gimpl::GModel::dataNodeOf(gm, out[1]);
|
||||
|
||||
EXPECT_FALSE(gm.metadata(in0_nh) .contains<cv::gimpl::Island>());
|
||||
EXPECT_FALSE(gm.metadata(in1_nh) .contains<cv::gimpl::Island>());
|
||||
EXPECT_FALSE(gm.metadata(tmp0_nh) .contains<cv::gimpl::Island>());
|
||||
EXPECT_FALSE(gm.metadata(tmp1_nh) .contains<cv::gimpl::Island>());
|
||||
EXPECT_FALSE(gm.metadata(tmp2_nh) .contains<cv::gimpl::Island>());
|
||||
EXPECT_FALSE(gm.metadata(tmp3_nh) .contains<cv::gimpl::Island>());
|
||||
EXPECT_FALSE(gm.metadata(scl_nh) .contains<cv::gimpl::Island>());
|
||||
EXPECT_FALSE(gm.metadata(out0_nh).contains<cv::gimpl::Island>());
|
||||
EXPECT_FALSE(gm.metadata(out1_nh).contains<cv::gimpl::Island>());
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
struct IslandStructureWithGArray
|
||||
{
|
||||
GIntArray in, out;
|
||||
GMat tmp;
|
||||
|
||||
IslandStructureWithGArray()
|
||||
{
|
||||
tmp = CreateMatWithDiag::on(in);
|
||||
out = Mat2Array::on(tmp);
|
||||
}
|
||||
};
|
||||
|
||||
struct IslandsWithGArray: public ::testing::Test, public IslandStructureWithGArray {};
|
||||
} // namespace
|
||||
|
||||
TEST_F(IslandsWithGArray, IslandWithGArrayAsInput)
|
||||
{
|
||||
cv::gapi::island("isl0", cv::GIn(in), cv::GOut(tmp));
|
||||
|
||||
const auto pkg = cv::gapi::kernels<CreateMatWithDiagImpl, Mat2ArrayImpl>();
|
||||
auto cc = cv::GComputation(cv::GIn(in), GOut(out)).compile(cv::empty_array_desc(), cv::compile_args(pkg));
|
||||
const auto &gm = cc.priv().model();
|
||||
|
||||
const auto in_nh = cv::gimpl::GModel::dataNodeOf(gm, in.strip());
|
||||
const auto out_nh = cv::gimpl::GModel::dataNodeOf(gm, out.strip());
|
||||
const auto tmp_nh = cv::gimpl::GModel::dataNodeOf(gm, tmp);
|
||||
GAPI_Assert(tmp_nh->inNodes().size() == 1);
|
||||
const auto create_diag_mat_nh = tmp_nh->inNodes().front();
|
||||
|
||||
EXPECT_EQ("isl0", gm.metadata(create_diag_mat_nh).get<cv::gimpl::Island>().island);
|
||||
EXPECT_FALSE(gm.metadata(in_nh) .contains<cv::gimpl::Island>());
|
||||
EXPECT_FALSE(gm.metadata(out_nh) .contains<cv::gimpl::Island>());
|
||||
EXPECT_FALSE(gm.metadata(tmp_nh) .contains<cv::gimpl::Island>());
|
||||
}
|
||||
|
||||
TEST_F(IslandsWithGArray, IslandWithGArrayAsOutput)
|
||||
{
|
||||
cv::gapi::island("isl0", cv::GIn(tmp), cv::GOut(out));
|
||||
|
||||
const auto pkg = cv::gapi::kernels<CreateMatWithDiagImpl, Mat2ArrayImpl>();
|
||||
auto cc = cv::GComputation(cv::GIn(in), GOut(out)).compile(cv::empty_array_desc(), cv::compile_args(pkg));
|
||||
const auto &gm = cc.priv().model();
|
||||
|
||||
const auto in_nh = cv::gimpl::GModel::dataNodeOf(gm, in.strip());
|
||||
const auto out_nh = cv::gimpl::GModel::dataNodeOf(gm, out.strip());
|
||||
const auto tmp_nh = cv::gimpl::GModel::dataNodeOf(gm, tmp);
|
||||
GAPI_Assert(tmp_nh->inNodes().size() == 1);
|
||||
const auto mat2array_nh = out_nh->inNodes().front();
|
||||
|
||||
EXPECT_EQ("isl0", gm.metadata(mat2array_nh).get<cv::gimpl::Island>().island);
|
||||
EXPECT_FALSE(gm.metadata(in_nh) .contains<cv::gimpl::Island>());
|
||||
EXPECT_FALSE(gm.metadata(out_nh) .contains<cv::gimpl::Island>());
|
||||
EXPECT_FALSE(gm.metadata(tmp_nh) .contains<cv::gimpl::Island>());
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Wrong input tests on island name
|
||||
//
|
||||
namespace
|
||||
{
|
||||
struct CheckName : public TestWithParam<std::tuple<bool, const char*> >,
|
||||
public PlainIslandsFixture
|
||||
{
|
||||
void assignIsland(const std::string &s)
|
||||
{
|
||||
cv::gapi::island(s, cv::GIn(tmp[0]), cv::GOut(tmp[2]));
|
||||
};
|
||||
};
|
||||
TEST_P(CheckName, Test)
|
||||
{
|
||||
bool correct = false;
|
||||
const char *name = "";
|
||||
std::tie(correct, name) = GetParam();
|
||||
if (correct) EXPECT_NO_THROW(assignIsland(name));
|
||||
else EXPECT_ANY_THROW(assignIsland(name));
|
||||
}
|
||||
} // namespace
|
||||
INSTANTIATE_TEST_CASE_P(IslandName, CheckName,
|
||||
Values(std::make_tuple(true, "name"),
|
||||
std::make_tuple(true, " name "),
|
||||
std::make_tuple(true, " n a m e "),
|
||||
std::make_tuple(true, " 123 $$ %%"),
|
||||
std::make_tuple(true, ".: -"),
|
||||
std::make_tuple(false, ""),
|
||||
std::make_tuple(false, " "),
|
||||
std::make_tuple(false, " \t "),
|
||||
std::make_tuple(false, " \t \t ")));
|
||||
|
||||
// FIXME: add <internal> test on unrollExpr() use for islands
|
||||
|
||||
} // opencv_test
|
||||
@@ -0,0 +1,71 @@
|
||||
// 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 "api/gcomputation_priv.hpp"
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
|
||||
TEST(GComputationCompile, NoRecompileWithSameMeta)
|
||||
{
|
||||
cv::GMat in;
|
||||
cv::GComputation cc(in, in+in);
|
||||
|
||||
cv::Mat in_mat1 = cv::Mat::eye (32, 32, CV_8UC1);
|
||||
cv::Mat in_mat2 = cv::Mat::zeros(32, 32, CV_8UC1);
|
||||
cv::Mat out_mat;
|
||||
|
||||
cc.apply(in_mat1, out_mat);
|
||||
auto comp1 = cc.priv().m_lastCompiled;
|
||||
|
||||
cc.apply(in_mat2, out_mat);
|
||||
auto comp2 = cc.priv().m_lastCompiled;
|
||||
|
||||
// Both compiled objects are actually the same unique executable
|
||||
EXPECT_EQ(&comp1.priv(), &comp2.priv());
|
||||
}
|
||||
|
||||
TEST(GComputationCompile, NoRecompileWithWrongMeta)
|
||||
{
|
||||
cv::GMat in;
|
||||
cv::GComputation cc(in, in+in);
|
||||
|
||||
cv::Mat in_mat1 = cv::Mat::eye (32, 32, CV_8UC1);
|
||||
cv::Mat in_mat2 = cv::Mat::zeros(32, 32, CV_8UC1);
|
||||
cv::Mat out_mat;
|
||||
|
||||
cc.apply(in_mat1, out_mat);
|
||||
auto comp1 = cc.priv().m_lastCompiled;
|
||||
|
||||
EXPECT_THROW(cc.apply(cv::gin(cv::Scalar(128)), cv::gout(out_mat)), std::logic_error);
|
||||
auto comp2 = cc.priv().m_lastCompiled;
|
||||
|
||||
// Both compiled objects are actually the same unique executable
|
||||
EXPECT_EQ(&comp1.priv(), &comp2.priv());
|
||||
}
|
||||
|
||||
TEST(GComputationCompile, RecompileWithDifferentMeta)
|
||||
{
|
||||
cv::GMat in;
|
||||
cv::GComputation cc(in, in+in);
|
||||
|
||||
cv::Mat in_mat1 = cv::Mat::eye (32, 32, CV_8UC1);
|
||||
cv::Mat in_mat2 = cv::Mat::zeros(64, 64, CV_32F);
|
||||
cv::Mat out_mat;
|
||||
|
||||
cc.apply(in_mat1, out_mat);
|
||||
auto comp1 = cc.priv().m_lastCompiled;
|
||||
|
||||
cc.apply(in_mat2, out_mat);
|
||||
auto comp2 = cc.priv().m_lastCompiled;
|
||||
|
||||
// Both compiled objects are different
|
||||
EXPECT_NE(&comp1.priv(), &comp2.priv());
|
||||
}
|
||||
|
||||
} // opencv_test
|
||||
@@ -0,0 +1,119 @@
|
||||
// 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_mock_kernels.hpp"
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
|
||||
TEST(Lookup, CreateOrder)
|
||||
{
|
||||
const auto order = cv::gapi::lookup_order({Jupiter::backend(),
|
||||
Saturn::backend()});
|
||||
EXPECT_EQ(2u, order.size());
|
||||
EXPECT_EQ(Jupiter::backend(), order[0]);
|
||||
EXPECT_EQ(Saturn ::backend(), order[1]);
|
||||
}
|
||||
|
||||
TEST(Lookup, NoOrder)
|
||||
{
|
||||
namespace J = Jupiter;
|
||||
namespace S = Saturn;
|
||||
const auto pkg = cv::gapi::kernels<J::Foo, J::Bar, J::Baz,
|
||||
S::Foo, S::Bar, S::Baz>();
|
||||
|
||||
EXPECT_NO_THROW (pkg.lookup<I::Foo>());
|
||||
EXPECT_NO_THROW (pkg.lookup<I::Bar>());
|
||||
EXPECT_NO_THROW (pkg.lookup<I::Baz>());
|
||||
EXPECT_ANY_THROW(pkg.lookup<I::Qux>());
|
||||
}
|
||||
|
||||
TEST(Lookup, Only_Jupiter)
|
||||
{
|
||||
namespace J = Jupiter;
|
||||
namespace S = Saturn;
|
||||
const auto pkg = cv::gapi::kernels<J::Foo, J::Bar, J::Baz,
|
||||
S::Foo, S::Bar, S::Baz>();
|
||||
|
||||
auto order = cv::gapi::lookup_order({J::backend()});
|
||||
|
||||
EXPECT_EQ(J::backend(), pkg.lookup<I::Foo>(order));
|
||||
EXPECT_EQ(J::backend(), pkg.lookup<I::Bar>(order));
|
||||
EXPECT_EQ(J::backend(), pkg.lookup<I::Baz>(order));
|
||||
EXPECT_ANY_THROW(pkg.lookup<I::Qux>(order));
|
||||
}
|
||||
|
||||
TEST(Lookup, Only_Saturn)
|
||||
{
|
||||
namespace J = Jupiter;
|
||||
namespace S = Saturn;
|
||||
const auto pkg = cv::gapi::kernels<J::Foo, J::Bar, J::Baz,
|
||||
S::Foo, S::Bar, S::Baz>();
|
||||
|
||||
auto order = cv::gapi::lookup_order({S::backend()});
|
||||
|
||||
EXPECT_EQ(S::backend(), pkg.lookup<I::Foo>(order));
|
||||
EXPECT_EQ(S::backend(), pkg.lookup<I::Bar>(order));
|
||||
EXPECT_EQ(S::backend(), pkg.lookup<I::Baz>(order));
|
||||
EXPECT_ANY_THROW(pkg.lookup<I::Qux>(order));
|
||||
}
|
||||
|
||||
TEST(Lookup, With_Order)
|
||||
{
|
||||
namespace J = Jupiter;
|
||||
namespace S = Saturn;
|
||||
const auto pkg = cv::gapi::kernels<J::Foo, J::Bar, J::Baz,
|
||||
S::Foo, S::Bar, S::Baz>();
|
||||
|
||||
auto prefer_j = cv::gapi::lookup_order({J::backend(), S::backend()});
|
||||
EXPECT_EQ(J::backend(), pkg.lookup<I::Foo>(prefer_j));
|
||||
EXPECT_EQ(J::backend(), pkg.lookup<I::Bar>(prefer_j));
|
||||
EXPECT_EQ(J::backend(), pkg.lookup<I::Baz>(prefer_j));
|
||||
EXPECT_ANY_THROW(pkg.lookup<I::Qux>(prefer_j));
|
||||
|
||||
auto prefer_s = cv::gapi::lookup_order({S::backend(), J::backend()});
|
||||
EXPECT_EQ(S::backend(), pkg.lookup<I::Foo>(prefer_s));
|
||||
EXPECT_EQ(S::backend(), pkg.lookup<I::Bar>(prefer_s));
|
||||
EXPECT_EQ(S::backend(), pkg.lookup<I::Baz>(prefer_s));
|
||||
EXPECT_ANY_THROW(pkg.lookup<I::Qux>(prefer_s));
|
||||
}
|
||||
|
||||
TEST(Lookup, NoOverlap)
|
||||
{
|
||||
namespace J = Jupiter;
|
||||
namespace S = Saturn;
|
||||
const auto pkg = cv::gapi::kernels<J::Foo, J::Bar, S::Baz, S::Qux>();
|
||||
EXPECT_EQ(J::backend(), pkg.lookup<I::Foo>());
|
||||
EXPECT_EQ(J::backend(), pkg.lookup<I::Bar>());
|
||||
EXPECT_EQ(S::backend(), pkg.lookup<I::Baz>());
|
||||
EXPECT_EQ(S::backend(), pkg.lookup<I::Qux>());
|
||||
}
|
||||
|
||||
TEST(Lookup, ExtraBackend)
|
||||
{
|
||||
namespace J = Jupiter;
|
||||
namespace S = Saturn;
|
||||
const auto pkg = cv::gapi::kernels<J::Foo, J::Bar, J::Baz>();
|
||||
|
||||
// Even if pkg doesn't contain S kernels while S is preferable,
|
||||
// it should work.
|
||||
const auto prefer_sj = cv::gapi::lookup_order({S::backend(), J::backend()});
|
||||
EXPECT_EQ(J::backend(), pkg.lookup<I::Foo>(prefer_sj));
|
||||
EXPECT_EQ(J::backend(), pkg.lookup<I::Bar>(prefer_sj));
|
||||
EXPECT_EQ(J::backend(), pkg.lookup<I::Baz>(prefer_sj));
|
||||
|
||||
// If search scope is limited to S only, neither J nor S kernels
|
||||
// shouldn't be found
|
||||
const auto only_s = cv::gapi::lookup_order({S::backend()});
|
||||
EXPECT_ANY_THROW(pkg.lookup<I::Foo>(only_s));
|
||||
EXPECT_ANY_THROW(pkg.lookup<I::Bar>(only_s));
|
||||
EXPECT_ANY_THROW(pkg.lookup<I::Baz>(only_s));
|
||||
}
|
||||
|
||||
} // namespace opencv_test
|
||||
@@ -0,0 +1,207 @@
|
||||
// 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"
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
|
||||
typedef ::testing::Types<int, cv::Point, cv::Rect> VectorRef_Test_Types;
|
||||
|
||||
template<typename T> struct VectorRefT: public ::testing::Test { using Type = T; };
|
||||
|
||||
TYPED_TEST_CASE(VectorRefT, VectorRef_Test_Types);
|
||||
|
||||
TYPED_TEST(VectorRefT, Reset_Valid)
|
||||
{
|
||||
using T = typename TestFixture::Type;
|
||||
cv::detail::VectorRefT<T> ref; // vector ref created empty
|
||||
EXPECT_NO_THROW(ref.reset()); // 1st reset is OK (initializes)
|
||||
EXPECT_NO_THROW(ref.reset()); // 2nd reset is also OK (resets)
|
||||
}
|
||||
|
||||
TYPED_TEST(VectorRefT, Reset_Invalid)
|
||||
{
|
||||
using T = typename TestFixture::Type;
|
||||
std::vector<T> vec(42); // create a std::vector of 42 elements
|
||||
cv::detail::VectorRefT<T> ref(vec); // RO_EXT (since reference is const)
|
||||
EXPECT_ANY_THROW(ref.reset()); // data-bound vector ref can't be reset
|
||||
}
|
||||
|
||||
TYPED_TEST(VectorRefT, ReadRef_External)
|
||||
{
|
||||
using T = typename TestFixture::Type;
|
||||
const std::vector<T> vec(42); // create a std::vector of 42 elements
|
||||
cv::detail::VectorRefT<T> ref(vec); // RO_EXT (since reference is const)
|
||||
auto &vref = ref.rref();
|
||||
EXPECT_EQ(vec.data(), vref.data());
|
||||
EXPECT_EQ(vec.size(), vref.size());
|
||||
}
|
||||
|
||||
TYPED_TEST(VectorRefT, ReadRef_Internal)
|
||||
{
|
||||
using T = typename TestFixture::Type;
|
||||
cv::detail::VectorRefT<T> ref;
|
||||
ref.reset(); // RW_OWN (reset on empty ref)
|
||||
auto &vref = ref.rref(); // read access is valid for RW_OWN
|
||||
EXPECT_EQ(0u, vref.size()); // by default vector is empty
|
||||
}
|
||||
|
||||
TYPED_TEST(VectorRefT, WriteRef_External)
|
||||
{
|
||||
using T = typename TestFixture::Type;
|
||||
std::vector<T> vec(42); // create a std::vector of 42 elements
|
||||
cv::detail::VectorRefT<T> ref(vec); // RW_EXT (since reference is not const)
|
||||
auto &vref = ref.wref(); // write access is valid with RW_EXT
|
||||
EXPECT_EQ(vec.data(), vref.data());
|
||||
EXPECT_EQ(vec.size(), vref.size());
|
||||
}
|
||||
|
||||
TYPED_TEST(VectorRefT, WriteRef_Internal)
|
||||
{
|
||||
using T = typename TestFixture::Type;
|
||||
cv::detail::VectorRefT<T> ref;
|
||||
ref.reset(); // RW_OWN (reset on empty ref)
|
||||
auto &vref = ref.wref(); // write access is valid for RW_OWN
|
||||
EXPECT_EQ(0u, vref.size()); // empty vector by default
|
||||
}
|
||||
|
||||
TYPED_TEST(VectorRefT, WriteToRO)
|
||||
{
|
||||
using T = typename TestFixture::Type;
|
||||
const std::vector<T> vec(42); // create a std::vector of 42 elements
|
||||
cv::detail::VectorRefT<T> ref(vec); // RO_EXT (since reference is const)
|
||||
EXPECT_ANY_THROW(ref.wref());
|
||||
}
|
||||
|
||||
TYPED_TEST(VectorRefT, ReadAfterWrite)
|
||||
{
|
||||
using T = typename TestFixture::Type;
|
||||
std::vector<T> vec; // Initial data holder (empty vector)
|
||||
cv::detail::VectorRefT<T> writer(vec); // RW_EXT
|
||||
|
||||
const auto& ro_ref = vec;
|
||||
cv::detail::VectorRefT<T> reader(ro_ref); // RO_EXT
|
||||
|
||||
EXPECT_EQ(0u, writer.wref().size()); // Check the initial state
|
||||
EXPECT_EQ(0u, reader.rref().size());
|
||||
|
||||
writer.wref().emplace_back(); // Check that write is successfull
|
||||
EXPECT_EQ(1u, writer.wref().size());
|
||||
|
||||
EXPECT_EQ(1u, vec.size()); // Check that changes are reflected to the original container
|
||||
EXPECT_EQ(1u, reader.rref().size()); // Check that changes are reflected to reader's view
|
||||
|
||||
EXPECT_EQ(T(), vec.at(0)); // Check the value (must be default-initialized)
|
||||
EXPECT_EQ(T(), reader.rref().at(0));
|
||||
EXPECT_EQ(T(), writer.wref().at(0));
|
||||
}
|
||||
|
||||
template<typename T> struct VectorRefU: public ::testing::Test { using Type = T; };
|
||||
|
||||
TYPED_TEST_CASE(VectorRefU, VectorRef_Test_Types);
|
||||
|
||||
template<class T> struct custom_struct { T a; T b; };
|
||||
|
||||
TYPED_TEST(VectorRefU, Reset_Valid)
|
||||
{
|
||||
using T = typename TestFixture::Type;
|
||||
cv::detail::VectorRef ref; // vector ref created empty
|
||||
EXPECT_NO_THROW(ref.reset<T>()); // 1st reset is OK (initializes)
|
||||
EXPECT_NO_THROW(ref.reset<T>()); // 2nd reset is also OK (resets)
|
||||
|
||||
EXPECT_ANY_THROW(ref.reset<custom_struct<T> >()); // type change is not allowed
|
||||
}
|
||||
|
||||
TYPED_TEST(VectorRefU, Reset_Invalid)
|
||||
{
|
||||
using T = typename TestFixture::Type;
|
||||
std::vector<T> vec(42); // create a std::vector of 42 elements
|
||||
cv::detail::VectorRef ref(vec); // RO_EXT (since reference is const)
|
||||
EXPECT_ANY_THROW(ref.reset<T>()); // data-bound vector ref can't be reset
|
||||
}
|
||||
|
||||
TYPED_TEST(VectorRefU, ReadRef_External)
|
||||
{
|
||||
using T = typename TestFixture::Type;
|
||||
const std::vector<T> vec(42); // create a std::vector of 42 elements
|
||||
cv::detail::VectorRef ref(vec); // RO_EXT (since reference is const)
|
||||
auto &vref = ref.rref<T>();
|
||||
EXPECT_EQ(vec.data(), vref.data());
|
||||
EXPECT_EQ(vec.size(), vref.size());
|
||||
}
|
||||
|
||||
TYPED_TEST(VectorRefU, ReadRef_Internal)
|
||||
{
|
||||
using T = typename TestFixture::Type;
|
||||
cv::detail::VectorRef ref;
|
||||
ref.reset<T>(); // RW_OWN (reset on empty ref)
|
||||
auto &vref = ref.rref<T>(); // read access is valid for RW_OWN
|
||||
EXPECT_EQ(0u, vref.size()); // by default vector is empty
|
||||
}
|
||||
|
||||
TYPED_TEST(VectorRefU, WriteRef_External)
|
||||
{
|
||||
using T = typename TestFixture::Type;
|
||||
std::vector<T> vec(42); // create a std::vector of 42 elements
|
||||
cv::detail::VectorRef ref(vec); // RW_EXT (since reference is not const)
|
||||
auto &vref = ref.wref<T>(); // write access is valid with RW_EXT
|
||||
EXPECT_EQ(vec.data(), vref.data());
|
||||
EXPECT_EQ(vec.size(), vref.size());
|
||||
}
|
||||
|
||||
TYPED_TEST(VectorRefU, WriteRef_Internal)
|
||||
{
|
||||
using T = typename TestFixture::Type;
|
||||
cv::detail::VectorRef ref;
|
||||
ref.reset<T>(); // RW_OWN (reset on empty ref)
|
||||
auto &vref = ref.wref<T>(); // write access is valid for RW_OWN
|
||||
EXPECT_EQ(0u, vref.size()); // empty vector by default
|
||||
}
|
||||
|
||||
TYPED_TEST(VectorRefU, WriteToRO)
|
||||
{
|
||||
using T = typename TestFixture::Type;
|
||||
const std::vector<T> vec(42); // create a std::vector of 42 elements
|
||||
cv::detail::VectorRef ref(vec); // RO_EXT (since reference is const)
|
||||
EXPECT_ANY_THROW(ref.wref<T>());
|
||||
}
|
||||
|
||||
TYPED_TEST(VectorRefU, ReadAfterWrite)
|
||||
{
|
||||
using T = typename TestFixture::Type;
|
||||
std::vector<T> vec; // Initial data holder (empty vector)
|
||||
cv::detail::VectorRef writer(vec); // RW_EXT
|
||||
|
||||
const auto& ro_ref = vec;
|
||||
cv::detail::VectorRef reader(ro_ref); // RO_EXT
|
||||
|
||||
EXPECT_EQ(0u, writer.wref<T>().size()); // Check the initial state
|
||||
EXPECT_EQ(0u, reader.rref<T>().size());
|
||||
|
||||
writer.wref<T>().emplace_back(); // Check that write is successfull
|
||||
EXPECT_EQ(1u, writer.wref<T>().size());
|
||||
|
||||
EXPECT_EQ(1u, vec.size()); // Check that changes are reflected to the original container
|
||||
EXPECT_EQ(1u, reader.rref<T>().size()); // Check that changes are reflected to reader's view
|
||||
|
||||
EXPECT_EQ(T(), vec.at(0)); // Check the value (must be default-initialized)
|
||||
EXPECT_EQ(T(), reader.rref<T>().at(0));
|
||||
EXPECT_EQ(T(), writer.wref<T>().at(0));
|
||||
}
|
||||
|
||||
TEST(VectorRefU, TypeCheck)
|
||||
{
|
||||
cv::detail::VectorRef ref;
|
||||
ref.reset<int>(); // RW_OWN
|
||||
|
||||
EXPECT_ANY_THROW(ref.reset<char>());
|
||||
EXPECT_ANY_THROW(ref.rref<char>());
|
||||
EXPECT_ANY_THROW(ref.wref<char>());
|
||||
}
|
||||
|
||||
} // namespace opencv_test
|
||||
@@ -0,0 +1,222 @@
|
||||
// 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 <ade/graph.hpp>
|
||||
#include "compiler/transactions.hpp"
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
namespace
|
||||
{
|
||||
|
||||
bool contains(const ade::Graph& graph, const ade::NodeHandle& node)
|
||||
{
|
||||
auto nodes = graph.nodes();
|
||||
return nodes.end() != std::find(nodes.begin(), nodes.end(), node);
|
||||
}
|
||||
|
||||
bool connected(const ade::NodeHandle& src_node, const ade::NodeHandle& dst_node)
|
||||
{
|
||||
auto nodes = src_node->outNodes();
|
||||
return nodes.end() != std::find(nodes.begin(), nodes.end(), dst_node);
|
||||
}
|
||||
|
||||
struct SimpleGraph
|
||||
{
|
||||
// ehs[0] ehs[1] ehs[2] ehs[3]
|
||||
// nhs[0] -- > nhs[1] --> nhs[2] --> nhs[3] --> nhs[4]
|
||||
|
||||
enum { node_nums = 5 };
|
||||
ade::Graph graph;
|
||||
ade::NodeHandle fused_nh; /* For check that fusion node is connected to the
|
||||
inputs of the prod and the outputs of the cons */
|
||||
std::array<ade::NodeHandle, node_nums> nhs;
|
||||
std::array<ade::EdgeHandle, node_nums - 1> ehs;
|
||||
Change::List changes;
|
||||
|
||||
SimpleGraph()
|
||||
{
|
||||
nhs[0] = graph.createNode();
|
||||
for (int i = 1; i < node_nums; ++i)
|
||||
{
|
||||
nhs[i ] = graph.createNode();
|
||||
ehs[i - 1] = graph.link(nhs[i - 1], nhs[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void fuse()
|
||||
{
|
||||
// nhs[0] --> fused_nh --> nhs[4]
|
||||
|
||||
fused_nh = graph.createNode();
|
||||
changes.enqueue<Change::NodeCreated>(fused_nh);
|
||||
changes.enqueue<Change::NewLink> (graph, nhs[0], fused_nh);
|
||||
changes.enqueue<Change::DropLink>(graph, nhs[1], ehs[0]);
|
||||
changes.enqueue<Change::NewLink> (graph, fused_nh, nhs[4]);
|
||||
changes.enqueue<Change::DropLink>(graph, nhs[3], ehs[3]);
|
||||
changes.enqueue<Change::DropLink>(graph, nhs[1], ehs[1]);
|
||||
changes.enqueue<Change::DropLink>(graph, nhs[2], ehs[2]);
|
||||
changes.enqueue<Change::DropNode>(nhs[1]);
|
||||
changes.enqueue<Change::DropNode>(nhs[2]);
|
||||
changes.enqueue<Change::DropNode>(nhs[3]);
|
||||
}
|
||||
|
||||
void commit() { changes.commit(graph); }
|
||||
void rollback() { changes.rollback(graph); }
|
||||
|
||||
};
|
||||
|
||||
struct Transactions: public ::testing::Test, public SimpleGraph {};
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
TEST_F(Transactions, NodeCreated_Create)
|
||||
{
|
||||
auto new_nh = graph.createNode();
|
||||
Change::NodeCreated node_created(new_nh);
|
||||
|
||||
EXPECT_EQ(6u, static_cast<std::size_t>(graph.nodes().size()));
|
||||
EXPECT_TRUE(contains(graph, new_nh));
|
||||
}
|
||||
|
||||
TEST_F(Transactions, NodeCreated_RollBack)
|
||||
{
|
||||
auto new_nh = graph.createNode();
|
||||
Change::NodeCreated node_created(new_nh);
|
||||
|
||||
node_created.rollback(graph);
|
||||
|
||||
EXPECT_EQ(5u, static_cast<std::size_t>(graph.nodes().size()));
|
||||
EXPECT_FALSE(contains(graph, new_nh));
|
||||
}
|
||||
|
||||
TEST_F(Transactions, NodeCreated_Commit)
|
||||
{
|
||||
auto new_nh = graph.createNode();
|
||||
Change::NodeCreated node_created(new_nh);
|
||||
|
||||
node_created.commit(graph);
|
||||
|
||||
EXPECT_EQ(6u, static_cast<std::size_t>(graph.nodes().size()));
|
||||
EXPECT_TRUE(contains(graph, new_nh));
|
||||
}
|
||||
|
||||
TEST_F(Transactions, DropLink_Create)
|
||||
{
|
||||
Change::DropLink drop_link(graph, nhs[0], ehs[0]);
|
||||
|
||||
EXPECT_FALSE(connected(nhs[0], nhs[1]));
|
||||
}
|
||||
|
||||
TEST_F(Transactions, DropLink_RollBack)
|
||||
{
|
||||
Change::DropLink drop_link(graph, nhs[0], ehs[0]);
|
||||
|
||||
drop_link.rollback(graph);
|
||||
|
||||
EXPECT_TRUE(connected(nhs[0], nhs[1]));
|
||||
}
|
||||
|
||||
TEST_F(Transactions, DropLink_Commit)
|
||||
{
|
||||
Change::DropLink drop_link(graph, nhs[0], ehs[0]);
|
||||
|
||||
drop_link.commit(graph);
|
||||
|
||||
EXPECT_FALSE(connected(nhs[0], nhs[1]));
|
||||
}
|
||||
|
||||
TEST_F(Transactions, NewLink_Create)
|
||||
{
|
||||
auto new_nh = graph.createNode();
|
||||
Change::NewLink new_link(graph, new_nh, nhs[0]);
|
||||
|
||||
EXPECT_TRUE(connected(new_nh, nhs[0]));
|
||||
}
|
||||
|
||||
TEST_F(Transactions, NewLink_RollBack)
|
||||
{
|
||||
auto new_nh = graph.createNode();
|
||||
Change::NewLink new_link(graph, new_nh, nhs[0]);
|
||||
|
||||
new_link.rollback(graph);
|
||||
|
||||
EXPECT_FALSE(connected(new_nh, nhs[0]));
|
||||
}
|
||||
|
||||
TEST_F(Transactions, NewLink_Commit)
|
||||
{
|
||||
auto new_nh = graph.createNode();
|
||||
Change::NewLink new_link(graph, new_nh, nhs[0]);
|
||||
|
||||
new_link.commit(graph);
|
||||
|
||||
EXPECT_TRUE(connected(new_nh, nhs[0]));
|
||||
}
|
||||
|
||||
TEST_F(Transactions, DropNode_Create)
|
||||
{
|
||||
auto new_nh = graph.createNode();
|
||||
Change::DropNode drop_node(new_nh);
|
||||
|
||||
EXPECT_EQ(6u, static_cast<std::size_t>(graph.nodes().size()));
|
||||
EXPECT_TRUE(contains(graph, new_nh));
|
||||
}
|
||||
|
||||
TEST_F(Transactions, DropNode_RollBack)
|
||||
{
|
||||
auto new_nh = graph.createNode();
|
||||
Change::DropNode drop_node(new_nh);
|
||||
|
||||
drop_node.rollback(graph);
|
||||
|
||||
EXPECT_EQ(6u, static_cast<std::size_t>(graph.nodes().size()));
|
||||
EXPECT_TRUE(contains(graph, new_nh));
|
||||
}
|
||||
|
||||
TEST_F(Transactions, DropNode_Commit)
|
||||
{
|
||||
auto new_nh = graph.createNode();
|
||||
Change::DropNode drop_node(new_nh);
|
||||
|
||||
drop_node.commit(graph);
|
||||
|
||||
EXPECT_EQ(5u, static_cast<std::size_t>(graph.nodes().size()));
|
||||
EXPECT_FALSE(contains(graph, new_nh));
|
||||
}
|
||||
|
||||
TEST_F(Transactions, Fusion_Commit)
|
||||
{
|
||||
namespace C = Change;
|
||||
|
||||
fuse();
|
||||
commit();
|
||||
|
||||
EXPECT_EQ(3u, static_cast<std::size_t>(graph.nodes().size()));
|
||||
EXPECT_TRUE(connected(nhs[0] , fused_nh));
|
||||
EXPECT_TRUE(connected(fused_nh, nhs[4]));
|
||||
}
|
||||
|
||||
TEST_F(Transactions, Fusion_RollBack)
|
||||
{
|
||||
namespace C = Change;
|
||||
|
||||
fuse();
|
||||
rollback();
|
||||
|
||||
EXPECT_EQ(static_cast<std::size_t>(node_nums),
|
||||
static_cast<std::size_t>(graph.nodes().size()));
|
||||
EXPECT_FALSE(contains(graph, fused_nh));
|
||||
|
||||
for (int i = 0; i < static_cast<int>(node_nums) - 1; ++i)
|
||||
{
|
||||
EXPECT_TRUE(connected(nhs[i], nhs[i + 1]));
|
||||
}
|
||||
}
|
||||
|
||||
} // opencv_test
|
||||
@@ -0,0 +1,159 @@
|
||||
// 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 "opencv2/gapi/own/types.hpp"
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
|
||||
TEST(Point, CreateEmpty)
|
||||
{
|
||||
cv::gapi::own::Point p;
|
||||
|
||||
EXPECT_EQ(0, p.x);
|
||||
EXPECT_EQ(0, p.y);
|
||||
}
|
||||
|
||||
TEST(Point, CreateWithParams)
|
||||
{
|
||||
cv::gapi::own::Point p = {1, 2};
|
||||
|
||||
EXPECT_EQ(1, p.x);
|
||||
EXPECT_EQ(2, p.y);
|
||||
}
|
||||
|
||||
TEST(Rect, CreateEmpty)
|
||||
{
|
||||
cv::gapi::own::Rect r;
|
||||
|
||||
EXPECT_EQ(0, r.x);
|
||||
EXPECT_EQ(0, r.y);
|
||||
EXPECT_EQ(0, r.width);
|
||||
EXPECT_EQ(0, r.height);
|
||||
}
|
||||
|
||||
TEST(Rect, CreateWithParams)
|
||||
{
|
||||
cv::gapi::own::Rect r(1, 2, 3, 4);
|
||||
|
||||
EXPECT_EQ(1, r.x);
|
||||
EXPECT_EQ(2, r.y);
|
||||
EXPECT_EQ(3, r.width);
|
||||
EXPECT_EQ(4, r.height);
|
||||
}
|
||||
|
||||
TEST(Rect, CompareEqual)
|
||||
{
|
||||
cv::gapi::own::Rect r1(1, 2, 3, 4);
|
||||
|
||||
cv::gapi::own::Rect r2(1, 2, 3, 4);
|
||||
|
||||
EXPECT_TRUE(r1 == r2);
|
||||
}
|
||||
|
||||
TEST(Rect, CompareDefaultEqual)
|
||||
{
|
||||
cv::gapi::own::Rect r1;
|
||||
|
||||
cv::gapi::own::Rect r2;
|
||||
|
||||
EXPECT_TRUE(r1 == r2);
|
||||
}
|
||||
|
||||
TEST(Rect, CompareNotEqual)
|
||||
{
|
||||
cv::gapi::own::Rect r1(1, 2, 3, 4);
|
||||
|
||||
cv::gapi::own::Rect r2;
|
||||
|
||||
EXPECT_TRUE(r1 != r2);
|
||||
}
|
||||
|
||||
TEST(Rect, Intersection)
|
||||
{
|
||||
cv::gapi::own::Rect r1(2, 2, 3, 3);
|
||||
cv::gapi::own::Rect r2(3, 1, 3, 3);
|
||||
|
||||
cv::gapi::own::Rect intersect = r1 & r2;
|
||||
|
||||
EXPECT_EQ(3, intersect.x);
|
||||
EXPECT_EQ(2, intersect.y);
|
||||
EXPECT_EQ(2, intersect.width);
|
||||
EXPECT_EQ(2, intersect.height);
|
||||
}
|
||||
|
||||
TEST(Rect, AssignIntersection)
|
||||
{
|
||||
cv::gapi::own::Rect r1(2, 2, 3, 3);
|
||||
cv::gapi::own::Rect r2(3, 1, 3, 3);
|
||||
|
||||
r1 &= r2;
|
||||
|
||||
EXPECT_EQ(3, r1.x);
|
||||
EXPECT_EQ(2, r1.y);
|
||||
EXPECT_EQ(2, r1.width);
|
||||
EXPECT_EQ(2, r1.height);
|
||||
}
|
||||
|
||||
TEST(Size, CreateEmpty)
|
||||
{
|
||||
cv::gapi::own::Size s;
|
||||
|
||||
EXPECT_EQ(0, s.width);
|
||||
EXPECT_EQ(0, s.height);
|
||||
}
|
||||
|
||||
TEST(Size, CreateWithParams)
|
||||
{
|
||||
cv::gapi::own::Size s(640, 480);
|
||||
|
||||
EXPECT_EQ(640, s.width);
|
||||
EXPECT_EQ(480, s.height);
|
||||
}
|
||||
|
||||
TEST(Size, AdditionAssignment)
|
||||
{
|
||||
cv::gapi::own::Size s1(1, 2);
|
||||
cv::gapi::own::Size s2(2, 3);
|
||||
|
||||
s1 += s2;
|
||||
|
||||
EXPECT_EQ(3, s1.width);
|
||||
EXPECT_EQ(5, s1.height);
|
||||
}
|
||||
|
||||
TEST(Size, CompareEqual)
|
||||
{
|
||||
cv::gapi::own::Size s1(1, 2);
|
||||
|
||||
cv::gapi::own::Size s2(1, 2);
|
||||
|
||||
EXPECT_TRUE(s1 == s2);
|
||||
EXPECT_FALSE(s1 != s2);
|
||||
}
|
||||
|
||||
TEST(Size, CompareDefaultEqual)
|
||||
{
|
||||
cv::gapi::own::Size s1;
|
||||
cv::gapi::own::Size s2;
|
||||
|
||||
EXPECT_TRUE(s1 == s2);
|
||||
EXPECT_FALSE(s1 != s2);
|
||||
}
|
||||
|
||||
TEST(Size, CompareNotEqual)
|
||||
{
|
||||
cv::gapi::own::Size s1(1, 2);
|
||||
|
||||
cv::gapi::own::Size s2(3, 4);
|
||||
|
||||
EXPECT_FALSE(s1 == s2);
|
||||
EXPECT_TRUE(s1 != s2);
|
||||
}
|
||||
|
||||
} // opencv_test
|
||||
@@ -0,0 +1,164 @@
|
||||
// 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 "opencv2/gapi/own/mat.hpp"
|
||||
#include <opencv2/gapi/util/compiler_hints.hpp> //suppress_unused_warning
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
using Mat = cv::gapi::own::Mat;
|
||||
|
||||
TEST(OwnMat, DefaultConstruction)
|
||||
{
|
||||
Mat m;
|
||||
ASSERT_EQ(m.data, nullptr);
|
||||
ASSERT_EQ(m.cols, 0);
|
||||
ASSERT_EQ(m.rows, 0);
|
||||
ASSERT_EQ(m.cols, 0);
|
||||
ASSERT_EQ(m.type(), 0);
|
||||
ASSERT_EQ(m.depth(), 0);
|
||||
}
|
||||
|
||||
TEST(OwnMat, Create)
|
||||
{
|
||||
auto size = cv::gapi::own::Size{32,16};
|
||||
Mat m;
|
||||
m.create(size, CV_8UC1);
|
||||
|
||||
ASSERT_NE(m.data, nullptr);
|
||||
ASSERT_EQ((cv::gapi::own::Size{m.cols, m.rows}), size);
|
||||
|
||||
ASSERT_EQ(m.type(), CV_8UC1);
|
||||
ASSERT_EQ(m.depth(), CV_8U);
|
||||
ASSERT_EQ(m.channels(), 1);
|
||||
ASSERT_EQ(m.step, sizeof(uint8_t) * m.cols);
|
||||
}
|
||||
|
||||
struct NonEmptyMat {
|
||||
cv::gapi::own::Size size{32,16};
|
||||
Mat m;
|
||||
NonEmptyMat() {
|
||||
m.create(size, CV_8UC1);
|
||||
}
|
||||
};
|
||||
|
||||
struct OwnMatSharedSemantics : NonEmptyMat, ::testing::Test {};
|
||||
|
||||
|
||||
namespace {
|
||||
auto state_of = [](Mat const& mat) {
|
||||
return std::make_tuple(
|
||||
mat.data,
|
||||
cv::Size{mat.cols, mat.rows},
|
||||
mat.type(),
|
||||
mat.depth(),
|
||||
mat.channels()
|
||||
);
|
||||
};
|
||||
|
||||
void ensure_mats_are_same(Mat const& copy, Mat const& m){
|
||||
EXPECT_NE(copy.data, nullptr);
|
||||
EXPECT_EQ(state_of(copy), state_of(m));
|
||||
}
|
||||
}
|
||||
TEST_F(OwnMatSharedSemantics, CopyConstruction)
|
||||
{
|
||||
Mat copy(m);
|
||||
ensure_mats_are_same(copy, m);
|
||||
}
|
||||
|
||||
TEST_F(OwnMatSharedSemantics, CopyAssignment)
|
||||
{
|
||||
Mat copy;
|
||||
copy = m;
|
||||
ensure_mats_are_same(copy, m);
|
||||
}
|
||||
|
||||
struct OwnMatMoveSemantics : NonEmptyMat, ::testing::Test {
|
||||
Mat& moved_from = m;
|
||||
decltype(state_of(moved_from)) initial_state = state_of(moved_from);
|
||||
|
||||
void ensure_state_moved_to(Mat const& moved_to)
|
||||
{
|
||||
EXPECT_EQ(state_of(moved_to), initial_state);
|
||||
EXPECT_EQ(state_of(moved_from), state_of(Mat{}));
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(OwnMatMoveSemantics, MoveConstruction)
|
||||
{
|
||||
Mat moved_to(std::move(moved_from));
|
||||
|
||||
ensure_state_moved_to(moved_to);
|
||||
}
|
||||
|
||||
TEST_F(OwnMatMoveSemantics, MoveAssignment)
|
||||
{
|
||||
Mat moved_to(std::move(moved_from));
|
||||
ensure_state_moved_to(moved_to);
|
||||
}
|
||||
|
||||
struct OwnMatNonOwningView : NonEmptyMat, ::testing::Test {
|
||||
decltype(state_of(m)) initial_state = state_of(m);
|
||||
|
||||
void TearDown() override {
|
||||
EXPECT_EQ(state_of(m), initial_state)<<"State of the source matrix changed?";
|
||||
//ASAN should complain here if memory is freed here (e.g. by bug in non owning logic of own::Mat)
|
||||
volatile uchar dummy = m.data[0];
|
||||
cv::util::suppress_unused_warning(dummy);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
TEST_F(OwnMatNonOwningView, Construction)
|
||||
{
|
||||
Mat non_owning_view(m.rows, m.cols, m.type(), static_cast<void*>(m.data));
|
||||
|
||||
ensure_mats_are_same(non_owning_view, m);
|
||||
}
|
||||
|
||||
TEST_F(OwnMatNonOwningView, CopyConstruction)
|
||||
{
|
||||
Mat non_owning_view{m.rows, m.cols, m.type(), static_cast<void*>(m.data)};
|
||||
|
||||
Mat non_owning_view_copy = non_owning_view;
|
||||
ensure_mats_are_same(non_owning_view_copy, m);
|
||||
}
|
||||
|
||||
TEST_F(OwnMatNonOwningView, Assignment)
|
||||
{
|
||||
Mat non_owning_view{m.rows, m.cols, m.type(), static_cast<void*>(m.data)};
|
||||
Mat non_owning_view_copy;
|
||||
|
||||
non_owning_view_copy = non_owning_view;
|
||||
ensure_mats_are_same(non_owning_view_copy, m);
|
||||
}
|
||||
|
||||
TEST(OwnMatConversion, WithStep)
|
||||
{
|
||||
constexpr int width = 8;
|
||||
constexpr int height = 8;
|
||||
constexpr int stepInPixels = 16;
|
||||
|
||||
std::array<int, height * stepInPixels> data;
|
||||
for (size_t i = 0; i < data.size(); i++)
|
||||
{
|
||||
data[i] = static_cast<int>(i);
|
||||
}
|
||||
cv::Mat cvMat(cv::Size{width, height}, CV_32S, data.data(), stepInPixels * sizeof(int));
|
||||
|
||||
auto ownMat = to_own(cvMat);
|
||||
auto cvMatFromOwn = cv::gapi::own::to_ocv(ownMat);
|
||||
|
||||
EXPECT_EQ(0, cv::countNonZero(cvMat != cvMatFromOwn))
|
||||
<< cvMat << std::endl
|
||||
<< (cvMat != cvMatFromOwn);
|
||||
}
|
||||
|
||||
|
||||
} // namespace opencv_test
|
||||
@@ -0,0 +1,44 @@
|
||||
// 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 "opencv2/gapi/own/scalar.hpp"
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
|
||||
TEST(Scalar, CreateEmpty)
|
||||
{
|
||||
cv::gapi::own::Scalar s;
|
||||
|
||||
for (int i = 0; i < 4; ++i)
|
||||
{
|
||||
EXPECT_EQ(s[i], 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Scalar, CreateFromVal)
|
||||
{
|
||||
cv::gapi::own::Scalar s(5.0);
|
||||
|
||||
EXPECT_EQ(s[0], 5.0);
|
||||
EXPECT_EQ(s[1], 0.0);
|
||||
EXPECT_EQ(s[2], 0.0);
|
||||
EXPECT_EQ(s[3], 0.0);
|
||||
}
|
||||
|
||||
TEST(Scalar, CreateFromVals)
|
||||
{
|
||||
cv::gapi::own::Scalar s(5.3, 3.3, 4.1, -2.0);
|
||||
|
||||
EXPECT_EQ(s[0], 5.3);
|
||||
EXPECT_EQ(s[1], 3.3);
|
||||
EXPECT_EQ(s[2], 4.1);
|
||||
EXPECT_EQ(s[3], -2.0);
|
||||
}
|
||||
|
||||
} // namespace opencv_test
|
||||
@@ -0,0 +1,12 @@
|
||||
// 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: OpenCV license header
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
CV_TEST_MAIN("gapi")
|
||||
@@ -0,0 +1,24 @@
|
||||
// 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: OpenCV header
|
||||
|
||||
#ifndef __OPENCV_GAPI_TEST_PRECOMP_HPP__
|
||||
#define __OPENCV_GAPI_TEST_PRECOMP_HPP__
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
#include "opencv2/ts.hpp"
|
||||
#include "opencv2/gapi.hpp"
|
||||
#include "opencv2/gapi/imgproc.hpp"
|
||||
#include "opencv2/gapi/core.hpp"
|
||||
#include "opencv2/gapi/cpu/gcpukernel.hpp"
|
||||
#include "opencv2/gapi/gcompoundkernel.hpp"
|
||||
#include "opencv2/gapi/operators.hpp"
|
||||
|
||||
#endif // __OPENCV_GAPI_TEST_PRECOMP_HPP__
|
||||
@@ -0,0 +1,121 @@
|
||||
// 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 "opencv2/gapi/util/any.hpp"
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
|
||||
TEST(Any, basic)
|
||||
{
|
||||
using namespace util;
|
||||
any a(8);
|
||||
auto casted_pointer = any_cast<int>(&a);
|
||||
ASSERT_NE(nullptr, casted_pointer);
|
||||
ASSERT_EQ(*casted_pointer, 8);
|
||||
|
||||
*casted_pointer = 7;
|
||||
ASSERT_EQ(any_cast<int>(a), 7);
|
||||
}
|
||||
|
||||
TEST(Any, any_cast_ref_throws_on_empty)
|
||||
{
|
||||
using namespace util;
|
||||
any a;
|
||||
|
||||
ASSERT_THROW(util::any_cast<int>(a), bad_any_cast);
|
||||
}
|
||||
|
||||
TEST(Any, copy)
|
||||
{
|
||||
using namespace util;
|
||||
any a(8);
|
||||
|
||||
ASSERT_EQ(any_cast<int>(a), 8);
|
||||
|
||||
any b (a);
|
||||
|
||||
ASSERT_NE(nullptr, any_cast<int>(&b));
|
||||
ASSERT_EQ(8 , any_cast<int>(b));
|
||||
ASSERT_EQ(8 , any_cast<int>(a));
|
||||
}
|
||||
|
||||
TEST(Any, copy_empty)
|
||||
{
|
||||
using namespace util;
|
||||
any a;
|
||||
|
||||
ASSERT_EQ(nullptr, any_cast<int>(&a));
|
||||
|
||||
any b (a);
|
||||
|
||||
ASSERT_EQ(nullptr, any_cast<int>(&a));
|
||||
ASSERT_EQ(nullptr, any_cast<int>(&b));
|
||||
}
|
||||
|
||||
TEST(Any, move)
|
||||
{
|
||||
using namespace util;
|
||||
any a(8);
|
||||
|
||||
ASSERT_EQ(any_cast<int>(a), 8);
|
||||
|
||||
any b (std::move(a));
|
||||
|
||||
ASSERT_NE(nullptr, any_cast<int>(&b));
|
||||
ASSERT_EQ(8 , any_cast<int>(b));
|
||||
ASSERT_EQ(nullptr, any_cast<int>(&a));
|
||||
}
|
||||
|
||||
TEST(Any, swap)
|
||||
{
|
||||
using namespace util;
|
||||
any a(8);
|
||||
any b(7);
|
||||
|
||||
ASSERT_EQ(7, any_cast<int>(b));
|
||||
ASSERT_EQ(8, any_cast<int>(a));
|
||||
|
||||
swap(a,b);
|
||||
|
||||
ASSERT_EQ(8, any_cast<int>(b));
|
||||
ASSERT_EQ(7, any_cast<int>(a));
|
||||
}
|
||||
|
||||
TEST(Any, move_assign)
|
||||
{
|
||||
using namespace util;
|
||||
any a(8);
|
||||
any b;
|
||||
|
||||
ASSERT_EQ(any_cast<int>(a), 8);
|
||||
|
||||
b = (std::move(a));
|
||||
|
||||
ASSERT_NE(nullptr, any_cast<int>(&b));
|
||||
ASSERT_EQ(8 , any_cast<int>(b));
|
||||
ASSERT_EQ(nullptr, any_cast<int>(&a));
|
||||
}
|
||||
|
||||
TEST(Any, copy_assign)
|
||||
{
|
||||
using namespace util;
|
||||
any a(8);
|
||||
any b;
|
||||
|
||||
ASSERT_EQ(any_cast<int>(a), 8);
|
||||
ASSERT_EQ(nullptr, any_cast<int>(&b));
|
||||
|
||||
b = a;
|
||||
|
||||
ASSERT_NE(nullptr, any_cast<int>(&b));
|
||||
ASSERT_EQ(8 , any_cast<int>(b));
|
||||
ASSERT_EQ(8 , any_cast<int>(a));
|
||||
}
|
||||
|
||||
} // namespace opencv_test
|
||||
@@ -0,0 +1,175 @@
|
||||
// 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 "opencv2/gapi/util/optional.hpp"
|
||||
#include <opencv2/gapi/util/compiler_hints.hpp> //suppress_unused_warning
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
|
||||
TEST(Optional, EmptyCtor)
|
||||
{
|
||||
util::optional<int> o;
|
||||
EXPECT_FALSE(o.has_value());
|
||||
EXPECT_FALSE(static_cast<bool>(o));
|
||||
}
|
||||
|
||||
TEST(Optional, ValueCTor)
|
||||
{
|
||||
util::optional<int> o(42);
|
||||
EXPECT_TRUE(o.has_value());
|
||||
EXPECT_TRUE(static_cast<bool>(o));
|
||||
}
|
||||
|
||||
TEST(Optional, MoveCtr)
|
||||
{
|
||||
util::optional<std::string> os1(std::string("text"));
|
||||
EXPECT_TRUE(os1.has_value());
|
||||
|
||||
util::optional<std::string> os2(std::move(os1));
|
||||
EXPECT_FALSE(os1.has_value());
|
||||
EXPECT_TRUE(os2.has_value());
|
||||
EXPECT_EQ("text", os2.value());
|
||||
}
|
||||
|
||||
TEST(Optional, EmptyThrows)
|
||||
{
|
||||
struct foo { int bar; };
|
||||
util::optional<foo> om;
|
||||
const util::optional<foo> oc;
|
||||
|
||||
int dummy;
|
||||
|
||||
EXPECT_THROW(dummy = om->bar, util::bad_optional_access);
|
||||
EXPECT_THROW(dummy = oc->bar, util::bad_optional_access);
|
||||
cv::util::suppress_unused_warning(dummy);
|
||||
EXPECT_THROW(*om, util::bad_optional_access);
|
||||
EXPECT_THROW(*oc, util::bad_optional_access);
|
||||
EXPECT_THROW(om.value(), util::bad_optional_access);
|
||||
EXPECT_THROW(oc.value(), util::bad_optional_access);
|
||||
}
|
||||
|
||||
TEST(Optional, ValueNoThrow)
|
||||
{
|
||||
struct foo { int bar; };
|
||||
util::optional<foo> om(foo{42});
|
||||
const util::optional<foo> oc(foo{42});
|
||||
|
||||
int dummy;
|
||||
EXPECT_NO_THROW(dummy = om->bar);
|
||||
EXPECT_NO_THROW(dummy = oc->bar);
|
||||
cv::util::suppress_unused_warning(dummy);
|
||||
EXPECT_NO_THROW(*om);
|
||||
EXPECT_NO_THROW(*oc);
|
||||
EXPECT_NO_THROW(om.value());
|
||||
EXPECT_NO_THROW(oc.value());
|
||||
}
|
||||
|
||||
TEST(Optional, Value)
|
||||
{
|
||||
util::optional<int> oi(42);
|
||||
|
||||
struct foo { int bar; };
|
||||
util::optional<foo> of(foo{42});
|
||||
|
||||
EXPECT_EQ(42, oi.value());
|
||||
EXPECT_EQ(42, *oi);
|
||||
|
||||
EXPECT_EQ(42, of.value().bar);
|
||||
EXPECT_EQ(42, of->bar);
|
||||
}
|
||||
|
||||
TEST(Optional, Mutable)
|
||||
{
|
||||
util::optional<int> oi(42);
|
||||
*oi = 43;
|
||||
EXPECT_EQ(43, *oi);
|
||||
|
||||
struct foo { int bar; int baz; };
|
||||
util::optional<foo> of(foo{11,22});
|
||||
|
||||
(*of).bar = 42;
|
||||
EXPECT_EQ(42, of->bar);
|
||||
EXPECT_EQ(22, of->baz);
|
||||
|
||||
of->baz = 33;
|
||||
EXPECT_EQ(42, of->bar);
|
||||
EXPECT_EQ(33, of->baz);
|
||||
}
|
||||
|
||||
TEST(Optional, MoveAssign)
|
||||
{
|
||||
util::optional<int> e, i(42);
|
||||
|
||||
EXPECT_FALSE(e.has_value());
|
||||
EXPECT_TRUE(i.has_value());
|
||||
EXPECT_EQ(42, *i);
|
||||
|
||||
e = std::move(i);
|
||||
EXPECT_TRUE(e.has_value());
|
||||
EXPECT_FALSE(i.has_value());
|
||||
EXPECT_EQ(42, *e);
|
||||
}
|
||||
|
||||
TEST(Optional, CopyAssign)
|
||||
{
|
||||
util::optional<int> e;
|
||||
const util::optional<int> i(42);
|
||||
|
||||
EXPECT_FALSE(e.has_value());
|
||||
EXPECT_TRUE(i.has_value());
|
||||
EXPECT_EQ(42, *i);
|
||||
|
||||
e = i;
|
||||
EXPECT_TRUE(e.has_value());
|
||||
EXPECT_TRUE(i.has_value());
|
||||
EXPECT_EQ(42, *e);
|
||||
EXPECT_EQ(42, *i);
|
||||
}
|
||||
|
||||
TEST(Optional, ValueOr)
|
||||
{
|
||||
util::optional<int> e;
|
||||
EXPECT_FALSE(e.has_value());
|
||||
EXPECT_EQ(42, e.value_or(42));
|
||||
EXPECT_EQ(42, e.value_or(42.1));
|
||||
}
|
||||
|
||||
TEST(Optional, Swap)
|
||||
{
|
||||
util::optional<int> e, i(42);
|
||||
|
||||
EXPECT_FALSE(e.has_value());
|
||||
EXPECT_TRUE(i.has_value());
|
||||
EXPECT_EQ(42, *i);
|
||||
|
||||
e.swap(i);
|
||||
|
||||
EXPECT_TRUE(e.has_value());
|
||||
EXPECT_FALSE(i.has_value());
|
||||
EXPECT_EQ(42, *e);
|
||||
}
|
||||
|
||||
TEST(Optional, Reset)
|
||||
{
|
||||
util::optional<int> i(42);
|
||||
EXPECT_TRUE(i.has_value());
|
||||
|
||||
i.reset();
|
||||
EXPECT_FALSE(i.has_value());
|
||||
}
|
||||
|
||||
TEST(Optional, MakeOptional)
|
||||
{
|
||||
std::string s("text");
|
||||
auto os = util::make_optional(s);
|
||||
EXPECT_TRUE(os.has_value());
|
||||
EXPECT_EQ(s, os.value());
|
||||
}
|
||||
|
||||
} // namespace opencv_test
|
||||
@@ -0,0 +1,386 @@
|
||||
// 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 "opencv2/gapi/util/variant.hpp"
|
||||
#include <cstddef> //std::max_align_t
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
typedef util::variant<int, std::string> TestVar;
|
||||
typedef util::variant<int, float> TestVar2;
|
||||
}
|
||||
|
||||
TEST(Variant, EmptyCTor)
|
||||
{
|
||||
util::variant<int> vi;
|
||||
EXPECT_EQ(0, util::get<int>(vi));
|
||||
|
||||
util::variant<int, std::string> vis;
|
||||
EXPECT_EQ(0, util::get<int>(vis));
|
||||
|
||||
util::variant<std::string> vs;
|
||||
EXPECT_EQ("", util::get<std::string>(vs));
|
||||
|
||||
util::variant<std::string, int> vsi;
|
||||
EXPECT_EQ("", util::get<std::string>(vsi));
|
||||
}
|
||||
|
||||
TEST(Variant, ValueMoveCTor)
|
||||
{
|
||||
util::variant<int> vi(42);
|
||||
EXPECT_EQ(0u, vi.index());
|
||||
EXPECT_EQ(42, util::get<int>(vi));
|
||||
|
||||
util::variant<int, std::string> vis(2017);
|
||||
EXPECT_EQ(0u, vis.index());
|
||||
EXPECT_EQ(2017, util::get<int>(vis));
|
||||
|
||||
util::variant<int, std::string> vis2(std::string("2017"));
|
||||
EXPECT_EQ(1u, vis2.index());
|
||||
EXPECT_EQ("2017", util::get<std::string>(vis2));
|
||||
|
||||
util::variant<std::string> vs(std::string("2017"));
|
||||
EXPECT_EQ(0u, vs.index());
|
||||
EXPECT_EQ("2017", util::get<std::string>(vs));
|
||||
|
||||
util::variant<std::string, int> vsi(std::string("2017"));
|
||||
EXPECT_EQ(0u, vsi.index());
|
||||
EXPECT_EQ("2017", util::get<std::string>(vsi));
|
||||
|
||||
util::variant<std::string, int> vsi2(42);
|
||||
EXPECT_EQ(1u, vsi2.index());
|
||||
EXPECT_EQ(42, util::get<int>(vsi2));
|
||||
}
|
||||
|
||||
TEST(Variant, ValueCopyCTor)
|
||||
{
|
||||
const int i42 = 42;
|
||||
const int i17 = 2017;
|
||||
const std::string s17 = "2017";
|
||||
|
||||
util::variant<int> vi(i42);
|
||||
EXPECT_EQ(0u, vi.index());
|
||||
EXPECT_EQ(i42, util::get<int>(vi));
|
||||
|
||||
util::variant<int, std::string> vis(i17);
|
||||
EXPECT_EQ(0u, vis.index());
|
||||
EXPECT_EQ(i17, util::get<int>(vis));
|
||||
|
||||
util::variant<int, std::string> vis2(s17);
|
||||
EXPECT_EQ(1u, vis2.index());
|
||||
EXPECT_EQ(s17, util::get<std::string>(vis2));
|
||||
|
||||
util::variant<std::string> vs(s17);
|
||||
EXPECT_EQ(0u, vs.index());
|
||||
EXPECT_EQ(s17, util::get<std::string>(vs));
|
||||
|
||||
util::variant<std::string, int> vsi(s17);
|
||||
EXPECT_EQ(0u, vsi.index());
|
||||
EXPECT_EQ(s17, util::get<std::string>(vsi));
|
||||
|
||||
util::variant<std::string, int> vsi2(i42);
|
||||
EXPECT_EQ(1u, vsi2.index());
|
||||
EXPECT_EQ(i42, util::get<int>(vsi2));
|
||||
}
|
||||
|
||||
TEST(Variant, CopyMoveCTor)
|
||||
{
|
||||
const TestVar tvconst(std::string("42"));
|
||||
|
||||
TestVar tv = tvconst;
|
||||
EXPECT_EQ( 1u, tv.index());
|
||||
EXPECT_EQ("42", util::get<std::string>(tv));
|
||||
|
||||
TestVar tv2(TestVar(40+2));
|
||||
EXPECT_EQ( 0u, tv2.index());
|
||||
EXPECT_EQ( 42, util::get<int>(tv2));
|
||||
}
|
||||
|
||||
TEST(Variant, Assign_Basic)
|
||||
{
|
||||
TestVar vis;
|
||||
EXPECT_EQ(0u, vis.index());
|
||||
EXPECT_EQ(0, util::get<int>(vis));
|
||||
|
||||
vis = 42;
|
||||
EXPECT_EQ(0u, vis.index());
|
||||
EXPECT_EQ(42, util::get<int>(vis));
|
||||
}
|
||||
|
||||
TEST(Variant, Assign_ValueUpdate_SameType)
|
||||
{
|
||||
TestVar vis(42);
|
||||
|
||||
EXPECT_EQ(0u, vis.index());
|
||||
EXPECT_EQ(42, util::get<int>(vis));
|
||||
|
||||
vis = 43;
|
||||
EXPECT_EQ(0u, vis.index());
|
||||
EXPECT_EQ(43, util::get<int>(vis));
|
||||
}
|
||||
|
||||
TEST(Variant, Assign_ValueUpdate_DiffType)
|
||||
{
|
||||
TestVar vis(42);
|
||||
|
||||
EXPECT_EQ(0u, vis.index());
|
||||
EXPECT_EQ(42, util::get<int>(vis));
|
||||
|
||||
vis = std::string("42");
|
||||
EXPECT_EQ(1u, vis.index());
|
||||
EXPECT_EQ("42", util::get<std::string>(vis));
|
||||
}
|
||||
|
||||
TEST(Variant, Assign_ValueUpdate_Const)
|
||||
{
|
||||
TestVar va(42);
|
||||
const TestVar vb(43);
|
||||
|
||||
EXPECT_EQ(0u, va.index());
|
||||
EXPECT_EQ(42, util::get<int>(va));
|
||||
|
||||
EXPECT_EQ(0u, vb.index());
|
||||
EXPECT_EQ(43, util::get<int>(vb));
|
||||
|
||||
va = vb;
|
||||
|
||||
EXPECT_EQ(0u, va.index());
|
||||
EXPECT_EQ(43, util::get<int>(va));
|
||||
}
|
||||
|
||||
TEST(Variant, Assign_ValueUpdate_Const_DiffType)
|
||||
{
|
||||
TestVar va(42);
|
||||
const TestVar vb(std::string("42"));
|
||||
|
||||
EXPECT_EQ(0u, va.index());
|
||||
EXPECT_EQ(42, util::get<int>(va));
|
||||
|
||||
EXPECT_EQ(1u, vb.index());
|
||||
EXPECT_EQ("42", util::get<std::string>(vb));
|
||||
|
||||
va = vb;
|
||||
|
||||
EXPECT_EQ(1u, va.index());
|
||||
EXPECT_EQ("42", util::get<std::string>(va));
|
||||
}
|
||||
|
||||
TEST(Variant, Assign_Move)
|
||||
{
|
||||
TestVar va(42);
|
||||
TestVar vb(std::string("42"));
|
||||
TestVar vc(43);
|
||||
|
||||
EXPECT_EQ(0u, va.index());
|
||||
EXPECT_EQ(42, util::get<int>(va));
|
||||
|
||||
EXPECT_EQ(1u, vb.index());
|
||||
EXPECT_EQ("42", util::get<std::string>(vb));
|
||||
|
||||
EXPECT_EQ(0u, vc.index());
|
||||
EXPECT_EQ(43, util::get<int>(vc));
|
||||
|
||||
va = std::move(vb);
|
||||
EXPECT_EQ(1u, va.index());
|
||||
EXPECT_EQ("42", util::get<std::string>(va));
|
||||
|
||||
va = std::move(vc);
|
||||
EXPECT_EQ(0u, va.index());
|
||||
EXPECT_EQ(43, util::get<int>(va));
|
||||
}
|
||||
|
||||
TEST(Variant, Swap_SameIndex)
|
||||
{
|
||||
TestVar tv1(42);
|
||||
TestVar tv2(43);
|
||||
|
||||
EXPECT_EQ(0u, tv1.index());
|
||||
EXPECT_EQ(42, util::get<int>(tv1));
|
||||
|
||||
EXPECT_EQ(0u, tv2.index());
|
||||
EXPECT_EQ(43, util::get<int>(tv2));
|
||||
|
||||
tv1.swap(tv2);
|
||||
|
||||
EXPECT_EQ(0u, tv1.index());
|
||||
EXPECT_EQ(43, util::get<int>(tv1));
|
||||
|
||||
EXPECT_EQ(0u, tv2.index());
|
||||
EXPECT_EQ(42, util::get<int>(tv2));
|
||||
}
|
||||
|
||||
TEST(Variant, Swap_DiffIndex)
|
||||
{
|
||||
TestVar2 tv1(42);
|
||||
TestVar2 tv2(3.14f);
|
||||
|
||||
EXPECT_EQ(0u, tv1.index());
|
||||
EXPECT_EQ(42, util::get<int>(tv1));
|
||||
|
||||
EXPECT_EQ(1u, tv2.index());
|
||||
EXPECT_EQ(3.14f, util::get<float>(tv2));
|
||||
|
||||
tv1.swap(tv2);
|
||||
|
||||
EXPECT_EQ(0u, tv2.index());
|
||||
EXPECT_EQ(42, util::get<int>(tv2));
|
||||
|
||||
EXPECT_EQ(1u, tv1.index());
|
||||
EXPECT_EQ(3.14f, util::get<float>(tv1));
|
||||
}
|
||||
|
||||
TEST(Variant, Get)
|
||||
{
|
||||
const TestVar cv(42);
|
||||
|
||||
// Test const& get()
|
||||
EXPECT_EQ(42, util::get<int>(cv));
|
||||
EXPECT_THROW(util::get<std::string>(cv), util::bad_variant_access);
|
||||
|
||||
// Test &get
|
||||
TestVar cv2(std::string("42"));
|
||||
EXPECT_EQ("42", util::get<std::string>(cv2));
|
||||
EXPECT_THROW(util::get<int>(cv2), util::bad_variant_access);
|
||||
}
|
||||
|
||||
TEST(Variant, GetWrite)
|
||||
{
|
||||
util::variant<int, std::string> v(42);
|
||||
EXPECT_EQ(42, util::get<int>(v));
|
||||
|
||||
util::get<int>(v) = 43;
|
||||
EXPECT_EQ(43, util::get<int>(v));
|
||||
}
|
||||
|
||||
TEST(Variant, NoDefaultCtor)
|
||||
{
|
||||
struct MyType
|
||||
{
|
||||
int m_a;
|
||||
MyType() = delete;
|
||||
};
|
||||
|
||||
// This code MUST compile
|
||||
util::variant<int, MyType> var;
|
||||
SUCCEED() << "Code compiled";
|
||||
|
||||
// At the same time, util::variant<MyType, ...> MUST NOT.
|
||||
}
|
||||
|
||||
TEST(Variant, MonoState)
|
||||
{
|
||||
struct MyType
|
||||
{
|
||||
int m_a;
|
||||
explicit MyType(int a) : m_a(a) {}
|
||||
MyType() = delete;
|
||||
};
|
||||
|
||||
util::variant<util::monostate, MyType> var;
|
||||
EXPECT_EQ(0u, var.index());
|
||||
|
||||
var = MyType{42};
|
||||
EXPECT_EQ(1u, var.index());
|
||||
EXPECT_EQ(42, util::get<MyType>(var).m_a);
|
||||
}
|
||||
|
||||
|
||||
TEST(Variant, Eq)
|
||||
{
|
||||
TestVar v1(42), v2(std::string("42"));
|
||||
TestVar v3(v1), v4(v2);
|
||||
|
||||
EXPECT_TRUE(v1 == v3);
|
||||
EXPECT_TRUE(v2 == v4);
|
||||
EXPECT_TRUE(v1 != v2);
|
||||
EXPECT_TRUE(v3 != v4);
|
||||
|
||||
EXPECT_FALSE(v1 == v2);
|
||||
EXPECT_FALSE(v3 == v4);
|
||||
EXPECT_FALSE(v1 != v3);
|
||||
EXPECT_FALSE(v2 != v4);
|
||||
}
|
||||
|
||||
TEST(Variant, Eq_Monostate)
|
||||
{
|
||||
using TestVar3 = util::variant<util::monostate, int>;
|
||||
TestVar3 v1;
|
||||
TestVar3 v2(42);
|
||||
|
||||
EXPECT_NE(v1, v2);
|
||||
|
||||
v2 = util::monostate{};
|
||||
EXPECT_EQ(v1, v2);
|
||||
}
|
||||
|
||||
TEST(Variant, VectorOfVariants)
|
||||
{
|
||||
std::vector<TestVar> vv1(1024);
|
||||
std::vector<TestVar> vv2(1024);
|
||||
|
||||
EXPECT_TRUE(vv1 == vv2);
|
||||
|
||||
std::vector<TestVar> vv3(2048, TestVar(std::string("42")));
|
||||
|
||||
// Just test chat the below code compiles:
|
||||
// 1: internal copy of variants from one vector to another,
|
||||
// with probable reallocation of 1st vector to host all elements
|
||||
std::copy(vv1.begin(), vv1.end(), std::back_inserter(vv2));
|
||||
EXPECT_EQ(2048u, vv2.size());
|
||||
|
||||
// 2: truncation of vector, with probable destruction of its tail memory
|
||||
vv2.resize(1024);
|
||||
EXPECT_EQ(1024u, vv2.size());
|
||||
|
||||
// 3. vector assignment, with overwriting underlying variants
|
||||
vv2 = vv3;
|
||||
EXPECT_EQ(2048u, vv2.size());
|
||||
EXPECT_TRUE(vv2 == vv3);
|
||||
}
|
||||
|
||||
TEST(Variant, HoldsAlternative)
|
||||
{
|
||||
TestVar v(42);
|
||||
EXPECT_TRUE (util::holds_alternative<int> (v));
|
||||
EXPECT_FALSE(util::holds_alternative<std::string>(v));
|
||||
|
||||
v = std::string("42");
|
||||
EXPECT_FALSE(util::holds_alternative<int> (v));
|
||||
EXPECT_TRUE (util::holds_alternative<std::string>(v));
|
||||
}
|
||||
|
||||
TEST(Variant, Sizeof)
|
||||
{
|
||||
//variant has to store index of the contained type as well as the type itself
|
||||
EXPECT_EQ(2 * sizeof(size_t), (sizeof(util::variant<int, char>)));
|
||||
#if !defined(__GNUG__) || __GNUG__ >= 5
|
||||
// GCC versions prior to 5.0 have limited C++11 support, e.g.
|
||||
// no std::max_align_t defined
|
||||
EXPECT_EQ((sizeof(std::max_align_t) + std::max(sizeof(size_t), alignof(std::max_align_t))), (sizeof(util::variant<std::max_align_t, char>)));
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(Variant, EXT_IndexOf)
|
||||
{
|
||||
struct MyType{};
|
||||
class MyClass{};
|
||||
|
||||
using V = util::variant<util::monostate, int, double, char, float, MyType, MyClass>;
|
||||
static_assert(0u == V::index_of<util::monostate>(), "Index is incorrect");
|
||||
static_assert(1u == V::index_of<int >(), "Index is incorrect");
|
||||
static_assert(2u == V::index_of<double >(), "Index is incorrect");
|
||||
static_assert(3u == V::index_of<char >(), "Index is incorrect");
|
||||
static_assert(4u == V::index_of<float >(), "Index is incorrect");
|
||||
static_assert(5u == V::index_of<MyType >(), "Index is incorrect");
|
||||
static_assert(6u == V::index_of<MyClass>(), "Index is incorrect");
|
||||
}
|
||||
|
||||
} // namespace opencv_test
|
||||
Reference in New Issue
Block a user