]> rtime.felk.cvut.cz Git - opencv.git/blobdiff - opencv/tests/cxcore/src/aarithm.cpp
round scalars in the case of integer arrays in adds, subrs and absdiffs tests (will...
[opencv.git] / opencv / tests / cxcore / src / aarithm.cpp
index 16d246b0c7cb924bcf78c6d89f742d9f9d7180fa..844a46bcb368fdcd7b3b332c24665c2fe05b1dff 100644 (file)
@@ -65,6 +65,7 @@ protected:
     void get_timing_test_array_types_and_sizes( int /*test_case_idx*/,
                         CvSize** sizes, int** types, CvSize** whole_sizes, bool *are_images );
     void generate_scalars( int depth );
+    void finalize_scalar( CvScalar& s );
     CvScalar alpha, beta, gamma;
     int gen_scalars;
     bool calc_abs;
@@ -170,16 +171,23 @@ void CxCore_ArithmTestImpl::generate_scalars( int depth )
     }
 }
 
+void CxCore_ArithmTestImpl::finalize_scalar( CvScalar& s )
+{
+    int depth = CV_MAT_DEPTH(test_mat[INPUT][0].type);
+    if( depth < CV_32F )
+        s = cvScalar(cvRound(s.val[0]), cvRound(s.val[1]), cvRound(s.val[2]), cvRound(s.val[3]));
+}
+
 void CxCore_ArithmTestImpl::get_test_array_types_and_sizes( int test_case_idx,
                                                             CvSize** sizes, int** types )
 {
     CvRNG* rng = ts->get_rng();
-    int depth = cvTsRandInt(rng)%CV_64F;
+    int depth = cvTsRandInt(rng)%(CV_64F+1);
     int cn = cvTsRandInt(rng) % 4 + 1;
     int i, j;
+    depth += depth == CV_8S;
     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++ )
     {
@@ -270,8 +278,8 @@ void CxCore_AddTest::run_func()
     {
         cv::MatND a = cv::cvarrToMatND(test_array[INPUT][0]);
         cv::MatND b = cv::cvarrToMatND(test_array[INPUT][1]);
-        cv::MatND c = cv::cvarrToMatND(test_array[INPUT_OUTPUT][2]);
-        if( test_array[MASK][0] )
+        cv::MatND c = cv::cvarrToMatND(test_array[INPUT_OUTPUT][0]);
+        if( !test_array[MASK][0] )
             cv::add(a, b, c);
         else
             cv::add(a, b, c, cv::cvarrToMatND(test_array[MASK][0]));
@@ -308,8 +316,8 @@ void CxCore_SubTest::run_func()
     {
         cv::MatND a = cv::cvarrToMatND(test_array[INPUT][0]);
         cv::MatND b = cv::cvarrToMatND(test_array[INPUT][1]);
-        cv::MatND c = cv::cvarrToMatND(test_array[INPUT_OUTPUT][2]);
-        if( test_array[MASK][0] )
+        cv::MatND c = cv::cvarrToMatND(test_array[INPUT_OUTPUT][0]);
+        if( !test_array[MASK][0] )
             cv::subtract(a, b, c);
         else
             cv::subtract(a, b, c, cv::cvarrToMatND(test_array[MASK][0]));
@@ -338,18 +346,26 @@ CxCore_AddSTest::CxCore_AddSTest()
 
 void CxCore_AddSTest::run_func()
 {
+    finalize_scalar(gamma);
     if(!test_nd)
     {
-        cvAddS( test_array[INPUT][0], gamma,
-            test_array[INPUT_OUTPUT][0], test_array[MASK][0] );
+        if( test_mat[INPUT][0].cols % 2 == 0 )
+            cvAddS( test_array[INPUT][0], gamma,
+                test_array[INPUT_OUTPUT][0], test_array[MASK][0] );
+        else
+        {
+            cv::Mat a = cv::cvarrToMat(test_array[INPUT][0]),
+                c = cv::cvarrToMat(test_array[INPUT_OUTPUT][0]);
+                cv::subtract(a, -cv::Scalar(gamma), c, test_array[MASK][0] ?
+                    cv::cvarrToMat(test_array[MASK][0]) : cv::Mat());
+        }
     }
     else
     {
         cv::MatND c = cv::cvarrToMatND(test_array[INPUT_OUTPUT][0]);
         cv::add( cv::cvarrToMatND(test_array[INPUT][0]),
-                 gamma, c,
-                 test_array[MASK][0] ?
-                    cv::cvarrToMatND(test_array[MASK][0]) : cv::MatND());
+                 gamma, c, test_array[MASK][0] ?
+                 cv::cvarrToMatND(test_array[MASK][0]) : cv::MatND());
     }
 }
 
@@ -374,6 +390,7 @@ CxCore_SubRSTest::CxCore_SubRSTest()
 
 void CxCore_SubRSTest::run_func()
 {
+    finalize_scalar(gamma);
     if(!test_nd)
     {
         cvSubRS( test_array[INPUT][0], gamma,
@@ -510,6 +527,7 @@ CxCore_AbsDiffSTest::CxCore_AbsDiffSTest()
 
 void CxCore_AbsDiffSTest::run_func()
 {
+    finalize_scalar(gamma);
     if(!test_nd)
     {
         cvAbsDiffS( test_array[INPUT][0], test_array[OUTPUT][0], gamma );
@@ -616,8 +634,18 @@ double CxCore_MulTest::get_success_error_level( int test_case_idx, int i, int j
 
 void CxCore_MulTest::run_func()
 {
-    cvMul( test_array[INPUT][0], test_array[INPUT][1],
-           test_array[OUTPUT][0], alpha.val[0] );
+    if(!test_nd)
+    {
+        cvMul( test_array[INPUT][0], test_array[INPUT][1],
+              test_array[OUTPUT][0], alpha.val[0] );
+    }
+    else
+    {
+        cv::MatND c = cv::cvarrToMatND(test_array[OUTPUT][0]);
+        cv::multiply(cv::cvarrToMatND(test_array[INPUT][0]),
+                     cv::cvarrToMatND(test_array[INPUT][1]),
+                     c, alpha.val[0]);
+    }
 }
 
 void CxCore_MulTest::prepare_to_validation( int /*test_case_idx*/ )
@@ -656,8 +684,18 @@ void CxCore_DivTest::print_timing_params( int test_case_idx, char* ptr, int para
 
 void CxCore_DivTest::run_func()
 {
-    cvDiv( test_array[INPUT][0], test_array[INPUT][1],
-           test_array[OUTPUT][0], alpha.val[0] );
+    if(!test_nd)
+    {
+        cvDiv( test_array[INPUT][0], test_array[INPUT][1],
+              test_array[OUTPUT][0], alpha.val[0] );
+    }
+    else
+    {
+        cv::MatND b = cv::cvarrToMatND(test_array[INPUT][1]);
+        cv::MatND c = cv::cvarrToMatND(test_array[OUTPUT][0]);
+        cv::divide(cv::cvarrToMatND(test_array[INPUT][0]),
+                   b, c, alpha.val[0]);
+    }
 }
 
 void CxCore_DivTest::prepare_to_validation( int /*test_case_idx*/ )
@@ -697,8 +735,17 @@ void CxCore_RecipTest::print_timing_params( int test_case_idx, char* ptr, int pa
 
 void CxCore_RecipTest::run_func()
 {
-    cvDiv( 0, test_array[INPUT][0],
-           test_array[OUTPUT][0], gamma.val[0] );
+    if(!test_nd)
+    {
+        cvDiv( 0, test_array[INPUT][0],
+              test_array[OUTPUT][0], gamma.val[0] );
+    }
+    else
+    {
+        cv::MatND b = cv::cvarrToMatND(test_array[INPUT][0]);
+        cv::MatND c = cv::cvarrToMatND(test_array[OUTPUT][0]);
+        cv::divide(gamma.val[0], b, c);
+    }
 }
 
 void CxCore_RecipTest::prepare_to_validation( int /*test_case_idx*/ )
@@ -778,7 +825,13 @@ CxCore_SetIdentityTest::CxCore_SetIdentityTest() :
 
 void CxCore_SetIdentityTest::run_func()
 {
-    cvSetIdentity(test_array[OUTPUT][0], gamma);
+    if(!test_nd)
+        cvSetIdentity(test_array[OUTPUT][0], gamma);
+    else
+    {
+        cv::Mat a = cv::cvarrToMat(test_array[OUTPUT][0]);
+        cv::setIdentity(a, gamma);
+    }
 }
 
 
@@ -811,7 +864,13 @@ CxCore_SetZeroTest::CxCore_SetZeroTest() :
 
 void CxCore_SetZeroTest::run_func()
 {
-    cvSetZero(test_array[OUTPUT][0]);
+    if(!test_nd)
+        cvSetZero(test_array[OUTPUT][0]);
+    else
+    {
+        cv::MatND a = cv::cvarrToMatND(test_array[OUTPUT][0]);
+        a.setTo(cv::Scalar());
+    }
 }
 
 
@@ -844,7 +903,14 @@ CxCore_FillTest::CxCore_FillTest() :
 
 void CxCore_FillTest::run_func()
 {
-    cvSet(test_array[INPUT_OUTPUT][0], gamma, test_array[MASK][0]);
+    const CvArr* mask = test_array[MASK][0];
+    if(!test_nd)
+        cvSet(test_array[INPUT_OUTPUT][0], gamma, mask);
+    else
+    {
+        cv::MatND a = cv::cvarrToMatND(test_array[INPUT_OUTPUT][0]);
+        a.setTo(gamma, mask ? cv::cvarrToMatND(mask) : cv::MatND());
+    }
 }
 
 
@@ -892,7 +958,18 @@ double CxCore_CopyTest::get_success_error_level( int /*test_case_idx*/, int /*i*
 
 void CxCore_CopyTest::run_func()
 {
-    cvCopy(test_array[INPUT][0], test_array[INPUT_OUTPUT][0], test_array[MASK][0]);
+    const CvArr* mask = test_array[MASK][0];
+    if(!test_nd)
+        cvCopy(test_array[INPUT][0], test_array[INPUT_OUTPUT][0], mask);
+    else
+    {
+        cv::MatND a = cv::cvarrToMatND(test_array[INPUT][0]);
+        cv::MatND c = cv::cvarrToMatND(test_array[INPUT_OUTPUT][0]);
+        if(!mask)
+            a.copyTo(c);
+        else
+            a.copyTo(c, cv::cvarrToMatND(mask));
+    }
 }
 
 
@@ -1314,7 +1391,17 @@ CxCore_SplitTest::CxCore_SplitTest() :
 
 void CxCore_SplitTest::run_func()
 {
-    cvSplit( test_array[INPUT][0], hdrs[0], hdrs[1], hdrs[2], hdrs[3] );
+    int i, nz = (hdrs[0] != 0) + (hdrs[1] != 0) + (hdrs[2] != 0) + (hdrs[3] != 0);
+    
+    if(!test_nd || nz != CV_MAT_CN(test_mat[INPUT][0].type))
+        cvSplit( test_array[INPUT][0], hdrs[0], hdrs[1], hdrs[2], hdrs[3] );
+    else
+    {
+        cv::MatND _hdrs[4];
+        for( i = 0; i < nz; i++ )
+            _hdrs[i] = cv::cvarrToMatND(hdrs[i]);
+        cv::split(cv::cvarrToMatND(test_array[INPUT][0]), _hdrs);
+    }
 }
 
 CxCore_SplitTest split_test;
@@ -1336,7 +1423,17 @@ CxCore_MergeTest::CxCore_MergeTest() :
 
 void CxCore_MergeTest::run_func()
 {
-    cvMerge( hdrs[0], hdrs[1], hdrs[2], hdrs[3], test_array[INPUT_OUTPUT][0] );
+    int i, nz = (hdrs[0] != 0) + (hdrs[1] != 0) + (hdrs[2] != 0) + (hdrs[3] != 0);
+    
+    if(!test_nd || nz != CV_MAT_CN(test_mat[INPUT_OUTPUT][0].type))
+        cvMerge( hdrs[0], hdrs[1], hdrs[2], hdrs[3], test_array[INPUT_OUTPUT][0] );
+    else
+    {
+        cv::MatND _hdrs[4], dst = cv::cvarrToMatND(test_array[INPUT_OUTPUT][0]);
+        for( i = 0; i < nz; i++ )
+            _hdrs[i] = cv::cvarrToMatND(hdrs[i]);
+        cv::merge(_hdrs, nz, dst);
+    }
 }
 
 CxCore_MergeTest merge_test;
@@ -1807,7 +1904,16 @@ CxCore_MinTest::CxCore_MinTest()
 
 void CxCore_MinTest::run_func()
 {
-    cvMin( test_array[INPUT][0], test_array[INPUT][1], test_array[OUTPUT][0] );
+    if(!test_nd)
+    {
+        cvMin( test_array[INPUT][0], test_array[INPUT][1], test_array[OUTPUT][0] );
+    }
+    else
+    {
+        cv::MatND c = cv::cvarrToMatND(test_array[OUTPUT][0]);
+        cv::min(cv::cvarrToMatND(test_array[INPUT][0]),
+                cv::cvarrToMatND(test_array[INPUT][1]), c);
+    }
 }
 
 CxCore_MinTest min_test;
@@ -1830,7 +1936,16 @@ CxCore_MaxTest::CxCore_MaxTest()
 
 void CxCore_MaxTest::run_func()
 {
-    cvMax( test_array[INPUT][0], test_array[INPUT][1], test_array[OUTPUT][0] );
+    if(!test_nd)
+    {
+        cvMax( test_array[INPUT][0], test_array[INPUT][1], test_array[OUTPUT][0] );
+    }
+    else
+    {
+        cv::MatND c = cv::cvarrToMatND(test_array[OUTPUT][0]);
+        cv::max(cv::cvarrToMatND(test_array[INPUT][0]),
+                cv::cvarrToMatND(test_array[INPUT][1]), c);
+    }
 }
 
 CxCore_MaxTest max_test;
@@ -1853,7 +1968,16 @@ CxCore_MinSTest::CxCore_MinSTest()
 
 void CxCore_MinSTest::run_func()
 {
-    cvMinS( test_array[INPUT][0], gamma.val[0], test_array[OUTPUT][0] );
+    if(!test_nd)
+    {
+        cvMinS( test_array[INPUT][0], gamma.val[0], test_array[OUTPUT][0] );
+    }
+    else
+    {
+        cv::MatND c = cv::cvarrToMatND(test_array[OUTPUT][0]);
+        cv::min(cv::cvarrToMatND(test_array[INPUT][0]),
+                gamma.val[0], c);
+    }
 }
 
 CxCore_MinSTest mins_test;
@@ -1875,7 +1999,16 @@ CxCore_MaxSTest::CxCore_MaxSTest()
 
 void CxCore_MaxSTest::run_func()
 {
-    cvMaxS( test_array[INPUT][0], gamma.val[0], test_array[OUTPUT][0] );
+    if(!test_nd)
+    {
+        cvMaxS( test_array[INPUT][0], gamma.val[0], test_array[OUTPUT][0] );
+    }
+    else
+    {
+        cv::MatND c = cv::cvarrToMatND(test_array[OUTPUT][0]);
+        cv::max(cv::cvarrToMatND(test_array[INPUT][0]),
+                gamma.val[0], c);
+    }
 }
 
 CxCore_MaxSTest maxs_test;
@@ -1990,8 +2123,18 @@ CxCore_AndTest::CxCore_AndTest()
 
 void CxCore_AndTest::run_func()
 {
-    cvAnd( test_array[INPUT][0], test_array[INPUT][1],
-           test_array[INPUT_OUTPUT][0], test_array[MASK][0] );
+    if(!test_nd)
+    {
+        cvAnd( test_array[INPUT][0], test_array[INPUT][1],
+              test_array[INPUT_OUTPUT][0], test_array[MASK][0] );
+    }
+    else
+    {
+        cv::MatND c = cv::cvarrToMatND(test_array[INPUT_OUTPUT][0]);
+        cv::bitwise_and(cv::cvarrToMatND(test_array[INPUT][0]),
+                        cv::cvarrToMatND(test_array[INPUT][1]),
+                        c, cv::cvarrToMatND(test_array[MASK][0]));
+    }
 }
 
 CxCore_AndTest and_test;
@@ -2012,8 +2155,18 @@ CxCore_AndSTest::CxCore_AndSTest()
 
 void CxCore_AndSTest::run_func()
 {
-    cvAndS( test_array[INPUT][0], gamma,
-            test_array[INPUT_OUTPUT][0], test_array[MASK][0] );
+    if(!test_nd)
+    {
+        cvAndS( test_array[INPUT][0], gamma,
+              test_array[INPUT_OUTPUT][0], test_array[MASK][0] );
+    }
+    else
+    {
+        cv::MatND c = cv::cvarrToMatND(test_array[INPUT_OUTPUT][0]);
+        cv::bitwise_and(cv::cvarrToMatND(test_array[INPUT][0]),
+                        gamma, c,
+                        cv::cvarrToMatND(test_array[MASK][0]));
+    }
 }
 
 CxCore_AndSTest ands_test;
@@ -2036,8 +2189,19 @@ CxCore_OrTest::CxCore_OrTest()
 
 void CxCore_OrTest::run_func()
 {
-    cvOr( test_array[INPUT][0], test_array[INPUT][1],
-          test_array[INPUT_OUTPUT][0], test_array[MASK][0] );
+    if(!test_nd)
+    {
+        cvOr( test_array[INPUT][0], test_array[INPUT][1],
+              test_array[INPUT_OUTPUT][0], test_array[MASK][0] );
+    }
+    else
+    {
+        cv::MatND c = cv::cvarrToMatND(test_array[INPUT_OUTPUT][0]);
+        cv::bitwise_or(cv::cvarrToMatND(test_array[INPUT][0]),
+                        cv::cvarrToMatND(test_array[INPUT][1]),
+                        c, cv::cvarrToMatND(test_array[MASK][0]));
+    }
+    
 }
 
 CxCore_OrTest or_test;
@@ -2058,8 +2222,18 @@ CxCore_OrSTest::CxCore_OrSTest()
 
 void CxCore_OrSTest::run_func()
 {
-    cvOrS( test_array[INPUT][0], gamma,
-           test_array[INPUT_OUTPUT][0], test_array[MASK][0] );
+    if(!test_nd)
+    {
+        cvOrS( test_array[INPUT][0], gamma,
+               test_array[INPUT_OUTPUT][0], test_array[MASK][0] );
+    }
+    else
+    {
+        cv::MatND c = cv::cvarrToMatND(test_array[INPUT_OUTPUT][0]);
+        cv::bitwise_or(cv::cvarrToMatND(test_array[INPUT][0]),
+                        gamma, c,
+                        cv::cvarrToMatND(test_array[MASK][0]));
+    }
 }
 
 CxCore_OrSTest ors_test;
@@ -2082,8 +2256,19 @@ CxCore_XorTest::CxCore_XorTest()
 
 void CxCore_XorTest::run_func()
 {
-    cvXor( test_array[INPUT][0], test_array[INPUT][1],
-           test_array[INPUT_OUTPUT][0], test_array[MASK][0] );
+    if(!test_nd)
+    {
+        cvXor( test_array[INPUT][0], test_array[INPUT][1],
+               test_array[INPUT_OUTPUT][0], test_array[MASK][0] );
+    }
+    else
+    {
+        cv::MatND c = cv::cvarrToMatND(test_array[INPUT_OUTPUT][0]);
+        cv::bitwise_xor(cv::cvarrToMatND(test_array[INPUT][0]),
+                        cv::cvarrToMatND(test_array[INPUT][1]),
+                        c, cv::cvarrToMatND(test_array[MASK][0]));
+    }
+    
 }
 
 CxCore_XorTest xor_test;
@@ -2104,8 +2289,18 @@ CxCore_XorSTest::CxCore_XorSTest()
 
 void CxCore_XorSTest::run_func()
 {
-    cvXorS( test_array[INPUT][0], gamma,
-            test_array[INPUT_OUTPUT][0], test_array[MASK][0] );
+    if(!test_nd)
+    {
+        cvXorS( test_array[INPUT][0], gamma,
+               test_array[INPUT_OUTPUT][0], test_array[MASK][0] );
+    }
+    else
+    {
+        cv::MatND c = cv::cvarrToMatND(test_array[INPUT_OUTPUT][0]);
+        cv::bitwise_xor(cv::cvarrToMatND(test_array[INPUT][0]),
+                        gamma, c,
+                        cv::cvarrToMatND(test_array[MASK][0]));
+    }
 }
 
 CxCore_XorSTest xors_test;
@@ -2128,8 +2323,15 @@ CxCore_NotTest::CxCore_NotTest()
 
 void CxCore_NotTest::run_func()
 {
-    cvNot( test_array[INPUT][0],
-           test_array[OUTPUT][0] );
+    if(!test_nd)
+    {
+        cvNot( test_array[INPUT][0], test_array[OUTPUT][0] );
+    }
+    else
+    {
+        cv::MatND c = cv::cvarrToMatND(test_array[OUTPUT][0]);
+        cv::bitwise_not(cv::cvarrToMatND(test_array[INPUT][0]), c);
+    }
 }
 
 CxCore_NotTest nots_test;
@@ -2359,8 +2561,18 @@ CxCore_CmpTest::CxCore_CmpTest()
 
 void CxCore_CmpTest::run_func()
 {
-    cvCmp( test_array[INPUT][0], test_array[INPUT][1],
-           test_array[OUTPUT][0], cmp_op );
+    if(!test_nd)
+    {
+        cvCmp( test_array[INPUT][0], test_array[INPUT][1],
+              test_array[OUTPUT][0], cmp_op );
+    }
+    else
+    {
+        cv::MatND c = cv::cvarrToMatND(test_array[OUTPUT][0]);
+        cv::compare(cv::cvarrToMatND(test_array[INPUT][0]),
+                    cv::cvarrToMatND(test_array[INPUT][1]),
+                    c, cmp_op);
+    }
 }
 
 CxCore_CmpTest cmp_test;
@@ -2381,8 +2593,17 @@ CxCore_CmpSTest::CxCore_CmpSTest()
 
 void CxCore_CmpSTest::run_func()
 {
-    cvCmpS( test_array[INPUT][0], gamma.val[0],
+    if(!test_nd)
+    {
+        cvCmpS( test_array[INPUT][0], gamma.val[0],
             test_array[OUTPUT][0], cmp_op );
+    }
+    else
+    {
+        cv::MatND c = cv::cvarrToMatND(test_array[OUTPUT][0]);
+        cv::compare(cv::cvarrToMatND(test_array[INPUT][0]),
+                    gamma.val[0], c, cmp_op);
+    }
 }
 
 CxCore_CmpSTest cmps_test;
@@ -2403,8 +2624,19 @@ CxCore_InRangeTest::CxCore_InRangeTest()
 
 void CxCore_InRangeTest::run_func()
 {
-    cvInRange( test_array[INPUT][0], test_array[INPUT][1],
-               test_array[INPUT][2], test_array[OUTPUT][0] );
+    if(!test_nd)
+    {
+        cvInRange( test_array[INPUT][0], test_array[INPUT][1],
+                  test_array[INPUT][2], test_array[OUTPUT][0] );
+    }
+    else
+    {
+        cv::MatND c = cv::cvarrToMatND(test_array[OUTPUT][0]);
+        cv::inRange(cv::cvarrToMatND(test_array[INPUT][0]),
+                    cv::cvarrToMatND(test_array[INPUT][1]),
+                    cv::cvarrToMatND(test_array[INPUT][2]),
+                    c);
+    }
 }
 
 CxCore_InRangeTest inrange_test;
@@ -2425,7 +2657,15 @@ CxCore_InRangeSTest::CxCore_InRangeSTest()
 
 void CxCore_InRangeSTest::run_func()
 {
-    cvInRangeS( test_array[INPUT][0], alpha, gamma, test_array[OUTPUT][0] );
+    if(!test_nd)
+    {
+        cvInRangeS( test_array[INPUT][0], alpha, gamma, test_array[OUTPUT][0] );
+    }
+    else
+    {
+        cv::MatND c = cv::cvarrToMatND(test_array[OUTPUT][0]);
+        cv::inRange(cv::cvarrToMatND(test_array[INPUT][0]), alpha, gamma, c);
+    }
 }
 
 CxCore_InRangeSTest inranges_test;
@@ -2632,8 +2872,16 @@ CxCore_CvtScaleTest::CxCore_CvtScaleTest()
 
 void CxCore_CvtScaleTest::run_func()
 {
-    cvConvertScale( test_array[INPUT][0], test_array[OUTPUT][0],
-                    alpha.val[0], gamma.val[0] );
+    if(!test_nd)
+    {
+        cvConvertScale( test_array[INPUT][0], test_array[OUTPUT][0],
+                       alpha.val[0], gamma.val[0] );
+    }
+    else
+    {
+        cv::MatND c = cv::cvarrToMatND(test_array[OUTPUT][0]);
+        cv::cvarrToMatND(test_array[INPUT][0]).convertTo(c,c.type(),alpha.val[0], gamma.val[0]);
+    }
 }
 
 CxCore_CvtScaleTest cvtscale_test;
@@ -2655,8 +2903,16 @@ CxCore_CvtScaleAbsTest::CxCore_CvtScaleAbsTest()
 
 void CxCore_CvtScaleAbsTest::run_func()
 {
-    cvConvertScaleAbs( test_array[INPUT][0], test_array[OUTPUT][0],
+    if(!test_nd)
+    {
+        cvConvertScaleAbs( test_array[INPUT][0], test_array[OUTPUT][0],
                        alpha.val[0], gamma.val[0] );
+    }
+    else
+    {
+        cv::Mat c = cv::cvarrToMat(test_array[OUTPUT][0]);
+        cv::convertScaleAbs(cv::cvarrToMat(test_array[INPUT][0]),c,alpha.val[0], gamma.val[0]);
+    }
 }
 
 CxCore_CvtScaleAbsTest cvtscaleabs_test;
@@ -2690,6 +2946,7 @@ protected:
     int output_count;
     bool single_channel;
     bool is_binary;
+    bool test_nd;
 };
 
 
@@ -2713,6 +2970,7 @@ CxCore_StatTestImpl::CxCore_StatTestImpl( const char* test_name,
     whole_size_list = arithm_whole_sizes;
     depth_list = arithm_depths;
     cn_list = arithm_channels;
+    test_nd = false;
 }
 
 
@@ -2741,6 +2999,7 @@ void CxCore_StatTestImpl::get_test_array_types_and_sizes( int test_case_idx,
         coi = cvTsRandInt(rng) % cn + 1;
         cvmat_allowed = false;
     }
+    test_nd = cvTsRandInt(rng) % 3 == 0;
 }
 
 
@@ -2878,7 +3137,14 @@ double CxCore_SumTest::get_success_error_level( int /*test_case_idx*/, int /*i*/
 
 void CxCore_SumTest::run_func()
 {
-    *(CvScalar*)(test_mat[OUTPUT][0].data.db) = cvSum(test_array[INPUT][0]);
+    if(!test_nd || coi)
+    {
+        *(CvScalar*)(test_mat[OUTPUT][0].data.db) = cvSum(test_array[INPUT][0]);
+    }
+    else
+    {
+        *(cv::Scalar*)(test_mat[OUTPUT][0].data.db) = cv::sum(cv::cvarrToMatND(test_array[INPUT][0]));
+    }
 }
 
 void CxCore_SumTest::prepare_to_validation( int /*test_case_idx*/ )
@@ -2921,7 +3187,14 @@ CxCore_NonZeroTest::CxCore_NonZeroTest()
 
 void CxCore_NonZeroTest::run_func()
 {
-    test_mat[OUTPUT][0].data.db[0] = cvCountNonZero(test_array[INPUT][0]);
+    if(!test_nd || coi)
+    {
+        test_mat[OUTPUT][0].data.db[0] = cvCountNonZero(test_array[INPUT][0]);
+    }
+    else
+    {
+        test_mat[OUTPUT][0].data.db[0] = cv::countNonZero(cv::cvarrToMatND(test_array[INPUT][0]));
+    }
 }
 
 void CxCore_NonZeroTest::get_test_array_types_and_sizes( int test_case_idx,
@@ -2972,8 +3245,17 @@ CxCore_MeanTest::CxCore_MeanTest()
 
 void CxCore_MeanTest::run_func()
 {
-    *(CvScalar*)(test_mat[OUTPUT][0].data.db) =
-        cvAvg(test_array[INPUT][0], test_array[MASK][0]);
+    if(!test_nd || coi)
+    {
+        *(CvScalar*)(test_mat[OUTPUT][0].data.db) =
+            cvAvg(test_array[INPUT][0], test_array[MASK][0]);
+    }
+    else
+    {
+        *(cv::Scalar*)(test_mat[OUTPUT][0].data.db) = cv::mean(
+                    cv::cvarrToMatND(test_array[INPUT][0]),
+                    cv::cvarrToMatND(test_array[MASK][0]));
+    }
 }
 
 void CxCore_MeanTest::prepare_to_validation( int /*test_case_idx*/ )
@@ -3007,17 +3289,20 @@ CxCore_MeanStdDevTest::CxCore_MeanStdDevTest()
 
 void CxCore_MeanStdDevTest::run_func()
 {
-    /*CvScalar s;
-    CvRNG* rng = ts->get_rng();
-    s.val[0] = cvTsRandReal(rng)*100. - 50.;
-    s.val[1] = cvTsRandReal(rng)*100. - 50.;
-    s.val[2] = cvTsRandReal(rng)*100. - 50.;
-    s.val[3] = cvTsRandReal(rng)*100. - 50.;
-    cvSet( &test_mat[INPUT][0], s );*/
-    cvAvgSdv( test_array[INPUT][0],
-              &((CvScalar*)(test_mat[OUTPUT][0].data.db))[0],
-              &((CvScalar*)(test_mat[OUTPUT][0].data.db))[1],
-              test_array[MASK][0] );
+    if(!test_nd || coi)
+    {
+        cvAvgSdv( test_array[INPUT][0],
+                  &((CvScalar*)(test_mat[OUTPUT][0].data.db))[0],
+                  &((CvScalar*)(test_mat[OUTPUT][0].data.db))[1],
+                  test_array[MASK][0] );
+    }
+    else
+    {
+        cv::meanStdDev(cv::cvarrToMatND(test_array[INPUT][0]),
+                       ((cv::Scalar*)(test_mat[OUTPUT][0].data.db))[0],
+                       ((cv::Scalar*)(test_mat[OUTPUT][0].data.db))[1],
+                       cv::cvarrToMatND(test_array[MASK][0]) );
+    }
 }
 
 double CxCore_MeanStdDevTest::get_success_error_level( int test_case_idx, int i, int j )
@@ -3229,8 +3514,20 @@ void CxCore_NormTest::print_timing_params( int test_case_idx, char* ptr, int par
 
 void CxCore_NormTest::run_func()
 {
-    test_mat[OUTPUT][0].data.db[0] = cvNorm( test_array[INPUT][0],
-            test_array[INPUT][1], norm_type, test_array[MASK][0] );
+    if(!test_nd || coi)
+    {
+        test_mat[OUTPUT][0].data.db[0] = cvNorm( test_array[INPUT][0],
+                 test_array[INPUT][1], norm_type, test_array[MASK][0] );
+    }
+    else
+    {
+        cv::MatND a = cv::cvarrToMatND(test_array[INPUT][0]);
+        cv::MatND b = cv::cvarrToMatND(test_array[INPUT][1]);
+        cv::MatND mask = cv::cvarrToMatND(test_array[MASK][0]);
+        test_mat[OUTPUT][0].data.db[0] = b.data ?
+            cv::norm( a, b, norm_type, mask ) :
+            cv::norm( a, norm_type, mask );
+    }
 }
 
 void CxCore_NormTest::prepare_to_validation( int /*test_case_idx*/ )