Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / fluid / modules / gapi / test / common / gapi_operators_tests_inl.hpp
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-2019 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     compare_f cmpF;
18     g_api_ocv_pair_mat_scalar op;
19     int type = 0, dtype = 0;
20     cv::Size sz;
21     bool initOutMatr = false;
22     cv::GCompileArgs compile_args;
23     std::tie(cmpF, op, type, sz, dtype, initOutMatr, compile_args) = GetParam();
24     initMatsRandU(type, sz, dtype, initOutMatr);
25
26     auto fun_gapi = op.g_api_function;
27     auto fun_ocv = op.ocv_function ;
28
29     // G-API code & corresponding OpenCV code ////////////////////////////////
30
31     cv::GMat in1;
32     cv::GScalar in2;
33     auto out = fun_gapi(in1, in2);
34     cv::GComputation c(GIn(in1, in2), GOut(out));
35
36     c.apply(gin(in_mat1, sc), gout(out_mat_gapi), std::move(compile_args));
37
38     fun_ocv(in_mat1, sc, out_mat_ocv);
39
40     // Comparison //////////////////////////////////////////////////////////////
41     {
42         EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
43         EXPECT_EQ(out_mat_gapi.size(), sz);
44     }
45 }
46
47 TEST_P(MathOperatorMatMatTest, OperatorAccuracyTest )
48 {
49     compare_f cmpF;
50     g_api_ocv_pair_mat_mat op;
51     int type = 0, dtype = 0;
52     cv::Size sz;
53     bool initOutMatr = false;
54     cv::GCompileArgs compile_args;
55     std::tie(cmpF, op, type, sz, dtype, initOutMatr, compile_args) = GetParam();
56     initMatsRandU(type, sz, dtype, initOutMatr);
57
58     auto fun_gapi = op.g_api_function;
59     auto fun_ocv = op.ocv_function ;
60
61     // G-API code & corresponding OpenCV code ////////////////////////////////
62
63     cv::GMat in1;
64     cv::GMat in2;
65     auto out = fun_gapi(in1, in2);
66     cv::GComputation c(GIn(in1, in2), GOut(out));
67
68     c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args));
69
70     fun_ocv(in_mat1, in_mat2, out_mat_ocv);
71
72     // Comparison //////////////////////////////////////////////////////////////
73     {
74         EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
75         EXPECT_EQ(out_mat_gapi.size(), sz);
76     }
77 }
78
79 TEST_P(NotOperatorTest, OperatorAccuracyTest)
80 {
81     cv::Size sz_in = std::get<1>(GetParam());
82     initMatrixRandU(std::get<0>(GetParam()), sz_in, std::get<0>(GetParam()), std::get<2>(GetParam()));
83     cv::GCompileArgs compile_args;
84
85     // G-API code //////////////////////////////////////////////////////////////
86     cv::GMat in;
87     auto out = ~in;
88     cv::GComputation c(in, out);
89
90     c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
91
92     // OpenCV code /////////////////////////////////////////////////////////////
93     {
94         out_mat_ocv =~in_mat1;
95     }
96     // Comparison //////////////////////////////////////////////////////////////
97     {
98         EXPECT_EQ(0, cv::countNonZero(out_mat_ocv != out_mat_gapi));
99         EXPECT_EQ(out_mat_gapi.size(), sz_in);
100     }
101 }
102 } // opencv_test
103
104 #endif // OPENCV_GAPI_OPERATOR_TESTS_INL_COMMON_HPP