main_nvidia.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  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. #include "test_precomp.hpp"
  43. #if defined _MSC_VER && _MSC_VER >= 1200
  44. # pragma warning (disable : 4408 4201 4100)
  45. #endif
  46. static std::string path;
  47. namespace {
  48. template <class T_in, class T_out>
  49. void generateIntegralTests(NCVAutoTestLister &testLister,
  50. NCVTestSourceProvider<T_in> &src,
  51. Ncv32u maxWidth, Ncv32u maxHeight)
  52. {
  53. for (Ncv32f _i=1.0; _i<maxWidth; _i*=1.2f)
  54. {
  55. Ncv32u i = (Ncv32u)_i;
  56. char testName[80];
  57. sprintf(testName, "LinIntImgW%dH%d", i, 2);
  58. testLister.add(new TestIntegralImage<T_in, T_out>(testName, src, i, 2));
  59. }
  60. for (Ncv32f _i=1.0; _i<maxHeight; _i*=1.2f)
  61. {
  62. Ncv32u i = (Ncv32u)_i;
  63. char testName[80];
  64. sprintf(testName, "LinIntImgW%dH%d", 2, i);
  65. testLister.add(new TestIntegralImage<T_in, T_out>(testName, src, 2, i));
  66. }
  67. testLister.add(new TestIntegralImage<T_in, T_out>("LinIntImg_VGA", src, 640, 480));
  68. }
  69. void generateSquaredIntegralTests(NCVAutoTestLister &testLister, NCVTestSourceProvider<Ncv8u> &src,
  70. Ncv32u maxWidth, Ncv32u maxHeight)
  71. {
  72. for (Ncv32f _i=1.0; _i<maxWidth; _i*=1.2f)
  73. {
  74. Ncv32u i = (Ncv32u)_i;
  75. char testName[80];
  76. sprintf(testName, "SqIntImgW%dH%d", i, 32);
  77. testLister.add(new TestIntegralImageSquared(testName, src, i, 32));
  78. }
  79. for (Ncv32f _i=1.0; _i<maxHeight; _i*=1.2f)
  80. {
  81. Ncv32u i = (Ncv32u)_i;
  82. char testName[80];
  83. sprintf(testName, "SqIntImgW%dH%d", 32, i);
  84. testLister.add(new TestIntegralImageSquared(testName, src, 32, i));
  85. }
  86. testLister.add(new TestIntegralImageSquared("SqLinIntImg_VGA", src, 640, 480));
  87. }
  88. void generateRectStdDevTests(NCVAutoTestLister &testLister, NCVTestSourceProvider<Ncv8u> &src,
  89. Ncv32u maxWidth, Ncv32u maxHeight)
  90. {
  91. NcvRect32u rect(1,1,18,18);
  92. for (Ncv32f _i=32; _i<maxHeight/2 && _i < maxWidth/2; _i*=1.2f)
  93. {
  94. Ncv32u i = (Ncv32u)_i;
  95. char testName[80];
  96. sprintf(testName, "RectStdDevW%dH%d", i*2, i);
  97. testLister.add(new TestRectStdDev(testName, src, i*2, i, rect, 1, true));
  98. testLister.add(new TestRectStdDev(testName, src, i*2, i, rect, 1.5, false));
  99. testLister.add(new TestRectStdDev(testName, src, i-1, i*2-1, rect, 1, false));
  100. testLister.add(new TestRectStdDev(testName, src, i-1, i*2-1, rect, 2.5, true));
  101. }
  102. testLister.add(new TestRectStdDev("RectStdDev_VGA", src, 640, 480, rect, 1, true));
  103. }
  104. template <class T>
  105. void generateResizeTests(NCVAutoTestLister &testLister, NCVTestSourceProvider<T> &src)
  106. {
  107. for (Ncv32u i=2; i<10; ++i)
  108. {
  109. char testName[80];
  110. sprintf(testName, "TestResize_VGA_s%d", i);
  111. testLister.add(new TestResize<T>(testName, src, 640, 480, i, true));
  112. testLister.add(new TestResize<T>(testName, src, 640, 480, i, false));
  113. }
  114. for (Ncv32u i=2; i<10; ++i)
  115. {
  116. char testName[80];
  117. sprintf(testName, "TestResize_1080_s%d", i);
  118. testLister.add(new TestResize<T>(testName, src, 1920, 1080, i, true));
  119. testLister.add(new TestResize<T>(testName, src, 1920, 1080, i, false));
  120. }
  121. }
  122. void generateNPPSTVectorTests(NCVAutoTestLister &testLister, NCVTestSourceProvider<Ncv32u> &src, Ncv32u maxLength)
  123. {
  124. //compaction
  125. for (Ncv32f _i=256.0; _i<maxLength; _i*=1.5f)
  126. {
  127. Ncv32u i = (Ncv32u)_i;
  128. char testName[80];
  129. sprintf(testName, "Compaction%d", i);
  130. testLister.add(new TestCompact(testName, src, i, 0xFFFFFFFF, 30));
  131. }
  132. for (Ncv32u i=1; i<260; i++)
  133. {
  134. char testName[80];
  135. sprintf(testName, "Compaction%d", i);
  136. testLister.add(new TestCompact(testName, src, i, 0xC001C0DE, 70));
  137. testLister.add(new TestCompact(testName, src, i, 0xC001C0DE, 0));
  138. testLister.add(new TestCompact(testName, src, i, 0xC001C0DE, 100));
  139. }
  140. for (Ncv32u i=256*256-10; i<256*256+10; i++)
  141. {
  142. char testName[80];
  143. sprintf(testName, "Compaction%d", i);
  144. testLister.add(new TestCompact(testName, src, i, 0xFFFFFFFF, 40));
  145. }
  146. for (Ncv32u i=256*256*256-2; i<256*256*256+2; i++)
  147. {
  148. char testName[80];
  149. sprintf(testName, "Compaction%d", i);
  150. testLister.add(new TestCompact(testName, src, i, 0x00000000, 2));
  151. }
  152. }
  153. template <class T>
  154. void generateTransposeTests(NCVAutoTestLister &testLister, NCVTestSourceProvider<T> &src)
  155. {
  156. for (int i=2; i<64; i+=4)
  157. {
  158. for (int j=2; j<64; j+=4)
  159. {
  160. char testName[80];
  161. sprintf(testName, "TestTranspose_%dx%d", i, j);
  162. testLister.add(new TestTranspose<T>(testName, src, i, j));
  163. }
  164. }
  165. for (int i=1; i<128; i+=1)
  166. {
  167. for (int j=1; j<2; j+=1)
  168. {
  169. char testName[80];
  170. sprintf(testName, "TestTranspose_%dx%d", i, j);
  171. testLister.add(new TestTranspose<T>(testName, src, i, j));
  172. }
  173. }
  174. testLister.add(new TestTranspose<T>("TestTranspose_VGA", src, 640, 480));
  175. testLister.add(new TestTranspose<T>("TestTranspose_HD1080", src, 1920, 1080));
  176. //regression tests
  177. testLister.add(new TestTranspose<T>("TestTranspose_reg_0", src, 1072, 375));
  178. }
  179. template <class T>
  180. void generateDrawRectsTests(NCVAutoTestLister &testLister,
  181. NCVTestSourceProvider<T> &src,
  182. NCVTestSourceProvider<Ncv32u> &src32u,
  183. Ncv32u maxWidth, Ncv32u maxHeight)
  184. {
  185. for (Ncv32f _i=16.0; _i<maxWidth; _i*=1.1f)
  186. {
  187. Ncv32u i = (Ncv32u)_i;
  188. Ncv32u j = maxHeight * i / maxWidth;
  189. if (!j) continue;
  190. char testName[80];
  191. sprintf(testName, "DrawRectsW%dH%d", i, j);
  192. if (sizeof(T) == sizeof(Ncv32u))
  193. {
  194. testLister.add(new TestDrawRects<T>(testName, src, src32u, i, j, i*j/1000+1, (T)0xFFFFFFFF));
  195. }
  196. else if (sizeof(T) == sizeof(Ncv8u))
  197. {
  198. testLister.add(new TestDrawRects<T>(testName, src, src32u, i, j, i*j/1000+1, (T)0xFF));
  199. }
  200. else
  201. {
  202. ncvAssertPrintCheck(false, "Attempted to instantiate non-existing DrawRects test suite");
  203. }
  204. }
  205. //test VGA
  206. testLister.add(new TestDrawRects<T>("DrawRects_VGA", src, src32u, 640, 480, 640*480/1000, (T)0xFF));
  207. }
  208. void generateVectorTests(NCVAutoTestLister &testLister, NCVTestSourceProvider<Ncv32u> &src, Ncv32u maxLength)
  209. {
  210. //growth
  211. for (Ncv32f _i=10.0; _i<maxLength; _i*=1.5f)
  212. {
  213. Ncv32u i = (Ncv32u)_i;
  214. char testName[80];
  215. sprintf(testName, "VectorGrow%d", i);
  216. testLister.add(new TestHypothesesGrow(testName, src, 20, 20, 2.2f, i, i/2, i, i/4));
  217. testLister.add(new TestHypothesesGrow(testName, src, 10, 42, 1.2f, i, i, i, 0));
  218. }
  219. testLister.add(new TestHypothesesGrow("VectorGrow01b", src, 10, 42, 1.2f, 10, 0, 10, 1));
  220. testLister.add(new TestHypothesesGrow("VectorGrow11b", src, 10, 42, 1.2f, 10, 1, 10, 1));
  221. testLister.add(new TestHypothesesGrow("VectorGrow10b", src, 10, 42, 1.2f, 10, 1, 10, 0));
  222. testLister.add(new TestHypothesesGrow("VectorGrow00b", src, 10, 42, 1.2f, 10, 0, 10, 0));
  223. }
  224. void generateHypothesesFiltrationTests(NCVAutoTestLister &testLister, NCVTestSourceProvider<Ncv32u> &src, Ncv32u maxLength)
  225. {
  226. for (Ncv32f _i=1.0; _i<maxLength; _i*=1.1f)
  227. {
  228. Ncv32u i = (Ncv32u)_i;
  229. char testName[80];
  230. sprintf(testName, "HypFilter%d", i);
  231. testLister.add(new TestHypothesesFilter(testName, src, i, 3, 0.2f));
  232. testLister.add(new TestHypothesesFilter(testName, src, i, 0, 0.2f));
  233. testLister.add(new TestHypothesesFilter(testName, src, i, 1, 0.1f));
  234. }
  235. }
  236. void generateHaarLoaderTests(NCVAutoTestLister &testLister)
  237. {
  238. testLister.add(new TestHaarCascadeLoader("haarcascade_eye.xml", path + "haarcascade_eye.xml"));
  239. testLister.add(new TestHaarCascadeLoader("haarcascade_frontalface_alt.xml", path + "haarcascade_frontalface_alt.xml"));
  240. testLister.add(new TestHaarCascadeLoader("haarcascade_frontalface_alt2.xml", path + "haarcascade_frontalface_alt2.xml"));
  241. testLister.add(new TestHaarCascadeLoader("haarcascade_frontalface_alt_tree.xml", path + "haarcascade_frontalface_alt_tree.xml"));
  242. testLister.add(new TestHaarCascadeLoader("haarcascade_eye_tree_eyeglasses.xml", path + "haarcascade_eye_tree_eyeglasses.xml"));
  243. }
  244. void generateHaarApplicationTests(NCVAutoTestLister &testLister, NCVTestSourceProvider<Ncv8u> &src,
  245. Ncv32u maxWidth, Ncv32u maxHeight)
  246. {
  247. CV_UNUSED(maxHeight);
  248. for (Ncv32u i=100; i<512; i+=41)
  249. {
  250. for (Ncv32u j=100; j<128; j+=25)
  251. {
  252. char testName[80];
  253. sprintf(testName, "HaarAppl%d_%d", i, j);
  254. testLister.add(new TestHaarCascadeApplication(testName, src, path + "haarcascade_frontalface_alt.xml", j, i));
  255. }
  256. }
  257. for (Ncv32f _i=20.0; _i<maxWidth; _i*=1.5f)
  258. {
  259. Ncv32u i = (Ncv32u)_i;
  260. char testName[80];
  261. sprintf(testName, "HaarAppl%d", i);
  262. testLister.add(new TestHaarCascadeApplication(testName, src, path + "haarcascade_frontalface_alt.xml", i, i));
  263. }
  264. }
  265. static void devNullOutput(const cv::String& msg)
  266. {
  267. CV_UNUSED(msg);
  268. }
  269. }
  270. bool nvidia_NPPST_Integral_Image(const std::string& test_data_path, OutputLevel outputLevel)
  271. {
  272. path = test_data_path.c_str();
  273. ncvSetDebugOutputHandler(devNullOutput);
  274. NCVAutoTestLister testListerII("NPPST Integral Image", outputLevel);
  275. NCVTestSourceProvider<Ncv8u> testSrcRandom_8u(2010, 0, 255, 2048, 2048);
  276. NCVTestSourceProvider<Ncv32f> testSrcRandom_32f(2010, -1.0f, 1.0f, 2048, 2048);
  277. generateIntegralTests<Ncv8u, Ncv32u>(testListerII, testSrcRandom_8u, 2048, 2048);
  278. generateIntegralTests<Ncv32f, Ncv32f>(testListerII, testSrcRandom_32f, 2048, 2048);
  279. return testListerII.invoke();
  280. }
  281. bool nvidia_NPPST_Squared_Integral_Image(const std::string& test_data_path, OutputLevel outputLevel)
  282. {
  283. path = test_data_path;
  284. ncvSetDebugOutputHandler(devNullOutput);
  285. NCVAutoTestLister testListerSII("NPPST Squared Integral Image", outputLevel);
  286. NCVTestSourceProvider<Ncv8u> testSrcRandom_8u(2010, 0, 255, 2048, 2048);
  287. generateSquaredIntegralTests(testListerSII, testSrcRandom_8u, 2048, 2048);
  288. return testListerSII.invoke();
  289. }
  290. bool nvidia_NPPST_RectStdDev(const std::string& test_data_path, OutputLevel outputLevel)
  291. {
  292. path = test_data_path;
  293. ncvSetDebugOutputHandler(devNullOutput);
  294. NCVAutoTestLister testListerRStdDev("NPPST RectStdDev", outputLevel);
  295. NCVTestSourceProvider<Ncv8u> testSrcRandom_8u(2010, 0, 255, 2048, 2048);
  296. generateRectStdDevTests(testListerRStdDev, testSrcRandom_8u, 2048, 2048);
  297. return testListerRStdDev.invoke();
  298. }
  299. bool nvidia_NPPST_Resize(const std::string& test_data_path, OutputLevel outputLevel)
  300. {
  301. path = test_data_path;
  302. ncvSetDebugOutputHandler(devNullOutput);
  303. NCVAutoTestLister testListerResize("NPPST Resize", outputLevel);
  304. NCVTestSourceProvider<Ncv32u> testSrcRandom_32u(2010, 0, 0xFFFFFFFF, 2048, 2048);
  305. NCVTestSourceProvider<Ncv64u> testSrcRandom_64u(2010, 0, (Ncv64u) -1, 2048, 2048);
  306. generateResizeTests(testListerResize, testSrcRandom_32u);
  307. generateResizeTests(testListerResize, testSrcRandom_64u);
  308. return testListerResize.invoke();
  309. }
  310. bool nvidia_NPPST_Vector_Operations(const std::string& test_data_path, OutputLevel outputLevel)
  311. {
  312. path = test_data_path;
  313. ncvSetDebugOutputHandler(devNullOutput);
  314. NCVAutoTestLister testListerNPPSTVectorOperations("NPPST Vector Operations", outputLevel);
  315. NCVTestSourceProvider<Ncv32u> testSrcRandom_32u(2010, 0, 0xFFFFFFFF, 2048, 2048);
  316. generateNPPSTVectorTests(testListerNPPSTVectorOperations, testSrcRandom_32u, 2048*2048);
  317. return testListerNPPSTVectorOperations.invoke();
  318. }
  319. bool nvidia_NPPST_Transpose(const std::string& test_data_path, OutputLevel outputLevel)
  320. {
  321. path = test_data_path;
  322. ncvSetDebugOutputHandler(devNullOutput);
  323. NCVAutoTestLister testListerTranspose("NPPST Transpose", outputLevel);
  324. NCVTestSourceProvider<Ncv32u> testSrcRandom_32u(2010, 0, 0xFFFFFFFF, 2048, 2048);
  325. NCVTestSourceProvider<Ncv64u> testSrcRandom_64u(2010, 0, (Ncv64u) -1, 2048, 2048);
  326. generateTransposeTests(testListerTranspose, testSrcRandom_32u);
  327. generateTransposeTests(testListerTranspose, testSrcRandom_64u);
  328. return testListerTranspose.invoke();
  329. }
  330. bool nvidia_NCV_Vector_Operations(const std::string& test_data_path, OutputLevel outputLevel)
  331. {
  332. path = test_data_path;
  333. ncvSetDebugOutputHandler(devNullOutput);
  334. NCVAutoTestLister testListerVectorOperations("Vector Operations", outputLevel);
  335. NCVTestSourceProvider<Ncv32u> testSrcRandom_32u(2010, 0, 0xFFFFFFFF, 2048, 2048);
  336. generateVectorTests(testListerVectorOperations, testSrcRandom_32u, 2048*2048);
  337. return testListerVectorOperations.invoke();
  338. }
  339. bool nvidia_NCV_Haar_Cascade_Loader(const std::string& test_data_path, OutputLevel outputLevel)
  340. {
  341. path = test_data_path;
  342. ncvSetDebugOutputHandler(devNullOutput);
  343. NCVAutoTestLister testListerHaarLoader("Haar Cascade Loader", outputLevel);
  344. generateHaarLoaderTests(testListerHaarLoader);
  345. return testListerHaarLoader.invoke();
  346. }
  347. bool nvidia_NCV_Haar_Cascade_Application(const std::string& test_data_path, OutputLevel outputLevel)
  348. {
  349. path = test_data_path;
  350. ncvSetDebugOutputHandler(devNullOutput);
  351. NCVAutoTestLister testListerHaarAppl("Haar Cascade Application", outputLevel);
  352. NCVTestSourceProvider<Ncv8u> testSrcFacesVGA_8u(path + "group_1_640x480_VGA.pgm");
  353. generateHaarApplicationTests(testListerHaarAppl, testSrcFacesVGA_8u, 640, 480);
  354. return testListerHaarAppl.invoke();
  355. }
  356. bool nvidia_NCV_Hypotheses_Filtration(const std::string& test_data_path, OutputLevel outputLevel)
  357. {
  358. path = test_data_path;
  359. ncvSetDebugOutputHandler(devNullOutput);
  360. NCVAutoTestLister testListerHypFiltration("Hypotheses Filtration", outputLevel);
  361. NCVTestSourceProvider<Ncv32u> testSrcRandom_32u(2010, 0, 0xFFFFFFFF, 2048, 2048);
  362. generateHypothesesFiltrationTests(testListerHypFiltration, testSrcRandom_32u, 512);
  363. return testListerHypFiltration.invoke();
  364. }
  365. bool nvidia_NCV_Visualization(const std::string& test_data_path, OutputLevel outputLevel)
  366. {
  367. path = test_data_path;
  368. ncvSetDebugOutputHandler(devNullOutput);
  369. NCVAutoTestLister testListerVisualize("Visualization", outputLevel);
  370. NCVTestSourceProvider<Ncv8u> testSrcRandom_8u(2010, 0, 255, 2048, 2048);
  371. NCVTestSourceProvider<Ncv32u> testSrcRandom_32u(2010, 0, RAND_MAX, 2048, 2048);
  372. generateDrawRectsTests(testListerVisualize, testSrcRandom_8u, testSrcRandom_32u, 2048, 2048);
  373. generateDrawRectsTests(testListerVisualize, testSrcRandom_32u, testSrcRandom_32u, 2048, 2048);
  374. return testListerVisualize.invoke();
  375. }