Path: blob/master/modules/gapi/test/common/gapi_operators_tests_inl.hpp
16339 views
// This file is part of OpenCV project.1// It is subject to the license terms in the LICENSE file found in the top-level directory2// of this distribution and at http://opencv.org/license.html.3//4// Copyright (C) 2018 Intel Corporation567#ifndef OPENCV_GAPI_OPERATOR_TESTS_INL_COMMON_HPP8#define OPENCV_GAPI_OPERATOR_TESTS_INL_COMMON_HPP910#include "gapi_operators_tests.hpp"1112namespace opencv_test13{14TEST_P(MathOperatorMatScalarTest, OperatorAccuracyTest )15{16g_api_ocv_pair_mat_scalar op;17int type = 0, dtype = 0;18cv::Size sz;19bool initOutMatr = false;20cv::GCompileArgs compile_args;21std::tie(op, type, sz, dtype, initOutMatr, compile_args) = GetParam();22initMatsRandU(type, sz, dtype, initOutMatr);2324auto fun_gapi = op.g_api_function;25auto fun_ocv = op.ocv_function ;2627// G-API code & corresponding OpenCV code ////////////////////////////////2829cv::GMat in1;30cv::GScalar in2;31auto out = fun_gapi(in1, in2);32cv::GComputation c(GIn(in1, in2), GOut(out));3334c.apply(gin(in_mat1, sc), gout(out_mat_gapi), std::move(compile_args));3536fun_ocv(in_mat1, sc, out_mat_ocv);3738// Comparison //////////////////////////////////////////////////////////////39{40EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv));41EXPECT_EQ(out_mat_gapi.size(), sz);42}43}4445TEST_P(MathOperatorMatMatTest, OperatorAccuracyTest )46{47g_api_ocv_pair_mat_mat op;48int type = 0, dtype = 0;49cv::Size sz;50bool initOutMatr = false;51cv::GCompileArgs compile_args;52std::tie(op, type, sz, dtype, initOutMatr, compile_args) = GetParam();53initMatsRandU(type, sz, dtype, initOutMatr);5455auto fun_gapi = op.g_api_function;56auto fun_ocv = op.ocv_function ;5758// G-API code & corresponding OpenCV code ////////////////////////////////5960cv::GMat in1;61cv::GMat in2;62auto out = fun_gapi(in1, in2);63cv::GComputation c(GIn(in1, in2), GOut(out));6465c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args));6667fun_ocv(in_mat1, in_mat2, out_mat_ocv);6869// Comparison //////////////////////////////////////////////////////////////70{71EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv));72EXPECT_EQ(out_mat_gapi.size(), sz);73}74}7576TEST_P(NotOperatorTest, OperatorAccuracyTest)77{78cv::Size sz_in = std::get<1>(GetParam());79initMatrixRandU(std::get<0>(GetParam()), sz_in, std::get<0>(GetParam()), std::get<2>(GetParam()));80cv::GCompileArgs compile_args;8182// G-API code //////////////////////////////////////////////////////////////83cv::GMat in;84auto out = ~in;85cv::GComputation c(in, out);8687c.apply(in_mat1, out_mat_gapi, std::move(compile_args));8889// OpenCV code /////////////////////////////////////////////////////////////90{91out_mat_ocv =~in_mat1;92}93// Comparison //////////////////////////////////////////////////////////////94{95EXPECT_EQ(0, cv::countNonZero(out_mat_ocv != out_mat_gapi));96EXPECT_EQ(out_mat_gapi.size(), sz_in);97}98}99} // opencv_test100101#endif // OPENCV_GAPI_OPERATOR_TESTS_INL_COMMON_HPP102103104