perf_reg.cpp 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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) 2000-2008, Intel Corporation, all rights reserved.
  14. // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
  15. // Copyright (C) 2013, Alfonso Sanchez-Beato, all rights reserved.
  16. // Third party copyrights are property of their respective owners.
  17. //
  18. // Redistribution and use in source and binary forms, with or without modification,
  19. // are permitted provided that the following conditions are met:
  20. //
  21. // * Redistribution's of source code must retain the above copyright notice,
  22. // this list of conditions and the following disclaimer.
  23. //
  24. // * Redistribution's in binary form must reproduce the above copyright notice,
  25. // this list of conditions and the following disclaimer in the documentation
  26. // and/or other materials provided with the distribution.
  27. //
  28. // * The name of the copyright holders may not be used to endorse or promote products
  29. // derived from this software without specific prior written permission.
  30. //
  31. // This software is provided by the copyright holders and contributors "as is" and
  32. // any express or implied warranties, including, but not limited to, the implied
  33. // warranties of merchantability and fitness for a particular purpose are disclaimed.
  34. // In no event shall the Intel Corporation or contributors be liable for any direct,
  35. // indirect, incidental, special, exemplary, or consequential damages
  36. // (including, but not limited to, procurement of substitute goods or services;
  37. // loss of use, data, or profits; or business interruption) however caused
  38. // and on any theory of liability, whether in contract, strict liability,
  39. // or tort (including negligence or otherwise) arising in any way out of
  40. // the use of this software, even if advised of the possibility of such damage.
  41. //
  42. //M*/
  43. #include "perf_precomp.hpp"
  44. namespace opencv_test { namespace {
  45. using namespace perf;
  46. Vec<double, 2> perfShift(const Mat& img1)
  47. {
  48. Mat img2;
  49. // Warp original image
  50. Vec<double, 2> shift(5., 5.);
  51. MapShift mapTest(shift);
  52. mapTest.warp(img1, img2);
  53. // Register
  54. Ptr<MapperGradShift> mapper = makePtr<MapperGradShift>();
  55. MapperPyramid mappPyr(mapper);
  56. Ptr<Map> mapPtr = mappPyr.calculate(img1, img2);
  57. MapShift* mapShift = dynamic_cast<MapShift*>(mapPtr.get());
  58. return mapShift->getShift();
  59. }
  60. Matx<double, 2, 6> perfEuclidean(const Mat& img1)
  61. {
  62. Mat img2;
  63. Matx<double, 2, 6> transf;
  64. // Warp original image
  65. double theta = 3*CV_PI/180;
  66. double cosT = cos(theta);
  67. double sinT = sin(theta);
  68. Matx<double, 2, 2> linTr(cosT, -sinT, sinT, cosT);
  69. Vec<double, 2> shift(5., 5.);
  70. MapAffine mapTest(linTr, shift);
  71. mapTest.warp(img1, img2);
  72. // Register
  73. Ptr<MapperGradEuclid> mapper = makePtr<MapperGradEuclid>();
  74. MapperPyramid mappPyr(mapper);
  75. Ptr<Map> mapPtr = mappPyr.calculate(img1, img2);
  76. MapAffine* mapAff = dynamic_cast<MapAffine*>(mapPtr.get());
  77. Matx<double, 2, 2> resLinTr = mapAff->getLinTr();
  78. transf(0, 0) = resLinTr(0, 0), transf(0, 1) = resLinTr(0, 1);
  79. transf(1, 0) = resLinTr(1, 0), transf(1, 1) = resLinTr(1, 1);
  80. Vec<double, 2> resShift = mapAff->getShift();
  81. transf(0, 2) = resShift(0);
  82. transf(1, 2) = resShift(1);
  83. return transf;
  84. }
  85. Matx<double, 2, 6> perfSimilarity(const Mat& img1)
  86. {
  87. Mat img2;
  88. Matx<double, 2, 6> transf;
  89. // Warp original image
  90. double theta = 3*CV_PI/180;
  91. double scale = 0.95;
  92. double a = scale*cos(theta);
  93. double b = scale*sin(theta);
  94. Matx<double, 2, 2> linTr(a, -b, b, a);
  95. Vec<double, 2> shift(5., 5.);
  96. MapAffine mapTest(linTr, shift);
  97. mapTest.warp(img1, img2);
  98. // Register
  99. Ptr<MapperGradSimilar> mapper = makePtr<MapperGradSimilar>();
  100. MapperPyramid mappPyr(mapper);
  101. Ptr<Map> mapPtr = mappPyr.calculate(img1, img2);
  102. MapAffine* mapAff = dynamic_cast<MapAffine*>(mapPtr.get());
  103. Matx<double, 2, 2> resLinTr = mapAff->getLinTr();
  104. transf(0, 0) = resLinTr(0, 0), transf(0, 1) = resLinTr(0, 1);
  105. transf(1, 0) = resLinTr(1, 0), transf(1, 1) = resLinTr(1, 1);
  106. Vec<double, 2> resShift = mapAff->getShift();
  107. transf(0, 2) = resShift(0);
  108. transf(1, 2) = resShift(1);
  109. return transf;
  110. }
  111. Matx<double, 2, 6> perfAffine(const Mat& img1)
  112. {
  113. Mat img2;
  114. Matx<double, 2, 6> transf;
  115. // Warp original image
  116. Matx<double, 2, 2> linTr(1., 0.1, -0.01, 1.);
  117. Vec<double, 2> shift(1., 1.);
  118. MapAffine mapTest(linTr, shift);
  119. mapTest.warp(img1, img2);
  120. // Register
  121. Ptr<MapperGradAffine> mapper = makePtr<MapperGradAffine>();
  122. MapperPyramid mappPyr(mapper);
  123. Ptr<Map> mapPtr = mappPyr.calculate(img1, img2);
  124. MapAffine* mapAff = dynamic_cast<MapAffine*>(mapPtr.get());
  125. Matx<double, 2, 2> resLinTr = mapAff->getLinTr();
  126. transf(0, 0) = resLinTr(0, 0), transf(0, 1) = resLinTr(0, 1);
  127. transf(1, 0) = resLinTr(1, 0), transf(1, 1) = resLinTr(1, 1);
  128. Vec<double, 2> resShift = mapAff->getShift();
  129. transf(0, 2) = resShift(0);
  130. transf(1, 2) = resShift(1);
  131. return transf;
  132. }
  133. Matx<double, 3, 3> perfProjective(const Mat& img1)
  134. {
  135. Mat img2;
  136. // Warp original image
  137. Matx<double, 3, 3> projTr(1., 0., 0., 0., 1., 0., 0.0001, 0.0001, 1);
  138. MapProjec mapTest(projTr);
  139. mapTest.warp(img1, img2);
  140. // Register
  141. Ptr<MapperGradProj> mapper = makePtr<MapperGradProj>();
  142. MapperPyramid mappPyr(mapper);
  143. Ptr<Map> mapPtr = mappPyr.calculate(img1, img2);
  144. MapProjec* mapProj = dynamic_cast<MapProjec*>(mapPtr.get());
  145. mapProj->normalize();
  146. return mapProj->getProjTr();
  147. }
  148. PERF_TEST_P(Size_MatType, Registration_Shift,
  149. Combine(Values(szSmall64, szSmall128),
  150. Values(MatType(CV_64FC1), MatType(CV_64FC3))))
  151. {
  152. declare.time(60);
  153. const Size size = get<0>(GetParam());
  154. const int type = get<1>(GetParam());
  155. Mat frame(size, type);
  156. Vec<double, 2> shift;
  157. declare.in(frame, WARMUP_RNG).out(shift);
  158. TEST_CYCLE() shift = perfShift(frame);
  159. SANITY_CHECK_NOTHING();
  160. }
  161. PERF_TEST_P(Size_MatType, Registration_Euclidean,
  162. Combine(Values(szSmall64, szSmall128),
  163. Values(MatType(CV_64FC1), MatType(CV_64FC3))))
  164. {
  165. declare.time(60);
  166. const Size size = get<0>(GetParam());
  167. const int type = get<1>(GetParam());
  168. Mat frame(size, type);
  169. Matx<double, 2, 6> result;
  170. declare.in(frame, WARMUP_RNG).out(result);
  171. TEST_CYCLE() result = perfEuclidean(frame);
  172. SANITY_CHECK_NOTHING();
  173. }
  174. PERF_TEST_P(Size_MatType, Registration_Similarity,
  175. Combine(Values(szSmall64, szSmall128),
  176. Values(MatType(CV_64FC1), MatType(CV_64FC3))))
  177. {
  178. declare.time(60);
  179. const Size size = get<0>(GetParam());
  180. const int type = get<1>(GetParam());
  181. Mat frame(size, type);
  182. Matx<double, 2, 6> result;
  183. declare.in(frame, WARMUP_RNG).out(result);
  184. TEST_CYCLE() result = perfSimilarity(frame);
  185. SANITY_CHECK_NOTHING();
  186. }
  187. PERF_TEST_P(Size_MatType, Registration_Affine,
  188. Combine(Values(szSmall64, szSmall128),
  189. Values(MatType(CV_64FC1), MatType(CV_64FC3))))
  190. {
  191. declare.time(60);
  192. const Size size = get<0>(GetParam());
  193. const int type = get<1>(GetParam());
  194. Mat frame(size, type);
  195. Matx<double, 2, 6> result;
  196. declare.in(frame, WARMUP_RNG).out(result);
  197. TEST_CYCLE() result = perfAffine(frame);
  198. SANITY_CHECK_NOTHING();
  199. }
  200. PERF_TEST_P(Size_MatType, Registration_Projective,
  201. Combine(Values(szSmall64, szSmall128),
  202. Values(MatType(CV_64FC1), MatType(CV_64FC3))))
  203. {
  204. declare.time(60);
  205. const Size size = get<0>(GetParam());
  206. const int type = get<1>(GetParam());
  207. Mat frame(size, type);
  208. Matx<double, 3, 3> result;
  209. declare.in(frame, WARMUP_RNG).out(result);
  210. TEST_CYCLE() result = perfProjective(frame);
  211. SANITY_CHECK_NOTHING();
  212. }
  213. }} // namespace