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.
5 // Copyright (C) 2018-2019 Intel Corporation
8 #ifndef OPENCV_GAPI_OPERATOR_TESTS_INL_COMMON_HPP
9 #define OPENCV_GAPI_OPERATOR_TESTS_INL_COMMON_HPP
11 #include "gapi_operators_tests.hpp"
15 TEST_P(MathOperatorMatScalarTest, OperatorAccuracyTest )
18 g_api_ocv_pair_mat_scalar op;
19 int type = 0, dtype = 0;
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);
26 auto fun_gapi = op.g_api_function;
27 auto fun_ocv = op.ocv_function ;
29 // G-API code & corresponding OpenCV code ////////////////////////////////
33 auto out = fun_gapi(in1, in2);
34 cv::GComputation c(GIn(in1, in2), GOut(out));
36 c.apply(gin(in_mat1, sc), gout(out_mat_gapi), std::move(compile_args));
38 fun_ocv(in_mat1, sc, out_mat_ocv);
40 // Comparison //////////////////////////////////////////////////////////////
42 EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
43 EXPECT_EQ(out_mat_gapi.size(), sz);
47 TEST_P(MathOperatorMatMatTest, OperatorAccuracyTest )
50 g_api_ocv_pair_mat_mat op;
51 int type = 0, dtype = 0;
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);
58 auto fun_gapi = op.g_api_function;
59 auto fun_ocv = op.ocv_function ;
61 // G-API code & corresponding OpenCV code ////////////////////////////////
65 auto out = fun_gapi(in1, in2);
66 cv::GComputation c(GIn(in1, in2), GOut(out));
68 c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args));
70 fun_ocv(in_mat1, in_mat2, out_mat_ocv);
72 // Comparison //////////////////////////////////////////////////////////////
74 EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
75 EXPECT_EQ(out_mat_gapi.size(), sz);
79 TEST_P(NotOperatorTest, OperatorAccuracyTest)
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;
85 // G-API code //////////////////////////////////////////////////////////////
88 cv::GComputation c(in, out);
90 c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
92 // OpenCV code /////////////////////////////////////////////////////////////
94 out_mat_ocv =~in_mat1;
96 // Comparison //////////////////////////////////////////////////////////////
98 EXPECT_EQ(0, cv::countNonZero(out_mat_ocv != out_mat_gapi));
99 EXPECT_EQ(out_mat_gapi.size(), sz_in);
104 #endif // OPENCV_GAPI_OPERATOR_TESTS_INL_COMMON_HPP