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 //                           License Agreement
11 //                For Open Source Computer Vision Library
12 //
13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15 // Third party copyrights are property of their respective owners.
16 //
17 // Redistribution and use in source and binary forms, with or without modification,
18 // are permitted provided that the following conditions are met:
19 //
20 //   * Redistribution's of source code must retain the above copyright notice,
21 //     this list of conditions and the following disclaimer.
22 //
23 //   * Redistribution's in binary form must reproduce the above copyright notice,
24 //     this list of conditions and the following disclaimer in the documentation
25 //     and/or other materials provided with the distribution.
26 //
27 //   * The name of the copyright holders may not be used to endorse or promote products
28 //     derived from this software without specific prior written permission.
29 //
30 // This software is provided by the copyright holders and contributors "as is" and
31 // any express or implied warranties, including, but not limited to, the implied
32 // warranties of merchantability and fitness for a particular purpose are disclaimed.
33 // In no event shall the Intel Corporation or contributors be liable for any direct,
34 // indirect, incidental, special, exemplary, or consequential damages
35 // (including, but not limited to, procurement of substitute goods or services;
36 // loss of use, data, or profits; or business interruption) however caused
37 // and on any theory of liability, whether in contract, strict liability,
38 // or tort (including negligence or otherwise) arising in any way out of
39 // the use of this software, even if advised of the possibility of such damage.
40 //
41 //M*/
42 
43 #include "test_precomp.hpp"
44 
45 #if defined _MSC_VER && _MSC_VER >= 1200
46 # pragma warning (disable : 4408 4201 4100)
47 #endif
48 
49 static std::string path;
50 
51 namespace {
52 
53 template <class T_in, class T_out>
generateIntegralTests(NCVAutoTestLister & testLister,NCVTestSourceProvider<T_in> & src,Ncv32u maxWidth,Ncv32u maxHeight)54 void generateIntegralTests(NCVAutoTestLister &testLister,
55                            NCVTestSourceProvider<T_in> &src,
56                            Ncv32u maxWidth, Ncv32u maxHeight)
57 {
58     for (Ncv32f _i=1.0; _i<maxWidth; _i*=1.2f)
59     {
60         Ncv32u i = (Ncv32u)_i;
61         char testName[80];
62         sprintf(testName, "LinIntImgW%dH%d", i, 2);
63         testLister.add(new TestIntegralImage<T_in, T_out>(testName, src, i, 2));
64     }
65     for (Ncv32f _i=1.0; _i<maxHeight; _i*=1.2f)
66     {
67         Ncv32u i = (Ncv32u)_i;
68         char testName[80];
69         sprintf(testName, "LinIntImgW%dH%d", 2, i);
70         testLister.add(new TestIntegralImage<T_in, T_out>(testName, src, 2, i));
71     }
72 
73     testLister.add(new TestIntegralImage<T_in, T_out>("LinIntImg_VGA", src, 640, 480));
74 }
75 
generateSquaredIntegralTests(NCVAutoTestLister & testLister,NCVTestSourceProvider<Ncv8u> & src,Ncv32u maxWidth,Ncv32u maxHeight)76 void generateSquaredIntegralTests(NCVAutoTestLister &testLister, NCVTestSourceProvider<Ncv8u> &src,
77                                   Ncv32u maxWidth, Ncv32u maxHeight)
78 {
79     for (Ncv32f _i=1.0; _i<maxWidth; _i*=1.2f)
80     {
81         Ncv32u i = (Ncv32u)_i;
82         char testName[80];
83         sprintf(testName, "SqIntImgW%dH%d", i, 32);
84         testLister.add(new TestIntegralImageSquared(testName, src, i, 32));
85     }
86     for (Ncv32f _i=1.0; _i<maxHeight; _i*=1.2f)
87     {
88         Ncv32u i = (Ncv32u)_i;
89         char testName[80];
90         sprintf(testName, "SqIntImgW%dH%d", 32, i);
91         testLister.add(new TestIntegralImageSquared(testName, src, 32, i));
92     }
93 
94     testLister.add(new TestIntegralImageSquared("SqLinIntImg_VGA", src, 640, 480));
95 }
96 
generateRectStdDevTests(NCVAutoTestLister & testLister,NCVTestSourceProvider<Ncv8u> & src,Ncv32u maxWidth,Ncv32u maxHeight)97 void generateRectStdDevTests(NCVAutoTestLister &testLister, NCVTestSourceProvider<Ncv8u> &src,
98                              Ncv32u maxWidth, Ncv32u maxHeight)
99 {
100     NcvRect32u rect(1,1,18,18);
101 
102     for (Ncv32f _i=32; _i<maxHeight/2 && _i < maxWidth/2; _i*=1.2f)
103     {
104         Ncv32u i = (Ncv32u)_i;
105         char testName[80];
106         sprintf(testName, "RectStdDevW%dH%d", i*2, i);
107         testLister.add(new TestRectStdDev(testName, src, i*2, i, rect, 1, true));
108         testLister.add(new TestRectStdDev(testName, src, i*2, i, rect, 1.5, false));
109         testLister.add(new TestRectStdDev(testName, src, i-1, i*2-1, rect, 1, false));
110         testLister.add(new TestRectStdDev(testName, src, i-1, i*2-1, rect, 2.5, true));
111     }
112 
113     testLister.add(new TestRectStdDev("RectStdDev_VGA", src, 640, 480, rect, 1, true));
114 }
115 
116 template <class T>
generateResizeTests(NCVAutoTestLister & testLister,NCVTestSourceProvider<T> & src)117 void generateResizeTests(NCVAutoTestLister &testLister, NCVTestSourceProvider<T> &src)
118 {
119     for (Ncv32u i=2; i<10; ++i)
120     {
121         char testName[80];
122         sprintf(testName, "TestResize_VGA_s%d", i);
123         testLister.add(new TestResize<T>(testName, src, 640, 480, i, true));
124         testLister.add(new TestResize<T>(testName, src, 640, 480, i, false));
125     }
126 
127     for (Ncv32u i=2; i<10; ++i)
128     {
129         char testName[80];
130         sprintf(testName, "TestResize_1080_s%d", i);
131         testLister.add(new TestResize<T>(testName, src, 1920, 1080, i, true));
132         testLister.add(new TestResize<T>(testName, src, 1920, 1080, i, false));
133     }
134 }
135 
generateNPPSTVectorTests(NCVAutoTestLister & testLister,NCVTestSourceProvider<Ncv32u> & src,Ncv32u maxLength)136 void generateNPPSTVectorTests(NCVAutoTestLister &testLister, NCVTestSourceProvider<Ncv32u> &src, Ncv32u maxLength)
137 {
138     //compaction
139     for (Ncv32f _i=256.0; _i<maxLength; _i*=1.5f)
140     {
141         Ncv32u i = (Ncv32u)_i;
142         char testName[80];
143         sprintf(testName, "Compaction%d", i);
144         testLister.add(new TestCompact(testName, src, i, 0xFFFFFFFF, 30));
145     }
146     for (Ncv32u i=1; i<260; i++)
147     {
148         char testName[80];
149         sprintf(testName, "Compaction%d", i);
150         testLister.add(new TestCompact(testName, src, i, 0xC001C0DE, 70));
151         testLister.add(new TestCompact(testName, src, i, 0xC001C0DE, 0));
152         testLister.add(new TestCompact(testName, src, i, 0xC001C0DE, 100));
153     }
154     for (Ncv32u i=256*256-10; i<256*256+10; i++)
155     {
156         char testName[80];
157         sprintf(testName, "Compaction%d", i);
158         testLister.add(new TestCompact(testName, src, i, 0xFFFFFFFF, 40));
159     }
160     for (Ncv32u i=256*256*256-2; i<256*256*256+2; i++)
161     {
162         char testName[80];
163         sprintf(testName, "Compaction%d", i);
164         testLister.add(new TestCompact(testName, src, i, 0x00000000, 2));
165     }
166 }
167 
168 
169 template <class T>
generateTransposeTests(NCVAutoTestLister & testLister,NCVTestSourceProvider<T> & src)170 void generateTransposeTests(NCVAutoTestLister &testLister, NCVTestSourceProvider<T> &src)
171 {
172     for (int i=2; i<64; i+=4)
173     {
174         for (int j=2; j<64; j+=4)
175         {
176             char testName[80];
177             sprintf(testName, "TestTranspose_%dx%d", i, j);
178             testLister.add(new TestTranspose<T>(testName, src, i, j));
179         }
180     }
181 
182     for (int i=1; i<128; i+=1)
183     {
184         for (int j=1; j<2; j+=1)
185         {
186             char testName[80];
187             sprintf(testName, "TestTranspose_%dx%d", i, j);
188             testLister.add(new TestTranspose<T>(testName, src, i, j));
189         }
190     }
191 
192     testLister.add(new TestTranspose<T>("TestTranspose_VGA", src, 640, 480));
193     testLister.add(new TestTranspose<T>("TestTranspose_HD1080", src, 1920, 1080));
194 
195     //regression tests
196     testLister.add(new TestTranspose<T>("TestTranspose_reg_0", src, 1072, 375));
197 }
198 
199 template <class T>
generateDrawRectsTests(NCVAutoTestLister & testLister,NCVTestSourceProvider<T> & src,NCVTestSourceProvider<Ncv32u> & src32u,Ncv32u maxWidth,Ncv32u maxHeight)200 void generateDrawRectsTests(NCVAutoTestLister &testLister,
201                             NCVTestSourceProvider<T> &src,
202                             NCVTestSourceProvider<Ncv32u> &src32u,
203                             Ncv32u maxWidth, Ncv32u maxHeight)
204 {
205     for (Ncv32f _i=16.0; _i<maxWidth; _i*=1.1f)
206     {
207         Ncv32u i = (Ncv32u)_i;
208         Ncv32u j = maxHeight * i / maxWidth;
209         if (!j) continue;
210         char testName[80];
211         sprintf(testName, "DrawRectsW%dH%d", i, j);
212 
213         if (sizeof(T) == sizeof(Ncv32u))
214         {
215             testLister.add(new TestDrawRects<T>(testName, src, src32u, i, j, i*j/1000+1, (T)0xFFFFFFFF));
216         }
217         else if (sizeof(T) == sizeof(Ncv8u))
218         {
219             testLister.add(new TestDrawRects<T>(testName, src, src32u, i, j, i*j/1000+1, (T)0xFF));
220         }
221         else
222         {
223             ncvAssertPrintCheck(false, "Attempted to instantiate non-existing DrawRects test suite");
224         }
225     }
226 
227     //test VGA
228     testLister.add(new TestDrawRects<T>("DrawRects_VGA", src, src32u, 640, 480, 640*480/1000, (T)0xFF));
229 }
230 
generateVectorTests(NCVAutoTestLister & testLister,NCVTestSourceProvider<Ncv32u> & src,Ncv32u maxLength)231 void generateVectorTests(NCVAutoTestLister &testLister, NCVTestSourceProvider<Ncv32u> &src, Ncv32u maxLength)
232 {
233     //growth
234     for (Ncv32f _i=10.0; _i<maxLength; _i*=1.5f)
235     {
236         Ncv32u i = (Ncv32u)_i;
237         char testName[80];
238         sprintf(testName, "VectorGrow%d", i);
239         testLister.add(new TestHypothesesGrow(testName, src, 20, 20, 2.2f, i, i/2, i, i/4));
240         testLister.add(new TestHypothesesGrow(testName, src, 10, 42, 1.2f, i, i, i, 0));
241     }
242     testLister.add(new TestHypothesesGrow("VectorGrow01b", src, 10, 42, 1.2f, 10, 0, 10, 1));
243     testLister.add(new TestHypothesesGrow("VectorGrow11b", src, 10, 42, 1.2f, 10, 1, 10, 1));
244     testLister.add(new TestHypothesesGrow("VectorGrow10b", src, 10, 42, 1.2f, 10, 1, 10, 0));
245     testLister.add(new TestHypothesesGrow("VectorGrow00b", src, 10, 42, 1.2f, 10, 0, 10, 0));
246 }
247 
generateHypothesesFiltrationTests(NCVAutoTestLister & testLister,NCVTestSourceProvider<Ncv32u> & src,Ncv32u maxLength)248 void generateHypothesesFiltrationTests(NCVAutoTestLister &testLister, NCVTestSourceProvider<Ncv32u> &src, Ncv32u maxLength)
249 {
250     for (Ncv32f _i=1.0; _i<maxLength; _i*=1.1f)
251     {
252         Ncv32u i = (Ncv32u)_i;
253         char testName[80];
254         sprintf(testName, "HypFilter%d", i);
255         testLister.add(new TestHypothesesFilter(testName, src, i, 3, 0.2f));
256         testLister.add(new TestHypothesesFilter(testName, src, i, 0, 0.2f));
257         testLister.add(new TestHypothesesFilter(testName, src, i, 1, 0.1f));
258     }
259 }
260 
261 
generateHaarLoaderTests(NCVAutoTestLister & testLister)262 void generateHaarLoaderTests(NCVAutoTestLister &testLister)
263 {
264     testLister.add(new TestHaarCascadeLoader("haarcascade_eye.xml", path + "haarcascade_eye.xml"));
265     testLister.add(new TestHaarCascadeLoader("haarcascade_frontalface_alt.xml", path + "haarcascade_frontalface_alt.xml"));
266     testLister.add(new TestHaarCascadeLoader("haarcascade_frontalface_alt2.xml", path + "haarcascade_frontalface_alt2.xml"));
267     testLister.add(new TestHaarCascadeLoader("haarcascade_frontalface_alt_tree.xml", path + "haarcascade_frontalface_alt_tree.xml"));
268     testLister.add(new TestHaarCascadeLoader("haarcascade_eye_tree_eyeglasses.xml", path + "haarcascade_eye_tree_eyeglasses.xml"));
269 }
270 
generateHaarApplicationTests(NCVAutoTestLister & testLister,NCVTestSourceProvider<Ncv8u> & src,Ncv32u maxWidth,Ncv32u maxHeight)271 void generateHaarApplicationTests(NCVAutoTestLister &testLister, NCVTestSourceProvider<Ncv8u> &src,
272                                   Ncv32u maxWidth, Ncv32u maxHeight)
273 {
274     (void)maxHeight;
275     for (Ncv32u i=100; i<512; i+=41)
276     {
277         for (Ncv32u j=100; j<128; j+=25)
278         {
279             char testName[80];
280             sprintf(testName, "HaarAppl%d_%d", i, j);
281             testLister.add(new TestHaarCascadeApplication(testName, src, path + "haarcascade_frontalface_alt.xml", j, i));
282         }
283     }
284     for (Ncv32f _i=20.0; _i<maxWidth; _i*=1.5f)
285     {
286         Ncv32u i = (Ncv32u)_i;
287         char testName[80];
288         sprintf(testName, "HaarAppl%d", i);
289         testLister.add(new TestHaarCascadeApplication(testName, src, path + "haarcascade_frontalface_alt.xml", i, i));
290     }
291 }
292 
devNullOutput(const cv::String & msg)293 static void devNullOutput(const cv::String& msg)
294 {
295     (void)msg;
296 }
297 
298 }
299 
nvidia_NPPST_Integral_Image(const std::string & test_data_path,OutputLevel outputLevel)300 bool nvidia_NPPST_Integral_Image(const std::string& test_data_path, OutputLevel outputLevel)
301 {
302     path = test_data_path.c_str();
303     ncvSetDebugOutputHandler(devNullOutput);
304 
305     NCVAutoTestLister testListerII("NPPST Integral Image", outputLevel);
306 
307     NCVTestSourceProvider<Ncv8u> testSrcRandom_8u(2010, 0, 255, 2048, 2048);
308     NCVTestSourceProvider<Ncv32f> testSrcRandom_32f(2010, -1.0f, 1.0f, 2048, 2048);
309 
310     generateIntegralTests<Ncv8u, Ncv32u>(testListerII, testSrcRandom_8u, 2048, 2048);
311     generateIntegralTests<Ncv32f, Ncv32f>(testListerII, testSrcRandom_32f, 2048, 2048);
312 
313     return testListerII.invoke();
314 }
315 
nvidia_NPPST_Squared_Integral_Image(const std::string & test_data_path,OutputLevel outputLevel)316 bool nvidia_NPPST_Squared_Integral_Image(const std::string& test_data_path, OutputLevel outputLevel)
317 {
318     path = test_data_path;
319     ncvSetDebugOutputHandler(devNullOutput);
320 
321     NCVAutoTestLister testListerSII("NPPST Squared Integral Image", outputLevel);
322 
323     NCVTestSourceProvider<Ncv8u> testSrcRandom_8u(2010, 0, 255, 2048, 2048);
324 
325     generateSquaredIntegralTests(testListerSII, testSrcRandom_8u, 2048, 2048);
326 
327     return testListerSII.invoke();
328 }
329 
nvidia_NPPST_RectStdDev(const std::string & test_data_path,OutputLevel outputLevel)330 bool nvidia_NPPST_RectStdDev(const std::string& test_data_path, OutputLevel outputLevel)
331 {
332     path = test_data_path;
333     ncvSetDebugOutputHandler(devNullOutput);
334 
335     NCVAutoTestLister testListerRStdDev("NPPST RectStdDev", outputLevel);
336 
337     NCVTestSourceProvider<Ncv8u> testSrcRandom_8u(2010, 0, 255, 2048, 2048);
338 
339     generateRectStdDevTests(testListerRStdDev, testSrcRandom_8u, 2048, 2048);
340 
341     return testListerRStdDev.invoke();
342 }
343 
nvidia_NPPST_Resize(const std::string & test_data_path,OutputLevel outputLevel)344 bool nvidia_NPPST_Resize(const std::string& test_data_path, OutputLevel outputLevel)
345 {
346     path = test_data_path;
347     ncvSetDebugOutputHandler(devNullOutput);
348 
349     NCVAutoTestLister testListerResize("NPPST Resize", outputLevel);
350 
351     NCVTestSourceProvider<Ncv32u> testSrcRandom_32u(2010, 0, 0xFFFFFFFF, 2048, 2048);
352     NCVTestSourceProvider<Ncv64u> testSrcRandom_64u(2010, 0, (Ncv64u) -1, 2048, 2048);
353 
354     generateResizeTests(testListerResize, testSrcRandom_32u);
355     generateResizeTests(testListerResize, testSrcRandom_64u);
356 
357     return testListerResize.invoke();
358 }
359 
nvidia_NPPST_Vector_Operations(const std::string & test_data_path,OutputLevel outputLevel)360 bool nvidia_NPPST_Vector_Operations(const std::string& test_data_path, OutputLevel outputLevel)
361 {
362     path = test_data_path;
363     ncvSetDebugOutputHandler(devNullOutput);
364 
365     NCVAutoTestLister testListerNPPSTVectorOperations("NPPST Vector Operations", outputLevel);
366 
367     NCVTestSourceProvider<Ncv32u> testSrcRandom_32u(2010, 0, 0xFFFFFFFF, 2048, 2048);
368 
369     generateNPPSTVectorTests(testListerNPPSTVectorOperations, testSrcRandom_32u, 2048*2048);
370 
371     return testListerNPPSTVectorOperations.invoke();
372 }
373 
nvidia_NPPST_Transpose(const std::string & test_data_path,OutputLevel outputLevel)374 bool nvidia_NPPST_Transpose(const std::string& test_data_path, OutputLevel outputLevel)
375 {
376     path = test_data_path;
377     ncvSetDebugOutputHandler(devNullOutput);
378 
379     NCVAutoTestLister testListerTranspose("NPPST Transpose", outputLevel);
380 
381     NCVTestSourceProvider<Ncv32u> testSrcRandom_32u(2010, 0, 0xFFFFFFFF, 2048, 2048);
382     NCVTestSourceProvider<Ncv64u> testSrcRandom_64u(2010, 0, (Ncv64u) -1, 2048, 2048);
383 
384     generateTransposeTests(testListerTranspose, testSrcRandom_32u);
385     generateTransposeTests(testListerTranspose, testSrcRandom_64u);
386 
387     return testListerTranspose.invoke();
388 }
389 
nvidia_NCV_Vector_Operations(const std::string & test_data_path,OutputLevel outputLevel)390 bool nvidia_NCV_Vector_Operations(const std::string& test_data_path, OutputLevel outputLevel)
391 {
392     path = test_data_path;
393     ncvSetDebugOutputHandler(devNullOutput);
394 
395     NCVAutoTestLister testListerVectorOperations("Vector Operations", outputLevel);
396 
397     NCVTestSourceProvider<Ncv32u> testSrcRandom_32u(2010, 0, 0xFFFFFFFF, 2048, 2048);
398 
399     generateVectorTests(testListerVectorOperations, testSrcRandom_32u, 2048*2048);
400 
401     return testListerVectorOperations.invoke();
402 
403 }
404 
nvidia_NCV_Haar_Cascade_Loader(const std::string & test_data_path,OutputLevel outputLevel)405 bool nvidia_NCV_Haar_Cascade_Loader(const std::string& test_data_path, OutputLevel outputLevel)
406 {
407     path = test_data_path;
408     ncvSetDebugOutputHandler(devNullOutput);
409 
410     NCVAutoTestLister testListerHaarLoader("Haar Cascade Loader", outputLevel);
411 
412     generateHaarLoaderTests(testListerHaarLoader);
413 
414     return testListerHaarLoader.invoke();
415 }
416 
nvidia_NCV_Haar_Cascade_Application(const std::string & test_data_path,OutputLevel outputLevel)417 bool nvidia_NCV_Haar_Cascade_Application(const std::string& test_data_path, OutputLevel outputLevel)
418 {
419     path = test_data_path;
420     ncvSetDebugOutputHandler(devNullOutput);
421 
422     NCVAutoTestLister testListerHaarAppl("Haar Cascade Application", outputLevel);
423 
424     NCVTestSourceProvider<Ncv8u> testSrcFacesVGA_8u(path + "group_1_640x480_VGA.pgm");
425 
426     generateHaarApplicationTests(testListerHaarAppl, testSrcFacesVGA_8u, 640, 480);
427 
428     return testListerHaarAppl.invoke();
429 }
430 
nvidia_NCV_Hypotheses_Filtration(const std::string & test_data_path,OutputLevel outputLevel)431 bool nvidia_NCV_Hypotheses_Filtration(const std::string& test_data_path, OutputLevel outputLevel)
432 {
433     path = test_data_path;
434     ncvSetDebugOutputHandler(devNullOutput);
435 
436     NCVAutoTestLister testListerHypFiltration("Hypotheses Filtration", outputLevel);
437 
438     NCVTestSourceProvider<Ncv32u> testSrcRandom_32u(2010, 0, 0xFFFFFFFF, 2048, 2048);
439 
440     generateHypothesesFiltrationTests(testListerHypFiltration, testSrcRandom_32u, 512);
441 
442     return testListerHypFiltration.invoke();
443 }
444 
nvidia_NCV_Visualization(const std::string & test_data_path,OutputLevel outputLevel)445 bool nvidia_NCV_Visualization(const std::string& test_data_path, OutputLevel outputLevel)
446 {
447     path = test_data_path;
448     ncvSetDebugOutputHandler(devNullOutput);
449 
450     NCVAutoTestLister testListerVisualize("Visualization", outputLevel);
451 
452     NCVTestSourceProvider<Ncv8u> testSrcRandom_8u(2010, 0, 255, 2048, 2048);
453     NCVTestSourceProvider<Ncv32u> testSrcRandom_32u(2010, 0, RAND_MAX, 2048, 2048);
454 
455     generateDrawRectsTests(testListerVisualize, testSrcRandom_8u, testSrcRandom_32u, 2048, 2048);
456     generateDrawRectsTests(testListerVisualize, testSrcRandom_32u, testSrcRandom_32u, 2048, 2048);
457 
458     return testListerVisualize.invoke();
459 }
460