Path: blob/master/modules/gapi/test/gapi_gcompiled_tests.cpp
16337 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#include "test_precomp.hpp"89namespace opencv_test10{1112namespace13{14static cv::GMat DemoCC(cv::GMat in, cv::GScalar scale)15{16return cv::gapi::medianBlur(in + in*scale, 3);17}1819struct GCompiledValidateMetaTyped: public ::testing::Test20{21cv::GComputationT<cv::GMat(cv::GMat,cv::GScalar)> m_cc;2223GCompiledValidateMetaTyped() : m_cc(DemoCC)24{25}26};2728struct GCompiledValidateMetaUntyped: public ::testing::Test29{30cv::GMat in;31cv::GScalar scale;32cv::GComputation m_ucc;3334GCompiledValidateMetaUntyped() : m_ucc(cv::GIn(in, scale),35cv::GOut(DemoCC(in, scale)))36{37}38};39} // anonymous namespace4041TEST_F(GCompiledValidateMetaTyped, ValidMeta)42{43cv::Mat in = cv::Mat::eye(cv::Size(128, 32), CV_8UC1);44cv::Scalar sc(127);4546auto f = m_cc.compile(cv::descr_of(in),47cv::descr_of(sc));4849// Correct operation when meta is exactly the same50cv::Mat out;51EXPECT_NO_THROW(f(in, sc, out));5253// Correct operation on next invocation with same meta54// taken from different input objects55cv::Mat in2 = cv::Mat::zeros(cv::Size(128, 32), CV_8UC1);56cv::Scalar sc2(64);57cv::Mat out2;58EXPECT_NO_THROW(f(in2, sc2, out2));59}6061TEST_F(GCompiledValidateMetaTyped, InvalidMeta)62{63auto f = m_cc.compile(cv::GMatDesc{CV_8U,1,cv::gapi::own::Size(64,32)},64cv::empty_scalar_desc());6566cv::Scalar sc(33);67cv::Mat out;6869// 3 channels intead 170cv::Mat in1 = cv::Mat::eye(cv::Size(64,32), CV_8UC3);71EXPECT_THROW(f(in1, sc, out), std::logic_error);7273// 32f intead 8u74cv::Mat in2 = cv::Mat::eye(cv::Size(64,32), CV_32F);75EXPECT_THROW(f(in2, sc, out), std::logic_error);7677// 32x32 instead of 64x3278cv::Mat in3 = cv::Mat::eye(cv::Size(32,32), CV_8UC1);79EXPECT_THROW(f(in3, sc, out), std::logic_error);8081// All is wrong82cv::Mat in4 = cv::Mat::eye(cv::Size(128,64), CV_32FC3);83EXPECT_THROW(f(in4, sc, out), std::logic_error);84}8586TEST_F(GCompiledValidateMetaUntyped, ValidMeta)87{88cv::Mat in1 = cv::Mat::eye(cv::Size(128, 32), CV_8UC1);89cv::Scalar sc(127);9091auto f = m_ucc.compile(cv::descr_of(in1),92cv::descr_of(sc));9394// Correct operation when meta is exactly the same95cv::Mat out1;96EXPECT_NO_THROW(f(cv::gin(in1, sc), cv::gout(out1)));9798// Correct operation on next invocation with same meta99// taken from different input objects100cv::Mat in2 = cv::Mat::zeros(cv::Size(128, 32), CV_8UC1);101cv::Scalar sc2(64);102cv::Mat out2;103EXPECT_NO_THROW(f(cv::gin(in2, sc2), cv::gout(out2)));104}105106TEST_F(GCompiledValidateMetaUntyped, InvalidMetaValues)107{108auto f = m_ucc.compile(cv::GMatDesc{CV_8U,1,cv::gapi::own::Size(64,32)},109cv::empty_scalar_desc());110111cv::Scalar sc(33);112cv::Mat out;113114// 3 channels intead 1115cv::Mat in1 = cv::Mat::eye(cv::Size(64,32), CV_8UC3);116EXPECT_THROW(f(cv::gin(in1, sc), cv::gout(out)), std::logic_error);117118// 32f intead 8u119cv::Mat in2 = cv::Mat::eye(cv::Size(64,32), CV_32F);120EXPECT_THROW(f(cv::gin(in2, sc), cv::gout(out)), std::logic_error);121122// 32x32 instead of 64x32123cv::Mat in3 = cv::Mat::eye(cv::Size(32,32), CV_8UC1);124EXPECT_THROW(f(cv::gin(in3, sc), cv::gout(out)), std::logic_error);125126// All is wrong127cv::Mat in4 = cv::Mat::eye(cv::Size(128,64), CV_32FC3);128EXPECT_THROW(f(cv::gin(in4, sc), cv::gout(out)), std::logic_error);129}130131TEST_F(GCompiledValidateMetaUntyped, InvalidMetaShape)132{133auto f = m_ucc.compile(cv::GMatDesc{CV_8U,1,cv::gapi::own::Size(64,32)},134cv::empty_scalar_desc());135136cv::Mat in1 = cv::Mat::eye(cv::Size(64,32), CV_8UC1);137cv::Scalar sc(33);138cv::Mat out1;139140// call as f(Mat,Mat) while f(Mat,Scalar) is expected141EXPECT_THROW(f(cv::gin(in1, in1), cv::gout(out1)), std::logic_error);142143// call as f(Scalar,Mat) while f(Mat,Scalar) is expected144EXPECT_THROW(f(cv::gin(sc, in1), cv::gout(out1)), std::logic_error);145146// call as f(Scalar,Scalar) while f(Mat,Scalar) is expected147EXPECT_THROW(f(cv::gin(sc, sc), cv::gout(out1)), std::logic_error);148}149150TEST_F(GCompiledValidateMetaUntyped, InvalidMetaNumber)151{152auto f = m_ucc.compile(cv::GMatDesc{CV_8U,1,cv::Size(64,32)},153cv::empty_scalar_desc());154155cv::Mat in1 = cv::Mat::eye(cv::Size(64,32), CV_8UC1);156cv::Scalar sc(33);157cv::Mat out1, out2;158159// call as f(Mat,Scalar,Scalar) while f(Mat,Scalar) is expected160EXPECT_THROW(f(cv::gin(in1, sc, sc), cv::gout(out1)), std::logic_error);161162// call as f(Scalar,Mat,Scalar) while f(Mat,Scalar) is expected163EXPECT_THROW(f(cv::gin(sc, in1, sc), cv::gout(out1)), std::logic_error);164165// call as f(Scalar) while f(Mat,Scalar) is expected166EXPECT_THROW(f(cv::gin(sc), cv::gout(out1)), std::logic_error);167168// call as f(Mat,Scalar,[out1],[out2]) while f(Mat,Scalar,[out]) is expected169EXPECT_THROW(f(cv::gin(in1, sc), cv::gout(out1, out2)), std::logic_error);170}171172} // namespace opencv_test173174175