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.
44 static const char* accum_param_names[] = { "size", "channels", "depth", "use_mask", 0 };
45 static const CvSize accum_sizes[] = {{30,30}, {320, 240}, {720,480}, {-1,-1}};
46 static const CvSize accum_whole_sizes[] = {{320,240}, {320, 240}, {720,480}, {-1,-1}};
47 static const int accum_depths[] = { CV_8U, CV_32F, -1 };
48 static const int accum_channels[] = { 1, 3, -1 };
50 class CV_AccumBaseTestImpl : public CvArrTest
53 CV_AccumBaseTestImpl( const char* test_name, const char* test_funcs );
56 void get_test_array_types_and_sizes( int test_case_idx, CvSize** sizes, int** types );
57 double get_success_error_level( int test_case_idx, int i, int j );
58 void get_timing_test_array_types_and_sizes( int test_case_idx, CvSize** sizes, int** types,
59 CvSize** whole_sizes, bool *are_images );
64 CV_AccumBaseTestImpl::CV_AccumBaseTestImpl( const char* test_name, const char* test_funcs )
65 : CvArrTest( test_name, test_funcs, "" )
67 test_array[INPUT].push(NULL);
68 test_array[INPUT_OUTPUT].push(NULL);
69 test_array[REF_INPUT_OUTPUT].push(NULL);
70 test_array[TEMP].push(NULL);
71 test_array[MASK].push(NULL);
73 element_wise_relative_error = false;
75 default_timing_param_names = 0;
76 depth_list = accum_depths;
77 size_list = accum_sizes;
78 whole_size_list = accum_whole_sizes;
79 cn_list = accum_channels;
83 void CV_AccumBaseTestImpl::get_test_array_types_and_sizes( int test_case_idx,
84 CvSize** sizes, int** types )
86 CvRNG* rng = ts->get_rng();
87 int depth = cvTsRandInt(rng) % 2, cn = cvTsRandInt(rng) & 1 ? 3 : 1;
88 int i, input_count = test_array[INPUT].size();
89 CvArrTest::get_test_array_types_and_sizes( test_case_idx, sizes, types );
90 depth = depth == 0 ? CV_8U : CV_32F;
92 for( i = 0; i < input_count; i++ )
93 types[INPUT][i] = CV_MAKETYPE(depth,cn);
94 types[INPUT_OUTPUT][0] = types[REF_INPUT_OUTPUT][0] = types[TEMP][0] = CV_MAKETYPE(CV_32F,cn);
96 alpha = cvTsRandReal(rng);
100 double CV_AccumBaseTestImpl::get_success_error_level( int /*test_case_idx*/, int /*i*/, int /*j*/ )
102 return FLT_EPSILON*10;
106 void CV_AccumBaseTestImpl::get_timing_test_array_types_and_sizes( int test_case_idx,
107 CvSize** sizes, int** types, CvSize** whole_sizes, bool *are_images )
109 CvArrTest::get_timing_test_array_types_and_sizes( test_case_idx, sizes, types,
110 whole_sizes, are_images );
111 types[INPUT_OUTPUT][0] = CV_MAKETYPE(CV_32F, CV_MAT_CN(types[INPUT][0]));
112 alpha = 0.333333333333333;
116 CV_AccumBaseTestImpl accum_base( "accum", "" );
119 class CV_AccumBaseTest : public CV_AccumBaseTestImpl
122 CV_AccumBaseTest( const char* test_name, const char* test_funcs );
126 CV_AccumBaseTest::CV_AccumBaseTest( const char* test_name, const char* test_funcs )
127 : CV_AccumBaseTestImpl( test_name, test_funcs )
134 default_timing_param_names = accum_param_names;
139 class CV_AccTest : public CV_AccumBaseTest
145 void prepare_to_validation( int );
149 CV_AccTest::CV_AccTest()
150 : CV_AccumBaseTest( "accum-acc", "cvAcc" )
155 void CV_AccTest::run_func()
157 cvAcc( test_array[INPUT][0], test_array[INPUT_OUTPUT][0], test_array[MASK][0] );
161 void CV_AccTest::prepare_to_validation( int )
163 const CvMat* src = &test_mat[INPUT][0];
164 CvMat* dst = &test_mat[REF_INPUT_OUTPUT][0];
165 CvMat* temp = &test_mat[TEMP][0];
166 const CvMat* mask = test_array[MASK][0] ? &test_mat[MASK][0] : 0;
168 cvTsAdd( src, cvScalarAll(1.), dst, cvScalarAll(1.), cvScalarAll(0.), temp, 0 );
169 cvTsCopy( temp, dst, mask );
176 class CV_SquareAccTest : public CV_AccumBaseTest
182 void prepare_to_validation( int );
186 CV_SquareAccTest::CV_SquareAccTest()
187 : CV_AccumBaseTest( "accum-squareacc", "cvSquareAcc" )
192 void CV_SquareAccTest::run_func()
194 cvSquareAcc( test_array[INPUT][0], test_array[INPUT_OUTPUT][0], test_array[MASK][0] );
198 void CV_SquareAccTest::prepare_to_validation( int )
200 const CvMat* src = &test_mat[INPUT][0];
201 CvMat* dst = &test_mat[REF_INPUT_OUTPUT][0];
202 CvMat* temp = &test_mat[TEMP][0];
203 const CvMat* mask = test_array[MASK][0] ? &test_mat[MASK][0] : 0;
205 cvTsMul( src, src, cvScalarAll(1.), temp );
206 cvTsAdd( temp, cvScalarAll(1.), dst, cvScalarAll(1.), cvScalarAll(0.), temp, 0 );
207 cvTsCopy( temp, dst, mask );
210 CV_SquareAccTest squareacc_test;
214 class CV_MultiplyAccTest : public CV_AccumBaseTest
217 CV_MultiplyAccTest();
220 void prepare_to_validation( int );
224 CV_MultiplyAccTest::CV_MultiplyAccTest()
225 : CV_AccumBaseTest( "accum-mulacc", "cvMultiplyAcc" )
227 test_array[INPUT].push(NULL);
231 void CV_MultiplyAccTest::run_func()
233 cvMultiplyAcc( test_array[INPUT][0], test_array[INPUT][1],
234 test_array[INPUT_OUTPUT][0], test_array[MASK][0] );
238 void CV_MultiplyAccTest::prepare_to_validation( int )
240 const CvMat* src1 = &test_mat[INPUT][0];
241 const CvMat* src2 = &test_mat[INPUT][1];
242 CvMat* dst = &test_mat[REF_INPUT_OUTPUT][0];
243 CvMat* temp = &test_mat[TEMP][0];
244 const CvMat* mask = test_array[MASK][0] ? &test_mat[MASK][0] : 0;
246 cvTsMul( src1, src2, cvScalarAll(1.), temp );
247 cvTsAdd( temp, cvScalarAll(1.), dst, cvScalarAll(1.), cvScalarAll(0.), temp, 0 );
248 cvTsCopy( temp, dst, mask );
251 CV_MultiplyAccTest mulacc_test;
255 class CV_RunningAvgTest : public CV_AccumBaseTest
261 void prepare_to_validation( int );
265 CV_RunningAvgTest::CV_RunningAvgTest()
266 : CV_AccumBaseTest( "accum-runavg", "cvRunningAvg" )
271 void CV_RunningAvgTest::run_func()
273 cvRunningAvg( test_array[INPUT][0], test_array[INPUT_OUTPUT][0],
274 alpha, test_array[MASK][0] );
278 void CV_RunningAvgTest::prepare_to_validation( int )
280 const CvMat* src = &test_mat[INPUT][0];
281 CvMat* dst = &test_mat[REF_INPUT_OUTPUT][0];
282 CvMat* temp = &test_mat[TEMP][0];
283 const CvMat* mask = test_array[MASK][0] ? &test_mat[MASK][0] : 0;
285 CvMat A = cvMat(1,1,CV_32F,a), B = cvMat(1,1,CV_32F,b);
286 cvSetReal1D( &A, 0, alpha);
287 cvSetReal1D( &B, 0, 1 - A.data.fl[0] );
289 cvTsAdd( src, cvScalarAll(A.data.fl[0]), dst, cvScalarAll(B.data.fl[0]), cvScalarAll(0.), temp, 0 );
290 cvTsCopy( temp, dst, mask );
293 CV_RunningAvgTest runavg_test;