@ -8,6 +8,9 @@
# include "test_precomp.hpp"
# include "test_precomp.hpp"
# include "opencv2/gapi/gtransform.hpp"
# include "opencv2/gapi/gtransform.hpp"
# include "opencv2/gapi/gtype_traits.hpp"
// explicit include to use GComputation::Priv
# include "api/gcomputation_priv.hpp"
namespace opencv_test
namespace opencv_test
{
{
@ -68,6 +71,12 @@ GAPI_TRANSFORM(gmat_in_garr_out, <GArray<int>(GMat)>, "gmat_in_garr_out")
static GArray < int > substitute ( GMat ) { return { } ; }
static GArray < int > substitute ( GMat ) { return { } ; }
} ;
} ;
GAPI_TRANSFORM ( gmat_gsc_garray_in_gmat2_out , < GMat2 ( GMat , GScalar , GArray < int > ) > , " gmat_gsc_garray_in_gmat2_out " )
{
static GMat2 pattern ( GMat , GScalar , GArray < int > ) { return { } ; }
static GMat2 substitute ( GMat , GScalar , GArray < int > ) { return { } ; }
} ;
} // anonymous namespace
} // anonymous namespace
TEST ( KernelPackageTransform , CreatePackage )
TEST ( KernelPackageTransform , CreatePackage )
@ -76,12 +85,16 @@ TEST(KernelPackageTransform, CreatePackage)
< gmat_in_gmat_out
< gmat_in_gmat_out
, gmat2_in_gmat_out
, gmat2_in_gmat_out
, gmat2_in_gmat3_out
, gmat2_in_gmat3_out
, gmatp_in_gmatp_out
, gsc_in_gmat_out
, gsc_in_gmat_out
, gmat_in_gsc_out
, gmat_in_gsc_out
, garr_in_gmat_out
, gmat_in_garr_out
, gmat_gsc_garray_in_gmat2_out
> ( ) ;
> ( ) ;
auto tr = pkg . get_transformations ( ) ;
auto tr = pkg . get_transformations ( ) ;
EXPECT_EQ ( 5 u, tr . size ( ) ) ;
EXPECT_EQ ( 9 u, tr . size ( ) ) ;
}
}
TEST ( KernelPackageTransform , Include )
TEST ( KernelPackageTransform , Include )
@ -103,81 +116,74 @@ TEST(KernelPackageTransform, Combine)
EXPECT_EQ ( 2u , tr . size ( ) ) ;
EXPECT_EQ ( 2u , tr . size ( ) ) ;
}
}
TEST ( KernelPackageTransform , Pattern )
namespace {
{
template < typename T >
auto tr = gmat2_in_gmat3_out : : transformation ( ) ;
inline bool ProtoContainsT ( const cv : : GProtoArg & arg ) {
GMat a , b ;
return cv : : GProtoArg : : index_of < T > ( ) = = arg . index ( ) ;
auto pattern = tr . pattern ( { cv : : GArg ( a ) , cv : : GArg ( b ) } ) ;
// return type of '2gmat_in_gmat3_out' is GMat3
EXPECT_EQ ( 3u , pattern . size ( ) ) ;
for ( const auto & p : pattern )
{
EXPECT_NO_THROW ( p . get < GMat > ( ) ) ;
}
}
}
} // anonymous namespace
TEST ( KernelPackageTransform , Substitute )
TEST ( KernelPackageTransform , gmat_gsc_in_gmat_out )
{
{
auto tr = gmat2_in_gmat3_out : : transformation ( ) ;
auto tr = gmat_gsc_garray_in_gmat2_out : : transformation ( ) ;
GMat a , b ;
auto subst = tr . substitute ( { cv : : GArg ( a ) , cv : : GArg ( b ) } ) ;
EXPECT_EQ ( 3u , subst . size ( ) ) ;
auto check = [ ] ( const cv : : GComputation & comp ) {
for ( const auto & s : subst )
const auto & p = comp . priv ( ) ;
{
EXPECT_EQ ( 3u , p . m_ins . size ( ) ) ;
EXPECT_NO_THROW ( s . get < GMat > ( ) ) ;
EXPECT_EQ ( 2u , p . m_outs . size ( ) ) ;
}
}
template < typename Transformation , typename InType , typename OutType >
static void transformTest ( )
{
auto tr = Transformation : : transformation ( ) ;
InType in ;
auto pattern = tr . pattern ( { cv : : GArg ( in ) } ) ;
auto subst = tr . substitute ( { cv : : GArg ( in ) } ) ;
EXPECT_EQ ( 1u , pattern . size ( ) ) ;
EXPECT_TRUE ( ProtoContainsT < GMat > ( p . m_ins [ 0 ] ) ) ;
EXPECT_EQ ( 1u , subst . size ( ) ) ;
EXPECT_TRUE ( ProtoContainsT < GScalar > ( p . m_ins [ 1 ] ) ) ;
EXPECT_TRUE ( ProtoContainsT < cv : : detail : : GArrayU > ( p . m_ins [ 2 ] ) ) ;
EXPECT_TRUE ( cv : : util : : get < cv : : detail : : GArrayU > ( p . m_ins [ 2 ] ) . holds < int > ( ) ) ;
EXPECT_FALSE ( cv : : util : : get < cv : : detail : : GArrayU > ( p . m_ins [ 2 ] ) . holds < char > ( ) ) ;
auto checkOut = [ ] ( GArg & garg ) {
EXPECT_TRUE ( ProtoContainsT < GMat > ( p . m_outs [ 0 ] ) ) ;
EXPECT_TRUE ( garg . kind = = cv : : detail : : GTypeTraits < OutType > : : kind ) ;
EXPECT_TRUE ( ProtoContainsT < GMat > ( p . m_outs [ 1 ] ) ) ;
EXPECT_NO_THROW ( garg . get < OutType > ( ) ) ;
} ;
} ;
checkOut ( pattern [ 0 ] ) ;
check ( tr . pattern ( ) ) ;
checkOut ( subst [ 0 ] ) ;
check ( tr . substitute ( ) ) ;
}
}
TEST ( KernelPackageTransform , GMa t)
TEST ( KernelPackageTransform , gmat_in_garr_ou t)
{
{
transformTest < gmat_in_gmat_out , GMat , GMat > ( ) ;
auto tr = gmat_in_garr_out : : transformation ( ) ;
}
TEST ( KernelPackageTransform , GMatP )
auto check = [ ] ( const cv : : GComputation & comp ) {
{
const auto & p = comp . priv ( ) ;
transformTest < gmatp_in_gmatp_out , GMatP , GMatP > ( ) ;
EXPECT_EQ ( 1u , p . m_ins . size ( ) ) ;
}
EXPECT_EQ ( 1u , p . m_outs . size ( ) ) ;
TEST ( KernelPackageTransform , GScalarIn )
EXPECT_TRUE ( ProtoContainsT < GMat > ( p . m_ins [ 0 ] ) ) ;
{
transformTest < gsc_in_gmat_out , GScalar , GMat > ( ) ;
}
TEST ( KernelPackageTransform , GScalarOut )
EXPECT_TRUE ( ProtoContainsT < cv : : detail : : GArrayU > ( p . m_outs [ 0 ] ) ) ;
{
EXPECT_TRUE ( cv : : util : : get < cv : : detail : : GArrayU > ( p . m_outs [ 0 ] ) . holds < int > ( ) ) ;
transformTest < gmat_in_gsc_out , GMat , GScalar > ( ) ;
EXPECT_FALSE ( cv : : util : : get < cv : : detail : : GArrayU > ( p . m_outs [ 0 ] ) . holds < float > ( ) ) ;
}
} ;
TEST ( KernelPackageTransform , DISABLED_GArrayIn )
check ( tr . pattern ( ) ) ;
{
check ( tr . substitute ( ) ) ;
transformTest < garr_in_gmat_out , GArray < int > , GMat > ( ) ;
}
}
TEST ( KernelPackageTransform , DISABLED_GArrayO ut)
TEST ( KernelPackageTransform , garr_in_gmat_o ut)
{
{
transformTest < gmat_in_garr_out , GMat , GArray < int > > ( ) ;
auto tr = garr_in_gmat_out : : transformation ( ) ;
auto check = [ ] ( const cv : : GComputation & comp ) {
const auto & p = comp . priv ( ) ;
EXPECT_EQ ( 1u , p . m_ins . size ( ) ) ;
EXPECT_EQ ( 1u , p . m_outs . size ( ) ) ;
EXPECT_TRUE ( ProtoContainsT < cv : : detail : : GArrayU > ( p . m_ins [ 0 ] ) ) ;
EXPECT_TRUE ( cv : : util : : get < cv : : detail : : GArrayU > ( p . m_ins [ 0 ] ) . holds < int > ( ) ) ;
EXPECT_FALSE ( cv : : util : : get < cv : : detail : : GArrayU > ( p . m_ins [ 0 ] ) . holds < bool > ( ) ) ;
EXPECT_TRUE ( ProtoContainsT < GMat > ( p . m_outs [ 0 ] ) ) ;
} ;
check ( tr . pattern ( ) ) ;
check ( tr . substitute ( ) ) ;
}
}
} // namespace opencv_test
} // namespace opencv_test