perf_mat.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. #include "perf_precomp.hpp"
  2. namespace opencv_test
  3. {
  4. using namespace perf;
  5. PERF_TEST_P(Size_MatType, Mat_Eye,
  6. testing::Combine(testing::Values(TYPICAL_MAT_SIZES),
  7. testing::Values(TYPICAL_MAT_TYPES))
  8. )
  9. {
  10. Size size = get<0>(GetParam());
  11. int type = get<1>(GetParam());
  12. Mat diagonalMatrix(size.height, size.width, type);
  13. declare.out(diagonalMatrix);
  14. int runs = (size.width <= 640) ? 15 : 5;
  15. TEST_CYCLE_MULTIRUN(runs)
  16. {
  17. diagonalMatrix = Mat::eye(size, type);
  18. }
  19. SANITY_CHECK(diagonalMatrix, 1);
  20. }
  21. PERF_TEST_P(Size_MatType, Mat_Zeros,
  22. testing::Combine(testing::Values(TYPICAL_MAT_SIZES),
  23. testing::Values(TYPICAL_MAT_TYPES, CV_32FC3))
  24. )
  25. {
  26. Size size = get<0>(GetParam());
  27. int type = get<1>(GetParam());
  28. Mat zeroMatrix(size.height, size.width, type);
  29. declare.out(zeroMatrix);
  30. int runs = (size.width <= 640) ? 15 : 5;
  31. TEST_CYCLE_MULTIRUN(runs)
  32. {
  33. zeroMatrix = Mat::zeros(size, type);
  34. }
  35. SANITY_CHECK(zeroMatrix, 1);
  36. }
  37. PERF_TEST_P(Size_MatType, Mat_Clone,
  38. testing::Combine(testing::Values(TYPICAL_MAT_SIZES),
  39. testing::Values(TYPICAL_MAT_TYPES))
  40. )
  41. {
  42. Size size = get<0>(GetParam());
  43. int type = get<1>(GetParam());
  44. Mat source(size.height, size.width, type);
  45. Mat destination(size.height, size.width, type);
  46. declare.in(source, WARMUP_RNG).out(destination);
  47. TEST_CYCLE()
  48. {
  49. Mat tmp = source.clone();
  50. CV_UNUSED(tmp);
  51. }
  52. destination = source.clone();
  53. SANITY_CHECK(destination, 1);
  54. }
  55. PERF_TEST_P(Size_MatType, Mat_Clone_Roi,
  56. testing::Combine(testing::Values(TYPICAL_MAT_SIZES),
  57. testing::Values(TYPICAL_MAT_TYPES))
  58. )
  59. {
  60. Size size = get<0>(GetParam());
  61. int type = get<1>(GetParam());
  62. unsigned int width = size.width;
  63. unsigned int height = size.height;
  64. Mat source(height, width, type);
  65. Mat destination(size.height/2, size.width/2, type);
  66. declare.in(source, WARMUP_RNG).out(destination);
  67. Mat roi(source, Rect(width/4, height/4, 3*width/4, 3*height/4));
  68. TEST_CYCLE()
  69. {
  70. Mat tmp = roi.clone();
  71. CV_UNUSED(tmp);
  72. }
  73. destination = roi.clone();
  74. SANITY_CHECK(destination, 1);
  75. }
  76. PERF_TEST_P(Size_MatType, Mat_CopyToWithMask,
  77. testing::Combine(testing::Values(::perf::sz1080p, ::perf::szODD),
  78. testing::Values(CV_8UC1, CV_8UC2, CV_8UC3, CV_16UC1, CV_32SC1, CV_32FC4))
  79. )
  80. {
  81. const Size_MatType_t params = GetParam();
  82. const Size size = get<0>(params);
  83. const int type = get<1>(params);
  84. Mat src(size, type), dst(size, type), mask(size, CV_8UC1);
  85. declare.in(src, mask, WARMUP_RNG).out(dst);
  86. TEST_CYCLE()
  87. {
  88. src.copyTo(dst, mask);
  89. }
  90. SANITY_CHECK(dst);
  91. }
  92. PERF_TEST_P(Size_MatType, Mat_SetToWithMask,
  93. testing::Combine(testing::Values(TYPICAL_MAT_SIZES),
  94. testing::Values(CV_8UC1, CV_8UC2))
  95. )
  96. {
  97. const Size_MatType_t params = GetParam();
  98. const Size size = get<0>(params);
  99. const int type = get<1>(params);
  100. const Scalar sc = Scalar::all(27);
  101. Mat src(size, type), mask(size, CV_8UC1);
  102. declare.in(src, mask, WARMUP_RNG).out(src);
  103. TEST_CYCLE()
  104. {
  105. src.setTo(sc, mask);
  106. }
  107. SANITY_CHECK(src);
  108. }
  109. ///////////// Transform ////////////////////////
  110. PERF_TEST_P(Size_MatType, Mat_Transform,
  111. testing::Combine(testing::Values(TYPICAL_MAT_SIZES),
  112. testing::Values(CV_8UC3, CV_8SC3, CV_16UC3, CV_16SC3, CV_32SC3, CV_32FC3, CV_64FC3))
  113. )
  114. {
  115. const Size_MatType_t params = GetParam();
  116. const Size srcSize0 = get<0>(params);
  117. const Size srcSize = Size(1, srcSize0.width*srcSize0.height);
  118. const int type = get<1>(params);
  119. const float transform[] = { 0.5f, 0.f, 0.86602540378f, 128,
  120. 0.f, 1.f, 0.f, -64,
  121. 0.86602540378f, 0.f, 0.5f, 32,};
  122. Mat mtx(Size(4, 3), CV_32FC1, (void*)transform);
  123. Mat src(srcSize, type), dst(srcSize, type);
  124. randu(src, 0, 30);
  125. declare.in(src).out(dst);
  126. TEST_CYCLE()
  127. {
  128. cv::transform(src, dst, mtx);
  129. }
  130. SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);
  131. }
  132. } // namespace