@ -681,10 +681,11 @@ TEST_P(AbsDiffCTest, AccuracyTest)
TEST_P ( SumTest , AccuracyTest )
TEST_P ( SumTest , AccuracyTest )
{
{
auto param = GetParam ( ) ;
auto param = GetParam ( ) ;
compare_scalar_f cmpF = get < 3 > ( GetParam ( ) ) ;
MatType type = std : : get < 0 > ( param ) ;
cv : : Size sz_in = std : : get < 1 > ( param ) ;
cv : : Size sz_in = std : : get < 1 > ( param ) ;
auto tolerance = std : : get < 3 > ( param ) ;
auto compile_args = std : : get < 4 > ( param ) ;
auto compile_args = std : : get < 4 > ( param ) ;
initMatrixRandU ( std : : get < 0 > ( param ) , sz_in , std : : get < 2 > ( param ) ) ;
initMatrixRandU ( type , sz_in , type , std : : get < 2 > ( param ) ) ;
cv : : Scalar out_sum ;
cv : : Scalar out_sum ;
@ -702,8 +703,7 @@ TEST_P(SumTest, AccuracyTest)
}
}
// Comparison //////////////////////////////////////////////////////////////
// Comparison //////////////////////////////////////////////////////////////
{
{
EXPECT_LE ( std : : abs ( out_sum [ 0 ] - out_sum_ocv [ 0 ] ) / std : : max ( 1.0 , std : : abs ( out_sum_ocv [ 0 ] ) ) , tolerance )
EXPECT_TRUE ( cmpF ( out_sum , out_sum_ocv ) ) ;
< < " OCV= " < < out_sum_ocv [ 0 ] < < " GAPI= " < < out_sum [ 0 ] ;
}
}
}
}
@ -713,8 +713,8 @@ TEST_P(AddWeightedTest, AccuracyTest)
cv : : Size sz_in ;
cv : : Size sz_in ;
bool initOut = false ;
bool initOut = false ;
cv : : GCompileArgs compile_args ;
cv : : GCompileArgs compile_args ;
double tolerance = 0.0 ;
compare_f cmpF ;
std : : tie ( type , sz_in , dtype , initOut , tolerance , compile_args ) = GetParam ( ) ;
std : : tie ( type , sz_in , dtype , initOut , cmpF , compile_args ) = GetParam ( ) ;
auto & rng = cv : : theRNG ( ) ;
auto & rng = cv : : theRNG ( ) ;
double alpha = rng . uniform ( 0.0 , 1.0 ) ;
double alpha = rng . uniform ( 0.0 , 1.0 ) ;
@ -734,53 +734,19 @@ TEST_P(AddWeightedTest, AccuracyTest)
cv : : addWeighted ( in_mat1 , alpha , in_mat2 , beta , gamma , out_mat_ocv , dtype ) ;
cv : : addWeighted ( in_mat1 , alpha , in_mat2 , beta , gamma , out_mat_ocv , dtype ) ;
}
}
// Comparison //////////////////////////////////////////////////////////////
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_TRUE ( cmpF ( out_mat_gapi , out_mat_ocv ) ) ;
// Note, that we cannot expect bitwise results for add-weighted:
EXPECT_EQ ( out_mat_gapi . size ( ) , sz_in ) ;
//
// tmp = src1*alpha + src2*beta + gamma;
// dst = saturate<DST>( round(tmp) );
//
// Because tmp is floating-point, dst depends on compiler optimizations
//
// However, we must expect good accuracy of tmp, and rounding correctly
cv : : Mat failures ;
if ( out_mat_ocv . type ( ) = = CV_32FC1 )
{
// result: float - may vary in 7th decimal digit
failures = abs ( out_mat_gapi - out_mat_ocv ) > abs ( out_mat_ocv ) * 1e-6 ;
}
else
{
// result: integral - rounding may vary if fractional part of tmp
// is nearly 0.5
cv : : Mat inexact , incorrect , diff , tmp ;
inexact = out_mat_gapi ! = out_mat_ocv ;
// even if rounded differently, check if still rounded correctly
cv : : addWeighted ( in_mat1 , alpha , in_mat2 , beta , gamma , tmp , CV_32F ) ;
cv : : subtract ( out_mat_gapi , tmp , diff , cv : : noArray ( ) , CV_32F ) ;
incorrect = abs ( diff ) > = tolerance ; // 0.5000005f; // relative to 6 digits
failures = inexact & incorrect ;
}
EXPECT_EQ ( 0 , cv : : countNonZero ( failures ) ) ;
EXPECT_EQ ( out_mat_gapi . size ( ) , sz_in ) ;
}
}
}
TEST_P ( NormTest , AccuracyTest )
TEST_P ( NormTest , AccuracyTest )
{
{
compare_scalar_f cmpF ;
NormTypes opType = NORM_INF ;
NormTypes opType = NORM_INF ;
int type = 0 ;
int type = 0 ;
cv : : Size sz ;
cv : : Size sz ;
double tolerance = 0.0 ;
cv : : GCompileArgs compile_args ;
cv : : GCompileArgs compile_args ;
std : : tie ( opType , type , sz , tolerance , compile_args ) = GetParam ( ) ;
std : : tie ( opType , type , sz , cmpF , compile_args ) = GetParam ( ) ;
initMatrixRandU ( type , sz , type , false ) ;
initMatrixRandU ( type , sz , type , false ) ;
cv : : Scalar out_norm ;
cv : : Scalar out_norm ;
@ -802,8 +768,7 @@ TEST_P(NormTest, AccuracyTest)
// Comparison //////////////////////////////////////////////////////////////
// Comparison //////////////////////////////////////////////////////////////
{
{
EXPECT_LE ( std : : abs ( out_norm [ 0 ] - out_norm_ocv [ 0 ] ) / std : : max ( 1.0 , std : : abs ( out_norm_ocv [ 0 ] ) ) , tolerance )
EXPECT_TRUE ( cmpF ( out_norm , out_norm_ocv ) ) ;
< < " OCV= " < < out_norm_ocv [ 0 ] < < " GAPI= " < < out_norm [ 0 ] ;
}
}
}
}