1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
10 // Intel License Agreement
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
19 // * Redistribution's of source code must retain the above copyright notice,
20 // this list of conditions and the following disclaimer.
22 // * Redistribution's in binary form must reproduce the above copyright notice,
23 // this list of conditions and the following disclaimer in the documentation
24 // and/or other materials provided with the distribution.
26 // * The name of Intel Corporation may not be used to endorse or promote products
27 // derived from this software without specific prior written permission.
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the Intel Corporation or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 // (including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort (including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
42 //////////////////////////////////////////////////////////////////////////////////////////
43 ////////////////// tests for arithmetic, logic and statistical functions /////////////////
44 //////////////////////////////////////////////////////////////////////////////////////////
46 #include "cxcoretest.h"
49 static const CvSize arithm_sizes[] = {{10,10}, {100,100}, {720,480}, {-1,-1}};
50 static const CvSize arithm_whole_sizes[] = {{10,10}, {720,480}, {720,480}, {-1,-1}};
51 static const int arithm_depths[] = { CV_8U, CV_16U, CV_16S, CV_32S, CV_32F, CV_64F, -1 };
52 static const int arithm_channels[] = { 1, 2, 3, 4, -1 };
53 static const char* arithm_mask_param_names[] = { "size", "channels", "depth", "use_mask", 0 };
54 static const char* arithm_param_names[] = { "size", "channels", "depth", 0 };
55 static const char* minmax_param_names[] = { "size", "depth", 0 };
57 class CxCore_ArithmTestImpl : public CvArrTest
60 CxCore_ArithmTestImpl( const char* test_name, const char* test_funcs,
61 int _generate_scalars=0, bool _allow_mask=true, bool _calc_abs=false );
63 void prepare_to_validation( int test_case_idx );
64 void get_test_array_types_and_sizes( int test_case_idx, CvSize** sizes, int** types );
65 void get_timing_test_array_types_and_sizes( int /*test_case_idx*/,
66 CvSize** sizes, int** types, CvSize** whole_sizes, bool *are_images );
67 void generate_scalars( int depth );
68 CvScalar alpha, beta, gamma;
74 CxCore_ArithmTestImpl::CxCore_ArithmTestImpl( const char* test_name, const char* test_funcs,
75 int _generate_scalars, bool _allow_mask, bool _calc_abs )
76 : CvArrTest( test_name, test_funcs, "" ),
77 gen_scalars(_generate_scalars), calc_abs(_calc_abs)
79 test_array[INPUT].push(NULL);
80 test_array[INPUT].push(NULL);
81 optional_mask = _allow_mask;
85 test_array[INPUT_OUTPUT].push(NULL);
86 test_array[REF_INPUT_OUTPUT].push(NULL);
87 test_array[TEMP].push(NULL);
88 test_array[MASK].push(NULL);
92 test_array[OUTPUT].push(NULL);
93 test_array[REF_OUTPUT].push(NULL);
95 alpha = beta = gamma = cvScalarAll(0);
97 size_list = arithm_sizes;
98 whole_size_list = arithm_whole_sizes;
99 depth_list = arithm_depths;
100 cn_list = arithm_channels;
104 void CxCore_ArithmTestImpl::generate_scalars( int depth )
106 bool is_timing = ts->get_testing_mode() == CvTS::TIMING_MODE;
107 double ab_min_val = -1.;
108 double ab_max_val = 1.;
109 double gamma_min_val = depth == CV_8U ? -100 : depth < CV_32F ? -10000 : -1e6;
110 double gamma_max_val = depth == CV_8U ? 100 : depth < CV_32F ? 10000 : 1e6;
114 CvRNG* rng = ts->get_rng();
117 for( i = 0; i < 4; i++ )
119 if( gen_scalars & 1 )
121 alpha.val[i] = exp((cvTsRandReal(rng)-0.5)*m*2*CV_LOG2);
122 alpha.val[i] *= (cvTsRandInt(rng) & 1) ? 1 : -1;
125 alpha.val[i] = MAX( alpha.val[i], ab_min_val );
126 alpha.val[i] = MIN( alpha.val[i], ab_max_val );
129 if( gen_scalars & 2 )
131 beta.val[i] = exp((cvTsRandReal(rng)-0.5)*m*2*CV_LOG2);
132 beta.val[i] *= (cvTsRandInt(rng) & 1) ? 1 : -1;
135 beta.val[i] = MAX( beta.val[i], ab_min_val );
136 beta.val[i] = MIN( beta.val[i], ab_max_val );
139 if( gen_scalars & 4 )
141 gamma.val[i] = exp((cvTsRandReal(rng)-0.5)*m*2*CV_LOG2);
142 gamma.val[i] *= (cvTsRandInt(rng) & 1) ? 1 : -1;
145 gamma.val[i] = MAX( gamma.val[i], gamma_min_val );
146 gamma.val[i] = MIN( gamma.val[i], gamma_max_val );
152 if( depth == CV_32F )
154 CvMat fl = cvMat( 1, 4, CV_32F, buf );
155 CvMat db = cvMat( 1, 4, CV_64F, 0 );
157 db.data.db = alpha.val;
158 cvTsConvert( &db, &fl );
159 cvTsConvert( &fl, &db );
161 db.data.db = beta.val;
162 cvTsConvert( &db, &fl );
163 cvTsConvert( &fl, &db );
165 db.data.db = gamma.val;
166 cvTsConvert( &db, &fl );
167 cvTsConvert( &fl, &db );
171 void CxCore_ArithmTestImpl::get_test_array_types_and_sizes( int test_case_idx,
172 CvSize** sizes, int** types )
174 CvRNG* rng = ts->get_rng();
175 int depth = cvTsRandInt(rng)%CV_64F;
176 int cn = cvTsRandInt(rng) % 4 + 1;
178 CvArrTest::get_test_array_types_and_sizes( test_case_idx, sizes, types );
179 generate_scalars( depth );
180 depth += depth == CV_8S;
182 for( i = 0; i < max_arr; i++ )
184 int count = test_array[i].size();
185 int type = i != MASK ? CV_MAKETYPE(depth, cn) : CV_8UC1;
186 for( j = 0; j < count; j++ )
194 void CxCore_ArithmTestImpl::get_timing_test_array_types_and_sizes( int test_case_idx,
195 CvSize** sizes, int** types, CvSize** whole_sizes, bool *are_images )
197 CvArrTest::get_timing_test_array_types_and_sizes( test_case_idx, sizes, types,
198 whole_sizes, are_images );
199 generate_scalars( types[INPUT][0] );
203 void CxCore_ArithmTestImpl::prepare_to_validation( int /*test_case_idx*/ )
205 const CvMat* mask = test_array[MASK].size() > 0 && test_array[MASK][0] ? &test_mat[MASK][0] : 0;
206 CvMat* output = test_array[REF_INPUT_OUTPUT].size() > 0 ?
207 &test_mat[REF_INPUT_OUTPUT][0] : &test_mat[REF_OUTPUT][0];
208 CvMat* temp_dst = mask ? &test_mat[TEMP][0] : output;
209 cvTsAdd( &test_mat[INPUT][0], alpha,
210 test_array[INPUT].size() > 1 ? &test_mat[INPUT][1] : 0, beta,
211 gamma, temp_dst, calc_abs );
213 cvTsCopy( temp_dst, output, mask );
217 CxCore_ArithmTestImpl arithm( "arithm", "", 0, false );
220 class CxCore_ArithmTest : public CxCore_ArithmTestImpl
223 CxCore_ArithmTest( const char* test_name, const char* test_funcs,
224 int _generate_scalars=0, bool _allow_mask=true, bool _calc_abs=false );
228 CxCore_ArithmTest::CxCore_ArithmTest( const char* test_name, const char* test_funcs,
229 int _generate_scalars, bool _allow_mask, bool _calc_abs ) :
230 CxCore_ArithmTestImpl( test_name, test_funcs, _generate_scalars, _allow_mask, _calc_abs )
232 default_timing_param_names = optional_mask ? arithm_mask_param_names : arithm_param_names;
234 // inherit the default parameters from arithmetical test
242 ////////////////////////////// add /////////////////////////////
244 class CxCore_AddTest : public CxCore_ArithmTest
252 CxCore_AddTest::CxCore_AddTest()
253 : CxCore_ArithmTest( "arithm-add", "cvAdd", 0, true )
255 alpha = beta = cvScalarAll(1.);
258 void CxCore_AddTest::run_func()
260 cvAdd( test_array[INPUT][0], test_array[INPUT][1],
261 test_array[INPUT_OUTPUT][0], test_array[MASK][0] );
264 CxCore_AddTest add_test;
266 ////////////////////////////// sub /////////////////////////////
268 class CxCore_SubTest : public CxCore_ArithmTest
276 CxCore_SubTest::CxCore_SubTest()
277 : CxCore_ArithmTest( "arithm-sub", "cvSub", 0, true )
279 alpha = cvScalarAll(1.);
280 beta = cvScalarAll(-1.);
283 void CxCore_SubTest::run_func()
285 cvSub( test_array[INPUT][0], test_array[INPUT][1],
286 test_array[INPUT_OUTPUT][0], test_array[MASK][0] );
289 CxCore_SubTest sub_test;
292 ////////////////////////////// adds /////////////////////////////
294 class CxCore_AddSTest : public CxCore_ArithmTest
302 CxCore_AddSTest::CxCore_AddSTest()
303 : CxCore_ArithmTest( "arithm-adds", "cvAddS", 4, true )
305 test_array[INPUT].pop();
306 alpha = cvScalarAll(1.);
309 void CxCore_AddSTest::run_func()
311 cvAddS( test_array[INPUT][0], gamma,
312 test_array[INPUT_OUTPUT][0], test_array[MASK][0] );
315 CxCore_AddSTest adds_test;
317 ////////////////////////////// subrs /////////////////////////////
319 class CxCore_SubRSTest : public CxCore_ArithmTest
327 CxCore_SubRSTest::CxCore_SubRSTest()
328 : CxCore_ArithmTest( "arithm-subrs", "cvSubRS", 4, true )
330 test_array[INPUT].pop();
331 alpha = cvScalarAll(-1.);
334 void CxCore_SubRSTest::run_func()
336 cvSubRS( test_array[INPUT][0], gamma,
337 test_array[INPUT_OUTPUT][0], test_array[MASK][0] );
340 CxCore_SubRSTest subrs_test;
342 ////////////////////////////// addweighted /////////////////////////////
344 class CxCore_AddWeightedTest : public CxCore_ArithmTest
347 CxCore_AddWeightedTest();
349 void get_test_array_types_and_sizes( int test_case_idx,
350 CvSize** sizes, int** types );
351 double get_success_error_level( int test_case_idx, int i, int j );
355 CxCore_AddWeightedTest::CxCore_AddWeightedTest()
356 : CxCore_ArithmTest( "arithm-addweighted", "cvAddWeighted", 7, false )
360 void CxCore_AddWeightedTest::get_test_array_types_and_sizes( int test_case_idx,
361 CvSize** sizes, int** types )
363 CxCore_ArithmTest::get_test_array_types_and_sizes( test_case_idx, sizes, types );
364 alpha = cvScalarAll(alpha.val[0]);
365 beta = cvScalarAll(beta.val[0]);
366 gamma = cvScalarAll(gamma.val[0]);
370 double CxCore_AddWeightedTest::get_success_error_level( int test_case_idx, int i, int j )
372 int type = cvGetElemType(test_array[i][j]), depth = CV_MAT_DEPTH(type);
373 if( depth <= CV_32S )
375 if( depth == CV_32F )
377 CvScalar low=cvScalarAll(0), high=low;
378 get_minmax_bounds(i,j,type, &low, &high);
379 double a = (fabs(alpha.val[0])+fabs(beta.val[0]))*(fabs(low.val[0])+fabs(high.val[0]));
380 double b = fabs(gamma.val[0]);
381 return (a+b)*500*FLT_EPSILON;
383 return CvArrTest::get_success_error_level( test_case_idx, i, j );
387 void CxCore_AddWeightedTest::run_func()
389 cvAddWeighted( test_array[INPUT][0], alpha.val[0],
390 test_array[INPUT][1], beta.val[0],
391 gamma.val[0], test_array[OUTPUT][0] );
394 CxCore_AddWeightedTest addweighted_test;
397 ////////////////////////////// absdiff /////////////////////////////
399 class CxCore_AbsDiffTest : public CxCore_ArithmTest
402 CxCore_AbsDiffTest();
407 CxCore_AbsDiffTest::CxCore_AbsDiffTest()
408 : CxCore_ArithmTest( "arithm-absdiff", "cvAbsDiff", 0, false, true )
410 alpha = cvScalarAll(1.);
411 beta = cvScalarAll(-1.);
414 void CxCore_AbsDiffTest::run_func()
416 cvAbsDiff( test_array[INPUT][0], test_array[INPUT][1], test_array[OUTPUT][0] );
419 CxCore_AbsDiffTest absdiff_test;
421 ////////////////////////////// absdiffs /////////////////////////////
423 class CxCore_AbsDiffSTest : public CxCore_ArithmTest
426 CxCore_AbsDiffSTest();
431 CxCore_AbsDiffSTest::CxCore_AbsDiffSTest()
432 : CxCore_ArithmTest( "arithm-absdiffs", "cvAbsDiffS", 4, false, true )
434 alpha = cvScalarAll(-1.);
435 test_array[INPUT].pop();
438 void CxCore_AbsDiffSTest::run_func()
440 cvAbsDiffS( test_array[INPUT][0], test_array[OUTPUT][0], gamma );
443 CxCore_AbsDiffSTest absdiffs_test;
446 ////////////////////////////// mul /////////////////////////////
448 static const char* mul_param_names[] = { "size", "scale", "channels", "depth", 0 };
449 static const char* mul_scale_flags[] = { "scale==1", "scale!=1", 0 };
451 class CxCore_MulTest : public CxCore_ArithmTest
457 void get_timing_test_array_types_and_sizes( int test_case_idx,
458 CvSize** sizes, int** types,
459 CvSize** whole_sizes, bool* are_images );
460 double get_success_error_level( int test_case_idx, int i, int j );
461 void print_timing_params( int test_case_idx, char* ptr, int params_left );
462 void prepare_to_validation( int test_case_idx );
463 int write_default_params( CvFileStorage* fs );
467 CxCore_MulTest::CxCore_MulTest()
468 : CxCore_ArithmTest( "arithm-mul", "cvMul", 4, false, false )
470 default_timing_param_names = mul_param_names;
474 int CxCore_MulTest::write_default_params( CvFileStorage* fs )
476 int code = CxCore_ArithmTest::write_default_params(fs);
477 if( code < 0 || ts->get_testing_mode() != CvTS::TIMING_MODE )
479 write_string_list( fs, "scale", mul_scale_flags );
484 void CxCore_MulTest::get_timing_test_array_types_and_sizes( int test_case_idx,
485 CvSize** sizes, int** types,
486 CvSize** whole_sizes, bool* are_images )
488 CxCore_ArithmTest::get_timing_test_array_types_and_sizes( test_case_idx,
489 sizes, types, whole_sizes, are_images );
490 const char* scale_flag_str = cvReadString( find_timing_param( "scale" ), "scale==1" );
491 if( strstr( scale_flag_str, "==1" ) )
495 double val = alpha.val[0];
496 int depth = CV_MAT_DEPTH(types[INPUT][0]);
499 if( depth == CV_16U || depth == CV_16S || depth == CV_32S )
501 double minmax = 1./cvTsMaxVal(depth);
504 else if( val > minmax )
506 if( depth == CV_16U && val < 0 )
510 ts->printf( CvTS::LOG, "alpha = %g\n", alpha.val[0] );
515 void CxCore_MulTest::print_timing_params( int test_case_idx, char* ptr, int params_left )
517 sprintf( ptr, "%s,", alpha.val[0] == 1. ? "scale==1" : "scale!=1" );
520 CxCore_ArithmTest::print_timing_params( test_case_idx, ptr, params_left );
524 double CxCore_MulTest::get_success_error_level( int test_case_idx, int i, int j )
526 if( CV_MAT_DEPTH(cvGetElemType(test_array[i][j])) <= CV_32S )
528 return gamma.val[0] != cvRound(gamma.val[0]);
531 return CvArrTest::get_success_error_level( test_case_idx, i, j );
535 void CxCore_MulTest::run_func()
537 cvMul( test_array[INPUT][0], test_array[INPUT][1],
538 test_array[OUTPUT][0], alpha.val[0] );
541 void CxCore_MulTest::prepare_to_validation( int /*test_case_idx*/ )
543 cvTsMul( &test_mat[INPUT][0], &test_mat[INPUT][1],
544 cvScalarAll(alpha.val[0]),
545 &test_mat[REF_OUTPUT][0] );
548 CxCore_MulTest mul_test;
550 ////////////////////////////// div /////////////////////////////
552 class CxCore_DivTest : public CxCore_ArithmTest
558 void print_timing_params( int test_case_idx, char* ptr, int params_left );
559 void prepare_to_validation( int /*test_case_idx*/ );
562 CxCore_DivTest::CxCore_DivTest()
563 : CxCore_ArithmTest( "arithm-div", "cvDiv", 4, false, false )
567 void CxCore_DivTest::print_timing_params( int test_case_idx, char* ptr, int params_left )
569 sprintf( ptr, "s*A(i)/B(i)," );
572 CxCore_ArithmTest::print_timing_params( test_case_idx, ptr, params_left );
575 void CxCore_DivTest::run_func()
577 cvDiv( test_array[INPUT][0], test_array[INPUT][1],
578 test_array[OUTPUT][0], alpha.val[0] );
581 void CxCore_DivTest::prepare_to_validation( int /*test_case_idx*/ )
583 cvTsDiv( &test_mat[INPUT][0], &test_mat[INPUT][1],
584 cvScalarAll(alpha.val[0]),
585 &test_mat[REF_OUTPUT][0] );
588 CxCore_DivTest div_test;
590 ////////////////////////////// recip /////////////////////////////
592 class CxCore_RecipTest : public CxCore_ArithmTest
598 void print_timing_params( int test_case_idx, char* ptr, int params_left );
599 void prepare_to_validation( int /*test_case_idx*/ );
602 CxCore_RecipTest::CxCore_RecipTest()
603 : CxCore_ArithmTest( "arithm-recip", "cvDiv", 4, false, false )
605 test_array[INPUT].pop();
608 void CxCore_RecipTest::print_timing_params( int test_case_idx, char* ptr, int params_left )
610 sprintf( ptr, "s/B(i)," );
613 CxCore_ArithmTest::print_timing_params( test_case_idx, ptr, params_left );
616 void CxCore_RecipTest::run_func()
618 cvDiv( 0, test_array[INPUT][0],
619 test_array[OUTPUT][0], gamma.val[0] );
622 void CxCore_RecipTest::prepare_to_validation( int /*test_case_idx*/ )
624 cvTsDiv( 0, &test_mat[INPUT][0],
625 cvScalarAll(gamma.val[0]),
626 &test_mat[REF_OUTPUT][0] );
629 CxCore_RecipTest recip_test;
632 ///////////////// matrix copy/initializing/permutations /////////////////////
634 class CxCore_MemTestImpl : public CxCore_ArithmTestImpl
637 CxCore_MemTestImpl( const char* test_name, const char* test_funcs,
638 int _generate_scalars=0, bool _allow_mask=true );
640 double get_success_error_level( int /*test_case_idx*/, int /*i*/, int /*j*/ );
643 CxCore_MemTestImpl::CxCore_MemTestImpl( const char* test_name, const char* test_funcs,
644 int _generate_scalars, bool _allow_mask ) :
645 CxCore_ArithmTestImpl( test_name, test_funcs, _generate_scalars, _allow_mask, false )
649 double CxCore_MemTestImpl::get_success_error_level( int /*test_case_idx*/, int /*i*/, int /*j*/ )
654 CxCore_MemTestImpl mem_test( "mem", "", 0, false );
657 class CxCore_MemTest : public CxCore_MemTestImpl
660 CxCore_MemTest( const char* test_name, const char* test_funcs,
661 int _generate_scalars=0, bool _allow_mask=true );
664 CxCore_MemTest::CxCore_MemTest( const char* test_name, const char* test_funcs,
665 int _generate_scalars, bool _allow_mask ) :
666 CxCore_MemTestImpl( test_name, test_funcs, _generate_scalars, _allow_mask )
668 default_timing_param_names = optional_mask ? arithm_mask_param_names : arithm_param_names;
670 // inherit the default parameters from arithmerical test
678 ///////////////// setidentity /////////////////////
680 class CxCore_SetIdentityTest : public CxCore_MemTest
683 CxCore_SetIdentityTest();
686 void prepare_to_validation( int test_case_idx );
690 CxCore_SetIdentityTest::CxCore_SetIdentityTest() :
691 CxCore_MemTest( "mem-setidentity", "cvSetIdentity", 4, false )
693 test_array[INPUT].clear();
697 void CxCore_SetIdentityTest::run_func()
699 cvSetIdentity(test_array[OUTPUT][0], gamma);
703 void CxCore_SetIdentityTest::prepare_to_validation( int )
705 cvTsSetIdentity( &test_mat[REF_OUTPUT][0], gamma );
708 CxCore_SetIdentityTest setidentity_test;
711 ///////////////// SetZero /////////////////////
713 class CxCore_SetZeroTest : public CxCore_MemTest
716 CxCore_SetZeroTest();
719 void prepare_to_validation( int test_case_idx );
723 CxCore_SetZeroTest::CxCore_SetZeroTest() :
724 CxCore_MemTest( "mem-setzero", "cvSetZero", 0, false )
726 test_array[INPUT].clear();
730 void CxCore_SetZeroTest::run_func()
732 cvSetZero(test_array[OUTPUT][0]);
736 void CxCore_SetZeroTest::prepare_to_validation( int )
738 cvTsZero( &test_mat[REF_OUTPUT][0] );
741 CxCore_SetZeroTest setzero_test;
744 ///////////////// Set /////////////////////
746 class CxCore_FillTest : public CxCore_MemTest
752 void prepare_to_validation( int test_case_idx );
756 CxCore_FillTest::CxCore_FillTest() :
757 CxCore_MemTest( "mem-fill", "cvSet", 4, true )
759 test_array[INPUT].clear();
763 void CxCore_FillTest::run_func()
765 cvSet(test_array[INPUT_OUTPUT][0], gamma, test_array[MASK][0]);
769 void CxCore_FillTest::prepare_to_validation( int )
771 if( test_array[MASK][0] )
773 cvTsAdd( 0, cvScalarAll(0.), 0, cvScalarAll(0.), gamma, &test_mat[TEMP][0], 0 );
774 cvTsCopy( &test_mat[TEMP][0], &test_mat[REF_INPUT_OUTPUT][0], &test_mat[MASK][0] );
778 cvTsAdd( 0, cvScalarAll(0.), 0, cvScalarAll(0.), gamma, &test_mat[REF_INPUT_OUTPUT][0], 0 );
782 CxCore_FillTest fill_test;
785 ///////////////// Copy /////////////////////
787 class CxCore_CopyTest : public CxCore_MemTest
792 double get_success_error_level( int test_case_idx, int i, int j );
794 void prepare_to_validation( int test_case_idx );
798 CxCore_CopyTest::CxCore_CopyTest() :
799 CxCore_MemTest( "mem-copy", "cvCopy", 0, true )
801 test_array[INPUT].pop();
805 double CxCore_CopyTest::get_success_error_level( int /*test_case_idx*/, int /*i*/, int /*j*/ )
811 void CxCore_CopyTest::run_func()
813 cvCopy(test_array[INPUT][0], test_array[INPUT_OUTPUT][0], test_array[MASK][0]);
817 void CxCore_CopyTest::prepare_to_validation( int )
819 cvTsCopy( &test_mat[INPUT][0], &test_mat[REF_INPUT_OUTPUT][0],
820 test_array[MASK].size() > 0 && test_array[MASK][0] ? &test_mat[MASK][0] : 0 );
823 CxCore_CopyTest copy_test;
825 ///////////////// Transpose /////////////////////
827 class CxCore_TransposeTest : public CxCore_MemTest
830 CxCore_TransposeTest();
832 void get_test_array_types_and_sizes( int test_case_idx, CvSize** sizes, int** types );
833 void get_timing_test_array_types_and_sizes( int test_case_idx,
834 CvSize** sizes, int** types,
835 CvSize** whole_sizes, bool* are_images );
836 int prepare_test_case( int test_case_idx );
838 void prepare_to_validation( int test_case_idx );
843 CxCore_TransposeTest::CxCore_TransposeTest() :
844 CxCore_MemTest( "mem-transpose", "cvTranspose", 0, false ), inplace(false)
846 test_array[INPUT].pop();
850 void CxCore_TransposeTest::get_test_array_types_and_sizes( int test_case_idx, CvSize** sizes, int** types )
852 int bits = cvTsRandInt(ts->get_rng());
853 CxCore_MemTest::get_test_array_types_and_sizes( test_case_idx, sizes, types );
858 sizes[INPUT][0].height = sizes[INPUT][0].width;
859 inplace = (bits & 2) != 0;
862 sizes[OUTPUT][0] = sizes[REF_OUTPUT][0] = cvSize(sizes[INPUT][0].height, sizes[INPUT][0].width );
866 void CxCore_TransposeTest::get_timing_test_array_types_and_sizes( int test_case_idx,
867 CvSize** sizes, int** types, CvSize** whole_sizes, bool* are_images )
869 CxCore_MemTest::get_timing_test_array_types_and_sizes( test_case_idx,
870 sizes, types, whole_sizes, are_images );
871 CvSize size = sizes[INPUT][0];
872 if( size.width != size.height )
874 sizes[OUTPUT][0] = sizes[REF_OUTPUT][0] =
875 whole_sizes[OUTPUT][0] = whole_sizes[REF_OUTPUT][0] = cvSize(size.height,size.width);
880 int CxCore_TransposeTest::prepare_test_case( int test_case_idx )
882 int code = CxCore_MemTest::prepare_test_case( test_case_idx );
883 if( inplace && code > 0 )
884 cvTsCopy( &test_mat[INPUT][0], &test_mat[OUTPUT][0] );
888 void CxCore_TransposeTest::run_func()
890 cvTranspose( inplace ? test_array[OUTPUT][0] : test_array[INPUT][0], test_array[OUTPUT][0]);
894 void CxCore_TransposeTest::prepare_to_validation( int )
896 cvTsTranspose( &test_mat[INPUT][0], &test_mat[REF_OUTPUT][0] );
899 CxCore_TransposeTest transpose_test;
902 ///////////////// Flip /////////////////////
904 static const int flip_codes[] = { 0, 1, -1, INT_MIN };
905 static const char* flip_strings[] = { "center", "vert", "horiz", 0 };
906 static const char* flip_param_names[] = { "size", "flip_op", "channels", "depth", 0 };
908 class CxCore_FlipTest : public CxCore_MemTest
913 void get_test_array_types_and_sizes( int test_case_idx, CvSize** sizes, int** types );
914 void get_timing_test_array_types_and_sizes( int test_case_idx,
915 CvSize** sizes, int** types,
916 CvSize** whole_sizes, bool* are_images );
917 int prepare_test_case( int test_case_idx );
918 void print_timing_params( int test_case_idx, char* ptr, int params_left );
920 void prepare_to_validation( int test_case_idx );
921 int write_default_params( CvFileStorage* fs );
927 CxCore_FlipTest::CxCore_FlipTest() :
928 CxCore_MemTest( "mem-flip", "cvFlip", 0, false ), flip_type(0), inplace(false)
930 test_array[INPUT].pop();
931 default_timing_param_names = flip_param_names;
935 int CxCore_FlipTest::write_default_params( CvFileStorage* fs )
937 int i, code = CxCore_MemTest::write_default_params(fs);
938 if( code < 0 || ts->get_testing_mode() != CvTS::TIMING_MODE )
940 start_write_param( fs );
941 cvStartWriteStruct( fs, "flip_op", CV_NODE_SEQ + CV_NODE_FLOW );
942 for( i = 0; flip_codes[i] != INT_MIN; i++ )
943 cvWriteString( fs, 0, flip_strings[flip_codes[i]+1] );
944 cvEndWriteStruct(fs);
949 void CxCore_FlipTest::get_test_array_types_and_sizes( int test_case_idx, CvSize** sizes, int** types )
951 int bits = cvTsRandInt(ts->get_rng());
952 CxCore_MemTest::get_test_array_types_and_sizes( test_case_idx, sizes, types );
954 flip_type = (bits & 3) - 2;
955 flip_type += flip_type == -2;
956 inplace = (bits & 4) != 0;
960 void CxCore_FlipTest::get_timing_test_array_types_and_sizes( int test_case_idx,
961 CvSize** sizes, int** types,
962 CvSize** whole_sizes, bool* are_images )
964 CxCore_MemTest::get_timing_test_array_types_and_sizes( test_case_idx,
965 sizes, types, whole_sizes, are_images );
966 const char* flip_op_str = cvReadString( find_timing_param( "flip_op" ), "center" );
967 if( strcmp( flip_op_str, "vert" ) == 0 )
969 else if( strcmp( flip_op_str, "horiz" ) == 0 )
976 void CxCore_FlipTest::print_timing_params( int test_case_idx, char* ptr, int params_left )
978 sprintf( ptr, "%s,", flip_type > 0 ? "horiz" : flip_type < 0 ? "center" : "vert" );
981 CxCore_MemTest::print_timing_params( test_case_idx, ptr, params_left );
985 int CxCore_FlipTest::prepare_test_case( int test_case_idx )
987 int code = CxCore_MemTest::prepare_test_case( test_case_idx );
988 if( inplace && code > 0 )
989 cvTsCopy( &test_mat[INPUT][0], &test_mat[OUTPUT][0] );
994 void CxCore_FlipTest::run_func()
996 cvFlip(inplace ? test_array[OUTPUT][0] : test_array[INPUT][0], test_array[OUTPUT][0], flip_type);
1000 void CxCore_FlipTest::prepare_to_validation( int )
1002 cvTsFlip( &test_mat[INPUT][0], &test_mat[REF_OUTPUT][0], flip_type );
1005 CxCore_FlipTest flip_test;
1008 ///////////////// Split/Merge /////////////////////
1010 static const char* split_merge_types[] = { "all", "single", 0 };
1011 static int split_merge_channels[] = { 2, 3, 4, -1 };
1012 static const char* split_merge_param_names[] = { "size", "planes", "channels", "depth", 0 };
1014 class CxCore_SplitMergeBaseTest : public CxCore_MemTest
1017 CxCore_SplitMergeBaseTest( const char* test_name, const char* test_funcs, int _is_split );
1019 void get_test_array_types_and_sizes( int test_case_idx, CvSize** sizes, int** types );
1020 void get_timing_test_array_types_and_sizes( int test_case_idx,
1021 CvSize** sizes, int** types,
1022 CvSize** whole_sizes, bool* are_images );
1023 int prepare_test_case( int test_case_idx );
1024 void print_timing_params( int test_case_idx, char* ptr, int params_left );
1025 void prepare_to_validation( int test_case_idx );
1026 int write_default_params( CvFileStorage* fs );
1033 CxCore_SplitMergeBaseTest::CxCore_SplitMergeBaseTest( const char* test_name,
1034 const char* test_funcs, int _is_split )
1035 : CxCore_MemTest( test_name, test_funcs, 0, false ), are_images(false), is_split(_is_split), coi(0)
1037 test_array[INPUT].pop();
1042 test_array[OUTPUT].clear();
1043 test_array[REF_OUTPUT].clear();
1044 test_array[INPUT_OUTPUT].push(NULL);
1045 test_array[REF_INPUT_OUTPUT].push(NULL);
1047 memset( hdrs, 0, sizeof(hdrs) );
1049 default_timing_param_names = split_merge_param_names;
1050 cn_list = split_merge_channels;
1054 int CxCore_SplitMergeBaseTest::write_default_params( CvFileStorage* fs )
1056 int code = CxCore_MemTest::write_default_params(fs);
1057 if( code < 0 || ts->get_testing_mode() != CvTS::TIMING_MODE )
1059 write_string_list( fs, "planes", split_merge_types );
1064 void CxCore_SplitMergeBaseTest::get_test_array_types_and_sizes( int test_case_idx, CvSize** sizes, int** types )
1067 CvRNG* rng = ts->get_rng();
1068 CxCore_MemTest::get_test_array_types_and_sizes( test_case_idx, sizes, types );
1069 cn = cvTsRandInt(rng)%3 + 2;
1070 depth = CV_MAT_DEPTH(types[INPUT][0]);
1074 types[INPUT][0] = CV_MAKETYPE(depth, cn);
1075 types[OUTPUT][0] = types[REF_OUTPUT][0] = depth;
1079 types[INPUT][0] = depth;
1080 types[INPUT_OUTPUT][0] = types[REF_INPUT_OUTPUT][0] = CV_MAKETYPE(depth, cn);
1083 if( (cvTsRandInt(rng) & 3) != 0 )
1085 coi = cvTsRandInt(rng) % cn;
1089 CvSize size = sizes[INPUT][0];
1093 sizes[OUTPUT][0] = sizes[REF_OUTPUT][0] = size;
1095 sizes[INPUT][0] = size;
1099 are_images = cvTsRandInt(rng)%2 != 0;
1103 void CxCore_SplitMergeBaseTest::get_timing_test_array_types_and_sizes( int test_case_idx,
1104 CvSize** sizes, int** types, CvSize** whole_sizes, bool* _are_images )
1106 CxCore_MemTest::get_timing_test_array_types_and_sizes( test_case_idx,
1107 sizes, types, whole_sizes, _are_images );
1108 const char* split_merge_type = cvReadString( find_timing_param( "planes" ), "all" );
1109 int type0 = types[INPUT][0];
1110 int depth = CV_MAT_DEPTH(type0);
1111 int cn = CV_MAT_CN(type0);
1112 CvSize size = sizes[INPUT][0];
1114 if( strcmp( split_merge_type, "single" ) == 0 )
1115 coi = cvTsRandInt(ts->get_rng()) % cn;
1124 types[OUTPUT][0] = types[REF_OUTPUT][0] = depth;
1125 sizes[OUTPUT][0] = sizes[REF_OUTPUT][0] = size;
1127 // planes are put into separate arrays, not ROI's
1128 whole_sizes[OUTPUT][0] = whole_sizes[REF_OUTPUT][0] = size;
1132 types[INPUT][0] = depth;
1133 sizes[INPUT][0] = size;
1135 // planes are put into separate arrays, not ROI's
1136 whole_sizes[INPUT][0] = size;
1143 void CxCore_SplitMergeBaseTest::print_timing_params( int test_case_idx, char* ptr, int params_left )
1147 sprintf( ptr, "%s,", coi >= 0 ? "single" : "all" );
1151 // at once, delete the headers, though is not very good from structural point of view ...
1152 for( i = 0; i < 4; i++ )
1153 cvRelease( &hdrs[i] );
1155 CxCore_MemTest::print_timing_params( test_case_idx, ptr, params_left );
1159 int CxCore_SplitMergeBaseTest::prepare_test_case( int test_case_idx )
1161 int code = CxCore_MemTest::prepare_test_case( test_case_idx );
1164 CvMat* input = &test_mat[INPUT][0];
1165 CvMat* output = &test_mat[is_split ? OUTPUT : INPUT_OUTPUT][0];
1166 CvMat* merged = is_split ? input : output;
1167 CvMat* planes = is_split ? output : input;
1168 int depth = CV_MAT_DEPTH(merged->type);
1169 int i, cn = CV_MAT_CN(merged->type), y = 0;
1170 CvSize sz = cvGetMatSize(merged);
1172 for( i = 0; i < cn; i++ )
1174 if( coi < 0 || coi == i )
1177 hdrs[i] = cvCreateImageHeader( sz, cvIplDepth(depth), 1 );
1179 hdrs[i] = cvCreateMatHeader( sz.height, sz.width, depth );
1180 cvSetData( hdrs[i], planes->data.ptr + planes->step*y, planes->step );
1190 void CxCore_SplitMergeBaseTest::prepare_to_validation( int )
1192 CvMat* input = &test_mat[INPUT][0];
1193 CvMat* output = &test_mat[is_split ? REF_OUTPUT : REF_INPUT_OUTPUT][0];
1194 CvMat* merged = is_split ? input : output;
1195 CvMat* planes = is_split ? output : input;
1196 int i, cn = CV_MAT_CN(merged->type), y = 0;
1197 CvSize sz = cvGetSize(merged);
1199 for( i = 0; i < cn; i++ )
1201 if( coi < 0 || coi == i )
1204 cvSetData( hdrs[i], planes->data.ptr + planes->step*y, planes->step );
1205 h = cvGetMat( hdrs[i], &stub );
1207 cvTsExtract( input, h, i );
1209 cvTsInsert( h, output, i );
1210 cvSetData( hdrs[i], 0, 0 );
1211 cvRelease( &hdrs[i] );
1218 class CxCore_SplitTest : public CxCore_SplitMergeBaseTest
1227 CxCore_SplitTest::CxCore_SplitTest() :
1228 CxCore_SplitMergeBaseTest( "mem-split", "cvSplit", 1 )
1233 void CxCore_SplitTest::run_func()
1235 cvSplit( test_array[INPUT][0], hdrs[0], hdrs[1], hdrs[2], hdrs[3] );
1238 CxCore_SplitTest split_test;
1240 class CxCore_MergeTest : public CxCore_SplitMergeBaseTest
1249 CxCore_MergeTest::CxCore_MergeTest() :
1250 CxCore_SplitMergeBaseTest( "mem-merge", "cvMerge", 0 )
1255 void CxCore_MergeTest::run_func()
1257 cvMerge( hdrs[0], hdrs[1], hdrs[2], hdrs[3], test_array[INPUT_OUTPUT][0] );
1260 CxCore_MergeTest merge_test;
1262 ///////////////// CompleteSymm /////////////////////
1264 class CxCore_CompleteSymm : public CvArrTest
1267 CxCore_CompleteSymm();
1269 void get_test_array_types_and_sizes( int test_case_idx, CvSize** sizes, int** types );
1270 int prepare_test_case( int test_case_idx );
1272 void prepare_to_validation( int test_case_idx );
1276 CxCore_CompleteSymm::CxCore_CompleteSymm() :
1277 CvArrTest("matrix-symm", "cvCompleteSymm", "Test of cvCompleteSymm function")
1279 /*Generates 1 input and 1 outputs (by default we have 2 inputs and 1 output)*/
1280 test_array[INPUT].clear();
1281 test_array[INPUT].push(NULL);
1282 test_array[OUTPUT].clear();
1283 test_array[OUTPUT].push(NULL);
1284 test_array[REF_OUTPUT].clear();
1285 test_array[REF_OUTPUT].push(NULL);
1289 void CxCore_CompleteSymm::get_test_array_types_and_sizes( int test_case_idx, CvSize** sizes, int** types )
1291 CvArrTest::get_test_array_types_and_sizes( test_case_idx, sizes, types );
1292 sizes[INPUT][0] =sizes[OUTPUT][0] = sizes[REF_OUTPUT][0] = cvSize(sizes[INPUT][0].height, sizes[INPUT][0].height );
1294 /*Making input and output matrixes one-channel*/
1296 switch (test_case_idx % 3)
1307 types[OUTPUT][0] = types[INPUT][0] = types[REF_OUTPUT][0] = type;
1310 int CxCore_CompleteSymm::prepare_test_case( int test_case_idx )
1312 int code = CvArrTest::prepare_test_case( test_case_idx );
1315 CvRNG* rng = ts->get_rng();
1316 unsigned val = cvRandInt(rng);
1318 cvConvert(&test_mat[INPUT][0], &test_mat[OUTPUT][0]);
1323 void CxCore_CompleteSymm::run_func()
1325 cvCompleteSymm(&test_mat[OUTPUT][0],LtoR);
1328 void CxCore_CompleteSymm::prepare_to_validation( int )
1330 CvMat* ref_output = cvCreateMat(test_mat[OUTPUT][0].rows, test_mat[OUTPUT][0].cols, CV_64F);
1331 CvMat* input = cvCreateMat(test_mat[INPUT][0].rows, test_mat[INPUT][0].cols, CV_64F);
1332 cvConvert(&test_mat[INPUT][0], input);
1334 for (int i=0;i<input->rows;i++)
1336 ref_output->data.db[i*input->cols+i]=input->data.db[i*input->cols+i];
1339 for (int j=0;j<i;j++)
1341 ref_output->data.db[j*input->cols+i] = ref_output->data.db[i*input->cols+j]=input->data.db[i*input->cols+j];
1347 for (int j=0;j<i;j++)
1349 ref_output->data.db[j*input->cols+i] = ref_output->data.db[i*input->cols+j]=input->data.db[j*input->cols+i];
1354 cvConvert(ref_output, &test_mat[REF_OUTPUT][0]);
1355 cvReleaseMat(&input);
1356 cvReleaseMat(&ref_output);
1359 CxCore_CompleteSymm complete_symm;
1362 ////////////////////////////// Sort /////////////////////////////////
1364 class CxCore_SortTest : public CxCore_MemTest
1369 void get_test_array_types_and_sizes( int test_case_idx, CvSize** sizes, int** types );
1370 int prepare_test_case( int test_case_idx );
1372 void prepare_to_validation( int test_case_idx );
1373 int flags; //flags for sorting
1375 static int compareIndexes (const void * a, const void * b); // comparing two elements of the matrix with pointers sorting
1376 static int compare(const void * a, const void * b); // comparing two elements of the matrix with pointers sorting
1377 bool useIndexMatrix;
1378 bool useInPlaceSort;
1383 CxCore_SortTest::CxCore_SortTest() :
1384 CxCore_MemTest( "matrix-sort", "cvSort", 0, false )
1386 /*Generates 1 input and 2 outputs (by default we have 2 inputs and 1 output)*/
1387 test_array[INPUT].clear();
1388 test_array[INPUT].push(NULL);
1389 test_array[OUTPUT].push(NULL);
1390 test_array[REF_OUTPUT].push(NULL);
1394 void CxCore_SortTest::get_test_array_types_and_sizes( int test_case_idx, CvSize** sizes, int** types )
1396 CxCore_MemTest::get_test_array_types_and_sizes( test_case_idx, sizes, types );
1397 sizes[INPUT][0] = sizes[OUTPUT][0] = sizes[REF_OUTPUT][0] = sizes[OUTPUT][1] = sizes[REF_OUTPUT][1] = cvSize(sizes[INPUT][0].height, sizes[INPUT][0].width );
1398 types[OUTPUT][1] = types[REF_OUTPUT][1] = CV_32SC1;
1400 /*Making input and output matrixes one-channel*/
1401 types[OUTPUT][0] = types[INPUT][0] = CV_MAKETYPE(CV_MAT_DEPTH(types[INPUT][0]), 1);
1402 types[REF_OUTPUT][0] = CV_MAKETYPE(CV_MAT_DEPTH(types[REF_OUTPUT][0]), 1);
1405 int CxCore_SortTest::prepare_test_case( int test_case_idx )
1407 if (test_case_idx==0)
1409 useIndexMatrix=true;
1410 useInPlaceSort=false;
1412 int code = CxCore_MemTest::prepare_test_case( test_case_idx );
1416 //Copying input data
1417 input = cvCreateMat(test_mat[INPUT][0].rows, test_mat[INPUT][0].cols, CV_64F);
1418 cvConvert(&test_mat[INPUT][0], input);
1419 CvRNG* rng = ts->get_rng();
1420 unsigned val = cvRandInt(rng);
1425 flags = CV_SORT_EVERY_ROW + CV_SORT_DESCENDING;
1428 flags = CV_SORT_EVERY_ROW + CV_SORT_ASCENDING;
1431 flags = CV_SORT_EVERY_COLUMN + CV_SORT_DESCENDING;
1434 flags = CV_SORT_EVERY_COLUMN + CV_SORT_ASCENDING;
1438 useIndexMatrix = !useIndexMatrix;
1441 useInPlaceSort = !useInPlaceSort;
1447 void CxCore_SortTest::run_func()
1449 //test_mat[OUTPUT][0] is sorted matrix
1450 //test_mat[OUTPUT][1] is index matrix
1453 cvConvert(&test_mat[INPUT][0], &test_mat[OUTPUT][0]);
1455 cvSort(&(test_mat[OUTPUT][0]),&(test_mat[OUTPUT][0]),&(test_mat[OUTPUT][1]),flags);
1458 cvSort(&(test_mat[OUTPUT][0]),&(test_mat[OUTPUT][0]),0,flags);
1465 cvSort(&(test_mat[INPUT][0]),&(test_mat[OUTPUT][0]),&(test_mat[OUTPUT][1]),flags);
1468 cvSort(&(test_mat[INPUT][0]),&(test_mat[OUTPUT][0]),0,flags);
1473 int CxCore_SortTest::compareIndexes (const void * a, const void * b)
1475 double zero = 1e-30;
1476 double res=(**((double**)a)-**((double**)b));
1477 return res<-zero?-1:(res>zero?1:0);
1479 int CxCore_SortTest::compare (const void * a, const void * b)
1481 return *((int*)a)-*((int*)b);
1484 void CxCore_SortTest::prepare_to_validation(int)
1486 /*Creating matrixes copies to work with*/
1487 CvMat* ref_indexes = cvCreateMat(test_mat[REF_OUTPUT][1].rows, test_mat[REF_OUTPUT][1].cols, CV_32SC1);
1488 CvMat* indexes = cvCreateMat(test_mat[OUTPUT][1].rows, test_mat[OUTPUT][1].cols, CV_32SC1);
1489 CvMat* ref_output = cvCreateMat(test_mat[OUTPUT][0].rows, test_mat[OUTPUT][0].cols,CV_64F);
1492 cvConvert(&test_mat[REF_OUTPUT][1], ref_indexes);
1493 cvConvert(&test_mat[OUTPUT][1], indexes);
1495 /*Following block generates REF_OUTPUT indexes matrix*/
1496 if ((flags == (CV_SORT_EVERY_ROW+CV_SORT_ASCENDING)) ||(flags == (CV_SORT_EVERY_ROW+CV_SORT_DESCENDING)))
1497 for (int i=0;i<test_mat[REF_OUTPUT][1].rows;i++)
1498 for (int j=0;j<test_mat[REF_OUTPUT][1].cols;j++)
1499 ref_indexes->data.i[ref_indexes->cols*i + j]=j;
1501 for (int i=0;i<test_mat[REF_OUTPUT][1].rows;i++)
1502 for (int j=0;j<test_mat[REF_OUTPUT][1].cols;j++)
1503 ref_indexes->data.i[ref_indexes->cols*i + j]=i;
1504 cvConvert(ref_indexes, &test_mat[REF_OUTPUT][1]);
1507 /* Matrix User's Sorting Algorithm */
1508 int order = -1; // order of sorting (ASCENDING or DESCENDING)
1509 //// Following to variables are for sorting rows or cols in one block without any conditions (if statements)
1512 if ((flags == CV_SORT_EVERY_ROW+CV_SORT_ASCENDING)||(flags == CV_SORT_EVERY_COLUMN+CV_SORT_ASCENDING)) order=1;
1513 if ((flags == CV_SORT_EVERY_ROW+CV_SORT_ASCENDING)||(flags == CV_SORT_EVERY_ROW+CV_SORT_DESCENDING)) rowsSort=1;
1517 // For accessing [i,j] element using index matrix we can use following formula
1518 // input->data.db[(input->cols*i+ref_indexes->cols*i+j)*rowsSort+(cols*(ref_indexes->cols*i+j)+j)*colsSort];
1520 if ((flags == CV_SORT_EVERY_ROW+CV_SORT_ASCENDING)||(flags == CV_SORT_EVERY_ROW+CV_SORT_DESCENDING))
1522 double** row = new double*[input->cols];
1523 for (i=0;i<input->rows; i++)
1525 for (int j=0;j<input->cols;j++)
1526 row[j]=&(input->data.db[(input->cols*i+j)]);
1527 qsort(row,input->cols,sizeof(row[0]),&CxCore_SortTest::compareIndexes);
1528 for (int j=0;j<ref_indexes->cols;j++)
1531 ref_indexes->data.i[ref_indexes->cols*i+j]=(int)(row[j]-&(input->data.db[input->cols*i]));
1533 ref_indexes->data.i[ref_indexes->cols*(i+1)-1-j]=(int)(row[j]-&(input->data.db[input->cols*i]));
1540 double** col = new double*[input->rows];
1541 for (j=0;j<input->cols; j++)
1543 for (int i=0;i<input->rows;i++)
1544 col[i]=&(input->data.db[(input->cols*i+j)]);
1545 qsort(col,input->rows,sizeof(col[0]),&CxCore_SortTest::compareIndexes);
1546 for (int i=0;i<ref_indexes->rows;i++)
1549 ref_indexes->data.i[ref_indexes->cols*i+j]=(int)((col[i]-&(input->data.db[j]))/(ref_output->cols));
1551 ref_indexes->data.i[ref_indexes->cols*(ref_indexes->rows-1-i)+j]=(int)(col[i]-&(input->data.db[j]))/(ref_output->cols);
1560 for (i=0;i<input->rows;i++)
1561 for (j=0;j<input->cols;j++)
1563 n=(input->cols*i+ref_indexes->data.i[ref_indexes->cols*i+j])*rowsSort+
1564 (input->cols*(ref_indexes->data.i[ref_indexes->cols*i+j])+j)*colsSort;
1565 ref_output->data.db[ref_output->cols*i+j] = input->data.db[n];
1570 /* Comparing indexes matrixes */
1571 if ((flags == CV_SORT_EVERY_ROW+CV_SORT_ASCENDING)||(flags == CV_SORT_EVERY_ROW+CV_SORT_DESCENDING))
1575 for (i=0;i<indexes->rows;i++)
1577 for (j=0;j<indexes->cols-1;j++)
1578 if (ref_output->data.db[ref_output->cols*i+j]==ref_output->data.db[ref_output->cols*i+j+1])
1580 temp=ref_output->data.db[ref_output->cols*i+j];
1582 while ((j<ref_output->cols)&&(temp==ref_output->data.db[ref_output->cols*i+j])) j++;
1584 int* row = new int[end-begin+1];
1585 int* row1 = new int[end-begin+1];
1587 for (int k=0;k<=end-begin;k++)
1589 row[k]=ref_indexes->data.i[ref_indexes->cols*i+k+begin];
1590 row1[k]=indexes->data.i[indexes->cols*i+k+begin];
1592 qsort(row,end-begin+1,sizeof(row[0]),&CxCore_SortTest::compare);
1593 qsort(row1,end-begin+1,sizeof(row1[0]),&CxCore_SortTest::compare);
1594 for (int k=0;k<=end-begin;k++)
1596 ref_indexes->data.i[ref_indexes->cols*i+k+begin]=row[k];
1597 indexes->data.i[indexes->cols*i+k+begin]=row1[k];
1608 for (j=0;j<indexes->cols;j++)
1610 for (i=0;i<indexes->rows-1;i++)
1611 if (ref_output->data.db[ref_output->cols*i+j]==ref_output->data.db[ref_output->cols*(i+1)+j])
1613 temp=ref_output->data.db[ref_output->cols*i+j];
1615 while ((i<ref_output->rows)&&(temp==ref_output->data.db[ref_output->cols*i+j])) i++;
1618 int* col = new int[end-begin+1];
1619 int* col1 = new int[end-begin+1];
1621 for (int k=0;k<=end-begin;k++)
1623 col[k]=ref_indexes->data.i[ref_indexes->cols*(k+begin)+j];
1624 col1[k]=indexes->data.i[indexes->cols*(k+begin)+j];
1626 qsort(col,end-begin+1,sizeof(col[0]),&CxCore_SortTest::compare);
1627 qsort(col1,end-begin+1,sizeof(col1[0]),&CxCore_SortTest::compare);
1628 for (int k=0;k<=end-begin;k++)
1630 ref_indexes->data.i[ref_indexes->cols*(k+begin)+j]=col[k];
1631 indexes->data.i[indexes->cols*(k+begin)+j]=col1[k];
1639 cvConvert(ref_indexes, &test_mat[REF_OUTPUT][1]);
1640 cvConvert(indexes, &test_mat[OUTPUT][1]);
1644 cvConvert(ref_indexes, &test_mat[REF_OUTPUT][1]);
1645 cvConvert(ref_indexes, &test_mat[OUTPUT][1]);
1648 cvConvert(ref_output, &test_mat[REF_OUTPUT][0]);
1650 /*releasing matrixes*/
1651 cvReleaseMat(&ref_output);
1652 cvReleaseMat(&input);
1653 cvReleaseMat(&indexes);
1654 cvReleaseMat(&ref_indexes);
1657 CxCore_SortTest sort_test;
1659 ////////////////////////////// min/max /////////////////////////////
1661 class CxCore_MinMaxBaseTest : public CxCore_ArithmTest
1664 CxCore_MinMaxBaseTest( const char* test_name, const char* test_funcs,
1665 int _op_type, int _generate_scalars=0 );
1667 void get_test_array_types_and_sizes( int test_case_idx, CvSize** sizes, int** types );
1668 double get_success_error_level( int /*test_case_idx*/, int /*i*/, int /*j*/ );
1669 void prepare_to_validation( int /*test_case_idx*/ );
1673 CxCore_MinMaxBaseTest::CxCore_MinMaxBaseTest( const char* test_name, const char* test_funcs,
1674 int _op_type, int _generate_scalars )
1675 : CxCore_ArithmTest( test_name, test_funcs, _generate_scalars, false, false ), op_type(_op_type)
1677 if( _generate_scalars )
1678 test_array[INPUT].pop();
1679 default_timing_param_names = minmax_param_names;
1682 double CxCore_MinMaxBaseTest::get_success_error_level( int /*test_case_idx*/, int /*i*/, int /*j*/ )
1687 void CxCore_MinMaxBaseTest::get_test_array_types_and_sizes( int test_case_idx, CvSize** sizes, int** types )
1690 CxCore_ArithmTest::get_test_array_types_and_sizes( test_case_idx, sizes, types );
1691 for( i = 0; i < max_arr; i++ )
1693 int count = test_array[i].size();
1694 for( j = 0; j < count; j++ )
1696 types[i][j] &= ~CV_MAT_CN_MASK;
1701 void CxCore_MinMaxBaseTest::prepare_to_validation( int /*test_case_idx*/ )
1704 cvTsMinMax( &test_mat[INPUT][0], &test_mat[INPUT][1],
1705 &test_mat[REF_OUTPUT][0], op_type );
1707 cvTsMinMaxS( &test_mat[INPUT][0], gamma.val[0],
1708 &test_mat[REF_OUTPUT][0], op_type );
1712 class CxCore_MinTest : public CxCore_MinMaxBaseTest
1721 CxCore_MinTest::CxCore_MinTest()
1722 : CxCore_MinMaxBaseTest( "arithm-min", "cvMin", CV_TS_MIN, 0 )
1726 void CxCore_MinTest::run_func()
1728 cvMin( test_array[INPUT][0], test_array[INPUT][1], test_array[OUTPUT][0] );
1731 CxCore_MinTest min_test;
1734 ////////////////////////////// max /////////////////////////////
1736 class CxCore_MaxTest : public CxCore_MinMaxBaseTest
1744 CxCore_MaxTest::CxCore_MaxTest()
1745 : CxCore_MinMaxBaseTest( "arithm-max", "cvMax", CV_TS_MAX, 0 )
1749 void CxCore_MaxTest::run_func()
1751 cvMax( test_array[INPUT][0], test_array[INPUT][1], test_array[OUTPUT][0] );
1754 CxCore_MaxTest max_test;
1757 ////////////////////////////// mins /////////////////////////////
1759 class CxCore_MinSTest : public CxCore_MinMaxBaseTest
1767 CxCore_MinSTest::CxCore_MinSTest()
1768 : CxCore_MinMaxBaseTest( "arithm-mins", "cvMinS", CV_TS_MIN, 4 )
1772 void CxCore_MinSTest::run_func()
1774 cvMinS( test_array[INPUT][0], gamma.val[0], test_array[OUTPUT][0] );
1777 CxCore_MinSTest mins_test;
1779 ////////////////////////////// maxs /////////////////////////////
1781 class CxCore_MaxSTest : public CxCore_MinMaxBaseTest
1789 CxCore_MaxSTest::CxCore_MaxSTest()
1790 : CxCore_MinMaxBaseTest( "arithm-maxs", "cvMaxS", CV_TS_MAX, 4 )
1794 void CxCore_MaxSTest::run_func()
1796 cvMaxS( test_array[INPUT][0], gamma.val[0], test_array[OUTPUT][0] );
1799 CxCore_MaxSTest maxs_test;
1802 //////////////////////////////// logic ///////////////////////////////////////
1804 class CxCore_LogicTestImpl : public CxCore_ArithmTestImpl
1807 CxCore_LogicTestImpl( const char* test_name, const char* test_funcs, int _logic_op,
1808 int _generate_scalars=0, bool _allow_mask=true );
1810 void prepare_to_validation( int test_case_idx );
1814 CxCore_LogicTestImpl::CxCore_LogicTestImpl( const char* test_name, const char* test_funcs,
1815 int _logic_op, int _generate_scalars, bool _allow_mask )
1816 : CxCore_ArithmTestImpl( test_name, test_funcs, _generate_scalars, _allow_mask, false ),
1819 if( _generate_scalars )
1820 test_array[INPUT].pop();
1823 void CxCore_LogicTestImpl::prepare_to_validation( int /*test_case_idx*/ )
1825 int ref_output_idx = optional_mask ? REF_INPUT_OUTPUT : REF_OUTPUT;
1826 int output_idx = optional_mask ? INPUT_OUTPUT : OUTPUT;
1827 const CvMat* mask = test_array[MASK].size() > 0 && test_array[MASK][0] ? &test_mat[MASK][0] : 0;
1828 CvMat* dst = mask ? &test_mat[TEMP][0] : &test_mat[ref_output_idx][0];
1830 if( test_array[INPUT].size() > 1 )
1832 cvTsLogic( &test_mat[INPUT][0], &test_mat[INPUT][1], dst, logic_op );
1836 cvTsLogicS( &test_mat[INPUT][0], gamma, dst, logic_op );
1839 cvTsCopy( dst, &test_mat[ref_output_idx][0], mask );
1841 for( i = 0; i < 2; i++ )
1843 dst = i == 0 ? &test_mat[ref_output_idx][0] : &test_mat[output_idx][0];
1845 if( CV_IS_MAT(dst) )
1847 CvMat* mat = (CvMat*)dst;
1848 mat->cols *= CV_ELEM_SIZE(mat->type);
1849 mat->type = (mat->type & ~CV_MAT_TYPE_MASK) | CV_8UC1;
1853 IplImage* img = (IplImage*)dst;
1856 assert( CV_IS_IMAGE(dst) );
1857 elem_size = ((img->depth & 255)>>3)*img->nChannels;
1858 img->width *= elem_size;
1862 img->roi->xOffset *= elem_size;
1863 img->roi->width *= elem_size;
1865 img->depth = IPL_DEPTH_8U;
1871 CxCore_LogicTestImpl logic_test("logic", "", -1, 0, false );
1873 class CxCore_LogicTest : public CxCore_LogicTestImpl
1876 CxCore_LogicTest( const char* test_name, const char* test_funcs, int _logic_op,
1877 int _generate_scalars=0, bool _allow_mask=true );
1880 CxCore_LogicTest::CxCore_LogicTest( const char* test_name, const char* test_funcs,
1881 int _logic_op, int _generate_scalars, bool _allow_mask )
1882 : CxCore_LogicTestImpl( test_name, test_funcs, _logic_op, _generate_scalars, _allow_mask )
1884 default_timing_param_names = optional_mask ? arithm_mask_param_names : arithm_param_names;
1886 // inherit the default parameters from arithmerical test
1888 whole_size_list = 0;
1894 ///////////////////////// and //////////////////////////
1896 class CxCore_AndTest : public CxCore_LogicTest
1904 CxCore_AndTest::CxCore_AndTest()
1905 : CxCore_LogicTest( "logic-and", "cvAnd", CV_TS_LOGIC_AND )
1909 void CxCore_AndTest::run_func()
1911 cvAnd( test_array[INPUT][0], test_array[INPUT][1],
1912 test_array[INPUT_OUTPUT][0], test_array[MASK][0] );
1915 CxCore_AndTest and_test;
1918 class CxCore_AndSTest : public CxCore_LogicTest
1926 CxCore_AndSTest::CxCore_AndSTest()
1927 : CxCore_LogicTest( "logic-ands", "cvAndS", CV_TS_LOGIC_AND, 4 )
1931 void CxCore_AndSTest::run_func()
1933 cvAndS( test_array[INPUT][0], gamma,
1934 test_array[INPUT_OUTPUT][0], test_array[MASK][0] );
1937 CxCore_AndSTest ands_test;
1940 ///////////////////////// or /////////////////////////
1942 class CxCore_OrTest : public CxCore_LogicTest
1950 CxCore_OrTest::CxCore_OrTest()
1951 : CxCore_LogicTest( "logic-or", "cvOr", CV_TS_LOGIC_OR )
1955 void CxCore_OrTest::run_func()
1957 cvOr( test_array[INPUT][0], test_array[INPUT][1],
1958 test_array[INPUT_OUTPUT][0], test_array[MASK][0] );
1961 CxCore_OrTest or_test;
1964 class CxCore_OrSTest : public CxCore_LogicTest
1972 CxCore_OrSTest::CxCore_OrSTest()
1973 : CxCore_LogicTest( "logic-ors", "cvOrS", CV_TS_LOGIC_OR, 4 )
1977 void CxCore_OrSTest::run_func()
1979 cvOrS( test_array[INPUT][0], gamma,
1980 test_array[INPUT_OUTPUT][0], test_array[MASK][0] );
1983 CxCore_OrSTest ors_test;
1986 ////////////////////////// xor ////////////////////////////
1988 class CxCore_XorTest : public CxCore_LogicTest
1996 CxCore_XorTest::CxCore_XorTest()
1997 : CxCore_LogicTest( "logic-xor", "cvXor", CV_TS_LOGIC_XOR )
2001 void CxCore_XorTest::run_func()
2003 cvXor( test_array[INPUT][0], test_array[INPUT][1],
2004 test_array[INPUT_OUTPUT][0], test_array[MASK][0] );
2007 CxCore_XorTest xor_test;
2010 class CxCore_XorSTest : public CxCore_LogicTest
2018 CxCore_XorSTest::CxCore_XorSTest()
2019 : CxCore_LogicTest( "logic-xors", "cvXorS", CV_TS_LOGIC_XOR, 4 )
2023 void CxCore_XorSTest::run_func()
2025 cvXorS( test_array[INPUT][0], gamma,
2026 test_array[INPUT_OUTPUT][0], test_array[MASK][0] );
2029 CxCore_XorSTest xors_test;
2032 ////////////////////////// not ////////////////////////////
2034 class CxCore_NotTest : public CxCore_LogicTest
2042 CxCore_NotTest::CxCore_NotTest()
2043 : CxCore_LogicTest( "logic-not", "cvNot", CV_TS_LOGIC_NOT, 4, false )
2047 void CxCore_NotTest::run_func()
2049 cvNot( test_array[INPUT][0],
2050 test_array[OUTPUT][0] );
2053 CxCore_NotTest nots_test;
2055 ///////////////////////// cmp //////////////////////////////
2057 static int cmp_op_values[] = { CV_CMP_GE, CV_CMP_EQ, CV_CMP_NE, -1 };
2059 class CxCore_CmpBaseTestImpl : public CxCore_ArithmTestImpl
2062 CxCore_CmpBaseTestImpl( const char* test_name, const char* test_funcs,
2063 int in_range, int _generate_scalars=0 );
2065 double get_success_error_level( int test_case_idx, int i, int j );
2066 void get_test_array_types_and_sizes( int test_case_idx,
2067 CvSize** sizes, int** types );
2068 void get_timing_test_array_types_and_sizes( int test_case_idx, CvSize** sizes,
2069 int** types, CvSize** whole_sizes, bool* are_images );
2070 void print_timing_params( int test_case_idx, char* ptr, int params_left );
2071 void prepare_to_validation( int test_case_idx );
2072 int write_default_params( CvFileStorage* fs );
2075 enum { CMP_OP_COUNT=6 };
2076 const char* cmp_op_strings[CMP_OP_COUNT];
2079 CxCore_CmpBaseTestImpl::CxCore_CmpBaseTestImpl( const char* test_name, const char* test_funcs,
2080 int _in_range, int _generate_scalars )
2081 : CxCore_ArithmTestImpl( test_name, test_funcs, _generate_scalars, 0, 0 ), in_range(_in_range)
2083 static const char* cmp_param_names[] = { "size", "cmp_op", "depth", 0 };
2084 static const char* inrange_param_names[] = { "size", "channels", "depth", 0 };
2088 test_array[INPUT].push(NULL);
2089 test_array[TEMP].push(NULL);
2090 test_array[TEMP].push(NULL);
2092 test_array[TEMP].push(NULL);
2095 test_array[INPUT].pop();
2097 default_timing_param_names = in_range == 1 ? inrange_param_names : cmp_param_names;
2099 cmp_op_strings[CV_CMP_EQ] = "eq";
2100 cmp_op_strings[CV_CMP_LT] = "lt";
2101 cmp_op_strings[CV_CMP_LE] = "le";
2102 cmp_op_strings[CV_CMP_GE] = "ge";
2103 cmp_op_strings[CV_CMP_GT] = "gt";
2104 cmp_op_strings[CV_CMP_NE] = "ne";
2109 double CxCore_CmpBaseTestImpl::get_success_error_level( int /*test_case_idx*/, int /*i*/, int /*j*/ )
2115 void CxCore_CmpBaseTestImpl::get_test_array_types_and_sizes( int test_case_idx,
2116 CvSize** sizes, int** types )
2119 CxCore_ArithmTestImpl::get_test_array_types_and_sizes( test_case_idx, sizes, types );
2120 types[OUTPUT][0] = types[REF_OUTPUT][0] = CV_8UC1;
2123 // for cmp tests make all the input arrays single-channel
2124 count = test_array[INPUT].size();
2125 for( j = 0; j < count; j++ )
2126 types[INPUT][j] &= ~CV_MAT_CN_MASK;
2128 cmp_op = cvTsRandInt(ts->get_rng()) % 6; // == > >= < <= !=
2130 else if( in_range == 1 )
2132 types[TEMP][0] = CV_8UC1;
2133 types[TEMP][1] &= ~CV_MAT_CN_MASK;
2135 types[TEMP][2] &= ~CV_MAT_CN_MASK;
2140 int CxCore_CmpBaseTestImpl::write_default_params( CvFileStorage* fs )
2142 int code = CxCore_ArithmTestImpl::write_default_params(fs);
2143 if( code < 0 || ts->get_testing_mode() != CvTS::TIMING_MODE )
2147 start_write_param( fs );
2149 cvStartWriteStruct( fs, "cmp_op", CV_NODE_SEQ + CV_NODE_FLOW );
2150 for( i = 0; cmp_op_values[i] >= 0; i++ )
2151 cvWriteString( fs, 0, cmp_op_strings[cmp_op_values[i]] );
2152 cvEndWriteStruct(fs);
2158 void CxCore_CmpBaseTestImpl::get_timing_test_array_types_and_sizes( int test_case_idx,
2159 CvSize** sizes, int** types,
2160 CvSize** whole_sizes, bool* are_images )
2162 CxCore_ArithmTestImpl::get_timing_test_array_types_and_sizes( test_case_idx,
2163 sizes, types, whole_sizes, are_images );
2164 types[OUTPUT][0] = CV_8UC1;
2167 const char* cmp_op_str = cvReadString( find_timing_param( "cmp_op" ), "ge" );
2170 for( i = 0; i < CMP_OP_COUNT; i++ )
2171 if( strcmp( cmp_op_str, cmp_op_strings[i] ) == 0 )
2180 void CxCore_CmpBaseTestImpl::print_timing_params( int test_case_idx, char* ptr, int params_left )
2184 sprintf( ptr, "%s,", cmp_op_strings[cmp_op] );
2188 CxCore_ArithmTestImpl::print_timing_params( test_case_idx, ptr, params_left );
2192 void CxCore_CmpBaseTestImpl::prepare_to_validation( int /*test_case_idx*/ )
2194 CvMat* dst = &test_mat[REF_OUTPUT][0];
2197 if( test_array[INPUT].size() > 1 )
2199 cvTsCmp( &test_mat[INPUT][0], &test_mat[INPUT][1], dst, cmp_op );
2203 cvTsCmpS( &test_mat[INPUT][0], gamma.val[0], dst, cmp_op );
2208 int el_type = CV_MAT_TYPE( test_mat[INPUT][0].type );
2209 int i, cn = CV_MAT_CN(el_type);
2212 for( i = 0; i < cn*2; i++ )
2214 int coi = i / 2, is_lower = (i % 2) == 0;
2215 int cmp_op = is_lower ? CV_CMP_GE : CV_CMP_LT;
2216 const CvMat* src = &test_mat[INPUT][0];
2217 const CvMat* lu = gen_scalars ? 0 : &test_mat[INPUT][is_lower?1:2];
2218 double luS = is_lower ? alpha.val[coi] : gamma.val[coi];
2222 cvTsExtract( src, &test_mat[TEMP][1], coi );
2223 src = &test_mat[TEMP][1];
2227 cvTsExtract( lu, &test_mat[TEMP][2], coi );
2228 lu = &test_mat[TEMP][2];
2233 cvTsCmp( src, lu, tdst, cmp_op );
2235 cvTsCmpS( src, luS, tdst, cmp_op );
2237 cvTsLogic( tdst, dst, dst, CV_TS_LOGIC_AND );
2238 tdst = &test_mat[TEMP][0];
2244 CxCore_CmpBaseTestImpl cmpbase_test( "cmp", "", -1 );
2247 class CxCore_CmpBaseTest : public CxCore_CmpBaseTestImpl
2250 CxCore_CmpBaseTest( const char* test_name, const char* test_funcs,
2251 int in_range, int _generate_scalars=0 );
2254 CxCore_CmpBaseTest::CxCore_CmpBaseTest( const char* test_name, const char* test_funcs,
2255 int _in_range, int _generate_scalars )
2256 : CxCore_CmpBaseTestImpl( test_name, test_funcs, _in_range, _generate_scalars )
2258 // inherit the default parameters from arithmerical test
2265 class CxCore_CmpTest : public CxCore_CmpBaseTest
2273 CxCore_CmpTest::CxCore_CmpTest()
2274 : CxCore_CmpBaseTest( "cmp-cmp", "cvCmp", 0, 0 )
2278 void CxCore_CmpTest::run_func()
2280 cvCmp( test_array[INPUT][0], test_array[INPUT][1],
2281 test_array[OUTPUT][0], cmp_op );
2284 CxCore_CmpTest cmp_test;
2287 class CxCore_CmpSTest : public CxCore_CmpBaseTest
2295 CxCore_CmpSTest::CxCore_CmpSTest()
2296 : CxCore_CmpBaseTest( "cmp-cmps", "cvCmpS", 0, 4 )
2300 void CxCore_CmpSTest::run_func()
2302 cvCmpS( test_array[INPUT][0], gamma.val[0],
2303 test_array[OUTPUT][0], cmp_op );
2306 CxCore_CmpSTest cmps_test;
2309 class CxCore_InRangeTest : public CxCore_CmpBaseTest
2312 CxCore_InRangeTest();
2317 CxCore_InRangeTest::CxCore_InRangeTest()
2318 : CxCore_CmpBaseTest( "cmp-inrange", "cvInRange", 1, 0 )
2322 void CxCore_InRangeTest::run_func()
2324 cvInRange( test_array[INPUT][0], test_array[INPUT][1],
2325 test_array[INPUT][2], test_array[OUTPUT][0] );
2328 CxCore_InRangeTest inrange_test;
2331 class CxCore_InRangeSTest : public CxCore_CmpBaseTest
2334 CxCore_InRangeSTest();
2339 CxCore_InRangeSTest::CxCore_InRangeSTest()
2340 : CxCore_CmpBaseTest( "cmp-inranges", "cvInRangeS", 1, 5 )
2344 void CxCore_InRangeSTest::run_func()
2346 cvInRangeS( test_array[INPUT][0], alpha, gamma, test_array[OUTPUT][0] );
2349 CxCore_InRangeSTest inranges_test;
2352 /////////////////////////// convertscale[abs] ////////////////////////////////////////
2354 static const char* cvt_param_names[] = { "size", "scale", "dst_depth", "depth", 0 };
2355 static const char* cvt_abs_param_names[] = { "size", "depth", 0 };
2356 static const int cvt_scale_flags[] = { 0, 1 };
2358 class CxCore_CvtBaseTestImpl : public CxCore_ArithmTestImpl
2361 CxCore_CvtBaseTestImpl( const char* test_name, const char* test_funcs, bool calc_abs );
2363 void get_test_array_types_and_sizes( int test_case_idx,
2364 CvSize** sizes, int** types );
2365 void get_timing_test_array_types_and_sizes( int test_case_idx,
2366 CvSize** sizes, int** types,
2367 CvSize** whole_sizes, bool *are_images );
2368 double get_success_error_level( int test_case_idx, int i, int j );
2370 int prepare_test_case( int test_case_idx );
2371 void print_timing_params( int test_case_idx, char* ptr, int params_left );
2372 int write_default_params( CvFileStorage* fs );
2374 void prepare_to_validation( int test_case_idx );
2378 CxCore_CvtBaseTestImpl::CxCore_CvtBaseTestImpl( const char* test_name,
2379 const char* test_funcs,
2381 : CxCore_ArithmTestImpl( test_name, test_funcs, 5, false, _calc_abs )
2383 test_array[INPUT].pop();
2384 default_timing_param_names = 0;
2389 // unlike many other arithmetic functions, conversion operations support 8s type,
2390 // also, for cvCvtScale output array depth may be arbitrary and
2391 // for cvCvtScaleAbs output depth = CV_8U
2392 void CxCore_CvtBaseTestImpl::get_test_array_types_and_sizes( int test_case_idx,
2393 CvSize** sizes, int** types )
2395 CxCore_ArithmTestImpl::get_test_array_types_and_sizes( test_case_idx, sizes, types );
2396 CvRNG* rng = ts->get_rng();
2397 int depth = CV_8U, rbits;
2398 types[INPUT][0] = (types[INPUT][0] & ~CV_MAT_DEPTH_MASK)|
2399 cvTsRandInt(rng)%(CV_64F+1);
2401 depth = cvTsRandInt(rng) % (CV_64F+1);
2402 types[OUTPUT][0] = types[REF_OUTPUT][0] = (types[INPUT][0] & ~CV_MAT_DEPTH_MASK)|depth;
2404 rbits = cvTsRandInt(rng);
2405 // check special cases: shift=0 and/or scale=1.
2406 if( (rbits & 3) == 0 )
2408 if( (rbits & 12) == 0 )
2413 double CxCore_CvtBaseTestImpl::get_success_error_level( int, int, int )
2415 if( CV_MAT_DEPTH(test_mat[OUTPUT][0].type) <= CV_32S )
2416 return alpha.val[0] != cvRound(alpha.val[0]) ||
2417 beta.val[0] != cvRound(beta.val[0]) ||
2418 gamma.val[0] != cvRound(gamma.val[0]);
2420 CvScalar l1, h1, l2, h2;
2421 int stype = CV_MAT_TYPE(test_mat[INPUT][0].type);
2422 int dtype = CV_MAT_TYPE(test_mat[OUTPUT][0].type);
2423 get_minmax_bounds( INPUT, 0, stype, &l1, &h1 );
2424 get_minmax_bounds( OUTPUT, 0, dtype, &l2, &h2 );
2426 for( int i = 0; i < 4; i++ )
2428 maxval = MAX(maxval, fabs(l1.val[i]));
2429 maxval = MAX(maxval, fabs(h1.val[i]));
2430 maxval = MAX(maxval, fabs(l2.val[i]));
2431 maxval = MAX(maxval, fabs(h2.val[i]));
2433 double max_err = (CV_MAT_DEPTH(stype) == CV_64F || CV_MAT_DEPTH(dtype) == CV_64F ?
2434 DBL_EPSILON : FLT_EPSILON)*maxval*MAX(fabs(alpha.val[0]), 1.)*100;
2439 void CxCore_CvtBaseTestImpl::get_timing_test_array_types_and_sizes( int test_case_idx,
2440 CvSize** sizes, int** types, CvSize** whole_sizes, bool* are_images )
2442 CxCore_ArithmTestImpl::get_timing_test_array_types_and_sizes( test_case_idx,
2443 sizes, types, whole_sizes, are_images );
2445 int dst_depth = CV_8U;
2446 int cn = CV_MAT_CN(types[INPUT][0]);
2449 scale = cvReadInt( find_timing_param( "scale" ), 1 ) != 0;
2450 dst_depth = cvTsTypeByName( cvReadString(find_timing_param( "dst_depth" ), "8u") );
2453 types[OUTPUT][0] = types[REF_OUTPUT][0] = CV_MAKETYPE(dst_depth, cn);
2458 gamma.val[0] = -100.;
2468 int CxCore_CvtBaseTestImpl::prepare_test_case( int test_case_idx )
2470 int code = CxCore_ArithmTestImpl::prepare_test_case( test_case_idx );
2472 if( code > 0 && ts->get_testing_mode() == CvTS::TIMING_MODE )
2474 if( CV_ARE_TYPES_EQ( &test_mat[INPUT][0], &test_mat[OUTPUT][0] ) &&
2475 !calc_abs && alpha.val[0] == 1 && gamma.val[0] == 0 )
2476 code = 0; // skip the case when no any transformation is done
2483 void CxCore_CvtBaseTestImpl::print_timing_params( int test_case_idx, char* ptr, int params_left )
2485 sprintf( ptr, "%s,", alpha.val[0] == 1. && gamma.val[0] == 0. ? "no_scale" : "scale" );
2488 CxCore_ArithmTestImpl::print_timing_params( test_case_idx, ptr, params_left );
2492 int CxCore_CvtBaseTestImpl::write_default_params( CvFileStorage* fs )
2494 int i, code = CxCore_ArithmTestImpl::write_default_params(fs);
2495 if( code < 0 || ts->get_testing_mode() != CvTS::TIMING_MODE )
2499 start_write_param( fs );
2500 cvStartWriteStruct( fs, "dst_depth", CV_NODE_SEQ + CV_NODE_FLOW );
2501 for( i = 0; arithm_depths[i] >= 0; i++ )
2502 cvWriteString( fs, 0, cvTsGetTypeName(arithm_depths[i]) );
2503 cvEndWriteStruct(fs);
2504 write_int_list( fs, "scale", cvt_scale_flags, CV_DIM(cvt_scale_flags) );
2510 void CxCore_CvtBaseTestImpl::prepare_to_validation( int /*test_case_idx*/ )
2512 cvTsAdd( &test_mat[INPUT][0], cvScalarAll(alpha.val[0]), 0, beta,
2513 cvScalarAll(gamma.val[0]), &test_mat[REF_OUTPUT][0], calc_abs );
2516 CxCore_CvtBaseTestImpl cvt_test( "cvt", "", true );
2519 class CxCore_CvtBaseTest : public CxCore_CvtBaseTestImpl
2522 CxCore_CvtBaseTest( const char* test_name, const char* test_funcs, bool calc_abs );
2526 CxCore_CvtBaseTest::CxCore_CvtBaseTest( const char* test_name, const char* test_funcs, bool _calc_abs )
2527 : CxCore_CvtBaseTestImpl( test_name, test_funcs, _calc_abs )
2529 // inherit the default parameters from arithmerical test
2531 whole_size_list = 0;
2537 class CxCore_CvtScaleTest : public CxCore_CvtBaseTest
2540 CxCore_CvtScaleTest();
2545 CxCore_CvtScaleTest::CxCore_CvtScaleTest()
2546 : CxCore_CvtBaseTest( "cvt-scale", "cvCvtScale", false )
2548 default_timing_param_names = cvt_param_names;
2551 void CxCore_CvtScaleTest::run_func()
2553 cvConvertScale( test_array[INPUT][0], test_array[OUTPUT][0],
2554 alpha.val[0], gamma.val[0] );
2557 CxCore_CvtScaleTest cvtscale_test;
2560 class CxCore_CvtScaleAbsTest : public CxCore_CvtBaseTest
2563 CxCore_CvtScaleAbsTest();
2568 CxCore_CvtScaleAbsTest::CxCore_CvtScaleAbsTest()
2569 : CxCore_CvtBaseTest( "cvt-scaleabs", "cvCvtScaleAbs", true )
2571 default_timing_param_names = cvt_abs_param_names;
2574 void CxCore_CvtScaleAbsTest::run_func()
2576 cvConvertScaleAbs( test_array[INPUT][0], test_array[OUTPUT][0],
2577 alpha.val[0], gamma.val[0] );
2580 CxCore_CvtScaleAbsTest cvtscaleabs_test;
2583 /////////////////////////////// statistics //////////////////////////////////
2585 static const char* stat_param_names[] = { "size", "coi", "channels", "depth", 0 };
2586 static const char* stat_mask_param_names[] = { "size", "coi", "channels", "depth", "use_mask", 0 };
2587 static const char* stat_single_param_names[] = { "size", "channels", "depth", 0 };
2588 static const char* stat_single_mask_param_names[] = { "size", "channels", "depth", "use_mask", 0 };
2589 static const char* stat_coi_modes[] = { "all", "single", 0 };
2591 class CxCore_StatTestImpl : public CvArrTest
2594 CxCore_StatTestImpl( const char* test_name, const char* test_funcs,
2595 int _output_count, bool _single_channel,
2596 bool _allow_mask=true, bool _is_binary=false );
2598 void get_test_array_types_and_sizes( int test_case_idx, CvSize** sizes, int** types );
2599 void get_timing_test_array_types_and_sizes( int test_case_idx,
2600 CvSize** sizes, int** types,
2601 CvSize** whole_sizes, bool* are_images );
2602 void print_timing_params( int test_case_idx, char* ptr, int params_left );
2603 int write_default_params( CvFileStorage* fs );
2604 int prepare_test_case( int test_case_idx );
2605 double get_success_error_level( int test_case_idx, int i, int j );
2609 bool single_channel;
2614 CxCore_StatTestImpl::CxCore_StatTestImpl( const char* test_name,
2615 const char* test_funcs, int _output_count,
2616 bool _single_channel, bool _allow_mask, bool _is_binary )
2617 : CvArrTest( test_name, test_funcs, "" ), output_count(_output_count),
2618 single_channel(_single_channel), is_binary(_is_binary)
2620 test_array[INPUT].push(NULL);
2622 test_array[INPUT].push(NULL);
2623 optional_mask = _allow_mask;
2625 test_array[MASK].push(NULL);
2626 test_array[OUTPUT].push(NULL);
2627 test_array[REF_OUTPUT].push(NULL);
2630 size_list = arithm_sizes;
2631 whole_size_list = arithm_whole_sizes;
2632 depth_list = arithm_depths;
2633 cn_list = arithm_channels;
2637 void CxCore_StatTestImpl::get_test_array_types_and_sizes( int test_case_idx,
2638 CvSize** sizes, int** types )
2640 CvRNG* rng = ts->get_rng();
2641 int depth = cvTsRandInt(rng)%(CV_64F+1);
2642 int cn = cvTsRandInt(rng) % 4 + 1;
2643 int j, count = test_array[INPUT].size();
2645 CvArrTest::get_test_array_types_and_sizes( test_case_idx, sizes, types );
2646 depth += depth == CV_8S;
2648 for( j = 0; j < count; j++ )
2649 types[INPUT][j] = CV_MAKETYPE(depth, cn);
2651 // regardless of the test case, the output is always a fixed-size tuple of numbers
2652 sizes[OUTPUT][0] = sizes[REF_OUTPUT][0] = cvSize( output_count, 1 );
2653 types[OUTPUT][0] = types[REF_OUTPUT][0] = CV_64FC1;
2656 cvmat_allowed = true;
2657 if( cn > 1 && (single_channel || (cvTsRandInt(rng) & 3) == 0) )
2659 coi = cvTsRandInt(rng) % cn + 1;
2660 cvmat_allowed = false;
2665 void CxCore_StatTestImpl::get_timing_test_array_types_and_sizes( int test_case_idx,
2666 CvSize** sizes, int** types, CvSize** whole_sizes, bool* are_images )
2668 CvArrTest::get_timing_test_array_types_and_sizes( test_case_idx, sizes, types,
2669 whole_sizes, are_images );
2670 const char* coi_mode_str = cvReadString(find_timing_param("coi"), single_channel ? "single" : "all");
2672 // regardless of the test case, the output is always a fixed-size tuple of numbers
2673 sizes[OUTPUT][0] = sizes[REF_OUTPUT][0] = cvSize( output_count, 1 );
2674 types[OUTPUT][0] = types[REF_OUTPUT][0] = CV_64FC1;
2676 int cn = CV_MAT_CN(types[INPUT][0]);
2678 cvmat_allowed = true;
2679 if( strcmp( coi_mode_str, "single" ) == 0 )
2681 CvRNG* rng = ts->get_rng();
2682 coi = cvTsRandInt(rng) % cn + 1;
2683 cvmat_allowed = false;
2689 int CxCore_StatTestImpl::write_default_params( CvFileStorage* fs )
2691 int code = CvArrTest::write_default_params(fs);
2692 if( code < 0 || ts->get_testing_mode() != CvTS::TIMING_MODE )
2694 if( !single_channel )
2695 write_string_list( fs, "coi", stat_coi_modes );
2700 int CxCore_StatTestImpl::prepare_test_case( int test_case_idx )
2702 int code = CvArrTest::prepare_test_case( test_case_idx );
2704 if( coi && code > 0 )
2706 int j, count = test_array[INPUT].size();
2708 if( ts->get_testing_mode() == CvTS::TIMING_MODE && CV_MAT_CN(test_mat[INPUT][0].type) == 1 )
2711 for( j = 0; j < count; j++ )
2713 IplImage* img = (IplImage*)test_array[INPUT][j];
2715 cvSetImageCOI( img, coi );
2723 void CxCore_StatTestImpl::print_timing_params( int test_case_idx, char* ptr, int params_left )
2725 sprintf( ptr, "%s,", coi > 0 || CV_MAT_CN(test_mat[INPUT][0].type) == 1 ? "single" : "all" );
2728 CvArrTest::print_timing_params( test_case_idx, ptr, params_left );
2732 double CxCore_StatTestImpl::get_success_error_level( int test_case_idx, int i, int j )
2734 int depth = CV_MAT_DEPTH(cvGetElemType(test_array[INPUT][0]));
2735 if( depth == CV_32F )
2736 return FLT_EPSILON*1000;
2737 if( depth == CV_64F )
2738 return DBL_EPSILON*100000;
2740 return CvArrTest::get_success_error_level( test_case_idx, i, j );
2743 CxCore_StatTestImpl stat_test( "stat", "", 0, true, false );
2746 class CxCore_StatTest : public CxCore_StatTestImpl
2749 CxCore_StatTest( const char* test_name, const char* test_funcs,
2750 int _output_count, bool _single_channel,
2751 bool _allow_mask=1, bool _is_binary=0 );
2754 CxCore_StatTest::CxCore_StatTest( const char* test_name, const char* test_funcs,
2755 int _output_count, bool _single_channel,
2756 bool _allow_mask, bool _is_binary )
2757 : CxCore_StatTestImpl( test_name, test_funcs, _output_count, _single_channel, _allow_mask, _is_binary )
2759 if( !single_channel )
2760 default_timing_param_names = optional_mask ? stat_single_mask_param_names : stat_single_param_names;
2762 default_timing_param_names = optional_mask ? stat_mask_param_names : stat_param_names;
2764 // inherit the default parameters from arithmerical test
2766 whole_size_list = 0;
2771 ////////////////// sum /////////////////
2772 class CxCore_SumTest : public CxCore_StatTest
2778 void prepare_to_validation( int test_case_idx );
2779 double get_success_error_level( int test_case_idx, int i, int j );
2783 CxCore_SumTest::CxCore_SumTest()
2784 : CxCore_StatTest( "stat-sum", "cvSum", 4 /* CvScalar */, false, false, false )
2788 double CxCore_SumTest::get_success_error_level( int /*test_case_idx*/, int /*i*/, int /*j*/ )
2790 int depth = CV_MAT_DEPTH(cvGetElemType(test_array[INPUT][0]));
2791 if( depth == CV_32F )
2792 return FLT_EPSILON*1000;
2793 return DBL_EPSILON*100000;
2797 void CxCore_SumTest::run_func()
2799 *(CvScalar*)(test_mat[OUTPUT][0].data.db) = cvSum(test_array[INPUT][0]);
2802 void CxCore_SumTest::prepare_to_validation( int /*test_case_idx*/ )
2805 int nonzero = cvTsMeanStdDevNonZero( &test_mat[INPUT][0], 0, &mean, 0, coi );
2807 *(CvScalar*)(test_mat[REF_OUTPUT][0].data.db) = mean;
2808 mean = *(CvScalar*)(test_mat[OUTPUT][0].data.db);
2810 mean.val[0] /= nonzero;
2811 mean.val[1] /= nonzero;
2812 mean.val[2] /= nonzero;
2813 mean.val[3] /= nonzero;
2814 *(CvScalar*)(test_mat[OUTPUT][0].data.db) = mean;
2817 CxCore_SumTest sum_test;
2820 ////////////////// nonzero /////////////////
2821 class CxCore_NonZeroTest : public CxCore_StatTest
2824 CxCore_NonZeroTest();
2827 void prepare_to_validation( int test_case_idx );
2828 void get_test_array_types_and_sizes( int test_case_idx,
2829 CvSize** sizes, int** types );
2833 CxCore_NonZeroTest::CxCore_NonZeroTest()
2834 : CxCore_StatTest( "stat-nonzero", "cvCountNonZero", 1 /* int */, true, false, false )
2836 test_array[TEMP].push(NULL);
2837 test_array[TEMP].push(NULL);
2840 void CxCore_NonZeroTest::run_func()
2842 test_mat[OUTPUT][0].data.db[0] = cvCountNonZero(test_array[INPUT][0]);
2845 void CxCore_NonZeroTest::get_test_array_types_and_sizes( int test_case_idx,
2846 CvSize** sizes, int** types )
2848 CxCore_StatTest::get_test_array_types_and_sizes( test_case_idx, sizes, types );
2849 types[TEMP][0] = CV_8UC1;
2850 if( CV_MAT_CN(types[INPUT][0]) > 1 )
2851 types[TEMP][1] = types[INPUT][0] & ~CV_MAT_CN_MASK;
2853 sizes[TEMP][1] = cvSize(0,0);
2857 void CxCore_NonZeroTest::prepare_to_validation( int /*test_case_idx*/ )
2859 CvMat* plane = &test_mat[INPUT][0];
2860 if( CV_MAT_CN(plane->type) > 1 )
2862 plane = &test_mat[TEMP][1];
2864 cvTsExtract( &test_mat[INPUT][0], plane, coi-1 );
2866 cvTsCmpS( plane, 0, &test_mat[TEMP][0], CV_CMP_NE );
2867 int nonzero = cvTsMeanStdDevNonZero( &test_mat[INPUT][0], &test_mat[TEMP][0], 0, 0, coi );
2868 test_mat[REF_OUTPUT][0].data.db[0] = nonzero;
2872 CxCore_NonZeroTest nonzero_test;
2875 /////////////////// mean //////////////////////
2876 class CxCore_MeanTest : public CxCore_StatTest
2882 void prepare_to_validation( int test_case_idx );
2886 CxCore_MeanTest::CxCore_MeanTest()
2887 : CxCore_StatTest( "stat-mean", "cvAvg", 4 /* CvScalar */, false, true, false )
2891 void CxCore_MeanTest::run_func()
2893 *(CvScalar*)(test_mat[OUTPUT][0].data.db) =
2894 cvAvg(test_array[INPUT][0], test_array[MASK][0]);
2897 void CxCore_MeanTest::prepare_to_validation( int /*test_case_idx*/ )
2900 cvTsMeanStdDevNonZero( &test_mat[INPUT][0],
2901 test_array[MASK][0] ? &test_mat[MASK][0] : 0,
2903 *(CvScalar*)(test_mat[REF_OUTPUT][0].data.db) = mean;
2906 CxCore_MeanTest mean_test;
2909 /////////////////// mean_stddev //////////////////////
2910 class CxCore_MeanStdDevTest : public CxCore_StatTest
2913 CxCore_MeanStdDevTest();
2916 void prepare_to_validation( int test_case_idx );
2917 double get_success_error_level( int test_case_idx, int i, int j );
2921 CxCore_MeanStdDevTest::CxCore_MeanStdDevTest()
2922 : CxCore_StatTest( "stat-mean_stddev", "cvAvgSdv", 8 /* CvScalar x 2 */, false, true, false )
2926 void CxCore_MeanStdDevTest::run_func()
2929 CvRNG* rng = ts->get_rng();
2930 s.val[0] = cvTsRandReal(rng)*100. - 50.;
2931 s.val[1] = cvTsRandReal(rng)*100. - 50.;
2932 s.val[2] = cvTsRandReal(rng)*100. - 50.;
2933 s.val[3] = cvTsRandReal(rng)*100. - 50.;
2934 cvSet( &test_mat[INPUT][0], s );*/
2935 cvAvgSdv( test_array[INPUT][0],
2936 &((CvScalar*)(test_mat[OUTPUT][0].data.db))[0],
2937 &((CvScalar*)(test_mat[OUTPUT][0].data.db))[1],
2938 test_array[MASK][0] );
2941 double CxCore_MeanStdDevTest::get_success_error_level( int test_case_idx, int i, int j )
2943 int depth = CV_MAT_DEPTH(cvGetElemType(test_array[INPUT][0]));
2944 if( depth < CV_64F && depth != CV_32S )
2945 return CxCore_StatTest::get_success_error_level( test_case_idx, i, j );
2946 return DBL_EPSILON*1e6;
2949 void CxCore_MeanStdDevTest::prepare_to_validation( int /*test_case_idx*/ )
2951 CvScalar mean, stddev;
2953 CvMat* output = &test_mat[OUTPUT][0];
2954 CvMat* ref_output = &test_mat[REF_OUTPUT][0];
2955 cvTsMeanStdDevNonZero( &test_mat[INPUT][0],
2956 test_array[MASK][0] ? &test_mat[MASK][0] : 0,
2957 &mean, &stddev, coi );
2958 ((CvScalar*)(ref_output->data.db))[0] = mean;
2959 ((CvScalar*)(ref_output->data.db))[1] = stddev;
2960 for( i = 0; i < 4; i++ )
2962 output->data.db[i] *= output->data.db[i];
2963 output->data.db[i+4] = output->data.db[i+4]*output->data.db[i+4] + 1000;
2964 ref_output->data.db[i] *= ref_output->data.db[i];
2965 ref_output->data.db[i+4] = ref_output->data.db[i+4]*ref_output->data.db[i+4] + 1000;
2969 CxCore_MeanStdDevTest mean_stddev_test;
2972 /////////////////// minmaxloc //////////////////////
2973 class CxCore_MinMaxLocTest : public CxCore_StatTest
2976 CxCore_MinMaxLocTest();
2979 void prepare_to_validation( int test_case_idx );
2983 CxCore_MinMaxLocTest::CxCore_MinMaxLocTest()
2984 : CxCore_StatTest( "stat-minmaxloc", "cvMinMaxLoc", 6 /* double x 2 + CvPoint x 2 */, true, true, false )
2988 void CxCore_MinMaxLocTest::run_func()
2990 CvPoint minloc = {0,0}, maxloc = {0,0};
2991 double* output = test_mat[OUTPUT][0].data.db;
2993 cvMinMaxLoc( test_array[INPUT][0],
2994 output, output+1, &minloc, &maxloc,
2995 test_array[MASK][0] );
2996 output[2] = minloc.x;
2997 output[3] = minloc.y;
2998 output[4] = maxloc.x;
2999 output[5] = maxloc.y;
3002 void CxCore_MinMaxLocTest::prepare_to_validation( int /*test_case_idx*/ )
3004 double minval = 0, maxval = 0;
3005 CvPoint minloc = {0,0}, maxloc = {0,0};
3006 double* ref_output = test_mat[REF_OUTPUT][0].data.db;
3007 cvTsMinMaxLoc( &test_mat[INPUT][0], test_array[MASK][0] ?
3008 &test_mat[MASK][0] : 0, &minval, &maxval, &minloc, &maxloc, coi );
3009 ref_output[0] = minval;
3010 ref_output[1] = maxval;
3011 ref_output[2] = minloc.x;
3012 ref_output[3] = minloc.y;
3013 ref_output[4] = maxloc.x;
3014 ref_output[5] = maxloc.y;
3017 CxCore_MinMaxLocTest minmaxloc_test;
3020 /////////////////// norm //////////////////////
3022 static const char* stat_norm_param_names[] = { "size", "coi", "norm_type", "channels", "depth", "use_mask", 0 };
3023 static const char* stat_norm_type_names[] = { "Inf", "L1", "L2", "diff_Inf", "diff_L1", "diff_L2", 0 };
3025 class CxCore_NormTest : public CxCore_StatTest
3031 void prepare_to_validation( int test_case_idx );
3032 void get_test_array_types_and_sizes( int test_case_idx,
3033 CvSize** sizes, int** types );
3034 void get_timing_test_array_types_and_sizes( int /*test_case_idx*/,
3035 CvSize** sizes, int** types, CvSize** whole_sizes, bool *are_images );
3036 int prepare_test_case( int test_case_idx );
3037 void print_timing_params( int test_case_idx, char* ptr, int params_left );
3038 int write_default_params( CvFileStorage* fs );
3039 double get_success_error_level( int test_case_idx, int i, int j );
3044 CxCore_NormTest::CxCore_NormTest()
3045 : CxCore_StatTest( "stat-norm", "cvNorm", 1 /* double */, false, true, true )
3047 test_array[TEMP].push(NULL);
3048 default_timing_param_names = stat_norm_param_names;
3052 double CxCore_NormTest::get_success_error_level( int test_case_idx, int i, int j )
3054 int depth = CV_MAT_DEPTH(cvGetElemType(test_array[INPUT][0]));
3055 if( (depth == CV_16U || depth == CV_16S) /*&& (norm_type&3) != CV_C*/ )
3058 return CxCore_StatTest::get_success_error_level( test_case_idx, i, j );
3062 void CxCore_NormTest::get_test_array_types_and_sizes( int test_case_idx,
3063 CvSize** sizes, int** types )
3067 CxCore_StatTest::get_test_array_types_and_sizes( test_case_idx, sizes, types );
3068 norm_type = cvTsRandInt(ts->get_rng()) % 3; // CV_C, CV_L1 or CV_L2
3069 norm_kind = cvTsRandInt(ts->get_rng()) % 3; // simple, difference or relative difference
3070 if( norm_kind == 0 )
3071 sizes[INPUT][1] = cvSize(0,0);
3072 norm_type = (1 << norm_type) | (norm_kind*8);
3073 intype = types[INPUT][0];
3074 if( CV_MAT_CN(intype) > 1 && coi == 0 )
3075 sizes[MASK][0] = cvSize(0,0);
3076 sizes[TEMP][0] = cvSize(0,0);
3077 if( (norm_type & (CV_DIFF|CV_RELATIVE)) && CV_MAT_DEPTH(intype) <= CV_32F )
3079 sizes[TEMP][0] = sizes[INPUT][0];
3080 types[TEMP][0] = (intype & ~CV_MAT_DEPTH_MASK)|
3081 (CV_MAT_DEPTH(intype) < CV_32F ? CV_32S : CV_64F);
3086 void CxCore_NormTest::get_timing_test_array_types_and_sizes( int test_case_idx,
3087 CvSize** sizes, int** types,
3088 CvSize** whole_sizes, bool* are_images )
3090 CxCore_StatTest::get_timing_test_array_types_and_sizes( test_case_idx,
3091 sizes, types, whole_sizes, are_images );
3092 const char* norm_type_str = cvReadString( find_timing_param( "norm_type" ), "L2" );
3094 if( strncmp( norm_type_str, "diff_", 5 ) == 0 )
3100 if( strcmp( norm_type_str, "L1" ) == 0 )
3102 else if( strcmp( norm_type_str, "L2" ) == 0 )
3108 norm_type += CV_DIFF;
3110 sizes[INPUT][1] = cvSize(0,0);
3114 int CxCore_NormTest::prepare_test_case( int test_case_idx )
3116 int code = CxCore_StatTest::prepare_test_case( test_case_idx );
3117 if( code > 0 && ts->get_testing_mode() == CvTS::TIMING_MODE )
3119 // currently it is not supported
3120 if( test_array[MASK][0] && CV_MAT_CN(test_mat[INPUT][0].type) > 1 && coi == 0 )
3127 int CxCore_NormTest::write_default_params( CvFileStorage* fs )
3129 int code = CxCore_StatTest::write_default_params(fs);
3130 if( code < 0 || ts->get_testing_mode() != CvTS::TIMING_MODE )
3132 write_string_list( fs, "norm_type", stat_norm_type_names );
3137 void CxCore_NormTest::print_timing_params( int test_case_idx, char* ptr, int params_left )
3139 int nt = norm_type & CV_NORM_MASK;
3140 sprintf( ptr, "%s%s,", norm_type & CV_DIFF ? "diff_" : "",
3141 nt == CV_C ? "Inf" : nt == CV_L1 ? "L1" : "L2" );
3144 CxCore_StatTest::print_timing_params( test_case_idx, ptr, params_left );
3148 void CxCore_NormTest::run_func()
3150 test_mat[OUTPUT][0].data.db[0] = cvNorm( test_array[INPUT][0],
3151 test_array[INPUT][1], norm_type, test_array[MASK][0] );
3154 void CxCore_NormTest::prepare_to_validation( int /*test_case_idx*/ )
3156 double a_norm = 0, b_norm = 0;
3157 CvMat* a = &test_mat[INPUT][0];
3158 CvMat* b = &test_mat[INPUT][1];
3159 CvMat* mask = test_array[MASK][0] ? &test_mat[MASK][0] : 0;
3162 if( norm_type & (CV_DIFF|CV_RELATIVE) )
3164 diff = test_array[TEMP][0] ? &test_mat[TEMP][0] : a;
3165 cvTsAdd( a, cvScalarAll(1.), b, cvScalarAll(-1.),
3166 cvScalarAll(0.), diff, 0 );
3168 a_norm = cvTsNorm( diff, mask, norm_type & CV_NORM_MASK, coi );
3169 if( norm_type & CV_RELATIVE )
3171 b_norm = cvTsNorm( b, mask, norm_type & CV_NORM_MASK, coi );
3172 a_norm /= (b_norm + DBL_EPSILON );
3174 test_mat[REF_OUTPUT][0].data.db[0] = a_norm;
3177 CxCore_NormTest norm_test;
3179 // TODO: repeat(?), reshape(?), lut