perf_imgproc.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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) 2010-2012, Multicoreware, Inc., all rights reserved.
  14. // Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
  15. // Third party copyrights are property of their respective owners.
  16. //
  17. // @Authors
  18. // Fangfang Bai, fangfang@multicorewareinc.com
  19. // Jin Ma, jin@multicorewareinc.com
  20. //
  21. // Redistribution and use in source and binary forms, with or without modification,
  22. // are permitted provided that the following conditions are met:
  23. //
  24. // * Redistribution's of source code must retain the above copyright notice,
  25. // this list of conditions and the following disclaimer.
  26. //
  27. // * Redistribution's in binary form must reproduce the above copyright notice,
  28. // this list of conditions and the following disclaimer in the documentation
  29. // and/or other materials provided with the distribution.
  30. //
  31. // * The name of the copyright holders may not be used to endorse or promote products
  32. // derived from this software without specific prior written permission.
  33. //
  34. // This software is provided by the copyright holders and contributors as is and
  35. // any express or implied warranties, including, but not limited to, the implied
  36. // warranties of merchantability and fitness for a particular purpose are disclaimed.
  37. // In no event shall the Intel Corporation or contributors be liable for any direct,
  38. // indirect, incidental, special, exemplary, or consequential damages
  39. // (including, but not limited to, procurement of substitute goods or services;
  40. // loss of use, data, or profits; or business interruption) however caused
  41. // and on any theory of liability, whether in contract, strict liability,
  42. // or tort (including negligence or otherwise) arising in any way out of
  43. // the use of this software, even if advised of the possibility of such damage.
  44. //
  45. //M*/
  46. #include "../perf_precomp.hpp"
  47. #include "opencv2/ts/ocl_perf.hpp"
  48. namespace opencv_test {
  49. namespace ocl {
  50. ///////////// equalizeHist ////////////////////////
  51. typedef TestBaseWithParam<Size> EqualizeHistFixture;
  52. OCL_PERF_TEST_P(EqualizeHistFixture, EqualizeHist, OCL_TEST_SIZES)
  53. {
  54. const Size srcSize = GetParam();
  55. const double eps = 1;
  56. checkDeviceMaxMemoryAllocSize(srcSize, CV_8UC1);
  57. UMat src(srcSize, CV_8UC1), dst(srcSize, CV_8UC1);
  58. declare.in(src, WARMUP_RNG).out(dst);
  59. OCL_TEST_CYCLE() cv::equalizeHist(src, dst);
  60. SANITY_CHECK(dst, eps);
  61. }
  62. ///////////// calcHist ////////////////////////
  63. typedef TestBaseWithParam<Size> CalcHistFixture;
  64. OCL_PERF_TEST_P(CalcHistFixture, CalcHist, OCL_TEST_SIZES)
  65. {
  66. const Size srcSize = GetParam();
  67. const std::vector<int> channels(1, 0);
  68. std::vector<float> ranges(2);
  69. std::vector<int> histSize(1, 256);
  70. ranges[0] = 0;
  71. ranges[1] = 256;
  72. checkDeviceMaxMemoryAllocSize(srcSize, CV_8UC1);
  73. UMat src(srcSize, CV_8UC1), hist(256, 1, CV_32FC1);
  74. declare.in(src, WARMUP_RNG).out(hist);
  75. OCL_TEST_CYCLE() cv::calcHist(std::vector<UMat>(1, src), channels, noArray(), hist, histSize, ranges, false);
  76. SANITY_CHECK(hist);
  77. }
  78. ///////////// calcHist ////////////////////////
  79. typedef TestBaseWithParam<Size> CalcBackProjFixture;
  80. OCL_PERF_TEST_P(CalcBackProjFixture, CalcBackProj, OCL_TEST_SIZES)
  81. {
  82. const Size srcSize = GetParam();
  83. const std::vector<int> channels(1, 0);
  84. std::vector<float> ranges(2);
  85. std::vector<int> histSize(1, 256);
  86. ranges[0] = 0;
  87. ranges[1] = 256;
  88. checkDeviceMaxMemoryAllocSize(srcSize, CV_8UC1);
  89. UMat src(srcSize, CV_8UC1), hist(256, 1, CV_32FC1), dst(srcSize, CV_8UC1);
  90. declare.in(src, WARMUP_RNG).out(hist);
  91. cv::calcHist(std::vector<UMat>(1, src), channels, noArray(), hist, histSize, ranges, false);
  92. declare.in(src, WARMUP_RNG).out(dst);
  93. OCL_TEST_CYCLE() cv::calcBackProject(std::vector<UMat>(1,src), channels, hist, dst, ranges, 1);
  94. SANITY_CHECK_NOTHING();
  95. }
  96. /////////// CopyMakeBorder //////////////////////
  97. CV_ENUM(Border, BORDER_CONSTANT, BORDER_REPLICATE, BORDER_REFLECT, BORDER_WRAP, BORDER_REFLECT_101)
  98. typedef tuple<Size, MatType, Border> CopyMakeBorderParamType;
  99. typedef TestBaseWithParam<CopyMakeBorderParamType> CopyMakeBorderFixture;
  100. OCL_PERF_TEST_P(CopyMakeBorderFixture, CopyMakeBorder,
  101. ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134, Border::all()))
  102. {
  103. const CopyMakeBorderParamType params = GetParam();
  104. const Size srcSize = get<0>(params);
  105. const int type = get<1>(params), borderType = get<2>(params);
  106. checkDeviceMaxMemoryAllocSize(srcSize, type);
  107. UMat src(srcSize, type), dst;
  108. const Size dstSize = srcSize + Size(12, 12);
  109. dst.create(dstSize, type);
  110. declare.in(src, WARMUP_RNG).out(dst);
  111. OCL_TEST_CYCLE() cv::copyMakeBorder(src, dst, 7, 5, 5, 7, borderType, cv::Scalar(1.0));
  112. SANITY_CHECK(dst);
  113. }
  114. ///////////// CornerMinEigenVal ////////////////////////
  115. typedef Size_MatType CornerMinEigenValFixture;
  116. OCL_PERF_TEST_P(CornerMinEigenValFixture, CornerMinEigenVal,
  117. ::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_8UC1, CV_32FC1)))
  118. {
  119. const Size_MatType_t params = GetParam();
  120. const Size srcSize = get<0>(params);
  121. const int type = get<1>(params), borderType = BORDER_REFLECT;
  122. const int blockSize = 7, apertureSize = 1 + 2 * 3;
  123. checkDeviceMaxMemoryAllocSize(srcSize, type);
  124. UMat src(srcSize, type), dst(srcSize, CV_32FC1);
  125. declare.in(src, WARMUP_RNG).out(dst);
  126. OCL_TEST_CYCLE() cv::cornerMinEigenVal(src, dst, blockSize, apertureSize, borderType);
  127. #ifdef HAVE_OPENCL
  128. bool strictCheck = !ocl::useOpenCL() || ocl::Device::getDefault().isIntel();
  129. #else
  130. bool strictCheck = true;
  131. #endif
  132. // using native_* OpenCL functions on non-intel devices may lose accuracy
  133. if (strictCheck)
  134. SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);
  135. else
  136. SANITY_CHECK(dst, 0.1, ERROR_RELATIVE);
  137. }
  138. ///////////// CornerHarris ////////////////////////
  139. typedef Size_MatType CornerHarrisFixture;
  140. OCL_PERF_TEST_P(CornerHarrisFixture, CornerHarris,
  141. ::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_8UC1, CV_32FC1)))
  142. {
  143. const Size_MatType_t params = GetParam();
  144. const Size srcSize = get<0>(params);
  145. const int type = get<1>(params), borderType = BORDER_REFLECT;
  146. checkDeviceMaxMemoryAllocSize(srcSize, type);
  147. UMat src(srcSize, type), dst(srcSize, CV_32FC1);
  148. declare.in(src, WARMUP_RNG).out(dst);
  149. OCL_TEST_CYCLE() cv::cornerHarris(src, dst, 5, 7, 0.1, borderType);
  150. SANITY_CHECK(dst, 5e-6, ERROR_RELATIVE);
  151. }
  152. ///////////// PreCornerDetect ////////////////////////
  153. typedef Size_MatType PreCornerDetectFixture;
  154. OCL_PERF_TEST_P(PreCornerDetectFixture, PreCornerDetect,
  155. ::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_8UC1, CV_32FC1)))
  156. {
  157. const Size_MatType_t params = GetParam();
  158. const Size srcSize = get<0>(params);
  159. const int type = get<1>(params), borderType = BORDER_REFLECT;
  160. checkDeviceMaxMemoryAllocSize(srcSize, type);
  161. UMat src(srcSize, type), dst(srcSize, CV_32FC1);
  162. declare.in(src, WARMUP_RNG).out(dst);
  163. OCL_TEST_CYCLE() cv::preCornerDetect(src, dst, 3, borderType);
  164. SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);
  165. }
  166. ///////////// Integral ////////////////////////
  167. typedef tuple<Size, MatDepth> IntegralParams;
  168. typedef TestBaseWithParam<IntegralParams> IntegralFixture;
  169. OCL_PERF_TEST_P(IntegralFixture, Integral1, ::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32S, CV_32F)))
  170. {
  171. const IntegralParams params = GetParam();
  172. const Size srcSize = get<0>(params);
  173. const int ddepth = get<1>(params);
  174. checkDeviceMaxMemoryAllocSize(srcSize, ddepth);
  175. UMat src(srcSize, CV_8UC1), dst(srcSize + Size(1, 1), ddepth);
  176. declare.in(src, WARMUP_RNG).out(dst);
  177. OCL_TEST_CYCLE() cv::integral(src, dst, ddepth);
  178. SANITY_CHECK(dst, 2e-6, ERROR_RELATIVE);
  179. }
  180. OCL_PERF_TEST_P(IntegralFixture, Integral2, ::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32S, CV_32F)))
  181. {
  182. const IntegralParams params = GetParam();
  183. const Size srcSize = get<0>(params);
  184. const int ddepth = get<1>(params);
  185. checkDeviceMaxMemoryAllocSize(srcSize, ddepth);
  186. UMat src(srcSize, CV_8UC1), sum(srcSize + Size(1, 1), ddepth), sqsum(srcSize + Size(1, 1), CV_32F);
  187. declare.in(src, WARMUP_RNG).out(sum, sqsum);
  188. OCL_TEST_CYCLE() cv::integral(src, sum, sqsum, ddepth, CV_32F);
  189. SANITY_CHECK(sum, 2e-4, ERROR_RELATIVE);
  190. SANITY_CHECK(sqsum, 5e-5, ERROR_RELATIVE);
  191. }
  192. ///////////// Threshold ////////////////////////
  193. CV_ENUM(ThreshType, THRESH_BINARY, THRESH_BINARY_INV, THRESH_TRUNC, THRESH_TOZERO_INV)
  194. typedef tuple<Size, MatType, ThreshType> ThreshParams;
  195. typedef TestBaseWithParam<ThreshParams> ThreshFixture;
  196. OCL_PERF_TEST_P(ThreshFixture, Threshold,
  197. ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES, ThreshType::all()))
  198. {
  199. const ThreshParams params = GetParam();
  200. const Size srcSize = get<0>(params);
  201. const int srcType = get<1>(params);
  202. const int threshType = get<2>(params);
  203. const double maxValue = 220.0, threshold = 50;
  204. checkDeviceMaxMemoryAllocSize(srcSize, srcType);
  205. UMat src(srcSize, srcType), dst(srcSize, srcType);
  206. declare.in(src, WARMUP_RNG).out(dst);
  207. OCL_TEST_CYCLE() cv::threshold(src, dst, threshold, maxValue, threshType);
  208. SANITY_CHECK(dst);
  209. }
  210. ///////////// CLAHE ////////////////////////
  211. typedef TestBaseWithParam<Size> CLAHEFixture;
  212. OCL_PERF_TEST_P(CLAHEFixture, CLAHE, OCL_TEST_SIZES)
  213. {
  214. const Size srcSize = GetParam();
  215. checkDeviceMaxMemoryAllocSize(srcSize, CV_8UC1);
  216. UMat src(srcSize, CV_8UC1), dst(srcSize, CV_8UC1);
  217. const double clipLimit = 40.0;
  218. declare.in(src, WARMUP_RNG).out(dst);
  219. cv::Ptr<cv::CLAHE> clahe = cv::createCLAHE(clipLimit);
  220. OCL_TEST_CYCLE() clahe->apply(src, dst);
  221. SANITY_CHECK(dst);
  222. }
  223. ///////////// Canny ////////////////////////
  224. typedef tuple<Size, int, bool> CannyParams;
  225. typedef TestBaseWithParam<CannyParams> CannyFixture;
  226. OCL_PERF_TEST_P(CannyFixture, Canny, ::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(3, 5), Bool()))
  227. {
  228. const CannyParams& params = GetParam();
  229. cv::Size imgSize = get<0>(params);
  230. int apertureSize = get<1>(params);
  231. bool L2Grad = get<2>(params);
  232. Mat _img = imread(getDataPath("gpu/stereobm/aloe-L.png"), cv::IMREAD_GRAYSCALE);
  233. ASSERT_TRUE(!_img.empty()) << "can't open aloe-L.png";
  234. UMat img;
  235. cv::resize(_img, img, imgSize, 0, 0, INTER_LINEAR_EXACT);
  236. UMat edges(img.size(), CV_8UC1);
  237. declare.in(img).out(edges);
  238. PERF_SAMPLE_BEGIN();
  239. cv::Canny(img, edges, 50.0, 100.0, apertureSize, L2Grad);
  240. PERF_SAMPLE_END();
  241. SANITY_CHECK_NOTHING();
  242. }
  243. } } // namespace opencv_test::ocl