• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*M///////////////////////////////////////////////////////////////////////////////////////
2 //
3 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 //
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.
8 //
9 //
10 //                        Intel License Agreement
11 //                For Open Source Computer Vision Library
12 //
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
15 //
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
18 //
19 //   * Redistribution's of source code must retain the above copyright notice,
20 //     this list of conditions and the following disclaimer.
21 //
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.
25 //
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.
28 //
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.
39 //
40 //M*/
41 
42 #include "test_precomp.hpp"
43 #include "opencv2/imgproc/imgproc_c.h"
44 
45 using namespace cv;
46 using namespace std;
47 
48 class CV_AccumBaseTest : public cvtest::ArrayTest
49 {
50 public:
51     CV_AccumBaseTest();
52 
53 protected:
54     void get_test_array_types_and_sizes( int test_case_idx, vector<vector<Size> >& sizes, vector<vector<int> >& types );
55     double get_success_error_level( int test_case_idx, int i, int j );
56     double alpha;
57 };
58 
59 
CV_AccumBaseTest()60 CV_AccumBaseTest::CV_AccumBaseTest()
61 {
62     test_array[INPUT].push_back(NULL);
63     test_array[INPUT_OUTPUT].push_back(NULL);
64     test_array[REF_INPUT_OUTPUT].push_back(NULL);
65     test_array[MASK].push_back(NULL);
66     optional_mask = true;
67     element_wise_relative_error = false;
68 } // ctor
69 
70 
get_test_array_types_and_sizes(int test_case_idx,vector<vector<Size>> & sizes,vector<vector<int>> & types)71 void CV_AccumBaseTest::get_test_array_types_and_sizes( int test_case_idx,
72                         vector<vector<Size> >& sizes, vector<vector<int> >& types )
73 {
74     RNG& rng = ts->get_rng();
75     int depth = cvtest::randInt(rng) % 3, cn = cvtest::randInt(rng) & 1 ? 3 : 1;
76     int accdepth = std::max((int)(cvtest::randInt(rng) % 2 + 1), depth);
77     int i, input_count = (int)test_array[INPUT].size();
78     cvtest::ArrayTest::get_test_array_types_and_sizes( test_case_idx, sizes, types );
79     depth = depth == 0 ? CV_8U : depth == 1 ? CV_32F : CV_64F;
80     accdepth = accdepth == 1 ? CV_32F : CV_64F;
81     accdepth = MAX(accdepth, depth);
82 
83     for( i = 0; i < input_count; i++ )
84         types[INPUT][i] = CV_MAKETYPE(depth,cn);
85 
86     types[INPUT_OUTPUT][0] = types[REF_INPUT_OUTPUT][0] = CV_MAKETYPE(accdepth,cn);
87 
88     alpha = cvtest::randReal(rng);
89 }
90 
91 
get_success_error_level(int,int,int)92 double CV_AccumBaseTest::get_success_error_level( int /*test_case_idx*/, int /*i*/, int /*j*/ )
93 {
94     return test_mat[INPUT_OUTPUT][0].depth() < CV_64F ||
95            test_mat[INPUT][0].depth() == CV_32F ? FLT_EPSILON*100 : DBL_EPSILON*1000;
96 }
97 
98 
99 /// acc
100 class CV_AccTest : public CV_AccumBaseTest
101 {
102 public:
CV_AccTest()103     CV_AccTest() { }
104 protected:
105     void run_func();
106     void prepare_to_validation( int );
107 };
108 
109 
run_func(void)110 void CV_AccTest::run_func(void)
111 {
112     cvAcc( test_array[INPUT][0], test_array[INPUT_OUTPUT][0], test_array[MASK][0] );
113 }
114 
115 
prepare_to_validation(int)116 void CV_AccTest::prepare_to_validation( int )
117 {
118     const Mat& src = test_mat[INPUT][0];
119     Mat& dst = test_mat[REF_INPUT_OUTPUT][0];
120     const Mat& mask = test_array[MASK][0] ? test_mat[MASK][0] : Mat();
121     Mat temp;
122     cvtest::add( src, 1, dst, 1, cvScalarAll(0.), temp, dst.type() );
123     cvtest::copy( temp, dst, mask );
124 }
125 
126 
127 /// square acc
128 class CV_SquareAccTest : public CV_AccumBaseTest
129 {
130 public:
131     CV_SquareAccTest();
132 protected:
133     void run_func();
134     void prepare_to_validation( int );
135 };
136 
137 
CV_SquareAccTest()138 CV_SquareAccTest::CV_SquareAccTest()
139 {
140 }
141 
142 
run_func()143 void CV_SquareAccTest::run_func()
144 {
145     cvSquareAcc( test_array[INPUT][0], test_array[INPUT_OUTPUT][0], test_array[MASK][0] );
146 }
147 
148 
prepare_to_validation(int)149 void CV_SquareAccTest::prepare_to_validation( int )
150 {
151     const Mat& src = test_mat[INPUT][0];
152     Mat& dst = test_mat[REF_INPUT_OUTPUT][0];
153     const Mat& mask = test_array[MASK][0] ? test_mat[MASK][0] : Mat();
154     Mat temp;
155 
156     cvtest::convert( src, temp, dst.type() );
157     cvtest::multiply( temp, temp, temp, 1 );
158     cvtest::add( temp, 1, dst, 1, cvScalarAll(0.), temp, dst.depth() );
159     cvtest::copy( temp, dst, mask );
160 }
161 
162 
163 /// multiply acc
164 class CV_MultiplyAccTest : public CV_AccumBaseTest
165 {
166 public:
167     CV_MultiplyAccTest();
168 protected:
169     void run_func();
170     void prepare_to_validation( int );
171 };
172 
173 
CV_MultiplyAccTest()174 CV_MultiplyAccTest::CV_MultiplyAccTest()
175 {
176     test_array[INPUT].push_back(NULL);
177 }
178 
179 
run_func()180 void CV_MultiplyAccTest::run_func()
181 {
182     cvMultiplyAcc( test_array[INPUT][0], test_array[INPUT][1],
183                    test_array[INPUT_OUTPUT][0], test_array[MASK][0] );
184 }
185 
186 
prepare_to_validation(int)187 void CV_MultiplyAccTest::prepare_to_validation( int )
188 {
189     const Mat& src1 = test_mat[INPUT][0];
190     const Mat& src2 = test_mat[INPUT][1];
191     Mat& dst = test_mat[REF_INPUT_OUTPUT][0];
192     const Mat& mask = test_array[MASK][0] ? test_mat[MASK][0] : Mat();
193     Mat temp1, temp2;
194 
195     cvtest::convert( src1, temp1, dst.type() );
196     cvtest::convert( src2, temp2, dst.type() );
197 
198     cvtest::multiply( temp1, temp2, temp1, 1 );
199     cvtest::add( temp1, 1, dst, 1, cvScalarAll(0.), temp1, dst.depth() );
200     cvtest::copy( temp1, dst, mask );
201 }
202 
203 
204 /// running average
205 class CV_RunningAvgTest : public CV_AccumBaseTest
206 {
207 public:
208     CV_RunningAvgTest();
209 protected:
210     void run_func();
211     void prepare_to_validation( int );
212 };
213 
214 
CV_RunningAvgTest()215 CV_RunningAvgTest::CV_RunningAvgTest()
216 {
217 }
218 
219 
run_func()220 void CV_RunningAvgTest::run_func()
221 {
222     cvRunningAvg( test_array[INPUT][0], test_array[INPUT_OUTPUT][0],
223                   alpha, test_array[MASK][0] );
224 }
225 
226 
prepare_to_validation(int)227 void CV_RunningAvgTest::prepare_to_validation( int )
228 {
229     const Mat& src = test_mat[INPUT][0];
230     Mat& dst = test_mat[REF_INPUT_OUTPUT][0];
231     Mat temp;
232     const Mat& mask = test_array[MASK][0] ? test_mat[MASK][0] : Mat();
233     double a[1], b[1];
234     int accdepth = test_mat[INPUT_OUTPUT][0].depth();
235     CvMat A = cvMat(1,1,accdepth,a), B = cvMat(1,1,accdepth,b);
236     cvSetReal1D( &A, 0, alpha);
237     cvSetReal1D( &B, 0, 1 - cvGetReal1D(&A, 0));
238 
239     cvtest::convert( src, temp, dst.type() );
240     cvtest::add( src, cvGetReal1D(&A, 0), dst, cvGetReal1D(&B, 0), cvScalarAll(0.), temp, temp.depth() );
241     cvtest::copy( temp, dst, mask );
242 }
243 
244 
TEST(Video_Acc,accuracy)245 TEST(Video_Acc, accuracy) { CV_AccTest test; test.safe_run(); }
TEST(Video_AccSquared,accuracy)246 TEST(Video_AccSquared, accuracy) { CV_SquareAccTest test; test.safe_run(); }
TEST(Video_AccProduct,accuracy)247 TEST(Video_AccProduct, accuracy) { CV_MultiplyAccTest test; test.safe_run(); }
TEST(Video_RunningAvg,accuracy)248 TEST(Video_RunningAvg, accuracy) { CV_RunningAvgTest test; test.safe_run(); }
249