Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/gapi/test/common/gapi_operators_tests_inl.hpp
16339 views
1
// This file is part of OpenCV project.
2
// It is subject to the license terms in the LICENSE file found in the top-level directory
3
// of this distribution and at http://opencv.org/license.html.
4
//
5
// Copyright (C) 2018 Intel Corporation
6
7
8
#ifndef OPENCV_GAPI_OPERATOR_TESTS_INL_COMMON_HPP
9
#define OPENCV_GAPI_OPERATOR_TESTS_INL_COMMON_HPP
10
11
#include "gapi_operators_tests.hpp"
12
13
namespace opencv_test
14
{
15
TEST_P(MathOperatorMatScalarTest, OperatorAccuracyTest )
16
{
17
g_api_ocv_pair_mat_scalar op;
18
int type = 0, dtype = 0;
19
cv::Size sz;
20
bool initOutMatr = false;
21
cv::GCompileArgs compile_args;
22
std::tie(op, type, sz, dtype, initOutMatr, compile_args) = GetParam();
23
initMatsRandU(type, sz, dtype, initOutMatr);
24
25
auto fun_gapi = op.g_api_function;
26
auto fun_ocv = op.ocv_function ;
27
28
// G-API code & corresponding OpenCV code ////////////////////////////////
29
30
cv::GMat in1;
31
cv::GScalar in2;
32
auto out = fun_gapi(in1, in2);
33
cv::GComputation c(GIn(in1, in2), GOut(out));
34
35
c.apply(gin(in_mat1, sc), gout(out_mat_gapi), std::move(compile_args));
36
37
fun_ocv(in_mat1, sc, out_mat_ocv);
38
39
// Comparison //////////////////////////////////////////////////////////////
40
{
41
EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv));
42
EXPECT_EQ(out_mat_gapi.size(), sz);
43
}
44
}
45
46
TEST_P(MathOperatorMatMatTest, OperatorAccuracyTest )
47
{
48
g_api_ocv_pair_mat_mat op;
49
int type = 0, dtype = 0;
50
cv::Size sz;
51
bool initOutMatr = false;
52
cv::GCompileArgs compile_args;
53
std::tie(op, type, sz, dtype, initOutMatr, compile_args) = GetParam();
54
initMatsRandU(type, sz, dtype, initOutMatr);
55
56
auto fun_gapi = op.g_api_function;
57
auto fun_ocv = op.ocv_function ;
58
59
// G-API code & corresponding OpenCV code ////////////////////////////////
60
61
cv::GMat in1;
62
cv::GMat in2;
63
auto out = fun_gapi(in1, in2);
64
cv::GComputation c(GIn(in1, in2), GOut(out));
65
66
c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args));
67
68
fun_ocv(in_mat1, in_mat2, out_mat_ocv);
69
70
// Comparison //////////////////////////////////////////////////////////////
71
{
72
EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv));
73
EXPECT_EQ(out_mat_gapi.size(), sz);
74
}
75
}
76
77
TEST_P(NotOperatorTest, OperatorAccuracyTest)
78
{
79
cv::Size sz_in = std::get<1>(GetParam());
80
initMatrixRandU(std::get<0>(GetParam()), sz_in, std::get<0>(GetParam()), std::get<2>(GetParam()));
81
cv::GCompileArgs compile_args;
82
83
// G-API code //////////////////////////////////////////////////////////////
84
cv::GMat in;
85
auto out = ~in;
86
cv::GComputation c(in, out);
87
88
c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
89
90
// OpenCV code /////////////////////////////////////////////////////////////
91
{
92
out_mat_ocv =~in_mat1;
93
}
94
// Comparison //////////////////////////////////////////////////////////////
95
{
96
EXPECT_EQ(0, cv::countNonZero(out_mat_ocv != out_mat_gapi));
97
EXPECT_EQ(out_mat_gapi.size(), sz_in);
98
}
99
}
100
} // opencv_test
101
102
#endif // OPENCV_GAPI_OPERATOR_TESTS_INL_COMMON_HPP
103
104