perf_remap.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. #include "perf_precomp.hpp"
  5. namespace opencv_test {
  6. CV_ENUM(InterType, INTER_NEAREST, INTER_LINEAR, INTER_CUBIC, INTER_LANCZOS4)
  7. typedef TestBaseWithParam< tuple<Size, MatType, MatType, InterType> > TestRemap;
  8. PERF_TEST_P( TestRemap, Remap,
  9. Combine(
  10. Values( szVGA, sz1080p ),
  11. Values( CV_16UC1, CV_16SC1, CV_32FC1 ),
  12. Values( CV_16SC2, CV_32FC1, CV_32FC2 ),
  13. InterType::all()
  14. )
  15. )
  16. {
  17. Size sz;
  18. int src_type, map1_type, inter_type;
  19. sz = get<0>(GetParam());
  20. src_type = get<1>(GetParam());
  21. map1_type = get<2>(GetParam());
  22. inter_type = get<3>(GetParam());
  23. Mat src(sz, src_type), dst(sz, src_type), map1(sz, map1_type), map2;
  24. if (map1_type == CV_32FC1)
  25. map2.create(sz, CV_32FC1);
  26. else if (inter_type != INTER_NEAREST && map1_type == CV_16SC2)
  27. {
  28. map2.create(sz, CV_16UC1);
  29. map2 = Scalar::all(0);
  30. }
  31. RNG rng;
  32. rng.fill(src, RNG::UNIFORM, 0, 256);
  33. for (int j = 0; j < map1.rows; ++j)
  34. for (int i = 0; i < map1.cols; ++i)
  35. switch (map1_type)
  36. {
  37. case CV_32FC1:
  38. map1.at<float>(j, i) = static_cast<float>(src.cols - i - 1);
  39. map2.at<float>(j, i) = static_cast<float>(j);
  40. break;
  41. case CV_32FC2:
  42. map1.at<Vec2f>(j, i)[0] = static_cast<float>(src.cols - i - 1);
  43. map1.at<Vec2f>(j, i)[1] = static_cast<float>(j);
  44. break;
  45. case CV_16SC2:
  46. map1.at<Vec2s>(j, i)[0] = static_cast<short>(src.cols - i - 1);
  47. map1.at<Vec2s>(j, i)[1] = static_cast<short>(j);
  48. break;
  49. default:
  50. CV_Assert(0);
  51. }
  52. declare.in(src, WARMUP_RNG).out(dst).time(20);
  53. int runs = (sz.width <= 640) ? 3 : 1;
  54. TEST_CYCLE_MULTIRUN(runs) remap(src, dst, map1, map2, inter_type);
  55. SANITY_CHECK(dst);
  56. }
  57. } // namespace