perf_3vs4.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. // This file is part of OpenCV project.
  2. // It is subject to the license terms in the LICENSE file found in the top-level directory
  3. // of this distribution and at http://opencv.org/license.html.
  4. // Copyright (C) 2014, Advanced Micro Devices, Inc., all rights reserved.
  5. // Third party copyrights are property of their respective owners.
  6. #include "../perf_precomp.hpp"
  7. #include "opencv2/ts/ocl_perf.hpp"
  8. #ifdef HAVE_OPENCL
  9. namespace opencv_test {
  10. namespace ocl {
  11. ///////////// 3 channels Vs 4 ////////////////////////
  12. enum
  13. {
  14. Pure = 0, Split, Convert
  15. };
  16. CV_ENUM(Modes, Pure, Split, Convert)
  17. typedef tuple <Size, MatType, Modes> _3vs4Params;
  18. typedef TestBaseWithParam<_3vs4Params> _3vs4_Fixture;
  19. OCL_PERF_TEST_P(_3vs4_Fixture, Resize,
  20. ::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_8UC3, CV_32FC3), Modes::all()))
  21. {
  22. _3vs4Params params = GetParam();
  23. const Size srcSize = get<0>(params);
  24. const int type = get<1>(params), depth = CV_MAT_DEPTH(type);
  25. const int mode = get<2>(params);
  26. checkDeviceMaxMemoryAllocSize(srcSize, type);
  27. UMat src(srcSize, type), dst(srcSize, type);
  28. declare.in(src, WARMUP_RNG).out(dst);
  29. if (mode == Pure)
  30. {
  31. OCL_TEST_CYCLE() resize(src, dst, Size(), 0.5, 0.5, INTER_LINEAR_EXACT);
  32. }
  33. else if (mode == Split)
  34. {
  35. std::vector<UMat> srcs(3), dsts(3);
  36. for (int i = 0; i < 3; ++i)
  37. {
  38. dsts[i] = UMat(srcSize, depth);
  39. srcs[i] = UMat(srcSize, depth);
  40. }
  41. OCL_TEST_CYCLE()
  42. {
  43. split(src, srcs);
  44. for (size_t i = 0; i < srcs.size(); ++i)
  45. resize(srcs[i], dsts[i], Size(), 0.5, 0.5, INTER_LINEAR_EXACT);
  46. merge(dsts, dst);
  47. }
  48. }
  49. else if (mode == Convert)
  50. {
  51. int type4 = CV_MAKE_TYPE(depth, 4);
  52. UMat src4(srcSize, type4), dst4(srcSize, type4);
  53. OCL_TEST_CYCLE()
  54. {
  55. cvtColor(src, src4, COLOR_RGB2RGBA);
  56. resize(src4, dst4, Size(), 0.5, 0.5, INTER_LINEAR_EXACT);
  57. cvtColor(dst4, dst, COLOR_RGBA2RGB);
  58. }
  59. }
  60. SANITY_CHECK_NOTHING();
  61. }
  62. OCL_PERF_TEST_P(_3vs4_Fixture, Subtract,
  63. ::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_8UC3, CV_32FC3), Modes::all()))
  64. {
  65. _3vs4Params params = GetParam();
  66. const Size srcSize = get<0>(params);
  67. const int type = get<1>(params), depth = CV_MAT_DEPTH(type);
  68. const int mode = get<2>(params);
  69. checkDeviceMaxMemoryAllocSize(srcSize, type);
  70. Scalar s(14);
  71. UMat src(srcSize, type), dst(srcSize, type);
  72. declare.in(src, WARMUP_RNG).out(dst);
  73. if (mode == Pure)
  74. {
  75. OCL_TEST_CYCLE() subtract(src, s, dst);
  76. }
  77. else if (mode == Split)
  78. {
  79. std::vector<UMat> srcs(3), dsts(3);
  80. for (int i = 0; i < 3; ++i)
  81. {
  82. dsts[i] = UMat(srcSize, depth);
  83. srcs[i] = UMat(srcSize, depth);
  84. }
  85. OCL_TEST_CYCLE()
  86. {
  87. split(src, srcs);
  88. for (size_t i = 0; i < srcs.size(); ++i)
  89. subtract(srcs[i], s, dsts[i]);
  90. merge(dsts, dst);
  91. }
  92. }
  93. else if (mode == Convert)
  94. {
  95. int type4 = CV_MAKE_TYPE(depth, 4);
  96. UMat src4(srcSize, type4), dst4(srcSize, type4);
  97. OCL_TEST_CYCLE()
  98. {
  99. cvtColor(src, src4, COLOR_RGB2RGBA);
  100. subtract(src4, s, dst4);
  101. cvtColor(dst4, dst, COLOR_RGBA2RGB);
  102. }
  103. }
  104. SANITY_CHECK_NOTHING();
  105. }
  106. } } // namespace opencv_test::ocl
  107. #endif // HAVE_OPENCL