]> rtime.felk.cvut.cz Git - opencv.git/commitdiff
fixed the test system and the tests according to the new cxcore
authorvp153 <vp153@73c94f0f-984f-4a5f-82bc-2d8db8d8ee08>
Tue, 3 Mar 2009 17:06:26 +0000 (17:06 +0000)
committervp153 <vp153@73c94f0f-984f-4a5f-82bc-2d8db8d8ee08>
Tue, 3 Mar 2009 17:06:26 +0000 (17:06 +0000)
git-svn-id: https://code.ros.org/svn/opencv/trunk@1615 73c94f0f-984f-4a5f-82bc-2d8db8d8ee08

opencv/tests/cxcore/src/aarithm.cpp
opencv/tests/cxcore/src/adatastruct.cpp
opencv/tests/cxcore/src/adxt.cpp
opencv/tests/cxcore/src/amath.cpp
opencv/tests/cxcore/src/asolvepoly.cpp
opencv/tests/cxcore/src/cxcoretest.h
opencv/tests/cxts/cxts.cpp
opencv/tests/cxts/cxts.h

index bfa985525a0c571ad04755cc967502e14cc129bd..387821f17a7c208b171d45b933a1087fc66a1287 100644 (file)
@@ -176,6 +176,7 @@ void CxCore_ArithmTestImpl::get_test_array_types_and_sizes( int test_case_idx,
     int cn = cvTsRandInt(rng) % 4 + 1;
     int i, j;
     CvArrTest::get_test_array_types_and_sizes( test_case_idx, sizes, types );
+    generate_scalars( depth );
     depth += depth == CV_8S;
 
     for( i = 0; i < max_arr; i++ )
@@ -368,14 +369,18 @@ void CxCore_AddWeightedTest::get_test_array_types_and_sizes( int test_case_idx,
 
 double CxCore_AddWeightedTest::get_success_error_level( int test_case_idx, int i, int j )
 {
-    if( CV_MAT_DEPTH(cvGetElemType(test_array[i][j])) <= CV_32S )
+    int type = cvGetElemType(test_array[i][j]), depth = CV_MAT_DEPTH(type);
+    if( depth <= CV_32S )
+        return 2;
+    if( depth == CV_32F )
     {
-        return alpha.val[0] != cvRound(alpha.val[0]) ||
-               beta.val[0] != cvRound(beta.val[0]) ||
-               gamma.val[0] != cvRound(gamma.val[0]);
+        CvScalar low=cvScalarAll(0), high=low;
+        get_minmax_bounds(i,j,type, &low, &high);
+        double a = (fabs(alpha.val[0])+fabs(beta.val[0]))*(fabs(low.val[0])+fabs(high.val[0]));
+        double b = fabs(gamma.val[0]);
+        return (a+b)*500*FLT_EPSILON;
     }
-    else
-        return CvArrTest::get_success_error_level( test_case_idx, i, j );
+    return CvArrTest::get_success_error_level( test_case_idx, i, j );
 }
 
 
@@ -2405,16 +2410,29 @@ void CxCore_CvtBaseTestImpl::get_test_array_types_and_sizes( int test_case_idx,
 }
 
 
-double CxCore_CvtBaseTestImpl::get_success_error_level( int test_case_idx, int i, int j )
+double CxCore_CvtBaseTestImpl::get_success_error_level( int, int, int )
 {
-    if( CV_MAT_DEPTH(cvGetElemType(test_array[i][j])) <= CV_32S )
-    {
+    if( CV_MAT_DEPTH(test_mat[OUTPUT][0].type) <= CV_32S )
         return alpha.val[0] != cvRound(alpha.val[0]) ||
                beta.val[0] != cvRound(beta.val[0]) ||
                gamma.val[0] != cvRound(gamma.val[0]);
+
+    CvScalar l1, h1, l2, h2;
+    int stype = CV_MAT_TYPE(test_mat[INPUT][0].type);
+    int dtype = CV_MAT_TYPE(test_mat[OUTPUT][0].type);
+    get_minmax_bounds( INPUT, 0, stype, &l1, &h1 );
+    get_minmax_bounds( OUTPUT, 0, dtype, &l2, &h2 );
+    double maxval = 0;
+    for( int i = 0; i < 4; i++ )
+    {
+        maxval = MAX(maxval, fabs(l1.val[i]));
+        maxval = MAX(maxval, fabs(h1.val[i]));
+        maxval = MAX(maxval, fabs(l2.val[i]));
+        maxval = MAX(maxval, fabs(h2.val[i]));
     }
-    else
-        return CvArrTest::get_success_error_level( test_case_idx, i, j );
+    double max_err = (CV_MAT_DEPTH(stype) == CV_64F || CV_MAT_DEPTH(dtype) == CV_64F ?
+        DBL_EPSILON : FLT_EPSILON)*maxval*MAX(fabs(alpha.val[0]), 1.)*100;
+    return max_err;
 }
 
 
index ac9a2e887eb76a5ac7307571e9849feb8c36c08c..69016c988f9f3a5e8f78d124c1029560b9c99f57 100644 (file)
@@ -499,12 +499,12 @@ void CxCore_DynStructBaseTest::update_progressbar()
     if( test_progress < 0 )
     {
         test_progress = 0;
-        cpu_freq = cvGetTickFrequency();
-        start_time = cvGetTickCount();
+        cpu_freq = cv::getTickFrequency();
+        start_time = cv::getTickCount();
     }
 
-    t = cvGetTickCount();
-    test_progress = update_progress( test_progress, 0, 0, ((double)(t - start_time))/(cpu_freq*1000) );
+    t = cv::getTickCount();
+    test_progress = update_progress( test_progress, 0, 0, (double)(t - start_time)/cpu_freq );
 }
 
 
index 6b7d37ed6af0d96fa810d7b52d0d01e2135153ca..7bffaa87c6ac0928c0a6768c9b7695d0815b3f9d 100644 (file)
@@ -607,7 +607,7 @@ void CxCore_DXTBaseTestImpl::get_test_array_types_and_sizes( int test_case_idx,
         sizes[INPUT][0] = sizes[INPUT][1] = size;
         types[INPUT][1] = types[INPUT][0];
     }
-    else if( (cn == 2 && (bits&32)) || (cn == 1 && allow_complex) )
+    else if( /*(cn == 2 && (bits&32)) ||*/ (cn == 1 && allow_complex) )
     {
         types[TEMP][0] = depth + 8; // CV_??FC2
         sizes[TEMP][0] = size;
index 3313250dfabbb1d114884f63ceed5ec117b9c58c..e8fd556f9db7aa9c7ff326a084abd3aa241a4a7f 100644 (file)
@@ -165,9 +165,9 @@ void CxCore_ExpTest::get_test_array_types_and_sizes( int test_case_idx, CvSize**
 {
     CxCore_MathTest::get_test_array_types_and_sizes( test_case_idx, sizes, types );
     out_type = types[OUTPUT][0];
-    if( CV_MAT_DEPTH(types[INPUT][0]) == CV_32F && (cvRandInt(ts->get_rng()) & 3) == 0 )
+    /*if( CV_MAT_DEPTH(types[INPUT][0]) == CV_32F && (cvRandInt(ts->get_rng()) & 3) == 0 )
         types[OUTPUT][0] = types[REF_OUTPUT][0] =
-            out_type = (types[INPUT][0] & ~CV_MAT_DEPTH_MASK)|CV_64F;
+            out_type = (types[INPUT][0] & ~CV_MAT_DEPTH_MASK)|CV_64F;*/
 }
 
 void CxCore_ExpTest::get_minmax_bounds( int /*i*/, int /*j*/, int /*type*/, CvScalar* low, CvScalar* high )
@@ -246,8 +246,8 @@ CxCore_LogTest::CxCore_LogTest()
 void CxCore_LogTest::get_test_array_types_and_sizes( int test_case_idx, CvSize** sizes, int** types )
 {
     CxCore_MathTest::get_test_array_types_and_sizes( test_case_idx, sizes, types );
-    if( CV_MAT_DEPTH(types[INPUT][0]) == CV_32F && (cvRandInt(ts->get_rng()) & 3) == 0 )
-        types[INPUT][0] = (types[INPUT][0] & ~CV_MAT_DEPTH_MASK)|CV_64F;
+    /*if( CV_MAT_DEPTH(types[INPUT][0]) == CV_32F && (cvRandInt(ts->get_rng()) & 3) == 0 )
+        types[INPUT][0] = (types[INPUT][0] & ~CV_MAT_DEPTH_MASK)|CV_64F;*/
 }
 
 
@@ -1175,7 +1175,7 @@ protected:
 };
 
 CxCore_ScaleAddTest::CxCore_ScaleAddTest() :
-    CxCore_MatrixTest( "matrix-scaleadd", "cvScaleAdd", 3, 1, false, false, 2 )
+    CxCore_MatrixTest( "matrix-scaleadd", "cvScaleAdd", 3, 1, false, false, 4 )
 {
     alpha = cvScalarAll(0);
 }
@@ -1185,6 +1185,7 @@ void CxCore_ScaleAddTest::get_test_array_types_and_sizes( int test_case_idx, CvS
 {
     CxCore_MatrixTest::get_test_array_types_and_sizes( test_case_idx, sizes, types );
     sizes[INPUT][2] = cvSize(1,1);
+    types[INPUT][2] &= CV_MAT_DEPTH_MASK;
 }
 
 
@@ -1195,6 +1196,7 @@ void CxCore_ScaleAddTest::get_timing_test_array_types_and_sizes( int test_case_i
     CxCore_MatrixTest::get_timing_test_array_types_and_sizes( test_case_idx, sizes, types,
                                                               whole_sizes, are_images );
     sizes[INPUT][2] = cvSize(1,1);
+    types[INPUT][2] &= CV_MAT_DEPTH_MASK;
 }
 
 
@@ -1215,50 +1217,9 @@ void CxCore_ScaleAddTest::run_func()
 
 void CxCore_ScaleAddTest::prepare_to_validation( int )
 {
-    int rows = test_mat[INPUT][0].rows;
-    int type = CV_MAT_TYPE(test_mat[INPUT][0].type);
-    int cn = CV_MAT_CN(type);
-    int ncols = test_mat[INPUT][0].cols*cn;
-    int i, j;
-
-    for( i = 0; i < rows; i++ )
-    {
-        uchar* src1 = test_mat[INPUT][0].data.ptr + test_mat[INPUT][0].step*i;
-        uchar* src2 = test_mat[INPUT][1].data.ptr + test_mat[INPUT][1].step*i;
-        uchar* dst = test_mat[REF_OUTPUT][0].data.ptr + test_mat[REF_OUTPUT][0].step*i;
-
-        switch( type )
-        {
-        case CV_32FC1:
-            for( j = 0; j < ncols; j++ )
-                ((float*)dst)[j] = (float)(((float*)src1)[j]*alpha.val[0] + ((float*)src2)[j]);
-            break;
-        case CV_32FC2:
-            for( j = 0; j < ncols; j += 2 )
-            {
-                double re = ((float*)src1)[j];
-                double im = ((float*)src1)[j+1];
-                ((float*)dst)[j] = (float)(re*alpha.val[0] - im*alpha.val[1] + ((float*)src2)[j]);
-                ((float*)dst)[j+1] = (float)(re*alpha.val[1] + im*alpha.val[0] + ((float*)src2)[j+1]);
-            }
-            break;
-        case CV_64FC1:
-            for( j = 0; j < ncols; j++ )
-                ((double*)dst)[j] = ((double*)src1)[j]*alpha.val[0] + ((double*)src2)[j];
-            break;
-        case CV_64FC2:
-            for( j = 0; j < ncols; j += 2 )
-            {
-                double re = ((double*)src1)[j];
-                double im = ((double*)src1)[j+1];
-                ((double*)dst)[j] = (double)(re*alpha.val[0] - im*alpha.val[1] + ((double*)src2)[j]);
-                ((double*)dst)[j+1] = (double)(re*alpha.val[1] + im*alpha.val[0] + ((double*)src2)[j+1]);
-            }
-            break;
-        default:
-            assert(0);
-        }
-    }
+    cvTsAdd( &test_mat[INPUT][0], cvScalarAll(alpha.val[0]),
+             &test_mat[INPUT][1], cvScalarAll(1.),
+             cvScalarAll(0.), &test_mat[REF_OUTPUT][0], 0 );
 }
 
 CxCore_ScaleAddTest scaleadd_test;
@@ -1290,7 +1251,7 @@ protected:
 };
 
 CxCore_GEMMTest::CxCore_GEMMTest() :
-    CxCore_MatrixTest( "matrix-gemm", "cvGEMM", 5, 1, false, false, 2 )
+    CxCore_MatrixTest( "matrix-gemm", "cvGEMM", 5, 1, false, false, 1 )
 {
     test_case_count = 100;
     default_timing_param_names = matrix_gemm_param_names;
@@ -1589,9 +1550,12 @@ protected:
     void get_timing_test_array_types_and_sizes( int test_case_idx,
                                                 CvSize** sizes, int** types,
                                                 CvSize** whole_sizes, bool* are_images );
+    int prepare_test_case( int test_case_idx );
     void print_timing_params( int test_case_idx, char* ptr, int params_left );
     void run_func();
     void prepare_to_validation( int test_case_idx );
+    
+    double scale;
 };
 
 
@@ -1621,6 +1585,8 @@ void CxCore_TransformTest::get_test_array_types_and_sizes( int test_case_idx, Cv
     mattype = depth < CV_32S ? CV_32F : depth == CV_64F ? CV_64F : bits & 1 ? CV_32F : CV_64F;
     types[INPUT][1] = mattype;
     types[INPUT][2] = CV_MAKETYPE(mattype, dst_cn);
+    
+    scale = 1./((cvTsRandInt(rng)%4)*50+1);
 
     if( bits & 2 )
     {
@@ -1651,8 +1617,17 @@ void CxCore_TransformTest::get_timing_test_array_types_and_sizes( int test_case_
     sizes[INPUT][1] = cvSize(cn + (cn < 4), cn);
     sizes[INPUT][2] = cvSize(0,0);
     types[INPUT][1] = types[INPUT][2] = CV_64FC1;
+    scale = 1./1000;
 }
 
+int CxCore_TransformTest::prepare_test_case( int test_case_idx )
+{
+    int code = CxCore_MatrixTest::prepare_test_case( test_case_idx );
+    if( code > 0 )
+        cvTsAdd(&test_mat[INPUT][1], cvScalarAll(scale), &test_mat[INPUT][1],
+                cvScalarAll(0), cvScalarAll(0), &test_mat[INPUT][1], 0 );
+    return code;
+}
 
 void CxCore_TransformTest::print_timing_params( int test_case_idx, char* ptr, int params_left )
 {
@@ -1995,10 +1970,22 @@ void CxCore_CovarMatrixTest::get_test_array_types_and_sizes( int test_case_idx,
     single_matrix = flags & CV_COVAR_ROWS;
     t_flag = (bits & 256) != 0;
 
+    const int min_count = 2;
+
     if( !t_flag )
-        len = sizes[INPUT][0].width, count = sizes[INPUT][0].height;
+    {
+        len = sizes[INPUT][0].width;
+        count = sizes[INPUT][0].height;
+        count = std::max(count, min_count);
+        sizes[INPUT][0] = cvSize(len, count);
+    }
     else
-        len = sizes[INPUT][0].height, count = sizes[INPUT][0].width;
+    {
+        len = sizes[INPUT][0].height;
+        count = sizes[INPUT][0].width;
+        count = std::max(count, min_count);
+        sizes[INPUT][0] = cvSize(count, len);
+    }
 
     if( single_matrix && t_flag )
         flags = (flags & ~CV_COVAR_ROWS) | CV_COVAR_COLS;
@@ -2471,7 +2458,7 @@ void CxCore_InvertTest::prepare_to_validation( int )
 {
     CvMat* input = &test_mat[INPUT][0];
     double det = method != CV_LU ? cvTsSVDet( input ) : 0;
-    double threshold = (CV_MAT_DEPTH(input->type) == CV_32F ? FLT_EPSILON : DBL_EPSILON)*100;
+    double threshold = (CV_MAT_DEPTH(input->type) == CV_32F ? FLT_EPSILON : DBL_EPSILON)*500;
 
     if( CV_MAT_TYPE(input->type) == CV_32FC1 )
         cvTsConvert( input, &test_mat[TEMP][1] );
index df8bfd671ec0b19544f25d58189bc9828a980961..bbd16cddd40e5af6f3a010cc0944d68627da8125 100644 (file)
@@ -7,6 +7,8 @@
 #include <vector>
 #include <iostream>
 
+#if 0
+
 typedef std::complex<double> complex_type;
 
 struct pred_complex {
@@ -117,3 +119,5 @@ void CV_SolvePolyTest::run( int )
 }
 
 CV_SolvePolyTest solve_poly_test;
+
+#endif
index 212b3fe7bf2df6b1ac0765110dba76dddf0ef7ca..15f0841a7fc320b404cc331e9ecc687e49801453 100644 (file)
@@ -44,6 +44,8 @@
 
 #if defined WIN32 || defined WIN64
 #include <windows.h>
+#undef min
+#undef max
 #endif
 
 #include "cxcore.h"
index 6bf6efdd35083f329a292cd022c51c1fdfccccf8..fce6a6426f3c128c2b990bcd9aef9bd86e39fe9e 100644 (file)
@@ -927,10 +927,10 @@ int CvTest::update_progress( int progress, int test_case_idx, int count, double
             progress = t;
         }
     }
-    else if( cvRound(dt*0.001) > progress )
+    else if( cvRound(dt) > progress )
     {
         ts->printf( CvTS::CONSOLE, "." );
-        progress = cvRound(dt*0.001);
+        progress = cvRound(dt);
     }
 
     return progress;
@@ -1010,6 +1010,7 @@ void CvTS::clear()
     params.test_mode = CORRECTNESS_CHECK_MODE;
     params.timing_mode = MIN_TIME;
     params.use_optimized = -1;
+    params.color_terminal = 1;
 
     if( memory_manager )
         memory_manager->clear_and_check();
@@ -1030,7 +1031,6 @@ CvTS::~CvTS()
 
     delete selected_tests;
     delete failed_tests;
-    cvSetMemoryManager( 0, 0 );
 }
 
 
@@ -1247,6 +1247,8 @@ int CvTS::run( int argc, char** argv )
             list_tests = 1;
         else if( strcmp( argv[i], "-d" ) == 0 )
             set_data_path(argv[++i]);
+        else if( strcmp( argv[i], "-nc" ) == 0 )
+            params.color_terminal = 0;
     }
 
     if( write_params )
@@ -1388,17 +1390,17 @@ int CvTS::run( int argc, char** argv )
             if( !params.print_only_failed )
             {
                 printf( SUMMARY + CONSOLE, "\t" );
-                change_color( CV_TS_GREEN );
+                set_color( CV_TS_GREEN );
                 printf( SUMMARY + CONSOLE, "Ok\n" );
-                change_color( CV_TS_NORMAL );
+                set_color( CV_TS_NORMAL );
             }
         }
         else
         {
             printf( SUMMARY + CONSOLE, "\t" );
-            change_color( CV_TS_RED );
+            set_color( CV_TS_RED );
             printf( SUMMARY + CONSOLE, "FAIL(%s)\n", str_from_code(code) );
-            change_color( CV_TS_NORMAL );
+            set_color( CV_TS_NORMAL );
             printf( LOG, "context: test case = %d, seed = %08x%08x\n",
                     current_test_info.test_case_idx,
                     (unsigned)(current_test_info.rng_seed>>32),
@@ -1443,6 +1445,7 @@ void CvTS::print_help()
         "-f - use parameters from the provided config XML/YAML file instead of the default parameters\n\n"
         "-h or --help - print this help information\n\n"
         "-l - list all the registered tests or subset of the tests, selected in the config file, and exit\n\n"
+        "-nc - do not use colors in the console output\n\n"     
         "-O{0|1} - disable/enable on-fly detection of IPP and other supported optimized libs. It's enabled by default\n\n"
         "-t - switch to the performance testing mode instead of the default algorithmic/correctness testing mode\n\n"
         "-w - write default parameters of the algorithmic or performance (when -t is passed) tests to the specifed config file (see -f) and exit\n\n"
@@ -1684,6 +1687,11 @@ void CvTS::printf( int streams, const char* fmt, ... )
     }
 }
 
+void CvTS::set_color(int color)
+{
+    if( params.color_terminal )
+        change_color(color);
+}
 
 static char* cv_strnstr( const char* str, int len,
                          const char* pattern,
index 54d2fbd826e46b63b7cba1e2186a70001220340a..4f07492659977d81f57f84c42d0ab396917a0331 100644 (file)
@@ -445,6 +445,9 @@ protected:
 
     // prints the information about command-line parameters
     virtual void print_help();
+    
+    // changes the text color in console
+    virtual void set_color(int color);
 
     // a sequence of tests to run
     CvTestPtrVec* selected_tests;
@@ -509,6 +512,9 @@ protected:
 
         // the path to data files used by tests
         char* data_path;
+        
+        // whether the output to console should be colored
+        int color_terminal;
     }
     params;