From: vp153 Date: Mon, 5 Apr 2010 09:40:33 +0000 (+0000) Subject: round scalars in the case of integer arrays in adds, subrs and absdiffs tests (will... X-Git-Url: https://rtime.felk.cvut.cz/gitweb/opencv.git/commitdiff_plain/d610368eada1a7988cee462dcde6bef639d941b1?hp=73a005f734797083326660fb02b6eae18ee7799c round scalars in the case of integer arrays in adds, subrs and absdiffs tests (will probably fix some failures in cxcoretest). added "-seed "<16-digit seed>" option to the test engine to reproduce failures more easily git-svn-id: https://code.ros.org/svn/opencv/trunk@2981 73c94f0f-984f-4a5f-82bc-2d8db8d8ee08 --- diff --git a/opencv/tests/cxcore/src/aarithm.cpp b/opencv/tests/cxcore/src/aarithm.cpp index ab77f838..844a46bc 100644 --- a/opencv/tests/cxcore/src/aarithm.cpp +++ b/opencv/tests/cxcore/src/aarithm.cpp @@ -65,6 +65,7 @@ protected: void get_timing_test_array_types_and_sizes( int /*test_case_idx*/, CvSize** sizes, int** types, CvSize** whole_sizes, bool *are_images ); void generate_scalars( int depth ); + void finalize_scalar( CvScalar& s ); CvScalar alpha, beta, gamma; int gen_scalars; bool calc_abs; @@ -170,6 +171,13 @@ void CxCore_ArithmTestImpl::generate_scalars( int depth ) } } +void CxCore_ArithmTestImpl::finalize_scalar( CvScalar& s ) +{ + int depth = CV_MAT_DEPTH(test_mat[INPUT][0].type); + if( depth < CV_32F ) + s = cvScalar(cvRound(s.val[0]), cvRound(s.val[1]), cvRound(s.val[2]), cvRound(s.val[3])); +} + void CxCore_ArithmTestImpl::get_test_array_types_and_sizes( int test_case_idx, CvSize** sizes, int** types ) { @@ -338,6 +346,7 @@ CxCore_AddSTest::CxCore_AddSTest() void CxCore_AddSTest::run_func() { + finalize_scalar(gamma); if(!test_nd) { if( test_mat[INPUT][0].cols % 2 == 0 ) @@ -381,6 +390,7 @@ CxCore_SubRSTest::CxCore_SubRSTest() void CxCore_SubRSTest::run_func() { + finalize_scalar(gamma); if(!test_nd) { cvSubRS( test_array[INPUT][0], gamma, @@ -517,6 +527,7 @@ CxCore_AbsDiffSTest::CxCore_AbsDiffSTest() void CxCore_AbsDiffSTest::run_func() { + finalize_scalar(gamma); if(!test_nd) { cvAbsDiffS( test_array[INPUT][0], test_array[OUTPUT][0], gamma ); diff --git a/opencv/tests/cxts/cxts.cpp b/opencv/tests/cxts/cxts.cpp index c94805da..b160ac7f 100644 --- a/opencv/tests/cxts/cxts.cpp +++ b/opencv/tests/cxts/cxts.cpp @@ -169,6 +169,26 @@ static void change_color( int color ) #endif + +// reads 16-digit hexadecimal number (i.e. 64-bit integer) +static int64 read_seed( const char* str ) +{ + int64 val = 0; + if( str && strlen(str) == 16 ) + { + for( int i = 0; str[i]; i++ ) + { + int c = tolower(str[i]); + if( !isxdigit(c) ) + return 0; + val = val * 16 + + (str[i] < 'a' ? str[i] - '0' : str[i] - 'a' + 10); + } + } + return val; +} + + /***************************** memory manager *****************************/ typedef struct CvTestAllocBlock @@ -1076,7 +1096,7 @@ void CvTS::clear() free( ostrm_base_name ); ostrm_base_name = 0; } - params.rng_seed = (uint64)-1; + params.rng_seed = 0; params.debug_mode = -1; params.print_only_failed = 0; params.skip_header = 0; @@ -1333,6 +1353,12 @@ int CvTS::run( int argc, char** argv ) params.test_filter_pattern = argv[++i]; params.test_filter_mode = CHOOSE_TESTS; } + else if( strcmp( argv[i], "-seed" ) == 0 ) + { + params.rng_seed = read_seed(argv[++i]); + if( params.rng_seed == 0 ) + fprintf(stderr, "Invalid or zero RNG seed. Will use the seed from the config file or default one\n"); + } } #if 0 @@ -1630,22 +1656,8 @@ int CvTS::read_params( CvFileStorage* fs ) if( params.test_case_count_scale <= 0 ) params.test_case_count_scale = 1.; str = cvReadStringByName( fs, node, "seed", 0 ); - params.rng_seed = 0; - if( str && strlen(str) == 16 ) - { - params.rng_seed = 0; - for( int i = 0; i < 16; i++ ) - { - int c = tolower(str[i]); - if( !isxdigit(c) ) - { - params.rng_seed = 0; - break; - } - params.rng_seed = params.rng_seed * 16 + - (str[i] < 'a' ? str[i] - '0' : str[i] - 'a' + 10); - } - } + if( str && params.rng_seed == 0 ) + params.rng_seed = read_seed(str); if( params.rng_seed == 0 ) params.rng_seed = cvGetTickCount(); diff --git a/opencv/tests/cxts/cxts.h b/opencv/tests/cxts/cxts.h index 610b4baa..0c10f658 100644 --- a/opencv/tests/cxts/cxts.h +++ b/opencv/tests/cxts/cxts.h @@ -431,7 +431,7 @@ protected: // reads common parameters of the test system; called from init() virtual int read_params( CvFileStorage* fs ); - + // checks, whether the test needs to be run (1) or not (0); called from run() virtual int filter( CvTest* test );