perf_affine2d.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*M///////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // By downloading, copying, installing or using the software you agree to this license.
  4. // If you do not agree to this license, do not download, install,
  5. // copy or use the software.
  6. //
  7. //
  8. // License Agreement
  9. // For Open Source Computer Vision Library
  10. // (3-clause BSD License)
  11. //
  12. // Copyright (C) 2015-2016, OpenCV Foundation, all rights reserved.
  13. // Third party copyrights are property of their respective owners.
  14. //
  15. // Redistribution and use in source and binary forms, with or without modification,
  16. // are permitted provided that the following conditions are met:
  17. //
  18. // * Redistributions of source code must retain the above copyright notice,
  19. // this list of conditions and the following disclaimer.
  20. //
  21. // * Redistributions in binary form must reproduce the above copyright notice,
  22. // this list of conditions and the following disclaimer in the documentation
  23. // and/or other materials provided with the distribution.
  24. //
  25. // * Neither the names of the copyright holders nor the names of the contributors
  26. // may be used to endorse or promote products derived from this software
  27. // without specific prior written permission.
  28. //
  29. // This software is provided by the copyright holders and contributors "as is" and
  30. // any express or implied warranties, including, but not limited to, the implied
  31. // warranties of merchantability and fitness for a particular purpose are disclaimed.
  32. // In no event shall copyright holders or contributors be liable for any direct,
  33. // indirect, incidental, special, exemplary, or consequential damages
  34. // (including, but not limited to, procurement of substitute goods or services;
  35. // loss of use, data, or profits; or business interruption) however caused
  36. // and on any theory of liability, whether in contract, strict liability,
  37. // or tort (including negligence or otherwise) arising in any way out of
  38. // the use of this software, even if advised of the possibility of such damage.
  39. //
  40. //M*/
  41. #include "perf_precomp.hpp"
  42. #include <algorithm>
  43. #include <functional>
  44. namespace opencv_test
  45. {
  46. using namespace perf;
  47. CV_ENUM(Method, RANSAC, LMEDS)
  48. typedef tuple<int, double, Method, size_t> AffineParams;
  49. typedef TestBaseWithParam<AffineParams> EstimateAffine;
  50. #define ESTIMATE_PARAMS Combine(Values(100000, 5000, 100), Values(0.99, 0.95, 0.9), Method::all(), Values(10, 0))
  51. static float rngIn(float from, float to) { return from + (to-from) * (float)theRNG(); }
  52. static Mat rngPartialAffMat() {
  53. double theta = rngIn(0, (float)CV_PI*2.f);
  54. double scale = rngIn(0, 3);
  55. double tx = rngIn(-2, 2);
  56. double ty = rngIn(-2, 2);
  57. double aff[2*3] = { std::cos(theta) * scale, -std::sin(theta) * scale, tx,
  58. std::sin(theta) * scale, std::cos(theta) * scale, ty };
  59. return Mat(2, 3, CV_64F, aff).clone();
  60. }
  61. PERF_TEST_P( EstimateAffine, EstimateAffine2D, ESTIMATE_PARAMS )
  62. {
  63. AffineParams params = GetParam();
  64. const int n = get<0>(params);
  65. const double confidence = get<1>(params);
  66. const int method = get<2>(params);
  67. const size_t refining = get<3>(params);
  68. Mat aff(2, 3, CV_64F);
  69. cv::randu(aff, -2., 2.);
  70. // LMEDS can't handle more than 50% outliers (by design)
  71. int m;
  72. if (method == LMEDS)
  73. m = 3*n/5;
  74. else
  75. m = 2*n/5;
  76. const float shift_outl = 15.f;
  77. const float noise_level = 20.f;
  78. Mat fpts(1, n, CV_32FC2);
  79. Mat tpts(1, n, CV_32FC2);
  80. randu(fpts, 0., 100.);
  81. transform(fpts, tpts, aff);
  82. /* adding noise to some points */
  83. Mat outliers = tpts.colRange(m, n);
  84. outliers.reshape(1) += shift_outl;
  85. Mat noise (outliers.size(), outliers.type());
  86. randu(noise, 0., noise_level);
  87. outliers += noise;
  88. Mat aff_est;
  89. vector<uchar> inliers (n);
  90. warmup(inliers, WARMUP_WRITE);
  91. warmup(fpts, WARMUP_READ);
  92. warmup(tpts, WARMUP_READ);
  93. TEST_CYCLE()
  94. {
  95. aff_est = estimateAffine2D(fpts, tpts, inliers, method, 3, 2000, confidence, refining);
  96. }
  97. // we already have accuracy tests
  98. SANITY_CHECK_NOTHING();
  99. }
  100. PERF_TEST_P( EstimateAffine, EstimateAffinePartial2D, ESTIMATE_PARAMS )
  101. {
  102. AffineParams params = GetParam();
  103. const int n = get<0>(params);
  104. const double confidence = get<1>(params);
  105. const int method = get<2>(params);
  106. const size_t refining = get<3>(params);
  107. Mat aff = rngPartialAffMat();
  108. int m;
  109. // LMEDS can't handle more than 50% outliers (by design)
  110. if (method == LMEDS)
  111. m = 3*n/5;
  112. else
  113. m = 2*n/5;
  114. const float shift_outl = 15.f; const float noise_level = 20.f;
  115. Mat fpts(1, n, CV_32FC2);
  116. Mat tpts(1, n, CV_32FC2);
  117. randu(fpts, 0., 100.);
  118. transform(fpts, tpts, aff);
  119. /* adding noise*/
  120. Mat outliers = tpts.colRange(m, n);
  121. outliers.reshape(1) += shift_outl;
  122. Mat noise (outliers.size(), outliers.type());
  123. randu(noise, 0., noise_level);
  124. outliers += noise;
  125. Mat aff_est;
  126. vector<uchar> inliers (n);
  127. warmup(inliers, WARMUP_WRITE);
  128. warmup(fpts, WARMUP_READ);
  129. warmup(tpts, WARMUP_READ);
  130. TEST_CYCLE()
  131. {
  132. aff_est = estimateAffinePartial2D(fpts, tpts, inliers, method, 3, 2000, confidence, refining);
  133. }
  134. // we already have accuracy tests
  135. SANITY_CHECK_NOTHING();
  136. }
  137. } // namespace opencv_test