feat: 切换后端至PaddleOCR-NCNN,切换工程为CMake

1.项目后端整体迁移至PaddleOCR-NCNN算法,已通过基本的兼容性测试
2.工程改为使用CMake组织,后续为了更好地兼容第三方库,不再提供QMake工程
3.重整权利声明文件,重整代码工程,确保最小化侵权风险

Log: 切换后端至PaddleOCR-NCNN,切换工程为CMake
Change-Id: I4d5d2c5d37505a4a24b389b1a4c5d12f17bfa38c
This commit is contained in:
wangzhengyang
2022-05-10 09:54:44 +08:00
parent ecdd171c6f
commit 718c41634f
10018 changed files with 3593797 additions and 186748 deletions

View File

@ -0,0 +1,592 @@
// 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);
}
};
G_TYPED_KERNEL(GToInterleaved, <GMat(GMatP)>, "org.opencv.test.to_interleaved")
{
static GMatDesc outMeta(GMatDesc in)
{
GAPI_Assert(in.planar == true);
GAPI_Assert(in.chan == 3);
return in.asInterleaved();
}
};
G_TYPED_KERNEL(GToPlanar, <GMatP(GMat)>, "org.opencv.test.to_planar")
{
static GMatDesc outMeta(GMatDesc in)
{
GAPI_Assert(in.planar == false);
GAPI_Assert(in.chan == 3);
return in.asPlanar();
}
};
GAPI_OCV_KERNEL(GToInterleavedImpl, GToInterleaved)
{
static void run(const cv::Mat& in, cv::Mat& out)
{
constexpr int inPlanesCount = 3;
int inPlaneHeight = in.rows / inPlanesCount;
std::vector<cv::Mat> inPlanes(inPlanesCount);
for (int i = 0; i < inPlanesCount; ++i)
{
int startRow = i * inPlaneHeight;
int endRow = startRow + inPlaneHeight;
inPlanes[i] = in.rowRange(startRow, endRow);
}
cv::merge(inPlanes, out);
}
};
GAPI_OCV_KERNEL(GToPlanarImpl, GToPlanar)
{
static void run(const cv::Mat& in, cv::Mat& out)
{
std::vector<cv::Mat> inPlanes;
cv::split(in, inPlanes);
cv::vconcat(inPlanes, out);
}
};
G_TYPED_KERNEL(GCompoundToInterleavedToPlanar, <GMatP(GMatP)>,
"org.opencv.test.compound_to_interleaved_to_planar")
{
static GMatDesc outMeta(GMatDesc in)
{
GAPI_Assert(in.planar == true);
GAPI_Assert(in.chan == 3);
return in;
}
};
GAPI_COMPOUND_KERNEL(GCompoundToInterleavedToPlanarImpl, GCompoundToInterleavedToPlanar)
{
static GMatP expand(cv::GMatP in)
{
return GToPlanar::on(GToInterleaved::on(in));
}
};
} // namespace
// FIXME avoid cv::combine that use custom and default kernels together
TEST(GCompoundKernel, ReplaceDefaultKernel)
{
cv::GMat in1, in2;
auto out = cv::gapi::add(in1, in2);
const auto custom_pkg = cv::gapi::kernels<GCompoundAddImpl>();
const auto full_pkg = cv::gapi::combine(cv::gapi::core::cpu::kernels(), custom_pkg);
cv::GComputation comp(cv::GIn(in1, in2), cv::GOut(out));
cv::Mat in_mat1 = cv::Mat::eye(3, 3, CV_8UC1),
in_mat2 = cv::Mat::eye(3, 3, CV_8UC1),
out_mat(3, 3, CV_8UC1),
ref_mat(3, 3, CV_8UC1);
comp.apply(cv::gin(in_mat1, in_mat2), cv::gout(out_mat), cv::compile_args(full_pkg));
ref_mat = in_mat1 - in_mat2 - in_mat2;
EXPECT_EQ(0, cvtest::norm(out_mat, ref_mat, NORM_INF));
}
TEST(GCompoundKernel, DoubleAddC)
{
cv::GMat in1, in2;
cv::GScalar s;
auto add_res = cv::gapi::add(in1, in2);
auto super = GCompoundDoubleAddC::on(add_res, s);
auto out = cv::gapi::addC(super, s);
const auto custom_pkg = cv::gapi::kernels<GCompoundDoubleAddCImpl>();
const auto full_pkg = cv::gapi::combine(custom_pkg, cv::gapi::core::cpu::kernels());
cv::GComputation comp(cv::GIn(in1, in2, s), cv::GOut(out));
cv::Mat in_mat1 = cv::Mat::eye(3, 3, CV_8UC1),
in_mat2 = cv::Mat::eye(3, 3, CV_8UC1),
out_mat(3, 3, CV_8UC1),
ref_mat(3, 3, CV_8UC1);
cv::Scalar scalar = 2;
comp.apply(cv::gin(in_mat1, in_mat2, scalar), cv::gout(out_mat), cv::compile_args(full_pkg));
ref_mat = in_mat1 + in_mat2 + scalar + scalar + scalar;
EXPECT_EQ(0, cvtest::norm(out_mat, ref_mat, NORM_INF));
}
TEST(GCompoundKernel, AddC)
{
cv::GMat in1, in2;
cv::GScalar s;
auto add_res = cv::gapi::add(in1, in2);
auto super = GCompoundAddC::on(add_res, s);
auto out = cv::gapi::addC(super, s);
const auto custom_pkg = cv::gapi::kernels<GCompoundAddCImpl>();
const auto full_pkg = cv::gapi::combine(custom_pkg, cv::gapi::core::cpu::kernels());
cv::GComputation comp(cv::GIn(in1, in2, s), cv::GOut(out));
cv::Mat in_mat1 = cv::Mat::eye(3, 3, CV_8UC1),
in_mat2 = cv::Mat::eye(3, 3, CV_8UC1),
out_mat(3, 3, CV_8UC1),
ref_mat(3, 3, CV_8UC1);
cv::Scalar scalar = 2;
comp.apply(cv::gin(in_mat1, in_mat2, scalar), cv::gout(out_mat), cv::compile_args(full_pkg));
ref_mat = in_mat1 + in_mat2 + scalar + scalar;
EXPECT_EQ(0, cvtest::norm(out_mat, ref_mat, NORM_INF));
}
TEST(GCompoundKernel, MergeWithSplit)
{
cv::GMat in, a1, b1, c1,
a2, b2, c2;
std::tie(a1, b1, c1) = cv::gapi::split3(in);
std::tie(a2, b2, c2) = GCompoundMergeWithSplit::on(a1, b1, c1);
auto out = cv::gapi::merge3(a2, b2, c2);
const auto custom_pkg = cv::gapi::kernels<GCompoundMergeWithSplitImpl>();
const auto full_pkg = cv::gapi::combine(custom_pkg, cv::gapi::core::cpu::kernels());
cv::GComputation comp(cv::GIn(in), cv::GOut(out));
cv::Mat in_mat = cv::Mat::eye(3, 3, CV_8UC3), out_mat, ref_mat;
comp.apply(cv::gin(in_mat), cv::gout(out_mat), cv::compile_args(full_pkg));
ref_mat = in_mat;
EXPECT_EQ(0, cvtest::norm(out_mat, ref_mat, NORM_INF));
}
TEST(GCompoundKernel, AddWithAddC)
{
cv::GMat in1, in2;
cv::GScalar s;
auto out = GCompoundAddWithAddC::on(in1, in2, s);
const auto custom_pkg = cv::gapi::kernels<GCompoundAddWithAddCImpl>();
const auto full_pkg = cv::gapi::combine(custom_pkg, cv::gapi::core::cpu::kernels());
cv::GComputation comp(cv::GIn(in1, in2, s), cv::GOut(out));
cv::Mat in_mat1 = cv::Mat::eye(3, 3, CV_8UC1),
in_mat2 = cv::Mat::eye(3, 3, CV_8UC1),
out_mat(3, 3, CV_8UC1),
ref_mat(3, 3, CV_8UC1);
cv::Scalar scalar = 2;
comp.apply(cv::gin(in_mat1, in_mat2, scalar), cv::gout(out_mat), cv::compile_args(full_pkg));
ref_mat = in_mat1 + in_mat2 + scalar;
EXPECT_EQ(0, cvtest::norm(out_mat, ref_mat, NORM_INF));
}
TEST(GCompoundKernel, SplitWithAdd)
{
cv::GMat in, out1, out2;
std::tie(out1, out2) = GCompoundSplitWithAdd::on(in);
const auto custom_pkg = cv::gapi::kernels<GCompoundSplitWithAddImpl>();
const auto full_pkg = cv::gapi::combine(custom_pkg, cv::gapi::core::cpu::kernels());
cv::GComputation comp(cv::GIn(in), cv::GOut(out1, out2));
cv::Mat in_mat = cv::Mat::eye(3, 3, CV_8UC3),
out_mat1(3, 3, CV_8UC1),
out_mat2(3, 3, CV_8UC1),
ref_mat1(3, 3, CV_8UC1),
ref_mat2(3, 3, CV_8UC1);
comp.apply(cv::gin(in_mat), cv::gout(out_mat1, out_mat2), cv::compile_args(full_pkg));
std::vector<cv::Mat> channels(3);
cv::split(in_mat, channels);
ref_mat1 = channels[0] + channels[1];
ref_mat2 = channels[2];
EXPECT_EQ(0, cvtest::norm(out_mat1, ref_mat1, NORM_INF));
EXPECT_EQ(0, cvtest::norm(out_mat2, ref_mat2, NORM_INF));
}
TEST(GCompoundKernel, ParallelAddC)
{
cv::GMat in1, out1, out2;
cv::GScalar in2;
std::tie(out1, out2) = GCompoundParallelAddC::on(in1, in2);
const auto custom_pkg = cv::gapi::kernels<GCompoundParallelAddCImpl>();
const auto full_pkg = cv::gapi::combine(custom_pkg, cv::gapi::core::cpu::kernels());
cv::GComputation comp(cv::GIn(in1, in2), cv::GOut(out1, out2));
cv::Mat in_mat = cv::Mat::eye(3, 3, CV_8UC1),
out_mat1(3, 3, CV_8UC1),
out_mat2(3, 3, CV_8UC1),
ref_mat1(3, 3, CV_8UC1),
ref_mat2(3, 3, CV_8UC1);
cv::Scalar scalar = 2;
comp.apply(cv::gin(in_mat, scalar), cv::gout(out_mat1, out_mat2), cv::compile_args(full_pkg));
ref_mat1 = in_mat + scalar;
ref_mat2 = in_mat + scalar;
EXPECT_EQ(0, cvtest::norm(out_mat1, ref_mat1, NORM_INF));
EXPECT_EQ(0, cvtest::norm(out_mat2, ref_mat2, NORM_INF));
}
TEST(GCompoundKernel, GCompundKernelAndDefaultUseOneData)
{
cv::GMat in1, in2;
cv::GScalar s;
auto out = cv::gapi::add(GCompoundAddWithAddC::on(in1, in2, s), cv::gapi::addC(in2, s));
const auto custom_pkg = cv::gapi::kernels<GCompoundAddWithAddCImpl>();
const auto full_pkg = cv::gapi::combine(custom_pkg, cv::gapi::core::cpu::kernels());
cv::GComputation comp(cv::GIn(in1, in2, s), cv::GOut(out));
cv::Mat in_mat1 = cv::Mat::eye(3, 3, CV_8UC1),
in_mat2 = cv::Mat::eye(3, 3, CV_8UC1),
out_mat(3, 3, CV_8UC1),
ref_mat(3, 3, CV_8UC1);
cv::Scalar scalar = 2;
comp.apply(cv::gin(in_mat1, in_mat2, scalar), cv::gout(out_mat), cv::compile_args(full_pkg));
ref_mat = in_mat1 + in_mat2 + scalar + in_mat2 + scalar;
EXPECT_EQ(0, cvtest::norm(out_mat, ref_mat, NORM_INF));
}
TEST(GCompoundKernel, CompoundExpandedToCompound)
{
cv::GMat in1, in2;
cv::GScalar s;
auto out = GCompoundAddWithAddCWithDoubleAddC::on(in1, in2, s);
const auto custom_pkg = cv::gapi::kernels<GCompoundAddWithAddCWithDoubleAddCImpl,
GCompoundAddWithAddCImpl,
GCompoundDoubleAddCImpl>();
const auto full_pkg = cv::gapi::combine(custom_pkg, cv::gapi::core::cpu::kernels());
cv::GComputation comp(cv::GIn(in1, in2, s), cv::GOut(out));
cv::Mat in_mat1 = cv::Mat::eye(3, 3, CV_8UC1),
in_mat2 = cv::Mat::eye(3, 3, CV_8UC1),
out_mat(3, 3, CV_8UC1),
ref_mat(3, 3, CV_8UC1);
cv::Scalar scalar = 2;
comp.apply(cv::gin(in_mat1, in_mat2, scalar), cv::gout(out_mat), cv::compile_args(full_pkg));
ref_mat = in_mat1 + in_mat2 + scalar + scalar + scalar;
EXPECT_EQ(0, cvtest::norm(out_mat, ref_mat, NORM_INF));
}
TEST(GCompoundKernel, MaxInArray)
{
GDoubleArray in;
auto out = GCompoundMaxInArray::on(in);
const auto custom_pkg = cv::gapi::kernels<GCompoundMaxInArrayImpl, GMaxInArrayImpl>();
const auto full_pkg = cv::gapi::combine(custom_pkg, cv::gapi::core::cpu::kernels());
cv::GComputation comp(cv::GIn(in), cv::GOut(out));
std::vector<double> v = { 1, 5, -2, 3, 10, 2};
cv::Scalar out_scl;
cv::Scalar ref_scl(*std::max_element(v.begin(), v.end()));
comp.apply(cv::gin(v), cv::gout(out_scl), cv::compile_args(full_pkg));
EXPECT_EQ(out_scl, ref_scl);
}
TEST(GCompoundKernel, NegateArray)
{
GDoubleArray in;
GDoubleArray out = GCompoundNegateArray::on(in);
const auto custom_pkg = cv::gapi::kernels<GCompoundNegateArrayImpl, GNegateArrayImpl>();
const auto full_pkg = cv::gapi::combine(custom_pkg, cv::gapi::core::cpu::kernels());
cv::GComputation comp(cv::GIn(in), cv::GOut(out));
std::vector<double> in_v = {1, 5, -2, -10, 3};
std::vector<double> out_v;
std::vector<double> ref_v;
ade::util::transform(in_v, std::back_inserter(ref_v), std::negate<double>());
comp.apply(cv::gin(in_v), cv::gout(out_v), cv::compile_args(full_pkg));
EXPECT_EQ(out_v, ref_v);
}
TEST(GCompoundKernel, RightGArrayHandle)
{
cv::GMat in[2];
GDoubleArray a;
cv::GMat out = GCompoundGMatGArrayGMat::on(in[0], a, in[1]);
const auto custom_pkg = cv::gapi::kernels<GCompoundGMatGArrayGMatImpl, SetDiagKernelImpl>();
const auto full_pkg = cv::gapi::combine(custom_pkg, cv::gapi::core::cpu::kernels());
cv::GComputation comp(cv::GIn(in[0], a, in[1]), cv::GOut(out));
std::vector<double> in_v(3, 1.0);
cv::Mat in_mat1 = cv::Mat::eye(cv::Size(3, 3), CV_8UC1),
in_mat2 = cv::Mat::eye(cv::Size(3, 3), CV_8UC1),
out_mat;
cv::Mat ref_mat= in_mat1 + in_mat2;
setDiag(ref_mat, in_v);
comp.apply(cv::gin(in_mat1, in_v, in_mat2), cv::gout(out_mat), cv::compile_args(full_pkg));
EXPECT_EQ(0, cvtest::norm(out_mat, ref_mat, NORM_INF));
}
TEST(GCompoundKernel, ToInterleavedToPlanar)
{
cv::GMatP in;
cv::GMatP out = GCompoundToInterleavedToPlanar::on(in);
const auto pkg = cv::gapi::kernels<GCompoundToInterleavedToPlanarImpl,
GToInterleavedImpl,
GToPlanarImpl>();
cv::GComputation comp(cv::GIn(in), cv::GOut(out));
constexpr int numPlanes = 3;
cv::Mat in_mat(cv::Size(15, 15), CV_8UC1),
out_mat,
ref_mat;
cv::randu(in_mat, 0, 255);
ref_mat = in_mat;
comp.compile(cv::descr_of(in_mat).asPlanar(numPlanes), cv::compile_args(pkg))
(cv::gin(in_mat), cv::gout(out_mat));
EXPECT_EQ(0, cvtest::norm(out_mat, ref_mat, NORM_INF));
}
} // opencv_test

View File

@ -0,0 +1,9 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
//
// Copyright (C) 2018 Intel Corporation
#include "../test_precomp.hpp"
#include "gapi_core_tests_inl.hpp"

View File

@ -0,0 +1,171 @@
// 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-2021 Intel Corporation
#ifndef OPENCV_GAPI_CORE_TESTS_HPP
#define OPENCV_GAPI_CORE_TESTS_HPP
#include <iostream>
#include "gapi_tests_common.hpp"
#include "gapi_parsers_tests_common.hpp"
namespace opencv_test
{
enum mathOp
{
ADD = 0,
SUB = 1,
MUL = 2,
DIV = 3
};
enum bitwiseOp
{
AND = 0,
OR = 1,
XOR = 2,
NOT = 3
};
// Note: namespace must match the namespace of the type of the printed object
inline std::ostream& operator<<(std::ostream& os, mathOp op)
{
#define CASE(v) case mathOp::v: os << #v; break
switch (op)
{
CASE(ADD);
CASE(SUB);
CASE(MUL);
CASE(DIV);
default: GAPI_Assert(false && "unknown mathOp value");
}
#undef CASE
return os;
}
// Note: namespace must match the namespace of the type of the printed object
inline std::ostream& operator<<(std::ostream& os, bitwiseOp op)
{
#define CASE(v) case bitwiseOp::v: os << #v; break
switch (op)
{
CASE(AND);
CASE(OR);
CASE(XOR);
CASE(NOT);
default: GAPI_Assert(false && "unknown bitwiseOp value");
}
#undef CASE
return os;
}
// Create new value-parameterized test fixture:
// MathOpTest - fixture name
// initMatsRandU - function that is used to initialize input/output data
// FIXTURE_API(mathOp,bool,double,bool) - test-specific parameters (types)
// 4 - number of test-specific parameters
// opType, testWithScalar, scale, doReverseOp - test-specific parameters (names)
//
// We get:
// 1. Default parameters: int type, cv::Size sz, int dtype, getCompileArgs() function
// - available in test body
// 2. Input/output matrices will be initialized by initMatsRandU (in this fixture)
// 3. Specific parameters: opType, testWithScalar, scale, doReverseOp of corresponding types
// - created (and initialized) automatically
// - available in test body
// Note: all parameter _values_ (e.g. type CV_8UC3) are set via INSTANTIATE_TEST_CASE_P macro
GAPI_TEST_FIXTURE(MathOpTest, initMatsRandU, FIXTURE_API(mathOp,bool,double,bool), 4,
opType, testWithScalar, scale, doReverseOp)
// No specific parameters for MulDoubleTest, so "fixture API" is empty - <>
GAPI_TEST_FIXTURE(MulDoubleTest, initMatrixRandU, <>, 0)
GAPI_TEST_FIXTURE(DivTest, initMatrixRandU, <>, 0)
GAPI_TEST_FIXTURE(DivCTest, initMatrixRandU, <>, 0)
GAPI_TEST_FIXTURE(MeanTest, initMatrixRandU, <>, 0)
GAPI_TEST_FIXTURE(MaskTest, initMatrixRandU, <>, 0)
GAPI_TEST_FIXTURE(Polar2CartTest, initMatsRandU, <>, 0)
GAPI_TEST_FIXTURE(Cart2PolarTest, initMatsRandU, <>, 0)
GAPI_TEST_FIXTURE(CmpTest, initMatsRandU, FIXTURE_API(CmpTypes,bool,CompareMats), 3, opType, testWithScalar, cmpF)
GAPI_TEST_FIXTURE(BitwiseTest, initMatsRandU, FIXTURE_API(bitwiseOp,bool), 2, opType, testWithScalar)
GAPI_TEST_FIXTURE(NotTest, initMatrixRandU, <>, 0)
GAPI_TEST_FIXTURE(SelectTest, initMatsRandU, <>, 0)
GAPI_TEST_FIXTURE(MinTest, initMatsRandU, <>, 0)
GAPI_TEST_FIXTURE(MaxTest, initMatsRandU, <>, 0)
GAPI_TEST_FIXTURE(AbsDiffTest, initMatsRandU, <>, 0)
GAPI_TEST_FIXTURE(AbsDiffCTest, initMatsRandU, <>, 0)
GAPI_TEST_FIXTURE(SumTest, initMatrixRandU, FIXTURE_API(CompareScalars), 1, cmpF)
GAPI_TEST_FIXTURE(CountNonZeroTest, initMatrixRandU, FIXTURE_API(CompareScalars), 1, cmpF)
GAPI_TEST_FIXTURE(AddWeightedTest, initMatsRandU, FIXTURE_API(CompareMats), 1, cmpF)
GAPI_TEST_FIXTURE(NormTest, initMatrixRandU, FIXTURE_API(CompareScalars,NormTypes), 2,
cmpF, opType)
GAPI_TEST_FIXTURE(IntegralTest, initNothing, <>, 0)
GAPI_TEST_FIXTURE(ThresholdTest, initMatrixRandU, FIXTURE_API(int, cv::Scalar), 2, tt, maxval)
GAPI_TEST_FIXTURE(ThresholdOTTest, initMatrixRandU, FIXTURE_API(int), 1, tt)
GAPI_TEST_FIXTURE(InRangeTest, initMatrixRandU, <>, 0)
GAPI_TEST_FIXTURE(Split3Test, initMatrixRandU, <>, 0)
GAPI_TEST_FIXTURE(Split4Test, initMatrixRandU, <>, 0)
GAPI_TEST_FIXTURE(ResizeTest, initNothing, FIXTURE_API(CompareMats,int,cv::Size), 3,
cmpF, interp, sz_out)
GAPI_TEST_FIXTURE(ResizePTest, initNothing, FIXTURE_API(CompareMats,int,cv::Size), 3,
cmpF, interp, sz_out)
GAPI_TEST_FIXTURE(ResizeTestFxFy, initNothing, FIXTURE_API(CompareMats,int,double,double), 4,
cmpF, interp, fx, fy)
GAPI_TEST_FIXTURE(Merge3Test, initMatsRandU, <>, 0)
GAPI_TEST_FIXTURE(Merge4Test, initMatsRandU, <>, 0)
GAPI_TEST_FIXTURE(RemapTest, initMatrixRandU, <>, 0)
GAPI_TEST_FIXTURE(FlipTest, initMatrixRandU, FIXTURE_API(int), 1, flipCode)
GAPI_TEST_FIXTURE(CropTest, initMatrixRandU, FIXTURE_API(cv::Rect), 1, rect_to)
GAPI_TEST_FIXTURE(CopyTest, initMatrixRandU, <>, 0)
GAPI_TEST_FIXTURE(ConcatHorTest, initNothing, <>, 0)
GAPI_TEST_FIXTURE(ConcatVertTest, initNothing, <>, 0)
GAPI_TEST_FIXTURE(ConcatVertVecTest, initNothing, <>, 0)
GAPI_TEST_FIXTURE(ConcatHorVecTest, initNothing, <>, 0)
GAPI_TEST_FIXTURE(LUTTest, initNothing, <>, 0)
GAPI_TEST_FIXTURE(ConvertToTest, initNothing, FIXTURE_API(CompareMats, double, double), 3,
cmpF, alpha, beta)
GAPI_TEST_FIXTURE(PhaseTest, initMatsRandU, FIXTURE_API(bool), 1, angle_in_degrees)
GAPI_TEST_FIXTURE(SqrtTest, initMatrixRandU, <>, 0)
GAPI_TEST_FIXTURE(NormalizeTest, initNothing, FIXTURE_API(CompareMats,double,double,int,MatType2), 5,
cmpF, a, b, norm_type, ddepth)
struct BackendOutputAllocationTest : TestWithParams<>
{
BackendOutputAllocationTest()
{
in_mat1 = cv::Mat(sz, type);
in_mat2 = cv::Mat(sz, type);
cv::randu(in_mat1, cv::Scalar::all(1), cv::Scalar::all(15));
cv::randu(in_mat2, cv::Scalar::all(1), cv::Scalar::all(15));
}
};
// FIXME: move all tests from this fixture to the base class once all issues are resolved
struct BackendOutputAllocationLargeSizeWithCorrectSubmatrixTest : BackendOutputAllocationTest {};
GAPI_TEST_FIXTURE(ReInitOutTest, initNothing, <cv::Size>, 1, out_sz)
GAPI_TEST_FIXTURE(WarpPerspectiveTest, initMatrixRandU,
FIXTURE_API(CompareMats, double , double, int, int, cv::Scalar),
6, cmpF, angle, scale, flags, border_mode, border_value)
GAPI_TEST_FIXTURE(WarpAffineTest, initMatrixRandU,
FIXTURE_API(CompareMats, double , double, int, int, cv::Scalar),
6, cmpF, angle, scale, flags, border_mode, border_value)
GAPI_TEST_FIXTURE(KMeansNDTest, initMatrixRandU, FIXTURE_API(CompareMats, int, cv::KmeansFlags), 3, cmpF, K, flags)
GAPI_TEST_FIXTURE(KMeans2DTest, initNothing, FIXTURE_API(int, cv::KmeansFlags), 2, K, flags)
GAPI_TEST_FIXTURE(KMeans3DTest, initNothing, FIXTURE_API(int, cv::KmeansFlags), 2, K, flags)
GAPI_TEST_FIXTURE(TransposeTest, initMatrixRandU, FIXTURE_API(CompareMats), 1, cmpF)
GAPI_TEST_EXT_BASE_FIXTURE(ParseSSDBLTest, ParserSSDTest, initNothing,
FIXTURE_API(float, int), 2, confidence_threshold, filter_label)
GAPI_TEST_EXT_BASE_FIXTURE(ParseSSDTest, ParserSSDTest, initNothing,
FIXTURE_API(float, bool, bool), 3, confidence_threshold, alignment_to_square, filter_out_of_bounds)
GAPI_TEST_EXT_BASE_FIXTURE(ParseYoloTest, ParserYoloTest, initNothing,
FIXTURE_API(float, float, int, std::pair<bool,int>), 4, confidence_threshold, nms_threshold, num_classes, dims_config)
GAPI_TEST_FIXTURE(SizeTest, initMatrixRandU, <>, 0)
GAPI_TEST_FIXTURE(SizeRTest, initNothing, <>, 0)
GAPI_TEST_FIXTURE(SizeMFTest, initNothing, <>, 0)
} // opencv_test
#endif //OPENCV_GAPI_CORE_TESTS_HPP

View File

@ -0,0 +1,180 @@
// 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) 2021 Intel Corporation
#ifndef OPENCV_GAPI_CORE_TESTS_COMMON_HPP
#define OPENCV_GAPI_CORE_TESTS_COMMON_HPP
#include "gapi_tests_common.hpp"
#include "../../include/opencv2/gapi/core.hpp"
#include <opencv2/core.hpp>
namespace opencv_test
{
namespace
{
template <typename Elem, typename CmpF>
inline bool compareKMeansOutputs(const std::vector<Elem>& outGAPI,
const std::vector<Elem>& outOCV,
const CmpF& = AbsExact().to_compare_obj())
{
return AbsExactVector<Elem>().to_compare_f()(outGAPI, outOCV);
}
inline bool compareKMeansOutputs(const cv::Mat& outGAPI,
const cv::Mat& outOCV,
const CompareMats& cmpF)
{
return cmpF(outGAPI, outOCV);
}
}
// Overload with initializing the labels
template<typename Labels, typename In>
cv::GComputation kmeansTestGAPI(const In& in, const Labels& bestLabels, const int K,
const cv::KmeansFlags flags, cv::GCompileArgs&& args,
double& compact_gapi, Labels& labels_gapi, In& centers_gapi)
{
const cv::TermCriteria criteria(cv::TermCriteria::MAX_ITER + cv::TermCriteria::EPS, 30, 0);
const int attempts = 1;
cv::detail::g_type_of_t<In> gIn, centers;
cv::GOpaque<double> compactness;
cv::detail::g_type_of_t<Labels> inLabels, outLabels;
std::tie(compactness, outLabels, centers) =
cv::gapi::kmeans(gIn, K, inLabels, criteria, attempts, flags);
cv::GComputation c(cv::GIn(gIn, inLabels), cv::GOut(compactness, outLabels, centers));
c.apply(cv::gin(in, bestLabels), cv::gout(compact_gapi, labels_gapi, centers_gapi),
std::move(args));
return c;
}
// Overload for vector<Point> tests w/o initializing the labels
template<typename Pt>
cv::GComputation kmeansTestGAPI(const std::vector<Pt>& in, const int K,
const cv::KmeansFlags flags, cv::GCompileArgs&& args,
double& compact_gapi, std::vector<int>& labels_gapi,
std::vector<Pt>& centers_gapi)
{
const cv::TermCriteria criteria(cv::TermCriteria::MAX_ITER + cv::TermCriteria::EPS, 30, 0);
const int attempts = 1;
cv::GArray<Pt> gIn, centers;
cv::GOpaque<double> compactness;
cv::GArray<int> inLabels(std::vector<int>{}), outLabels;
std::tie(compactness, outLabels, centers) =
cv::gapi::kmeans(gIn, K, inLabels, criteria, attempts, flags);
cv::GComputation c(cv::GIn(gIn), cv::GOut(compactness, outLabels, centers));
c.apply(cv::gin(in), cv::gout(compact_gapi, labels_gapi, centers_gapi), std::move(args));
return c;
}
// Overload for Mat tests w/o initializing the labels
static cv::GComputation kmeansTestGAPI(const cv::Mat& in, const int K,
const cv::KmeansFlags flags, cv::GCompileArgs&& args,
double& compact_gapi, cv::Mat& labels_gapi,
cv::Mat& centers_gapi)
{
const cv::TermCriteria criteria(cv::TermCriteria::MAX_ITER + cv::TermCriteria::EPS, 30, 0);
const int attempts = 1;
cv::GMat gIn, centers, labels;
cv::GOpaque<double> compactness;
std::tie(compactness, labels, centers) = cv::gapi::kmeans(gIn, K, criteria, attempts, flags);
cv::GComputation c(cv::GIn(gIn), cv::GOut(compactness, labels, centers));
c.apply(cv::gin(in), cv::gout(compact_gapi, labels_gapi, centers_gapi), std::move(args));
return c;
}
template<typename Pt>
void kmeansTestValidate(const cv::Size& sz, const MatType2&, const int K,
const double compact_gapi, const std::vector<int>& labels_gapi,
const std::vector<Pt>& centers_gapi)
{
const int amount = sz.height;
// Validation
EXPECT_GE(compact_gapi, 0.);
EXPECT_EQ(labels_gapi.size(), static_cast<size_t>(amount));
EXPECT_EQ(centers_gapi.size(), static_cast<size_t>(K));
}
static void kmeansTestValidate(const cv::Size& sz, const MatType2& type, const int K,
const double compact_gapi, const cv::Mat& labels_gapi,
const cv::Mat& centers_gapi)
{
const int chan = (type >> CV_CN_SHIFT) + 1;
const int amount = sz.height != 1 ? sz.height : sz.width;
const int dim = sz.height != 1 ? sz.width * chan : chan;
// Validation
EXPECT_GE(compact_gapi, 0.);
EXPECT_FALSE(labels_gapi.empty());
EXPECT_FALSE(centers_gapi.empty());
EXPECT_EQ(labels_gapi.rows, amount);
EXPECT_EQ(labels_gapi.cols, 1);
EXPECT_EQ(centers_gapi.rows, K);
EXPECT_EQ(centers_gapi.cols, dim);
}
template<typename Labels, typename In>
void kmeansTestOpenCVCompare(const In& in, const Labels& bestLabels, const int K,
const cv::KmeansFlags flags, const double compact_gapi,
const Labels& labels_gapi, const In& centers_gapi,
const CompareMats& cmpF = AbsExact().to_compare_obj())
{
const cv::TermCriteria criteria(cv::TermCriteria::MAX_ITER + cv::TermCriteria::EPS, 30, 0);
const int attempts = 1;
Labels labels_ocv;
In centers_ocv;
{ // step to generalize cv::Mat & std::vector cases of bestLabels' types
cv::Mat bestLabelsMat(bestLabels);
bestLabelsMat.copyTo(labels_ocv);
}
// OpenCV code /////////////////////////////////////////////////////////////
double compact_ocv = cv::kmeans(in, K, labels_ocv, criteria, attempts, flags, centers_ocv);
// Comparison //////////////////////////////////////////////////////////////
EXPECT_TRUE(compact_gapi == compact_ocv);
EXPECT_TRUE(compareKMeansOutputs(labels_gapi, labels_ocv, cmpF));
EXPECT_TRUE(compareKMeansOutputs(centers_gapi, centers_ocv, cmpF));
}
// If an input type is cv::Mat, labels' type is also cv::Mat;
// in other cases, their type has to be std::vector<int>
template<typename In>
using KMeansLabelType = typename std::conditional<std::is_same<In, cv::Mat>::value,
cv::Mat,
std::vector<int>
>::type;
template<typename In, typename Labels = KMeansLabelType<In> >
void kmeansTestBody(const In& in, const cv::Size& sz, const MatType2& type, const int K,
const cv::KmeansFlags flags, cv::GCompileArgs&& args,
const CompareMats& cmpF = AbsExact().to_compare_obj())
{
double compact_gapi = -1.;
Labels labels_gapi;
In centers_gapi;
if (flags & cv::KMEANS_USE_INITIAL_LABELS)
{
Labels bestLabels;
{ // step to generalize cv::Mat & std::vector cases of bestLabels' types
const int amount = (sz.height != 1 || sz.width == -1) ? sz.height : sz.width;
cv::Mat bestLabelsMat(cv::Size{1, amount}, CV_32SC1);
cv::randu(bestLabelsMat, 0, K);
bestLabelsMat.copyTo(bestLabels);
}
kmeansTestGAPI(in, bestLabels, K, flags, std::move(args), compact_gapi, labels_gapi,
centers_gapi);
kmeansTestOpenCVCompare(in, bestLabels, K, flags, compact_gapi, labels_gapi,
centers_gapi, cmpF);
}
else
{
kmeansTestGAPI(in, K, flags, std::move(args), compact_gapi, labels_gapi, centers_gapi);
kmeansTestValidate(sz, type, K, compact_gapi, labels_gapi, centers_gapi);
}
}
} // namespace opencv_test
#endif // OPENCV_GAPI_CORE_TESTS_COMMON_HPP

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,9 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
//
// Copyright (C) 2018 Intel Corporation
#include "../test_precomp.hpp"
#include "gapi_imgproc_tests_inl.hpp"

View File

@ -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-2020 Intel Corporation
#ifndef OPENCV_GAPI_IMGPROC_TESTS_HPP
#define OPENCV_GAPI_IMGPROC_TESTS_HPP
#include <iostream>
#include "gapi_tests_common.hpp"
namespace opencv_test
{
// Create new value-parameterized test fixture:
// Filter2DTest - fixture name
// initMatrixRandN - function that is used to initialize input/output data
// FIXTURE_API(CompareMats,int,int) - test-specific parameters (types)
// 3 - number of test-specific parameters
// cmpF, kernSize, borderType - test-specific parameters (names)
//
// We get:
// 1. Default parameters: int type, cv::Size sz, int dtype, getCompileArgs() function
// - available in test body
// 2. Input/output matrices will be initialized by initMatrixRandN (in this fixture)
// 3. Specific parameters: cmpF, kernSize, borderType of corresponding types
// - created (and initialized) automatically
// - available in test body
// Note: all parameter _values_ (e.g. type CV_8UC3) are set via INSTANTIATE_TEST_CASE_P macro
GAPI_TEST_FIXTURE(Filter2DTest, initMatrixRandN, FIXTURE_API(CompareMats,cv::Size,int), 3,
cmpF, filterSize, borderType)
GAPI_TEST_FIXTURE(BoxFilterTest, initMatrixRandN, FIXTURE_API(CompareMats,int,int), 3,
cmpF, filterSize, borderType)
GAPI_TEST_FIXTURE(SepFilterTest, initMatrixRandN, FIXTURE_API(CompareMats,int), 2, cmpF, kernSize)
GAPI_TEST_FIXTURE(BlurTest, initMatrixRandN, FIXTURE_API(CompareMats,int,int), 3,
cmpF, filterSize, borderType)
GAPI_TEST_FIXTURE(GaussianBlurTest, initMatrixRandN, FIXTURE_API(CompareMats,int), 2, cmpF, kernSize)
GAPI_TEST_FIXTURE(MedianBlurTest, initMatrixRandN, FIXTURE_API(CompareMats,int), 2, cmpF, kernSize)
GAPI_TEST_FIXTURE(ErodeTest, initMatrixRandN, FIXTURE_API(CompareMats,int,int), 3,
cmpF, kernSize, kernType)
GAPI_TEST_FIXTURE(Erode3x3Test, initMatrixRandN, FIXTURE_API(CompareMats,int), 2,
cmpF, numIters)
GAPI_TEST_FIXTURE(DilateTest, initMatrixRandN, FIXTURE_API(CompareMats,int,int), 3,
cmpF, kernSize, kernType)
GAPI_TEST_FIXTURE(Dilate3x3Test, initMatrixRandN, FIXTURE_API(CompareMats,int), 2, cmpF, numIters)
GAPI_TEST_FIXTURE(MorphologyExTest, initMatrixRandN, FIXTURE_API(CompareMats,cv::MorphTypes),
2, cmpF, op)
GAPI_TEST_FIXTURE(SobelTest, initMatrixRandN, FIXTURE_API(CompareMats,int,int,int), 4,
cmpF, kernSize, dx, dy)
GAPI_TEST_FIXTURE(SobelXYTest, initMatrixRandN, FIXTURE_API(CompareMats,int,int,int,int), 5,
cmpF, kernSize, order, border_type, border_val)
GAPI_TEST_FIXTURE(LaplacianTest, initMatrixRandN,
FIXTURE_API(CompareMats,int,double,int), 4,
cmpF, kernSize, scale, borderType)
GAPI_TEST_FIXTURE(BilateralFilterTest, initMatrixRandN,
FIXTURE_API(CompareMats,int,double,double,int), 5,
cmpF, d, sigmaColor, sigmaSpace, borderType)
GAPI_TEST_FIXTURE(EqHistTest, initMatrixRandN, FIXTURE_API(CompareMats), 1, cmpF)
GAPI_TEST_FIXTURE(CannyTest, initMatrixRandN, FIXTURE_API(CompareMats,double,double,int,bool), 5,
cmpF, thrLow, thrUp, apSize, l2gr)
GAPI_TEST_FIXTURE_SPEC_PARAMS(GoodFeaturesTest,
FIXTURE_API(CompareVectors<cv::Point2f>,std::string,int,int,double,
double,int,bool),
8, cmpF, fileName, type, maxCorners, qualityLevel, minDistance,
blockSize, useHarrisDetector)
GAPI_TEST_FIXTURE_SPEC_PARAMS(FindContoursNoOffsetTest,
FIXTURE_API(cv::Size,MatType2,cv::RetrievalModes,
cv::ContourApproximationModes, CompareMats),
5, sz, type, mode, method, cmpF)
GAPI_TEST_FIXTURE_SPEC_PARAMS(FindContoursOffsetTest, <>, 0)
GAPI_TEST_FIXTURE_SPEC_PARAMS(FindContoursHNoOffsetTest,
FIXTURE_API(cv::Size,MatType2,cv::RetrievalModes,
cv::ContourApproximationModes, CompareMats),
5, sz, type, mode, method, cmpF)
GAPI_TEST_FIXTURE_SPEC_PARAMS(FindContoursHOffsetTest, <>, 0)
GAPI_TEST_FIXTURE(BoundingRectMatTest, initNothing, FIXTURE_API(CompareRects,bool),
2, cmpF, initByVector)
GAPI_TEST_FIXTURE(BoundingRectVector32STest, initNothing, FIXTURE_API(CompareRects), 1, cmpF)
GAPI_TEST_FIXTURE(BoundingRectVector32FTest, initNothing, FIXTURE_API(CompareRects), 1, cmpF)
GAPI_TEST_FIXTURE(FitLine2DMatVectorTest, initMatByPointsVectorRandU<cv::Point_>,
FIXTURE_API(CompareVecs<float, 4>,cv::DistanceTypes), 2, cmpF, distType)
GAPI_TEST_FIXTURE(FitLine2DVector32STest, initNothing,
FIXTURE_API(CompareVecs<float, 4>,cv::DistanceTypes), 2, cmpF, distType)
GAPI_TEST_FIXTURE(FitLine2DVector32FTest, initNothing,
FIXTURE_API(CompareVecs<float, 4>,cv::DistanceTypes), 2, cmpF, distType)
GAPI_TEST_FIXTURE(FitLine2DVector64FTest, initNothing,
FIXTURE_API(CompareVecs<float, 4>,cv::DistanceTypes), 2, cmpF, distType)
GAPI_TEST_FIXTURE(FitLine3DMatVectorTest, initMatByPointsVectorRandU<cv::Point3_>,
FIXTURE_API(CompareVecs<float, 6>,cv::DistanceTypes), 2, cmpF, distType)
GAPI_TEST_FIXTURE(FitLine3DVector32STest, initNothing,
FIXTURE_API(CompareVecs<float, 6>,cv::DistanceTypes), 2, cmpF, distType)
GAPI_TEST_FIXTURE(FitLine3DVector32FTest, initNothing,
FIXTURE_API(CompareVecs<float, 6>,cv::DistanceTypes), 2, cmpF, distType)
GAPI_TEST_FIXTURE(FitLine3DVector64FTest, initNothing,
FIXTURE_API(CompareVecs<float, 6>,cv::DistanceTypes), 2, cmpF, distType)
GAPI_TEST_FIXTURE(BGR2RGBTest, initMatrixRandN, FIXTURE_API(CompareMats), 1, cmpF)
GAPI_TEST_FIXTURE(RGB2GrayTest, initMatrixRandN, FIXTURE_API(CompareMats), 1, cmpF)
GAPI_TEST_FIXTURE(BGR2GrayTest, initMatrixRandN, FIXTURE_API(CompareMats), 1, cmpF)
GAPI_TEST_FIXTURE(RGB2YUVTest, initMatrixRandN, FIXTURE_API(CompareMats), 1, cmpF)
GAPI_TEST_FIXTURE(BGR2I420Test, initMatrixRandN, FIXTURE_API(CompareMats), 1, cmpF)
GAPI_TEST_FIXTURE(RGB2I420Test, initMatrixRandN, FIXTURE_API(CompareMats), 1, cmpF)
GAPI_TEST_FIXTURE(I4202BGRTest, initMatrixRandN, FIXTURE_API(CompareMats), 1, cmpF)
GAPI_TEST_FIXTURE(I4202RGBTest, initMatrixRandN, FIXTURE_API(CompareMats), 1, cmpF)
GAPI_TEST_FIXTURE(YUV2RGBTest, initMatrixRandN, FIXTURE_API(CompareMats), 1, cmpF)
GAPI_TEST_FIXTURE(YUV2GrayTest, initMatrixRandN, FIXTURE_API(CompareMats), 1, cmpF)
GAPI_TEST_FIXTURE(NV12toRGBTest, initMatrixRandN, FIXTURE_API(CompareMats), 1, cmpF)
GAPI_TEST_FIXTURE(NV12toBGRpTest, initMatrixRandN, FIXTURE_API(CompareMats), 1, cmpF)
GAPI_TEST_FIXTURE(NV12toRGBpTest, initMatrixRandN, FIXTURE_API(CompareMats), 1, cmpF)
GAPI_TEST_FIXTURE(NV12toBGRTest, initMatrixRandN, FIXTURE_API(CompareMats), 1, cmpF)
GAPI_TEST_FIXTURE(NV12toGrayTest, initMatrixRandN, FIXTURE_API(CompareMats), 1, cmpF)
GAPI_TEST_FIXTURE(RGB2LabTest, initMatrixRandN, FIXTURE_API(CompareMats), 1, cmpF)
GAPI_TEST_FIXTURE(BGR2LUVTest, initMatrixRandN, FIXTURE_API(CompareMats), 1, cmpF)
GAPI_TEST_FIXTURE(LUV2BGRTest, initMatrixRandN, FIXTURE_API(CompareMats), 1, cmpF)
GAPI_TEST_FIXTURE(BGR2YUVTest, initMatrixRandN, FIXTURE_API(CompareMats), 1, cmpF)
GAPI_TEST_FIXTURE(YUV2BGRTest, initMatrixRandN, FIXTURE_API(CompareMats), 1, cmpF)
GAPI_TEST_FIXTURE(RGB2HSVTest, initMatrixRandN, FIXTURE_API(CompareMats), 1, cmpF)
GAPI_TEST_FIXTURE(BayerGR2RGBTest, initMatrixRandN, FIXTURE_API(CompareMats), 1, cmpF)
GAPI_TEST_FIXTURE(RGB2YUV422Test, initMatrixRandN, FIXTURE_API(CompareMats), 1, cmpF)
} // opencv_test
#endif //OPENCV_GAPI_IMGPROC_TESTS_HPP

View File

@ -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) 2020 Intel Corporation
#ifndef OPENCV_GAPI_IMGPROC_TESTS_COMMON_HPP
#define OPENCV_GAPI_IMGPROC_TESTS_COMMON_HPP
#include "gapi_tests_common.hpp"
#include "../../include/opencv2/gapi/imgproc.hpp"
#include <opencv2/imgproc.hpp>
namespace opencv_test
{
// Draw random ellipses on given cv::Mat of given size and type
static void initMatForFindingContours(cv::Mat& mat, const cv::Size& sz, const int type)
{
cv::RNG& rng = theRNG();
mat = cv::Mat(sz, type, cv::Scalar::all(0));
const size_t numEllipses = rng.uniform(1, 10);
for( size_t i = 0; i < numEllipses; i++ )
{
cv::Point center;
cv::Size axes;
center.x = rng.uniform(0, sz.width);
center.y = rng.uniform(0, sz.height);
axes.width = rng.uniform(2, sz.width);
axes.height = rng.uniform(2, sz.height);
const int color = rng.uniform(1, 256);
const double angle = rng.uniform(0., 180.);
cv::ellipse(mat, center, axes, angle, 0., 360., color, 1, FILLED);
}
}
enum OptionalFindContoursOutput {NONE, HIERARCHY};
template<OptionalFindContoursOutput optional = NONE>
cv::GComputation findContoursTestGAPI(const cv::Mat& in, const cv::RetrievalModes mode,
const cv::ContourApproximationModes method,
cv::GCompileArgs&& args,
std::vector<std::vector<cv::Point>>& out_cnts_gapi,
std::vector<cv::Vec4i>& /*out_hier_gapi*/,
const cv::Point& offset = cv::Point())
{
cv::GMat g_in;
cv::GOpaque<cv::Point> gOffset;
cv::GArray<cv::GArray<cv::Point>> outCts;
outCts = cv::gapi::findContours(g_in, mode, method, gOffset);
cv::GComputation c(GIn(g_in, gOffset), GOut(outCts));
c.apply(gin(in, offset), gout(out_cnts_gapi), std::move(args));
return c;
}
template<> cv::GComputation findContoursTestGAPI<HIERARCHY> (
const cv::Mat& in, const cv::RetrievalModes mode, const cv::ContourApproximationModes method,
cv::GCompileArgs&& args, std::vector<std::vector<cv::Point>>& out_cnts_gapi,
std::vector<cv::Vec4i>& out_hier_gapi, const cv::Point& offset)
{
cv::GMat g_in;
cv::GOpaque<cv::Point> gOffset;
cv::GArray<cv::GArray<cv::Point>> outCts;
cv::GArray<cv::Vec4i> outHier;
std::tie(outCts, outHier) = cv::gapi::findContoursH(g_in, mode, method, gOffset);
cv::GComputation c(GIn(g_in, gOffset), GOut(outCts, outHier));
c.apply(gin(in, offset), gout(out_cnts_gapi, out_hier_gapi), std::move(args));
return c;
}
template<OptionalFindContoursOutput optional = NONE>
void findContoursTestOpenCVCompare(const cv::Mat& in, const cv::RetrievalModes mode,
const cv::ContourApproximationModes method,
const std::vector<std::vector<cv::Point>>& out_cnts_gapi,
const std::vector<cv::Vec4i>& out_hier_gapi,
const CompareMats& cmpF, const cv::Point& offset = cv::Point())
{
// OpenCV code /////////////////////////////////////////////////////////////
std::vector<std::vector<cv::Point>> out_cnts_ocv;
std::vector<cv::Vec4i> out_hier_ocv;
cv::findContours(in, out_cnts_ocv, out_hier_ocv, mode, method, offset);
// Comparison //////////////////////////////////////////////////////////////
EXPECT_TRUE(out_cnts_gapi.size() == out_cnts_ocv.size());
cv::Mat out_mat_ocv = cv::Mat(cv::Size{ in.cols, in.rows }, in.type(), cv::Scalar::all(0));
cv::Mat out_mat_gapi = cv::Mat(cv::Size{ in.cols, in.rows }, in.type(), cv::Scalar::all(0));
cv::fillPoly(out_mat_ocv, out_cnts_ocv, cv::Scalar::all(1));
cv::fillPoly(out_mat_gapi, out_cnts_gapi, cv::Scalar::all(1));
EXPECT_TRUE(cmpF(out_mat_ocv, out_mat_gapi));
if (optional == HIERARCHY)
{
EXPECT_TRUE(out_hier_ocv.size() == out_hier_gapi.size());
EXPECT_TRUE(AbsExactVector<cv::Vec4i>().to_compare_f()(out_hier_ocv, out_hier_gapi));
}
}
template<OptionalFindContoursOutput optional = NONE>
void findContoursTestBody(const cv::Size& sz, const MatType2& type, const cv::RetrievalModes mode,
const cv::ContourApproximationModes method, const CompareMats& cmpF,
cv::GCompileArgs&& args, const cv::Point& offset = cv::Point())
{
cv::Mat in;
initMatForFindingContours(in, sz, type);
std::vector<std::vector<cv::Point>> out_cnts_gapi;
std::vector<cv::Vec4i> out_hier_gapi;
findContoursTestGAPI<optional>(in, mode, method, std::move(args), out_cnts_gapi, out_hier_gapi,
offset);
findContoursTestOpenCVCompare<optional>(in, mode, method, out_cnts_gapi, out_hier_gapi, cmpF,
offset);
}
//-------------------------------------------------------------------------------------------------
template<typename In>
static cv::GComputation boundingRectTestGAPI(const In& in, cv::GCompileArgs&& args,
cv::Rect& out_rect_gapi)
{
cv::detail::g_type_of_t<In> g_in;
auto out = cv::gapi::boundingRect(g_in);
cv::GComputation c(cv::GIn(g_in), cv::GOut(out));
c.apply(cv::gin(in), cv::gout(out_rect_gapi), std::move(args));
return c;
}
template<typename In>
static void boundingRectTestOpenCVCompare(const In& in, const cv::Rect& out_rect_gapi,
const CompareRects& cmpF)
{
// OpenCV code /////////////////////////////////////////////////////////////
cv::Rect out_rect_ocv = cv::boundingRect(in);
// Comparison //////////////////////////////////////////////////////////////
EXPECT_TRUE(cmpF(out_rect_gapi, out_rect_ocv));
}
template<typename In>
static void boundingRectTestBody(const In& in, const CompareRects& cmpF, cv::GCompileArgs&& args)
{
cv::Rect out_rect_gapi;
boundingRectTestGAPI(in, std::move(args), out_rect_gapi);
boundingRectTestOpenCVCompare(in, out_rect_gapi, cmpF);
}
//-------------------------------------------------------------------------------------------------
template<typename In>
static cv::GComputation fitLineTestGAPI(const In& in, const cv::DistanceTypes distType,
cv::GCompileArgs&& args, cv::Vec4f& out_vec_gapi)
{
const double paramDefault = 0., repsDefault = 0., aepsDefault = 0.;
cv::detail::g_type_of_t<In> g_in;
auto out = cv::gapi::fitLine2D(g_in, distType, paramDefault, repsDefault, aepsDefault);
cv::GComputation c(cv::GIn(g_in), cv::GOut(out));
c.apply(cv::gin(in), cv::gout(out_vec_gapi), std::move(args));
return c;
}
template<typename In>
static cv::GComputation fitLineTestGAPI(const In& in, const cv::DistanceTypes distType,
cv::GCompileArgs&& args, cv::Vec6f& out_vec_gapi)
{
const double paramDefault = 0., repsDefault = 0., aepsDefault = 0.;
cv::detail::g_type_of_t<In> g_in;
auto out = cv::gapi::fitLine3D(g_in, distType, paramDefault, repsDefault, aepsDefault);
cv::GComputation c(cv::GIn(g_in), cv::GOut(out));
c.apply(cv::gin(in), cv::gout(out_vec_gapi), std::move(args));
return c;
}
template<typename In, int dim>
static void fitLineTestOpenCVCompare(const In& in, const cv::DistanceTypes distType,
const cv::Vec<float, dim>& out_vec_gapi,
const CompareVecs<float, dim>& cmpF)
{
const double paramDefault = 0., repsDefault = 0., aepsDefault = 0.;
// OpenCV code /////////////////////////////////////////////////////////////
cv::Vec<float, dim> out_vec_ocv;
cv::fitLine(in, out_vec_ocv, distType, paramDefault, repsDefault, aepsDefault);
// Comparison //////////////////////////////////////////////////////////////
EXPECT_TRUE(cmpF(out_vec_gapi, out_vec_ocv));
}
template<typename In, int dim>
static void fitLineTestBody(const In& in, const cv::DistanceTypes distType,
const CompareVecs<float, dim>& cmpF, cv::GCompileArgs&& args)
{
cv::Vec<float, dim> out_vec_gapi;
fitLineTestGAPI(in, distType, std::move(args), out_vec_gapi);
fitLineTestOpenCVCompare(in, distType, out_vec_gapi, cmpF);
}
} // namespace opencv_test
#endif // OPENCV_GAPI_IMGPROC_TESTS_COMMON_HPP

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,9 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
//
// Copyright (C) 2018 Intel Corporation
#include "../test_precomp.hpp"
#include "gapi_operators_tests_inl.hpp"

View File

@ -0,0 +1,245 @@
// 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
{
enum operation
{
ADD, SUB, MUL, DIV,
ADDR, SUBR, MULR, DIVR,
GT, LT, GE, LE, EQ, NE,
GTR, LTR, GER, LER, EQR, NER,
AND, OR, XOR,
ANDR, ORR, XORR
};
// Note: namespace must match the namespace of the type of the printed object
inline std::ostream& operator<<(std::ostream& os, operation op)
{
#define CASE(v) case operation::v: os << #v; break
switch (op)
{
CASE(ADD); CASE(SUB); CASE(MUL); CASE(DIV);
CASE(ADDR); CASE(SUBR); CASE(MULR); CASE(DIVR);
CASE(GT); CASE(LT); CASE(GE); CASE(LE); CASE(EQ); CASE(NE);
CASE(GTR); CASE(LTR); CASE(GER); CASE(LER); CASE(EQR); CASE(NER);
CASE(AND); CASE(OR); CASE(XOR);
CASE(ANDR); CASE(ORR); CASE(XORR);
default: GAPI_Assert(false && "unknown operation value");
}
#undef CASE
return os;
}
namespace
{
// declare test cases for matrix and scalar operators
auto opADD_gapi = [](cv::GMat in,cv::GScalar c){return in + c;};
auto opADD_ocv = [](const cv::Mat& in, cv::Scalar c, cv::Mat& out){cv::add(in, c, out);};
auto opADDR_gapi = [](cv::GMat in,cv::GScalar c){return c + in;};
auto opADDR_ocv = [](const cv::Mat& in, cv::Scalar c, cv::Mat& out){cv::add(c, in, out);};
auto opSUB_gapi = [](cv::GMat in,cv::GScalar c){return in - c;};
auto opSUB_ocv = [](const cv::Mat& in, cv::Scalar c, cv::Mat& out){cv::subtract(in, c, out);};
auto opSUBR_gapi = [](cv::GMat in,cv::GScalar c){return c - in;};
auto opSUBR_ocv = [](const cv::Mat& in, cv::Scalar c, cv::Mat& out){cv::subtract(c, in, out);};
auto opMUL_gapi = [](cv::GMat in,cv::GScalar c){return in * c;};
auto opMUL_ocv = [](const cv::Mat& in, cv::Scalar c, cv::Mat& out){cv::multiply(in, c, out);};
auto opMULR_gapi = [](cv::GMat in,cv::GScalar c){return c * in;};
auto opMULR_ocv = [](const cv::Mat& in, cv::Scalar c, cv::Mat& out){cv::multiply(c, in, out);};
auto opDIV_gapi = [](cv::GMat in,cv::GScalar c){return in / c;};
auto opDIV_ocv = [](const cv::Mat& in, cv::Scalar c, cv::Mat& out){cv::divide(in, c, out);};
auto opDIVR_gapi = [](cv::GMat in,cv::GScalar c){return c / in;};
auto opDIVR_ocv = [](const cv::Mat& in, cv::Scalar c, cv::Mat& out){cv::divide(c, in, out);};
auto opGT_gapi = [](cv::GMat in,cv::GScalar c){return in > c;};
auto opGT_ocv = [](const cv::Mat& in, cv::Scalar c, cv::Mat& out){cv::compare(in, c, out,cv::CMP_GT);};
auto opGTR_gapi = [](cv::GMat in,cv::GScalar c){return c > in;};
auto opGTR_ocv = [](const cv::Mat& in, cv::Scalar c, cv::Mat& out){cv::compare(c, in, out,cv::CMP_GT);};
auto opLT_gapi = [](cv::GMat in,cv::GScalar c){return in < c;};
auto opLT_ocv = [](const cv::Mat& in, cv::Scalar c, cv::Mat& out){cv::compare(in, c, out,cv::CMP_LT);};
auto opLTR_gapi = [](cv::GMat in,cv::GScalar c){return c < in;};
auto opLTR_ocv = [](const cv::Mat& in, cv::Scalar c, cv::Mat& out){cv::compare(c, in, out,cv::CMP_LT);};
auto opGE_gapi = [](cv::GMat in,cv::GScalar c){return in >= c;};
auto opGE_ocv = [](const cv::Mat& in, cv::Scalar c, cv::Mat& out){cv::compare(in, c, out,cv::CMP_GE);};
auto opGER_gapi = [](cv::GMat in,cv::GScalar c){return c >= in;};
auto opGER_ocv = [](const cv::Mat& in, cv::Scalar c, cv::Mat& out){cv::compare(c, in, out,cv::CMP_GE);};
auto opLE_gapi = [](cv::GMat in,cv::GScalar c){return in <= c;};
auto opLE_ocv = [](const cv::Mat& in, cv::Scalar c, cv::Mat& out){cv::compare(in, c, out,cv::CMP_LE);};
auto opLER_gapi = [](cv::GMat in,cv::GScalar c){return c <= in;};
auto opLER_ocv = [](const cv::Mat& in, cv::Scalar c, cv::Mat& out){cv::compare(c, in, out,cv::CMP_LE);};
auto opEQ_gapi = [](cv::GMat in,cv::GScalar c){return in == c;};
auto opEQ_ocv = [](const cv::Mat& in, cv::Scalar c, cv::Mat& out){cv::compare(in, c, out,cv::CMP_EQ);};
auto opEQR_gapi = [](cv::GMat in,cv::GScalar c){return c == in;};
auto opEQR_ocv = [](const cv::Mat& in, cv::Scalar c, cv::Mat& out){cv::compare(c, in, out,cv::CMP_EQ);};
auto opNE_gapi = [](cv::GMat in,cv::GScalar c){return in != c;};
auto opNE_ocv = [](const cv::Mat& in, cv::Scalar c, cv::Mat& out){cv::compare(in, c, out,cv::CMP_NE);};
auto opNER_gapi = [](cv::GMat in,cv::GScalar c){return c != in;};
auto opNER_ocv = [](const cv::Mat& in, cv::Scalar c, cv::Mat& out){cv::compare(c, in, out,cv::CMP_NE);};
auto opAND_gapi = [](cv::GMat in,cv::GScalar c){return in & c;};
auto opAND_ocv = [](const cv::Mat& in, const cv::Scalar& c, cv::Mat& out){cv::bitwise_and(in, c, out);};
auto opOR_gapi = [](cv::GMat in,cv::GScalar c){return in | c;};
auto opOR_ocv = [](const cv::Mat& in, const cv::Scalar& c, cv::Mat& out){cv::bitwise_or(in, c, out);};
auto opXOR_gapi = [](cv::GMat in,cv::GScalar c){return in ^ c;};
auto opXOR_ocv = [](const cv::Mat& in, const cv::Scalar& c, cv::Mat& out){cv::bitwise_xor(in, c, out);};
auto opANDR_gapi = [](cv::GMat in,cv::GScalar c){return c & in;};
auto opANDR_ocv = [](const cv::Mat& in, const cv::Scalar& c, cv::Mat& out){cv::bitwise_and(c, in, out);};
auto opORR_gapi = [](cv::GMat in,cv::GScalar c){return c | in;};
auto opORR_ocv = [](const cv::Mat& in, const cv::Scalar& c, cv::Mat& out){cv::bitwise_or(c, in, out);};
auto opXORR_gapi = [](cv::GMat in,cv::GScalar c){return c ^ in;};
auto opXORR_ocv = [](const cv::Mat& in, const cv::Scalar& c, cv::Mat& out){cv::bitwise_xor(c, in, out);};
// declare test cases for matrix and matrix operators
auto opADDM_gapi = [](cv::GMat in1,cv::GMat in2){return in1 + in2;};
auto opADDM_ocv = [](const cv::Mat& in1, const cv::Mat& in2, cv::Mat& out){cv::add(in1, in2, out);};
auto opSUBM_gapi = [](cv::GMat in1,cv::GMat in2){return in1 - in2;};
auto opSUBM_ocv = [](const cv::Mat& in1, const cv::Mat& in2, cv::Mat& out){cv::subtract(in1, in2, out);};
auto opDIVM_gapi = [](cv::GMat in1,cv::GMat in2){return in1 / in2;};
auto opDIVM_ocv = [](const cv::Mat& in1, const cv::Mat& in2, cv::Mat& out){cv::divide(in1, in2, out);};
auto opGTM_gapi = [](cv::GMat in1,cv::GMat in2){return in1 > in2;};
auto opGTM_ocv = [](const cv::Mat& in1, const cv::Mat& in2, cv::Mat& out){cv::compare(in1, in2, out, cv::CMP_GT);};
auto opGEM_gapi = [](cv::GMat in1,cv::GMat in2){return in1 >= in2;};
auto opGEM_ocv = [](const cv::Mat& in1, const cv::Mat& in2, cv::Mat& out){cv::compare(in1, in2, out, cv::CMP_GE);};
auto opLTM_gapi = [](cv::GMat in1,cv::GMat in2){return in1 < in2;};
auto opLTM_ocv = [](const cv::Mat& in1, const cv::Mat& in2, cv::Mat& out){cv::compare(in1, in2, out, cv::CMP_LT);};
auto opLEM_gapi = [](cv::GMat in1,cv::GMat in2){return in1 <= in2;};
auto opLEM_ocv = [](const cv::Mat& in1, const cv::Mat& in2, cv::Mat& out){cv::compare(in1, in2, out, cv::CMP_LE);};
auto opEQM_gapi = [](cv::GMat in1,cv::GMat in2){return in1 == in2;};
auto opEQM_ocv = [](const cv::Mat& in1, const cv::Mat& in2, cv::Mat& out){cv::compare(in1, in2, out, cv::CMP_EQ);};
auto opNEM_gapi = [](cv::GMat in1,cv::GMat in2){return in1 != in2;};
auto opNEM_ocv = [](const cv::Mat& in1, const cv::Mat& in2, cv::Mat& out){cv::compare(in1, in2, out, cv::CMP_NE);};
auto opANDM_gapi = [](cv::GMat in1,cv::GMat in2){return in1 & in2;};
auto opANDM_ocv = [](const cv::Mat& in1, const cv::Mat& in2, cv::Mat& out){cv::bitwise_and(in1, in2, out);};
auto opORM_gapi = [](cv::GMat in1,cv::GMat in2){return in1 | in2;};
auto opORM_ocv = [](const cv::Mat& in1, const cv::Mat& in2, cv::Mat& out){cv::bitwise_or(in1, in2, out);};
auto opXORM_gapi = [](cv::GMat in1,cv::GMat in2){return in1 ^ in2;};
auto opXORM_ocv = [](const cv::Mat& in1, const cv::Mat& in2, cv::Mat& out){cv::bitwise_xor(in1, in2, out);};
} // anonymous namespace
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&)>;
g_api_function_t g_api_function;
ocv_function_t ocv_function;
g_api_ocv_pair_mat_scalar() = default;
#define CASE(v) case operation::v: \
g_api_function = op##v##_gapi; \
ocv_function = op##v##_ocv; \
break
g_api_ocv_pair_mat_scalar(operation op)
{
switch (op)
{
CASE(ADD); CASE(SUB); CASE(MUL); CASE(DIV);
CASE(ADDR); CASE(SUBR); CASE(MULR); CASE(DIVR);
CASE(GT); CASE(LT); CASE(GE); CASE(LE); CASE(EQ); CASE(NE);
CASE(GTR); CASE(LTR); CASE(GER); CASE(LER); CASE(EQR); CASE(NER);
CASE(AND); CASE(OR); CASE(XOR);
CASE(ANDR); CASE(ORR); CASE(XORR);
default: GAPI_Assert(false && "unknown operation value");
}
}
#undef CASE
};
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&)>;
g_api_function_t g_api_function;
ocv_function_t ocv_function;
g_api_ocv_pair_mat_mat() = default;
#define CASE(v) case operation::v: \
g_api_function = op##v##M_gapi; \
ocv_function = op##v##M_ocv; \
break
g_api_ocv_pair_mat_mat(operation op)
{
switch (op)
{
CASE(ADD); CASE(SUB); CASE(DIV);
CASE(GT); CASE(LT); CASE(GE); CASE(LE); CASE(EQ); CASE(NE);
CASE(AND); CASE(OR); CASE(XOR);
default: GAPI_Assert(false && "unknown operation value");
}
}
#undef CASE
};
// Create new value-parameterized test fixture:
// MathOperatorMatScalarTest - fixture name
// initMatsRandU - function that is used to initialize input/output data
// FIXTURE_API(CompareMats, g_api_ocv_pair_mat_scalar) - test-specific parameters (types)
// 2 - number of test-specific parameters
// cmpF, op - test-spcific parameters (names)
//
// We get:
// 1. Default parameters: int type, cv::Size sz, int dtype, getCompileArgs() function
// - available in test body
// 2. Input/output matrices will be initialized by initMatsRandU (in this fixture)
// 3. Specific parameters: cmpF, op of corresponding types
// - created (and initialized) automatically
// - available in test body
// Note: all parameter _values_ (e.g. type CV_8UC3) are set via INSTANTIATE_TEST_CASE_P macro
GAPI_TEST_FIXTURE(MathOperatorMatScalarTest, initMatsRandU,
FIXTURE_API(CompareMats, operation), 2, cmpF, op)
GAPI_TEST_FIXTURE(MathOperatorMatMatTest, initMatsRandU,
FIXTURE_API(CompareMats, operation), 2, cmpF, op)
GAPI_TEST_FIXTURE(NotOperatorTest, initMatrixRandU, <>, 0)
} // opencv_test
#endif // OPENCV_GAPI_OPERATOR_TESTS_COMMON_HPP

View File

@ -0,0 +1,167 @@
// 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 funcs(op);
auto fun_gapi = funcs.g_api_function;
auto fun_ocv = funcs.ocv_function;
if (op == DIVR)
in_mat1.setTo(1, in_mat1 == 0); // avoiding zeros in divide input data
if (op == DIV)
sc += Scalar(sc[0] == 0, sc[1] == 0, sc[2] == 0, sc[3] == 0); // avoiding zeros in divide input data
// G-API code & corresponding OpenCV code ////////////////////////////////
cv::GMat in1;
cv::GScalar in2;
auto out = fun_gapi(in1, in2);
cv::GComputation c(GIn(in1, in2), GOut(out));
c.apply(gin(in_mat1, sc), gout(out_mat_gapi), getCompileArgs());
fun_ocv(in_mat1, sc, out_mat_ocv);
// Comparison //////////////////////////////////////////////////////////////
{
ASSERT_EQ(out_mat_gapi.size(), sz);
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
}
}
TEST_P(MathOperatorMatMatTest, OperatorAccuracyTest )
{
g_api_ocv_pair_mat_mat funcs(op);
auto fun_gapi = funcs.g_api_function;
auto fun_ocv = funcs.ocv_function;
if (op == DIV)
in_mat2.setTo(1, in_mat2 == 0); // avoiding zeros in divide input data
// G-API code & corresponding OpenCV code ////////////////////////////////
cv::GMat in1;
cv::GMat in2;
auto out = fun_gapi(in1, in2);
cv::GComputation c(GIn(in1, in2), GOut(out));
c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), getCompileArgs());
fun_ocv(in_mat1, in_mat2, out_mat_ocv);
// Comparison //////////////////////////////////////////////////////////////
{
ASSERT_EQ(out_mat_gapi.size(), sz);
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
}
}
TEST_P(NotOperatorTest, OperatorAccuracyTest)
{
// G-API code //////////////////////////////////////////////////////////////
cv::GMat in;
auto out = ~in;
cv::GComputation c(in, out);
c.apply(in_mat1, out_mat_gapi, getCompileArgs());
// OpenCV code /////////////////////////////////////////////////////////////
{
out_mat_ocv =~in_mat1;
}
// Comparison //////////////////////////////////////////////////////////////
{
ASSERT_EQ(out_mat_gapi.size(), sz);
EXPECT_EQ(0, cvtest::norm(out_mat_ocv, out_mat_gapi, NORM_INF));
}
}
namespace for_test
{
class Foo {};
inline int operator&(Foo, int) { return 1; }
inline int operator|(Foo, int) { return 1; }
inline int operator^(Foo, int) { return 1; }
inline int operator~(Foo) { return 1; }
inline int operator+(Foo, int) { return 1; }
inline int operator-(Foo, int) { return 1; }
inline int operator*(Foo, int) { return 1; }
inline int operator/(Foo, int) { return 1; }
inline int operator> (Foo, int) { return 1; }
inline int operator>=(Foo, int) { return 1; }
inline int operator< (Foo, int) { return 1; }
inline int operator<=(Foo, int) { return 1; }
inline int operator==(Foo, int) { return 1; }
inline int operator!=(Foo, int) { return 1; }
TEST(CVNamespaceOperatorsTest, OperatorCompilationTest)
{
cv::GScalar sc;
cv::GMat mat_in1, mat_in2;
cv::GMat op_not = ~ mat_in1;
cv::GMat op_mat_mat1 = mat_in1 & mat_in2;
cv::GMat op_mat_mat2 = mat_in1 | mat_in2;
cv::GMat op_mat_mat3 = mat_in1 ^ mat_in2;
cv::GMat op_mat_mat4 = mat_in1 + mat_in2;
cv::GMat op_mat_mat5 = mat_in1 - mat_in2;
cv::GMat op_mat_mat6 = mat_in1 / mat_in2;
cv::GMat op_mat_mat7 = mat_in1 > mat_in2;
cv::GMat op_mat_mat8 = mat_in1 >= mat_in2;
cv::GMat op_mat_mat9 = mat_in1 < mat_in2;
cv::GMat op_mat_mat10 = mat_in1 <= mat_in2;
cv::GMat op_mat_mat11 = mat_in1 == mat_in2;
cv::GMat op_mat_mat12 = mat_in1 != mat_in2;
cv::GMat op_mat_sc1 = mat_in1 & sc;
cv::GMat op_mat_sc2 = mat_in1 | sc;
cv::GMat op_mat_sc3 = mat_in1 ^ sc;
cv::GMat op_mat_sc4 = mat_in1 + sc;
cv::GMat op_mat_sc5 = mat_in1 - sc;
cv::GMat op_mat_sc6 = mat_in1 * sc;
cv::GMat op_mat_sc7 = mat_in1 / sc;
cv::GMat op_mat_sc8 = mat_in1 > sc;
cv::GMat op_mat_sc9 = mat_in1 >= sc;
cv::GMat op_mat_sc10 = mat_in1 < sc;
cv::GMat op_mat_sc11 = mat_in1 <= sc;
cv::GMat op_mat_sc12 = mat_in1 == sc;
cv::GMat op_mat_sc13 = mat_in1 != sc;
cv::GMat op_sc_mat1 = sc & mat_in2;
cv::GMat op_sc_mat2 = sc | mat_in2;
cv::GMat op_sc_mat3 = sc ^ mat_in2;
cv::GMat op_sc_mat4 = sc + mat_in2;
cv::GMat op_sc_mat5 = sc - mat_in2;
cv::GMat op_sc_mat6 = sc * mat_in2;
cv::GMat op_sc_mat7 = sc / mat_in2;
cv::GMat op_sc_mat8 = sc > mat_in2;
cv::GMat op_sc_mat9 = sc >= mat_in2;
cv::GMat op_sc_mat10 = sc < mat_in2;
cv::GMat op_sc_mat11 = sc <= mat_in2;
cv::GMat op_sc_mat12 = sc == mat_in2;
cv::GMat op_sc_mat13 = sc != mat_in2;
cv::GMat mul_mat_float1 = mat_in1 * 1.0f;
cv::GMat mul_mat_float2 = 1.0f * mat_in2;
// No compilation errors expected
}
} // for_test
} // opencv_test
#endif // OPENCV_GAPI_OPERATOR_TESTS_INL_COMMON_HPP

View File

@ -0,0 +1,411 @@
// 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) 2020 Intel Corporation
#ifndef OPENCV_GAPI_PARSERS_TESTS_COMMON_HPP
#define OPENCV_GAPI_PARSERS_TESTS_COMMON_HPP
#include "gapi_tests_common.hpp"
#include "../../include/opencv2/gapi/infer/parsers.hpp"
namespace opencv_test
{
class ParserSSDTest
{
public:
cv::Mat generateSSDoutput(const cv::Size& in_sz)
{
constexpr int maxN = 200;
constexpr int objSize = 7;
std::vector<int> dims{ 1, 1, maxN, objSize };
cv::Mat mat(dims, CV_32FC1);
auto data = mat.ptr<float>();
for (int i = 0; i < maxN; ++i)
{
float* it = data + i * objSize;
auto ssdIt = generateItem(i, in_sz);
it[0] = ssdIt.image_id;
it[1] = ssdIt.label;
it[2] = ssdIt.confidence;
it[3] = ssdIt.rc_left;
it[4] = ssdIt.rc_top;
it[5] = ssdIt.rc_right;
it[6] = ssdIt.rc_bottom;
}
return mat;
}
void parseSSDref(const cv::Mat& in_ssd_result,
const cv::Size& in_size,
const float confidence_threshold,
const bool alignment_to_square,
const bool filter_out_of_bounds,
std::vector<cv::Rect>& out_boxes)
{
out_boxes.clear();
const auto &in_ssd_dims = in_ssd_result.size;
CV_Assert(in_ssd_dims.dims() == 4u);
const int MAX_PROPOSALS = in_ssd_dims[2];
const int OBJECT_SIZE = in_ssd_dims[3];
CV_Assert(OBJECT_SIZE == 7); // fixed SSD object size
const float *data = in_ssd_result.ptr<float>();
cv::Rect surface({0,0}, in_size), rc;
float image_id, confidence;
int label;
for (int i = 0; i < MAX_PROPOSALS; ++i)
{
std::tie(rc, image_id, confidence, label)
= extract(data + i*OBJECT_SIZE, in_size);
if (image_id < 0.f)
{
break; // marks end-of-detections
}
if (confidence < confidence_threshold)
{
continue; // skip objects with low confidence
}
if (alignment_to_square)
{
adjustBoundingBox(rc);
}
const auto clipped_rc = rc & surface;
if (filter_out_of_bounds)
{
if (clipped_rc.area() != rc.area())
{
continue;
}
}
out_boxes.emplace_back(clipped_rc);
}
}
void parseSSDBLref(const cv::Mat& in_ssd_result,
const cv::Size& in_size,
const float confidence_threshold,
const int filter_label,
std::vector<cv::Rect>& out_boxes,
std::vector<int>& out_labels)
{
out_boxes.clear();
out_labels.clear();
const auto &in_ssd_dims = in_ssd_result.size;
CV_Assert(in_ssd_dims.dims() == 4u);
const int MAX_PROPOSALS = in_ssd_dims[2];
const int OBJECT_SIZE = in_ssd_dims[3];
CV_Assert(OBJECT_SIZE == 7); // fixed SSD object size
cv::Rect surface({0,0}, in_size), rc;
float image_id, confidence;
int label;
const float *data = in_ssd_result.ptr<float>();
for (int i = 0; i < MAX_PROPOSALS; i++)
{
std::tie(rc, image_id, confidence, label)
= extract(data + i*OBJECT_SIZE, in_size);
if (image_id < 0.f)
{
break; // marks end-of-detections
}
if (confidence < confidence_threshold ||
(filter_label != -1 && label != filter_label))
{
continue; // filter out object classes if filter is specified
}
out_boxes.emplace_back(rc & surface);
out_labels.emplace_back(label);
}
}
private:
void adjustBoundingBox(cv::Rect& boundingBox)
{
auto w = boundingBox.width;
auto h = boundingBox.height;
boundingBox.x -= static_cast<int>(0.067 * w);
boundingBox.y -= static_cast<int>(0.028 * h);
boundingBox.width += static_cast<int>(0.15 * w);
boundingBox.height += static_cast<int>(0.13 * h);
if (boundingBox.width < boundingBox.height)
{
auto dx = (boundingBox.height - boundingBox.width);
boundingBox.x -= dx / 2;
boundingBox.width += dx;
}
else
{
auto dy = (boundingBox.width - boundingBox.height);
boundingBox.y -= dy / 2;
boundingBox.height += dy;
}
}
std::tuple<cv::Rect, float, float, int> extract(const float* it,
const cv::Size& in_size)
{
float image_id = it[0];
int label = static_cast<int>(it[1]);
float confidence = it[2];
float rc_left = it[3];
float rc_top = it[4];
float rc_right = it[5];
float rc_bottom = it[6];
cv::Rect rc; // map relative coordinates to the original image scale
rc.x = static_cast<int>(rc_left * in_size.width);
rc.y = static_cast<int>(rc_top * in_size.height);
rc.width = static_cast<int>(rc_right * in_size.width) - rc.x;
rc.height = static_cast<int>(rc_bottom * in_size.height) - rc.y;
return std::make_tuple(rc, image_id, confidence, label);
}
int randInRange(const int start, const int end)
{
GAPI_Assert(start <= end);
return theRNG().uniform(start, end);
}
cv::Rect generateBox(const cv::Size& in_sz)
{
// Generated rectangle can reside outside of the initial image by border pixels
constexpr int border = 10;
constexpr int minW = 16;
constexpr int minH = 16;
cv::Rect box;
box.width = randInRange(minW, in_sz.width + 2*border);
box.height = randInRange(minH, in_sz.height + 2*border);
box.x = randInRange(-border, in_sz.width + border - box.width);
box.y = randInRange(-border, in_sz.height + border - box.height);
return box;
}
struct SSDitem
{
float image_id = 0.0f;
float label = 0.0f;
float confidence = 0.0f;
float rc_left = 0.0f;
float rc_top = 0.0f;
float rc_right = 0.0f;
float rc_bottom = 0.0f;
};
SSDitem generateItem(const int i, const cv::Size& in_sz)
{
const auto normalize = [](int v, int range) { return static_cast<float>(v) / range; };
SSDitem it;
it.image_id = static_cast<float>(i);
it.label = static_cast<float>(randInRange(0, 9));
it.confidence = theRNG().uniform(0.f, 1.f);
auto box = generateBox(in_sz);
it.rc_left = normalize(box.x, in_sz.width);
it.rc_right = normalize(box.x + box.width, in_sz.width);
it.rc_top = normalize(box.y, in_sz.height);
it.rc_bottom = normalize(box.y + box.height, in_sz.height);
return it;
}
};
class ParserYoloTest
{
public:
cv::Mat generateYoloOutput(const int num_classes, std::pair<bool,int> dims_config = {false, 4})
{
bool one_dim = false;
int num_dims = 0;
std::tie(one_dim, num_dims) = dims_config;
GAPI_Assert(num_dims <= 4);
GAPI_Assert((!one_dim && num_dims >= 3) ||
( one_dim && num_dims >= 1));
std::vector<int> dims(num_dims, 1);
if (one_dim) {
dims.back() = (num_classes+5)*5*13*13;
} else {
dims.back() = (num_classes+5)*5;
dims[num_dims-2] = 13;
dims[num_dims-3] = 13;
}
cv::Mat mat(dims, CV_32FC1);
auto data = mat.ptr<float>();
const size_t range = std::accumulate(dims.begin(), dims.end(), 1, std::multiplies<int>());
cv::RNG& rng = theRNG();
for (size_t i = 0; i < range; ++i)
{
data[i] = rng.uniform(0.f, 1.f);
}
return mat;
}
void parseYoloRef(const cv::Mat& in_yolo_result,
const cv::Size& in_size,
const float confidence_threshold,
const float nms_threshold,
const int num_classes,
const std::vector<float>& anchors,
std::vector<cv::Rect>& out_boxes,
std::vector<int>& out_labels)
{
YoloParams params;
constexpr auto side_square = 13 * 13;
this->m_out = in_yolo_result.ptr<float>();
this->m_side = 13;
this->m_lcoords = params.coords;
this->m_lclasses = num_classes;
std::vector<Detection> detections;
for (int i = 0; i < side_square; ++i)
{
for (int b = 0; b < params.num; ++b)
{
float scale = this->scale(i, b);
if (scale < confidence_threshold)
{
continue;
}
double x = this->x(i, b);
double y = this->y(i, b);
double height = this->height(i, b, anchors[2 * b + 1]);
double width = this->width(i, b, anchors[2 * b]);
for (int label = 0; label < num_classes; ++label)
{
float prob = scale * classConf(i,b,label);
if (prob < confidence_threshold)
{
continue;
}
auto box = toBox(x, y, height, width, in_size);
detections.emplace_back(Detection(box, prob, label));
}
}
}
std::stable_sort(std::begin(detections), std::end(detections),
[](const Detection& a, const Detection& b)
{
return a.conf > b.conf;
});
if (nms_threshold < 1.0f)
{
for (const auto& d : detections)
{
if (std::end(out_boxes) ==
std::find_if(std::begin(out_boxes), std::end(out_boxes),
[&d, nms_threshold](const cv::Rect& r)
{
float rectOverlap = 1.f - static_cast<float>(jaccardDistance(r, d.rect));
return rectOverlap > nms_threshold;
}))
{
out_boxes. emplace_back(d.rect);
out_labels.emplace_back(d.label);
}
}
}
else
{
for (const auto& d: detections)
{
out_boxes. emplace_back(d.rect);
out_labels.emplace_back(d.label);
}
}
}
private:
struct Detection
{
Detection(const cv::Rect& in_rect, const float in_conf, const int in_label)
: rect(in_rect), conf(in_conf), label(in_label)
{}
cv::Rect rect;
float conf = 0.0f;
int label = 0;
};
struct YoloParams
{
int num = 5;
int coords = 4;
};
float scale(const int i, const int b)
{
int obj_index = index(i, b, m_lcoords);
return m_out[obj_index];
}
double x(const int i, const int b)
{
int box_index = index(i, b, 0);
int col = i % m_side;
return (col + m_out[box_index]) / m_side;
}
double y(const int i, const int b)
{
int box_index = index(i, b, 0);
int row = i / m_side;
return (row + m_out[box_index + m_side * m_side]) / m_side;
}
double width(const int i, const int b, const float anchor)
{
int box_index = index(i, b, 0);
return std::exp(m_out[box_index + 2 * m_side * m_side]) * anchor / m_side;
}
double height(const int i, const int b, const float anchor)
{
int box_index = index(i, b, 0);
return std::exp(m_out[box_index + 3 * m_side * m_side]) * anchor / m_side;
}
float classConf(const int i, const int b, const int label)
{
int class_index = index(i, b, m_lcoords + 1 + label);
return m_out[class_index];
}
cv::Rect toBox(const double x, const double y, const double h, const double w, const cv::Size& in_sz)
{
auto h_scale = in_sz.height;
auto w_scale = in_sz.width;
cv::Rect r;
r.x = static_cast<int>((x - w / 2) * w_scale);
r.y = static_cast<int>((y - h / 2) * h_scale);
r.width = static_cast<int>(w * w_scale);
r.height = static_cast<int>(h * h_scale);
return r;
}
int index(const int i, const int b, const int entry)
{
return b * m_side * m_side * (m_lcoords + m_lclasses + 1) + entry * m_side * m_side + i;
}
const float* m_out = nullptr;
int m_side = 0, m_lcoords = 0, m_lclasses = 0;
};
} // namespace opencv_test
#endif // OPENCV_GAPI_PARSERS_TESTS_COMMON_HPP

View File

@ -0,0 +1,97 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
//
// Copyright (C) 2019 Intel Corporation
#include "../test_precomp.hpp"
#include "gapi_render_tests.hpp"
namespace opencv_test
{
cv::Scalar cvtBGRToYUVC(const cv::Scalar& bgr)
{
double y = bgr[2] * 0.299000 + bgr[1] * 0.587000 + bgr[0] * 0.114000;
double u = bgr[2] * -0.168736 + bgr[1] * -0.331264 + bgr[0] * 0.500000 + 128;
double v = bgr[2] * 0.500000 + bgr[1] * -0.418688 + bgr[0] * -0.081312 + 128;
return {y, u, v};
}
void drawMosaicRef(const cv::Mat& mat, const cv::Rect &rect, int cellSz)
{
cv::Rect mat_rect(0, 0, mat.cols, mat.rows);
auto intersection = mat_rect & rect;
cv::Mat msc_roi = mat(intersection);
bool has_crop_x = false;
bool has_crop_y = false;
int cols = msc_roi.cols;
int rows = msc_roi.rows;
if (msc_roi.cols % cellSz != 0)
{
has_crop_x = true;
cols -= msc_roi.cols % cellSz;
}
if (msc_roi.rows % cellSz != 0)
{
has_crop_y = true;
rows -= msc_roi.rows % cellSz;
}
cv::Mat cell_roi;
for(int i = 0; i < rows; i += cellSz )
{
for(int j = 0; j < cols; j += cellSz)
{
cell_roi = msc_roi(cv::Rect(j, i, cellSz, cellSz));
cell_roi = cv::mean(cell_roi);
}
if (has_crop_x)
{
cell_roi = msc_roi(cv::Rect(cols, i, msc_roi.cols - cols, cellSz));
cell_roi = cv::mean(cell_roi);
}
}
if (has_crop_y)
{
for(int j = 0; j < cols; j += cellSz)
{
cell_roi = msc_roi(cv::Rect(j, rows, cellSz, msc_roi.rows - rows));
cell_roi = cv::mean(cell_roi);
}
if (has_crop_x)
{
cell_roi = msc_roi(cv::Rect(cols, rows, msc_roi.cols - cols, msc_roi.rows - rows));
cell_roi = cv::mean(cell_roi);
}
}
}
void blendImageRef(cv::Mat& mat, const cv::Point& org, const cv::Mat& img, const cv::Mat& alpha)
{
auto roi = mat(cv::Rect(org, img.size()));
cv::Mat img32f_w;
cv::merge(std::vector<cv::Mat>(3, alpha), img32f_w);
cv::Mat roi32f_w(roi.size(), CV_32FC3, cv::Scalar::all(1.0));
roi32f_w -= img32f_w;
cv::Mat img32f, roi32f;
img.convertTo(img32f, CV_32F, 1.0/255);
roi.convertTo(roi32f, CV_32F, 1.0/255);
cv::multiply(img32f, img32f_w, img32f);
cv::multiply(roi32f, roi32f_w, roi32f);
roi32f += img32f;
roi32f.convertTo(roi, CV_8U, 255.0);
};
} // namespace opencv_test

View File

@ -0,0 +1,147 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
//
// Copyright (C) 2018 Intel Corporation
#ifndef OPENCV_GAPI_RENDER_TESTS_HPP
#define OPENCV_GAPI_RENDER_TESTS_HPP
#include "gapi_tests_common.hpp"
namespace opencv_test
{
template<typename ...SpecificParams>
struct RenderParams : public Params<SpecificParams...>
{
using common_params_t = std::tuple<cv::Size>;
using specific_params_t = std::tuple<SpecificParams...>;
using params_t = std::tuple<cv::Size, SpecificParams...>;
static constexpr const size_t common_params_size = std::tuple_size<common_params_t>::value;
static constexpr const size_t specific_params_size = std::tuple_size<specific_params_t>::value;
template<size_t I>
static const typename std::tuple_element<I, common_params_t>::type&
getCommon(const params_t& t)
{
static_assert(I < common_params_size, "Index out of range");
return std::get<I>(t);
}
template<size_t I>
static const typename std::tuple_element<I, specific_params_t>::type&
getSpecific(const params_t& t)
{
static_assert(specific_params_size > 0,
"Impossible to call this function: no specific parameters specified");
static_assert(I < specific_params_size, "Index out of range");
return std::get<common_params_size + I>(t);
}
};
template<typename ...SpecificParams>
struct RenderTestBase : public TestWithParam<typename RenderParams<SpecificParams...>::params_t>
{
using AllParams = RenderParams<SpecificParams...>;
// Get common (pre-defined) parameter value by index
template<size_t I>
inline auto getCommonParam() const
-> decltype(AllParams::template getCommon<I>(this->GetParam()))
{
return AllParams::template getCommon<I>(this->GetParam());
}
// Get specific (user-defined) parameter value by index
template<size_t I>
inline auto getSpecificParam() const
-> decltype(AllParams::template getSpecific<I>(this->GetParam()))
{
return AllParams::template getSpecific<I>(this->GetParam());
}
cv::Size sz_ = getCommonParam<0>();
};
template <typename ...Args>
class RenderBGRTestBase : public RenderTestBase<Args...>
{
protected:
void Init(const cv::Size& sz)
{
MatType type = CV_8UC3;
ref_mat.create(sz, type);
gapi_mat.create(sz, type);
cv::randu(ref_mat, cv::Scalar::all(0), cv::Scalar::all(255));
ref_mat.copyTo(gapi_mat);
}
cv::Mat gapi_mat, ref_mat;
};
template <typename ...Args>
class RenderNV12TestBase : public RenderTestBase<Args...>
{
protected:
void Init(const cv::Size& sz)
{
auto create_rand_mats = [](const cv::Size& size, MatType type, cv::Mat& ref_mat, cv::Mat& gapi_mat) {
ref_mat.create(size, type);
cv::randu(ref_mat, cv::Scalar::all(0), cv::Scalar::all(255));
ref_mat.copyTo(gapi_mat);
};
create_rand_mats(sz, CV_8UC1, y_ref_mat , y_gapi_mat);
create_rand_mats(sz / 2, CV_8UC2, uv_ref_mat , uv_gapi_mat);
}
cv::Mat y_ref_mat, uv_ref_mat, y_gapi_mat, uv_gapi_mat;
};
cv::Scalar cvtBGRToYUVC(const cv::Scalar& bgr);
void drawMosaicRef(const cv::Mat& mat, const cv::Rect &rect, int cellSz);
void blendImageRef(cv::Mat& mat,
const cv::Point& org,
const cv::Mat& img,
const cv::Mat& alpha);
#define GAPI_RENDER_TEST_FIXTURE_NV12(Fixture, API, Number, ...) \
struct Fixture : public RenderNV12TestBase API { \
__WRAP_VAARGS(DEFINE_SPECIFIC_PARAMS_##Number(__VA_ARGS__)) \
Fixture() { \
Init(sz_); \
}; \
};
#define GAPI_RENDER_TEST_FIXTURE_BGR(Fixture, API, Number, ...) \
struct Fixture : public RenderBGRTestBase API { \
__WRAP_VAARGS(DEFINE_SPECIFIC_PARAMS_##Number(__VA_ARGS__)) \
Fixture() { \
Init(sz_); \
}; \
};
#define GET_VA_ARGS(...) __VA_ARGS__
#define GAPI_RENDER_TEST_FIXTURES(Fixture, API, Number, ...) \
GAPI_RENDER_TEST_FIXTURE_BGR(RenderBGR##Fixture, GET_VA_ARGS(API), Number, __VA_ARGS__) \
GAPI_RENDER_TEST_FIXTURE_NV12(RenderNV12##Fixture, GET_VA_ARGS(API), Number, __VA_ARGS__) \
GAPI_RENDER_TEST_FIXTURE_NV12(RenderMFrame##Fixture, GET_VA_ARGS(API), Number, __VA_ARGS__) \
using Points = std::vector<cv::Point>;
GAPI_RENDER_TEST_FIXTURES(TestTexts, FIXTURE_API(std::string, cv::Point, double, cv::Scalar), 4, text, org, fs, color)
GAPI_RENDER_TEST_FIXTURES(TestRects, FIXTURE_API(cv::Rect, cv::Scalar, int), 3, rect, color, thick)
GAPI_RENDER_TEST_FIXTURES(TestCircles, FIXTURE_API(cv::Point, int, cv::Scalar, int), 4, center, radius, color, thick)
GAPI_RENDER_TEST_FIXTURES(TestLines, FIXTURE_API(cv::Point, cv::Point, cv::Scalar, int), 4, pt1, pt2, color, thick)
GAPI_RENDER_TEST_FIXTURES(TestMosaics, FIXTURE_API(cv::Rect, int, int), 3, mos, cellsz, decim)
GAPI_RENDER_TEST_FIXTURES(TestImages, FIXTURE_API(cv::Rect, cv::Scalar, double), 3, rect, color, transparency)
GAPI_RENDER_TEST_FIXTURES(TestPolylines, FIXTURE_API(Points, cv::Scalar, int), 3, points, color, thick)
} // opencv_test
#endif //OPENCV_GAPI_RENDER_TESTS_HPP

View File

@ -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) 2021 Intel Corporation
#include "../test_precomp.hpp"
#include "gapi_stereo_tests_inl.hpp"

View File

@ -0,0 +1,26 @@
// 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) 2021 Intel Corporation
#ifndef OPENCV_GAPI_STEREO_TESTS_HPP
#define OPENCV_GAPI_STEREO_TESTS_HPP
#include <opencv2/gapi/stereo.hpp> // fore cv::gapi::StereoOutputFormat
#include "gapi_tests_common.hpp"
#include "gapi_parsers_tests_common.hpp"
namespace opencv_test
{
GAPI_TEST_FIXTURE(TestGAPIStereo, initMatsRandU, FIXTURE_API(cv::gapi::StereoOutputFormat, int, int, double, double, CompareMats), 6,
oF, numDisparities, blockSize, baseline,
focus, cmpF)
} // namespace opencv_test
#endif // OPENCV_GAPI_STEREO_TESTS_HPP

View File

@ -0,0 +1,74 @@
// 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) 2021 Intel Corporation
#ifndef OPENCV_GAPI_STEREO_TESTS_INL_HPP
#define OPENCV_GAPI_STEREO_TESTS_INL_HPP
#include <opencv2/gapi/stereo.hpp>
#include <opencv2/gapi/cpu/stereo.hpp>
#include "gapi_stereo_tests.hpp"
#ifdef HAVE_OPENCV_CALIB3D
#include <opencv2/calib3d.hpp>
namespace opencv_test {
TEST_P(TestGAPIStereo, DisparityDepthTest)
{
using format = cv::gapi::StereoOutputFormat;
switch(oF) {
case format::DEPTH_FLOAT16: dtype = CV_16FC1; break;
case format::DEPTH_FLOAT32: dtype = CV_32FC1; break;
case format::DISPARITY_FIXED16_12_4: dtype = CV_16SC1; break;
default: GAPI_Assert(false && "Unsupported format in test");
}
initOutMats(sz, dtype);
// G-API
cv::GMat inL, inR;
cv::GMat out = cv::gapi::stereo(inL, inR, oF);
cv::GComputation(cv::GIn(inL, inR), cv::GOut(out))
.apply(cv::gin(in_mat1, in_mat2), cv::gout(out_mat_gapi),
cv::compile_args(cv::gapi::calib3d::cpu::kernels(),
cv::gapi::calib3d::cpu::StereoInitParam {
numDisparities,
blockSize,
baseline,
focus}));
// OpenCV
cv::StereoBM::create(numDisparities, blockSize)->compute(in_mat1,
in_mat2,
out_mat_ocv);
static const int DISPARITY_SHIFT_16S = 4;
switch(oF) {
case format::DEPTH_FLOAT16:
out_mat_ocv.convertTo(out_mat_ocv, CV_32FC1, 1./(1 << DISPARITY_SHIFT_16S), 0);
out_mat_ocv = (focus * baseline) / out_mat_ocv;
out_mat_ocv.convertTo(out_mat_ocv, CV_16FC1);
break;
case format::DEPTH_FLOAT32:
out_mat_ocv.convertTo(out_mat_ocv, CV_32FC1, 1./(1 << DISPARITY_SHIFT_16S), 0);
out_mat_ocv = (focus * baseline) / out_mat_ocv;
break;
case format::DISPARITY_FIXED16_12_4:
break;
default:
GAPI_Assert(false && "Unsupported format in test");
}
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
}
} // namespace opencv_test
#endif // HAVE_OPENCV_CALIB3D
#endif // OPENCV_GAPI_STEREO_TESTS_INL_HPP

File diff suppressed because it is too large Load Diff

View File

@ -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) 2019 Intel Corporation
#ifndef OPENCV_GAPI_TESTS_HELPERS_HPP
#define OPENCV_GAPI_TESTS_HELPERS_HPP
#include <tuple>
#include <limits>
namespace opencv_test
{
// Ensure correct __VA_ARGS__ expansion on Windows
#define __WRAP_VAARGS(x) x
#define __TUPLE_PARAM_TYPE(i) std::tuple_element<i, AllParams::specific_params_t>::type
// implementation of recursive in-class declaration and initialization of member variables
#define __DEFINE_PARAMS_IMPL1(index, param_name) \
__TUPLE_PARAM_TYPE(index) param_name = getSpecificParam<index>();
#define __DEFINE_PARAMS_IMPL2(index, param_name, ...) \
__TUPLE_PARAM_TYPE(index) param_name = getSpecificParam<index>(); \
__WRAP_VAARGS(__DEFINE_PARAMS_IMPL1(index+1, __VA_ARGS__))
#define __DEFINE_PARAMS_IMPL3(index, param_name, ...) \
__TUPLE_PARAM_TYPE(index) param_name = getSpecificParam<index>(); \
__WRAP_VAARGS(__DEFINE_PARAMS_IMPL2(index+1, __VA_ARGS__))
#define __DEFINE_PARAMS_IMPL4(index, param_name, ...) \
__TUPLE_PARAM_TYPE(index) param_name = getSpecificParam<index>(); \
__WRAP_VAARGS(__DEFINE_PARAMS_IMPL3(index+1, __VA_ARGS__))
#define __DEFINE_PARAMS_IMPL5(index, param_name, ...) \
__TUPLE_PARAM_TYPE(index) param_name = getSpecificParam<index>(); \
__WRAP_VAARGS(__DEFINE_PARAMS_IMPL4(index+1, __VA_ARGS__))
#define __DEFINE_PARAMS_IMPL6(index, param_name, ...) \
__TUPLE_PARAM_TYPE(index) param_name = getSpecificParam<index>(); \
__WRAP_VAARGS(__DEFINE_PARAMS_IMPL5(index+1, __VA_ARGS__))
#define __DEFINE_PARAMS_IMPL7(index, param_name, ...) \
__TUPLE_PARAM_TYPE(index) param_name = getSpecificParam<index>(); \
__WRAP_VAARGS(__DEFINE_PARAMS_IMPL6(index+1, __VA_ARGS__))
#define __DEFINE_PARAMS_IMPL8(index, param_name, ...) \
__TUPLE_PARAM_TYPE(index) param_name = getSpecificParam<index>(); \
__WRAP_VAARGS(__DEFINE_PARAMS_IMPL7(index+1, __VA_ARGS__))
#define __DEFINE_PARAMS_IMPL9(index, param_name, ...) \
__TUPLE_PARAM_TYPE(index) param_name = getSpecificParam<index>(); \
__WRAP_VAARGS(__DEFINE_PARAMS_IMPL8(index+1, __VA_ARGS__))
#define __DEFINE_PARAMS_IMPL10(index, param_name, ...) \
__TUPLE_PARAM_TYPE(index) param_name = getSpecificParam<index>(); \
__WRAP_VAARGS(__DEFINE_PARAMS_IMPL9(index+1, __VA_ARGS__))
#define __DEFINE_PARAMS_IMPL11(index, param_name, ...) \
__TUPLE_PARAM_TYPE(index) param_name = getSpecificParam<index>(); \
__WRAP_VAARGS(__DEFINE_PARAMS_IMPL10(index+1, __VA_ARGS__))
// user interface to define member variables of specified names
#define DEFINE_SPECIFIC_PARAMS_0()
#define DEFINE_SPECIFIC_PARAMS_1(...) \
__WRAP_VAARGS(__DEFINE_PARAMS_IMPL1(0, __VA_ARGS__))
#define DEFINE_SPECIFIC_PARAMS_2(...) \
__WRAP_VAARGS(__DEFINE_PARAMS_IMPL2(0, __VA_ARGS__))
#define DEFINE_SPECIFIC_PARAMS_3(...) \
__WRAP_VAARGS(__DEFINE_PARAMS_IMPL3(0, __VA_ARGS__))
#define DEFINE_SPECIFIC_PARAMS_4(...) \
__WRAP_VAARGS(__DEFINE_PARAMS_IMPL4(0, __VA_ARGS__))
#define DEFINE_SPECIFIC_PARAMS_5(...) \
__WRAP_VAARGS(__DEFINE_PARAMS_IMPL5(0, __VA_ARGS__))
#define DEFINE_SPECIFIC_PARAMS_6(...) \
__WRAP_VAARGS(__DEFINE_PARAMS_IMPL6(0, __VA_ARGS__))
#define DEFINE_SPECIFIC_PARAMS_7(...) \
__WRAP_VAARGS(__DEFINE_PARAMS_IMPL7(0, __VA_ARGS__))
#define DEFINE_SPECIFIC_PARAMS_8(...) \
__WRAP_VAARGS(__DEFINE_PARAMS_IMPL8(0, __VA_ARGS__))
#define DEFINE_SPECIFIC_PARAMS_9(...) \
__WRAP_VAARGS(__DEFINE_PARAMS_IMPL9(0, __VA_ARGS__))
#define DEFINE_SPECIFIC_PARAMS_10(...) \
__WRAP_VAARGS(__DEFINE_PARAMS_IMPL10(0, __VA_ARGS__))
#define DEFINE_SPECIFIC_PARAMS_11(...) \
__WRAP_VAARGS(__DEFINE_PARAMS_IMPL11(0, __VA_ARGS__))
} // namespace opencv_test
#endif //OPENCV_GAPI_TESTS_HELPERS_HPP

View File

@ -0,0 +1,9 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
//
// Copyright (C) 2020 Intel Corporation
#include "../test_precomp.hpp"
#include "gapi_video_tests_inl.hpp"

View File

@ -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) 2020 Intel Corporation
#ifndef OPENCV_GAPI_VIDEO_TESTS_HPP
#define OPENCV_GAPI_VIDEO_TESTS_HPP
#include "gapi_video_tests_common.hpp"
namespace opencv_test
{
GAPI_TEST_FIXTURE_SPEC_PARAMS(BuildOptFlowPyramidTest,
FIXTURE_API(std::string,int,int,bool,int,int,bool), 7,
fileName, winSize, maxLevel, withDerivatives, pyrBorder,
derivBorder, tryReuseInputImage)
GAPI_TEST_FIXTURE_SPEC_PARAMS(OptFlowLKTest, FIXTURE_API(std::string,int,tuple<int,int>,int,
cv::TermCriteria),
5, fileNamePattern, channels, pointsNum, winSize, criteria)
GAPI_TEST_FIXTURE_SPEC_PARAMS(OptFlowLKTestForPyr, FIXTURE_API(std::string,int,tuple<int,int>,int,
cv::TermCriteria,bool),
6, fileNamePattern, channels, pointsNum, winSize, criteria,withDeriv)
GAPI_TEST_FIXTURE_SPEC_PARAMS(BuildPyr_CalcOptFlow_PipelineTest,
FIXTURE_API(std::string,int,int,bool), 4,
fileNamePattern, winSize, maxLevel, withDerivatives)
GAPI_TEST_FIXTURE_SPEC_PARAMS(BackgroundSubtractorTest, FIXTURE_API(tuple<cv::gapi::video::BackgroundSubtractorType,double>,
int, bool, double, std::string, std::size_t),
6, typeAndThreshold, histLength, detectShadows, learningRate, filePath, testNumFrames)
GAPI_TEST_FIXTURE_SPEC_PARAMS(KalmanFilterTest, FIXTURE_API(int, int, int, int, int), 5, type, dDim, mDim, cDim, numIter)
GAPI_TEST_FIXTURE_SPEC_PARAMS(KalmanFilterNoControlTest, FIXTURE_API(int, int, int, int), 4, type, dDim, mDim, numIter)
GAPI_TEST_FIXTURE_SPEC_PARAMS(KalmanFilterCircleSampleTest, FIXTURE_API(int, int), 2, type, numIter)
} // opencv_test
#endif // OPENCV_GAPI_VIDEO_TESTS_HPP

View File

@ -0,0 +1,491 @@
// 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) 2020 Intel Corporation
#ifndef OPENCV_GAPI_VIDEO_TESTS_COMMON_HPP
#define OPENCV_GAPI_VIDEO_TESTS_COMMON_HPP
#include "gapi_tests_common.hpp"
#include "../../include/opencv2/gapi/video.hpp"
#ifdef HAVE_OPENCV_VIDEO
#include <opencv2/video.hpp>
#endif // HAVE_OPENCV_VIDEO
namespace opencv_test
{
namespace
{
G_TYPED_KERNEL(GMinScalar, <GScalar(GScalar,GScalar)>, "custom.MinScalar") {
static GScalarDesc outMeta(GScalarDesc,GScalarDesc) { return empty_scalar_desc(); }
};
GAPI_OCV_KERNEL(GCPUMinScalar, GMinScalar) {
static void run(const Scalar &sc1, const Scalar &sc2, Scalar &scOut) {
scOut = Scalar(std::min(sc1[0], sc2[0]));
}
};
inline void initTrackingPointsArray(std::vector<cv::Point2f>& points, int width, int height,
int nPointsX, int nPointsY)
{
if (nPointsX > width || nPointsY > height)
{
FAIL() << "Specified points number is too big";
}
int stepX = width / nPointsX;
int stepY = height / nPointsY;
points.clear();
GAPI_Assert((nPointsX >= 0) && (nPointsY) >= 0);
points.reserve(nPointsX * nPointsY);
for (int x = stepX / 2; x < width; x += stepX)
{
for (int y = stepY / 2; y < height; y += stepY)
{
Point2f pt(static_cast<float>(x), static_cast<float>(y));
points.push_back(pt);
}
}
}
struct BuildOpticalFlowPyramidTestOutput
{
BuildOpticalFlowPyramidTestOutput(std::vector<Mat> &pyr, int maxLvl) :
pyramid(pyr), maxLevel(maxLvl) { }
std::vector<Mat> &pyramid;
int maxLevel = 0;
};
template<typename Type>
struct OptFlowLKTestInput
{
Type& prevData;
Type& nextData;
std::vector<cv::Point2f>& prevPoints;
};
struct OptFlowLKTestOutput
{
std::vector<cv::Point2f> &nextPoints;
std::vector<uchar> &statuses;
std::vector<float> &errors;
};
struct BuildOpticalFlowPyramidTestParams
{
BuildOpticalFlowPyramidTestParams() = default;
BuildOpticalFlowPyramidTestParams(const std::string& name, int winSz, int maxLvl,
bool withDeriv, int pBorder, int dBorder,
bool tryReuse, const GCompileArgs& compArgs):
fileName(name), winSize(winSz), maxLevel(maxLvl),
withDerivatives(withDeriv), pyrBorder(pBorder),
derivBorder(dBorder), tryReuseInputImage(tryReuse),
compileArgs(compArgs) { }
std::string fileName = "";
int winSize = -1;
int maxLevel = -1;
bool withDerivatives = false;
int pyrBorder = -1;
int derivBorder = -1;
bool tryReuseInputImage = false;
cv::GCompileArgs compileArgs;
};
struct OptFlowLKTestParams
{
OptFlowLKTestParams(): fileNamePattern(""), format(1), channels(0), pointsNum{0, 0},
winSize(0), maxLevel(3), minEigThreshold(1e-4), flags(0) { }
OptFlowLKTestParams(const std::string& namePat, int chans,
const std::tuple<int,int>& ptsNum, int winSz,
const cv::TermCriteria& crit, const cv::GCompileArgs& compArgs,
int flgs = 0, int fmt = 1, int maxLvl = 3, double minEigThresh = 1e-4):
fileNamePattern(namePat), format(fmt), channels(chans),
pointsNum(ptsNum), winSize(winSz), maxLevel(maxLvl),
criteria(crit), minEigThreshold(minEigThresh), compileArgs(compArgs),
flags(flgs) { }
std::string fileNamePattern = "";
int format = 1;
int channels = 0;
std::tuple<int,int> pointsNum = std::make_tuple(0, 0);
int winSize = 0;
int maxLevel = 3;
cv::TermCriteria criteria;
double minEigThreshold = 1e-4;
cv::GCompileArgs compileArgs;
int flags = 0;
};
inline void compareOutputPyramids(const BuildOpticalFlowPyramidTestOutput& outGAPI,
const BuildOpticalFlowPyramidTestOutput& outOCV)
{
GAPI_Assert(outGAPI.maxLevel == outOCV.maxLevel);
GAPI_Assert(outOCV.maxLevel >= 0);
const size_t maxLevel = static_cast<size_t>(outOCV.maxLevel);
for (size_t i = 0; i <= maxLevel; i++)
{
EXPECT_TRUE(AbsExact().to_compare_f()(outGAPI.pyramid[i], outOCV.pyramid[i]));
}
}
template <typename Elem>
inline bool compareVectorsAbsExactForOptFlow(const std::vector<Elem>& outGAPI,
const std::vector<Elem>& outOCV)
{
return AbsExactVector<Elem>().to_compare_f()(outGAPI, outOCV);
}
inline void compareOutputsOptFlow(const OptFlowLKTestOutput& outGAPI,
const OptFlowLKTestOutput& outOCV)
{
EXPECT_TRUE(compareVectorsAbsExactForOptFlow(outGAPI.nextPoints, outOCV.nextPoints));
EXPECT_TRUE(compareVectorsAbsExactForOptFlow(outGAPI.statuses, outOCV.statuses));
EXPECT_TRUE(compareVectorsAbsExactForOptFlow(outGAPI.errors, outOCV.errors));
}
inline std::ostream& operator<<(std::ostream& os, const cv::TermCriteria& criteria)
{
os << "{";
switch (criteria.type) {
case cv::TermCriteria::COUNT:
os << "COUNT; ";
break;
case cv::TermCriteria::EPS:
os << "EPS; ";
break;
case cv::TermCriteria::COUNT | cv::TermCriteria::EPS:
os << "COUNT | EPS; ";
break;
default:
os << "TypeUndefined; ";
break;
};
return os << criteria.maxCount << "; " << criteria.epsilon <<"}";
}
#ifdef HAVE_OPENCV_VIDEO
inline GComputation runOCVnGAPIBuildOptFlowPyramid(TestFunctional& testInst,
const BuildOpticalFlowPyramidTestParams& params,
BuildOpticalFlowPyramidTestOutput& outOCV,
BuildOpticalFlowPyramidTestOutput& outGAPI)
{
testInst.initMatFromImage(CV_8UC1, params.fileName);
// OpenCV code /////////////////////////////////////////////////////////////
{
outOCV.maxLevel = cv::buildOpticalFlowPyramid(testInst.in_mat1, outOCV.pyramid,
Size(params.winSize, params.winSize),
params.maxLevel, params.withDerivatives,
params.pyrBorder, params.derivBorder,
params.tryReuseInputImage);
}
// G-API code //////////////////////////////////////////////////////////////
GMat in;
GArray<GMat> out;
GScalar outMaxLevel;
std::tie(out, outMaxLevel) =
cv::gapi::buildOpticalFlowPyramid(in, Size(params.winSize, params.winSize),
params.maxLevel, params.withDerivatives,
params.pyrBorder, params.derivBorder,
params.tryReuseInputImage);
GComputation c(GIn(in), GOut(out, outMaxLevel));
Scalar outMaxLevelSc;
c.apply(gin(testInst.in_mat1), gout(outGAPI.pyramid, outMaxLevelSc),
std::move(const_cast<GCompileArgs&>(params.compileArgs)));
outGAPI.maxLevel = static_cast<int>(outMaxLevelSc[0]);
return c;
}
template<typename GType, typename Type>
cv::GComputation runOCVnGAPIOptFlowLK(OptFlowLKTestInput<Type>& in,
int width, int height,
const OptFlowLKTestParams& params,
OptFlowLKTestOutput& ocvOut,
OptFlowLKTestOutput& gapiOut)
{
int nPointsX = 0, nPointsY = 0;
std::tie(nPointsX, nPointsY) = params.pointsNum;
initTrackingPointsArray(in.prevPoints, width, height, nPointsX, nPointsY);
cv::Size winSize(params.winSize, params.winSize);
// OpenCV code /////////////////////////////////////////////////////////////
{
cv::calcOpticalFlowPyrLK(in.prevData, in.nextData, in.prevPoints,
ocvOut.nextPoints, ocvOut.statuses, ocvOut.errors,
winSize, params.maxLevel, params.criteria,
params.flags, params.minEigThreshold);
}
// G-API code //////////////////////////////////////////////////////////////
{
GType inPrev, inNext;
GArray<cv::Point2f> prevPts, predPts, nextPts;
GArray<uchar> statuses;
GArray<float> errors;
std::tie(nextPts, statuses, errors) = cv::gapi::calcOpticalFlowPyrLK(
inPrev, inNext,
prevPts, predPts, winSize,
params.maxLevel, params.criteria,
params.flags, params.minEigThreshold);
cv::GComputation c(cv::GIn(inPrev, inNext, prevPts, predPts),
cv::GOut(nextPts, statuses, errors));
c.apply(cv::gin(in.prevData, in.nextData, in.prevPoints, std::vector<cv::Point2f>{ }),
cv::gout(gapiOut.nextPoints, gapiOut.statuses, gapiOut.errors),
std::move(const_cast<cv::GCompileArgs&>(params.compileArgs)));
return c;
}
}
inline cv::GComputation runOCVnGAPIOptFlowLK(TestFunctional& testInst,
std::vector<cv::Point2f>& inPts,
const OptFlowLKTestParams& params,
OptFlowLKTestOutput& ocvOut,
OptFlowLKTestOutput& gapiOut)
{
testInst.initMatsFromImages(params.channels,
params.fileNamePattern,
params.format);
OptFlowLKTestInput<cv::Mat> in{ testInst.in_mat1, testInst.in_mat2, inPts };
return runOCVnGAPIOptFlowLK<cv::GMat>(in,
testInst.in_mat1.cols,
testInst.in_mat1.rows,
params,
ocvOut,
gapiOut);
}
inline cv::GComputation runOCVnGAPIOptFlowLKForPyr(TestFunctional& testInst,
OptFlowLKTestInput<std::vector<cv::Mat>>& in,
const OptFlowLKTestParams& params,
bool withDeriv,
OptFlowLKTestOutput& ocvOut,
OptFlowLKTestOutput& gapiOut)
{
testInst.initMatsFromImages(params.channels,
params.fileNamePattern,
params.format);
cv::Size winSize(params.winSize, params.winSize);
OptFlowLKTestParams updatedParams(params);
updatedParams.maxLevel = cv::buildOpticalFlowPyramid(testInst.in_mat1, in.prevData,
winSize, params.maxLevel, withDeriv);
updatedParams.maxLevel = cv::buildOpticalFlowPyramid(testInst.in_mat2, in.nextData,
winSize, params.maxLevel, withDeriv);
return runOCVnGAPIOptFlowLK<cv::GArray<cv::GMat>>(in,
testInst.in_mat1.cols,
testInst.in_mat1.rows,
updatedParams,
ocvOut,
gapiOut);
}
inline GComputation runOCVnGAPIOptFlowPipeline(TestFunctional& testInst,
const BuildOpticalFlowPyramidTestParams& params,
OptFlowLKTestOutput& outOCV,
OptFlowLKTestOutput& outGAPI,
std::vector<Point2f>& prevPoints)
{
testInst.initMatsFromImages(3, params.fileName, 1);
initTrackingPointsArray(prevPoints, testInst.in_mat1.cols, testInst.in_mat1.rows, 15, 15);
Size winSize = Size(params.winSize, params.winSize);
// OpenCV code /////////////////////////////////////////////////////////////
{
std::vector<Mat> pyr1, pyr2;
int maxLevel1 = cv::buildOpticalFlowPyramid(testInst.in_mat1, pyr1, winSize,
params.maxLevel, params.withDerivatives,
params.pyrBorder, params.derivBorder,
params.tryReuseInputImage);
int maxLevel2 = cv::buildOpticalFlowPyramid(testInst.in_mat2, pyr2, winSize,
params.maxLevel, params.withDerivatives,
params.pyrBorder, params.derivBorder,
params.tryReuseInputImage);
cv::calcOpticalFlowPyrLK(pyr1, pyr2, prevPoints,
outOCV.nextPoints, outOCV.statuses, outOCV.errors,
winSize, std::min(maxLevel1, maxLevel2));
}
// G-API code //////////////////////////////////////////////////////////////
GMat in1, in2;
GArray<GMat> gpyr1, gpyr2;
GScalar gmaxLevel1, gmaxLevel2;
GArray<cv::Point2f> gprevPts, gpredPts, gnextPts;
GArray<uchar> gstatuses;
GArray<float> gerrors;
std::tie(gpyr1, gmaxLevel1) = cv::gapi::buildOpticalFlowPyramid(
in1, winSize, params.maxLevel,
params.withDerivatives, params.pyrBorder,
params.derivBorder, params.tryReuseInputImage);
std::tie(gpyr2, gmaxLevel2) = cv::gapi::buildOpticalFlowPyramid(
in2, winSize, params.maxLevel,
params.withDerivatives, params.pyrBorder,
params.derivBorder, params.tryReuseInputImage);
GScalar gmaxLevel = GMinScalar::on(gmaxLevel1, gmaxLevel2);
std::tie(gnextPts, gstatuses, gerrors) = cv::gapi::calcOpticalFlowPyrLK(
gpyr1, gpyr2, gprevPts, gpredPts, winSize,
gmaxLevel);
cv::GComputation c(GIn(in1, in2, gprevPts, gpredPts), cv::GOut(gnextPts, gstatuses, gerrors));
c.apply(cv::gin(testInst.in_mat1, testInst.in_mat2, prevPoints, std::vector<cv::Point2f>{ }),
cv::gout(outGAPI.nextPoints, outGAPI.statuses, outGAPI.errors),
std::move(const_cast<cv::GCompileArgs&>(params.compileArgs)));
return c;
}
inline void testBackgroundSubtractorStreaming(cv::GStreamingCompiled& gapiBackSub,
const cv::Ptr<cv::BackgroundSubtractor>& pOCVBackSub,
const int diffPercent, const int tolerance,
const double lRate, const std::size_t testNumFrames)
{
cv::Mat frame, gapiForeground, ocvForeground;
double numDiff = diffPercent / 100.0;
gapiBackSub.start();
EXPECT_TRUE(gapiBackSub.running());
compare_f cmpF = AbsSimilarPoints(tolerance, numDiff).to_compare_f();
// Comparison of G-API and OpenCV substractors
std::size_t frames = 0u;
while (frames <= testNumFrames && gapiBackSub.pull(cv::gout(frame, gapiForeground)))
{
pOCVBackSub->apply(frame, ocvForeground, lRate);
EXPECT_TRUE(cmpF(gapiForeground, ocvForeground));
frames++;
}
if (gapiBackSub.running())
gapiBackSub.stop();
EXPECT_LT(0u, frames);
EXPECT_FALSE(gapiBackSub.running());
}
inline void initKalmanParams(const int type, const int dDim, const int mDim, const int cDim,
cv::gapi::KalmanParams& kp)
{
kp.state = Mat::zeros(dDim, 1, type);
cv::randu(kp.state, Scalar::all(0), Scalar::all(0.1));
kp.errorCov = Mat::eye(dDim, dDim, type);
kp.transitionMatrix = Mat::ones(dDim, dDim, type) * 2;
kp.processNoiseCov = Mat::eye(dDim, dDim, type) * (1e-5);
kp.measurementMatrix = Mat::eye(mDim, dDim, type) * 2;
kp.measurementNoiseCov = Mat::eye(mDim, mDim, type) * (1e-5);
if (cDim > 0)
kp.controlMatrix = Mat::eye(dDim, cDim, type) * (1e-3);
}
inline void initKalmanFilter(const cv::gapi::KalmanParams& kp, const bool control,
cv::KalmanFilter& ocvKalman)
{
kp.state.copyTo(ocvKalman.statePost);
kp.errorCov.copyTo(ocvKalman.errorCovPost);
kp.transitionMatrix.copyTo(ocvKalman.transitionMatrix);
kp.measurementMatrix.copyTo(ocvKalman.measurementMatrix);
kp.measurementNoiseCov.copyTo(ocvKalman.measurementNoiseCov);
kp.processNoiseCov.copyTo(ocvKalman.processNoiseCov);
if (control)
kp.controlMatrix.copyTo(ocvKalman.controlMatrix);
}
#else // !HAVE_OPENCV_VIDEO
inline cv::GComputation runOCVnGAPIBuildOptFlowPyramid(TestFunctional&,
const BuildOpticalFlowPyramidTestParams&,
BuildOpticalFlowPyramidTestOutput&,
BuildOpticalFlowPyramidTestOutput&)
{
GAPI_Assert(0 && "This function shouldn't be called without opencv_video");
}
inline cv::GComputation runOCVnGAPIOptFlowLK(TestFunctional&,
std::vector<cv::Point2f>&,
const OptFlowLKTestParams&,
OptFlowLKTestOutput&,
OptFlowLKTestOutput&)
{
GAPI_Assert(0 && "This function shouldn't be called without opencv_video");
}
inline cv::GComputation runOCVnGAPIOptFlowLKForPyr(TestFunctional&,
OptFlowLKTestInput<std::vector<cv::Mat>>&,
const OptFlowLKTestParams&,
bool,
OptFlowLKTestOutput&,
OptFlowLKTestOutput&)
{
GAPI_Assert(0 && "This function shouldn't be called without opencv_video");
}
inline GComputation runOCVnGAPIOptFlowPipeline(TestFunctional&,
const BuildOpticalFlowPyramidTestParams&,
OptFlowLKTestOutput&,
OptFlowLKTestOutput&,
std::vector<Point2f>&)
{
GAPI_Assert(0 && "This function shouldn't be called without opencv_video");
}
#endif // HAVE_OPENCV_VIDEO
} // namespace
} // namespace opencv_test
// Note: namespace must match the namespace of the type of the printed object
namespace cv { namespace gapi { namespace video
{
inline std::ostream& operator<<(std::ostream& os, const BackgroundSubtractorType op)
{
#define CASE(v) case BackgroundSubtractorType::v: os << #v; break
switch (op)
{
CASE(TYPE_BS_MOG2);
CASE(TYPE_BS_KNN);
default: GAPI_Assert(false && "unknown BackgroundSubtractor type");
}
#undef CASE
return os;
}
}}} // namespace cv::gapi::video
#endif // OPENCV_GAPI_VIDEO_TESTS_COMMON_HPP

View File

@ -0,0 +1,323 @@
// 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) 2020 Intel Corporation
#ifndef OPENCV_GAPI_VIDEO_TESTS_INL_HPP
#define OPENCV_GAPI_VIDEO_TESTS_INL_HPP
#include "gapi_video_tests.hpp"
#include <opencv2/gapi/streaming/cap.hpp>
namespace opencv_test
{
TEST_P(BuildOptFlowPyramidTest, AccuracyTest)
{
std::vector<Mat> outPyrOCV, outPyrGAPI;
int outMaxLevelOCV = 0, outMaxLevelGAPI = 0;
BuildOpticalFlowPyramidTestParams params { fileName, winSize, maxLevel,
withDerivatives, pyrBorder, derivBorder,
tryReuseInputImage, getCompileArgs() };
BuildOpticalFlowPyramidTestOutput outOCV { outPyrOCV, outMaxLevelOCV };
BuildOpticalFlowPyramidTestOutput outGAPI { outPyrGAPI, outMaxLevelGAPI };
runOCVnGAPIBuildOptFlowPyramid(*this, params, outOCV, outGAPI);
compareOutputPyramids(outGAPI, outOCV);
}
TEST_P(OptFlowLKTest, AccuracyTest)
{
std::vector<cv::Point2f> outPtsOCV, outPtsGAPI, inPts;
std::vector<uchar> outStatusOCV, outStatusGAPI;
std::vector<float> outErrOCV, outErrGAPI;
OptFlowLKTestParams params { fileNamePattern, channels, pointsNum,
winSize, criteria, getCompileArgs() };
OptFlowLKTestOutput outOCV { outPtsOCV, outStatusOCV, outErrOCV };
OptFlowLKTestOutput outGAPI { outPtsGAPI, outStatusGAPI, outErrGAPI };
runOCVnGAPIOptFlowLK(*this, inPts, params, outOCV, outGAPI);
compareOutputsOptFlow(outGAPI, outOCV);
}
TEST_P(OptFlowLKTestForPyr, AccuracyTest)
{
std::vector<cv::Mat> inPyr1, inPyr2;
std::vector<cv::Point2f> outPtsOCV, outPtsGAPI, inPts;
std::vector<uchar> outStatusOCV, outStatusGAPI;
std::vector<float> outErrOCV, outErrGAPI;
OptFlowLKTestParams params { fileNamePattern, channels, pointsNum,
winSize, criteria, getCompileArgs() };
OptFlowLKTestInput<std::vector<cv::Mat>> in { inPyr1, inPyr2, inPts };
OptFlowLKTestOutput outOCV { outPtsOCV, outStatusOCV, outErrOCV };
OptFlowLKTestOutput outGAPI { outPtsGAPI, outStatusGAPI, outErrGAPI };
runOCVnGAPIOptFlowLKForPyr(*this, in, params, withDeriv, outOCV, outGAPI);
compareOutputsOptFlow(outGAPI, outOCV);
}
TEST_P(BuildPyr_CalcOptFlow_PipelineTest, AccuracyTest)
{
std::vector<Point2f> outPtsOCV, outPtsGAPI, inPts;
std::vector<uchar> outStatusOCV, outStatusGAPI;
std::vector<float> outErrOCV, outErrGAPI;
BuildOpticalFlowPyramidTestParams params { fileNamePattern, winSize, maxLevel,
withDerivatives, BORDER_DEFAULT, BORDER_DEFAULT,
true, getCompileArgs() };
auto customKernel = gapi::kernels<GCPUMinScalar>();
auto kernels = gapi::combine(customKernel,
params.compileArgs[0].get<gapi::GKernelPackage>());
params.compileArgs = compile_args(kernels);
OptFlowLKTestOutput outOCV { outPtsOCV, outStatusOCV, outErrOCV };
OptFlowLKTestOutput outGAPI { outPtsGAPI, outStatusGAPI, outErrGAPI };
runOCVnGAPIOptFlowPipeline(*this, params, outOCV, outGAPI, inPts);
compareOutputsOptFlow(outGAPI, outOCV);
}
#ifdef HAVE_OPENCV_VIDEO
TEST_P(BackgroundSubtractorTest, AccuracyTest)
{
initTestDataPath();
cv::gapi::video::BackgroundSubtractorType opType;
double thr = -1;
std::tie(opType, thr) = typeAndThreshold;
cv::gapi::video::BackgroundSubtractorParams bsp(opType, histLength, thr,
detectShadows, learningRate);
// G-API graph declaration
cv::GMat in;
cv::GMat out = cv::gapi::BackgroundSubtractor(in, bsp);
// Preserving 'in' in output to have possibility to compare with OpenCV reference
cv::GComputation c(cv::GIn(in), cv::GOut(cv::gapi::copy(in), out));
// G-API compilation of graph for streaming mode
auto gapiBackSub = c.compileStreaming(getCompileArgs());
// Testing G-API Background Substractor in streaming mode
const auto path = findDataFile(filePath);
try
{
gapiBackSub.setSource(gapi::wip::make_src<cv::gapi::wip::GCaptureSource>(path));
}
catch (...)
{ throw SkipTestException("Video file can't be opened."); }
cv::Ptr<cv::BackgroundSubtractor> pOCVBackSub;
if (opType == cv::gapi::video::TYPE_BS_MOG2)
pOCVBackSub = cv::createBackgroundSubtractorMOG2(histLength, thr,
detectShadows);
else if (opType == cv::gapi::video::TYPE_BS_KNN)
pOCVBackSub = cv::createBackgroundSubtractorKNN(histLength, thr,
detectShadows);
// Allowing 1% difference of all pixels between G-API and reference OpenCV results
testBackgroundSubtractorStreaming(gapiBackSub, pOCVBackSub, 1, 1, learningRate, testNumFrames);
}
TEST_P(KalmanFilterTest, AccuracyTest)
{
cv::gapi::KalmanParams kp;
initKalmanParams(type, dDim, mDim, cDim, kp);
// OpenCV reference KalmanFilter initialization
cv::KalmanFilter ocvKalman(dDim, mDim, cDim, type);
initKalmanFilter(kp, true, ocvKalman);
// measurement vector
cv::Mat measure_vec(mDim, 1, type);
// control vector
cv::Mat ctrl_vec = Mat::zeros(cDim > 0 ? cDim : 2, 1, type);
// G-API Kalman's output state
cv::Mat gapiKState(dDim, 1, type);
// OCV Kalman's output state
cv::Mat ocvKState(dDim, 1, type);
// G-API graph initialization
cv::GMat m, ctrl;
cv::GOpaque<bool> have_m;
cv::GMat out = cv::gapi::KalmanFilter(m, have_m, ctrl, kp);
cv::GComputation comp(cv::GIn(m, have_m, ctrl), cv::GOut(out));
cv::RNG& rng = cv::theRNG();
bool haveMeasure;
for (int i = 0; i < numIter; i++)
{
haveMeasure = (rng(2u) == 1); // returns 0 or 1 - whether we have measurement at this iteration or not
if (haveMeasure)
cv::randu(measure_vec, Scalar::all(-1), Scalar::all(1));
if (cDim > 0)
cv::randu(ctrl_vec, Scalar::all(-1), Scalar::all(1));
// G-API KalmanFilter call
comp.apply(cv::gin(measure_vec, haveMeasure, ctrl_vec), cv::gout(gapiKState));
// OpenCV KalmanFilter call
ocvKState = cDim > 0 ? ocvKalman.predict(ctrl_vec) : ocvKalman.predict();
if (haveMeasure)
ocvKState = ocvKalman.correct(measure_vec);
}
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_TRUE(AbsExact().to_compare_f()(gapiKState, ocvKState));
}
}
TEST_P(KalmanFilterNoControlTest, AccuracyTest)
{
cv::gapi::KalmanParams kp;
initKalmanParams(type, dDim, mDim, 0, kp);
// OpenCV reference KalmanFilter initialization
cv::KalmanFilter ocvKalman(dDim, mDim, 0, type);
initKalmanFilter(kp, false, ocvKalman);
// measurement vector
cv::Mat measure_vec(mDim, 1, type);
// G-API Kalman's output state
cv::Mat gapiKState(dDim, 1, type);
// OCV Kalman's output state
cv::Mat ocvKState(dDim, 1, type);
// G-API graph initialization
cv::GMat m;
cv::GOpaque<bool> have_m;
cv::GMat out = cv::gapi::KalmanFilter(m, have_m, kp);
cv::GComputation comp(cv::GIn(m, have_m), cv::GOut(out));
cv::RNG& rng = cv::theRNG();
bool haveMeasure;
for (int i = 0; i < numIter; i++)
{
haveMeasure = (rng(2u) == 1); // returns 0 or 1 - whether we have measurement at this iteration or not
if (haveMeasure)
cv::randu(measure_vec, Scalar::all(-1), Scalar::all(1));
// G-API
comp.apply(cv::gin(measure_vec, haveMeasure), cv::gout(gapiKState));
// OpenCV
ocvKState = ocvKalman.predict();
if (haveMeasure)
ocvKState = ocvKalman.correct(measure_vec);
}
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_TRUE(AbsExact().to_compare_f()(gapiKState, ocvKState));
}
}
TEST_P(KalmanFilterCircleSampleTest, AccuracyTest)
{
// auxiliary variables
cv::Mat processNoise(2, 1, type);
// Input measurement
cv::Mat measurement = Mat::zeros(1, 1, type);
// Angle and it's delta(phi, delta_phi)
cv::Mat state(2, 1, type);
// G-API graph initialization
cv::gapi::KalmanParams kp;
kp.state = Mat::zeros(2, 1, type);
cv::randn(kp.state, Scalar::all(0), Scalar::all(0.1));
kp.errorCov = Mat::eye(2, 2, type);
if (type == CV_32F)
kp.transitionMatrix = (Mat_<float>(2, 2) << 1, 1, 0, 1);
else
kp.transitionMatrix = (Mat_<double>(2, 2) << 1, 1, 0, 1);
kp.processNoiseCov = Mat::eye(2, 2, type) * (1e-5);
kp.measurementMatrix = Mat::eye(1, 2, type);
kp.measurementNoiseCov = Mat::eye(1, 1, type) * (1e-1);
cv::GMat m;
cv::GOpaque<bool> have_measure;
cv::GMat out = cv::gapi::KalmanFilter(m, have_measure, kp);
cv::GComputation comp(cv::GIn(m, have_measure), cv::GOut(out));
// OCV Kalman initialization
cv::KalmanFilter KF(2, 1, 0);
initKalmanFilter(kp, false, KF);
cv::randn(state, Scalar::all(0), Scalar::all(0.1));
// GAPI Corrected state
cv::Mat gapiState(2, 1, type);
// OCV Corrected state
cv::Mat ocvCorrState(2, 1, type);
// OCV Predicted state
cv::Mat ocvPreState(2, 1, type);
bool haveMeasure;
for (int i = 0; i < numIter; ++i)
{
// Get OCV Prediction
ocvPreState = KF.predict();
GAPI_DbgAssert(cv::norm(kp.measurementNoiseCov, KF.measurementNoiseCov, cv::NORM_INF) == 0);
// generation measurement
cv::randn(measurement, Scalar::all(0), Scalar::all((type == CV_32FC1) ?
kp.measurementNoiseCov.at<float>(0) : kp.measurementNoiseCov.at<double>(0)));
GAPI_DbgAssert(cv::norm(kp.measurementMatrix, KF.measurementMatrix, cv::NORM_INF) == 0);
measurement += kp.measurementMatrix*state;
if (cv::theRNG().uniform(0, 4) != 0)
{
haveMeasure = true;
ocvCorrState = KF.correct(measurement);
comp.apply(cv::gin(measurement, haveMeasure), cv::gout(gapiState));
EXPECT_TRUE(AbsExact().to_compare_f()(gapiState, ocvCorrState));
}
else
{
// Get GAPI Prediction
haveMeasure = false;
comp.apply(cv::gin(measurement, haveMeasure), cv::gout(gapiState));
EXPECT_TRUE(AbsExact().to_compare_f()(gapiState, ocvPreState));
}
GAPI_DbgAssert(cv::norm(kp.processNoiseCov, KF.processNoiseCov, cv::NORM_INF) == 0);
cv::randn(processNoise, Scalar(0), Scalar::all(sqrt(type == CV_32FC1 ?
kp.processNoiseCov.at<float>(0, 0):
kp.processNoiseCov.at<double>(0, 0))));
GAPI_DbgAssert(cv::norm(kp.transitionMatrix, KF.transitionMatrix, cv::NORM_INF) == 0);
state = kp.transitionMatrix*state + processNoise;
}
}
#endif
} // opencv_test
#endif // OPENCV_GAPI_VIDEO_TESTS_INL_HPP