test_rotation_and_scale_invariance.cpp 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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 "test_precomp.hpp"
  5. #include "features2d/test/test_detectors_invariance.impl.hpp" // main OpenCV repo
  6. #include "features2d/test/test_descriptors_invariance.impl.hpp" // main OpenCV repo
  7. namespace opencv_test { namespace {
  8. static const char* const IMAGE_TSUKUBA = "features2d/tsukuba.png";
  9. static const char* const IMAGE_BIKES = "detectors_descriptors_evaluation/images_datasets/bikes/img1.png";
  10. // ========================== ROTATION INVARIANCE =============================
  11. #ifdef OPENCV_ENABLE_NONFREE
  12. INSTANTIATE_TEST_CASE_P(SURF, DetectorRotationInvariance, Values(
  13. make_tuple(IMAGE_TSUKUBA, SURF::create(), 0.40f, 0.76f)
  14. ));
  15. INSTANTIATE_TEST_CASE_P(SURF, DescriptorRotationInvariance, Values(
  16. make_tuple(IMAGE_TSUKUBA, SURF::create(), SURF::create(), 0.83f)
  17. ));
  18. #endif // NONFREE
  19. INSTANTIATE_TEST_CASE_P(LATCH, DescriptorRotationInvariance, Values(
  20. make_tuple(IMAGE_TSUKUBA, SIFT::create(), LATCH::create(), 0.98f)
  21. ));
  22. INSTANTIATE_TEST_CASE_P(BEBLID, DescriptorRotationInvariance, Values(
  23. make_tuple(IMAGE_TSUKUBA, SIFT::create(), BEBLID::create(6.75), 0.98f)
  24. ));
  25. INSTANTIATE_TEST_CASE_P(DAISY, DescriptorRotationInvariance, Values(
  26. make_tuple(IMAGE_TSUKUBA,
  27. BRISK::create(),
  28. DAISY::create(15, 3, 8, 8, DAISY::NRM_NONE, noArray(), true, true),
  29. 0.79f)
  30. ));
  31. #ifdef OPENCV_XFEATURES2D_HAS_VGG_DATA
  32. INSTANTIATE_TEST_CASE_P(VGG120, DescriptorRotationInvariance, Values(
  33. make_tuple(IMAGE_TSUKUBA,
  34. KAZE::create(),
  35. VGG::create(VGG::VGG_120, 1.4f, true, true, 48.0f, false),
  36. 0.97f)
  37. ));
  38. INSTANTIATE_TEST_CASE_P(VGG80, DescriptorRotationInvariance, Values(
  39. make_tuple(IMAGE_TSUKUBA,
  40. KAZE::create(),
  41. VGG::create(VGG::VGG_80, 1.4f, true, true, 48.0f, false),
  42. 0.97f)
  43. ));
  44. INSTANTIATE_TEST_CASE_P(VGG64, DescriptorRotationInvariance, Values(
  45. make_tuple(IMAGE_TSUKUBA,
  46. KAZE::create(),
  47. VGG::create(VGG::VGG_64, 1.4f, true, true, 48.0f, false),
  48. 0.97f)
  49. ));
  50. INSTANTIATE_TEST_CASE_P(VGG48, DescriptorRotationInvariance, Values(
  51. make_tuple(IMAGE_TSUKUBA,
  52. KAZE::create(),
  53. VGG::create(VGG::VGG_48, 1.4f, true, true, 48.0f, false),
  54. 0.97f)
  55. ));
  56. #endif // OPENCV_XFEATURES2D_HAS_VGG_DATA
  57. #ifdef OPENCV_ENABLE_NONFREE
  58. INSTANTIATE_TEST_CASE_P(BRIEF_64, DescriptorRotationInvariance, Values(
  59. make_tuple(IMAGE_TSUKUBA,
  60. SURF::create(),
  61. BriefDescriptorExtractor::create(64,true),
  62. 0.98f)
  63. ));
  64. INSTANTIATE_TEST_CASE_P(BRIEF_32, DescriptorRotationInvariance, Values(
  65. make_tuple(IMAGE_TSUKUBA,
  66. SURF::create(),
  67. BriefDescriptorExtractor::create(32,true),
  68. 0.97f)
  69. ));
  70. INSTANTIATE_TEST_CASE_P(BRIEF_16, DescriptorRotationInvariance, Values(
  71. make_tuple(IMAGE_TSUKUBA,
  72. SURF::create(),
  73. BriefDescriptorExtractor::create(16, true),
  74. 0.98f)
  75. ));
  76. INSTANTIATE_TEST_CASE_P(FREAK, DescriptorRotationInvariance, Values(
  77. make_tuple(IMAGE_TSUKUBA,
  78. SURF::create(),
  79. FREAK::create(),
  80. 0.90f)
  81. ));
  82. #ifdef OPENCV_XFEATURES2D_HAS_BOOST_DATA
  83. INSTANTIATE_TEST_CASE_P(BoostDesc_BGM, DescriptorRotationInvariance, Values(
  84. make_tuple(IMAGE_TSUKUBA,
  85. SURF::create(),
  86. BoostDesc::create(BoostDesc::BGM, true, 6.25f),
  87. 0.999f)
  88. ));
  89. INSTANTIATE_TEST_CASE_P(BoostDesc_BGM_HARD, DescriptorRotationInvariance, Values(
  90. make_tuple(IMAGE_TSUKUBA,
  91. SURF::create(),
  92. BoostDesc::create(BoostDesc::BGM_HARD, true, 6.25f),
  93. 0.98f)
  94. ));
  95. INSTANTIATE_TEST_CASE_P(BoostDesc_BGM_BILINEAR, DescriptorRotationInvariance, Values(
  96. make_tuple(IMAGE_TSUKUBA,
  97. SURF::create(),
  98. BoostDesc::create(BoostDesc::BGM_BILINEAR, true, 6.25f),
  99. 0.98f)
  100. ));
  101. INSTANTIATE_TEST_CASE_P(BoostDesc_BGM_LBGM, DescriptorRotationInvariance, Values(
  102. make_tuple(IMAGE_TSUKUBA,
  103. SURF::create(),
  104. BoostDesc::create(BoostDesc::LBGM, true, 6.25f),
  105. 0.999f)
  106. ));
  107. INSTANTIATE_TEST_CASE_P(BoostDesc_BINBOOST_64, DescriptorRotationInvariance, Values(
  108. make_tuple(IMAGE_TSUKUBA,
  109. SURF::create(),
  110. BoostDesc::create(BoostDesc::BINBOOST_64, true, 6.25f),
  111. 0.98f)
  112. ));
  113. INSTANTIATE_TEST_CASE_P(BoostDesc_BINBOOST_128, DescriptorRotationInvariance, Values(
  114. make_tuple(IMAGE_TSUKUBA,
  115. SURF::create(),
  116. BoostDesc::create(BoostDesc::BINBOOST_128, true, 6.25f),
  117. 0.98f)
  118. ));
  119. INSTANTIATE_TEST_CASE_P(BoostDesc_BINBOOST_256, DescriptorRotationInvariance, Values(
  120. make_tuple(IMAGE_TSUKUBA,
  121. SURF::create(),
  122. BoostDesc::create(BoostDesc::BINBOOST_256, true, 6.25f),
  123. 0.999f)
  124. ));
  125. #endif // OPENCV_XFEATURES2D_HAS_BOOST_DATA
  126. #endif
  127. // ============================ SCALE INVARIANCE ==============================
  128. #ifdef OPENCV_ENABLE_NONFREE
  129. INSTANTIATE_TEST_CASE_P(SURF, DetectorScaleInvariance, Values(
  130. make_tuple(IMAGE_BIKES, SURF::create(), 0.64f, 0.84f)
  131. ));
  132. INSTANTIATE_TEST_CASE_P(SURF, DescriptorScaleInvariance, Values(
  133. make_tuple(IMAGE_BIKES, SURF::create(), SURF::create(), 0.7f)
  134. ));
  135. #endif // NONFREE
  136. #if 0 // DAISY is not scale invariant
  137. INSTANTIATE_TEST_CASE_P(DISABLED_DAISY, DescriptorScaleInvariance, Values(
  138. make_tuple(IMAGE_BIKES,
  139. BRISK::create(),
  140. DAISY::create(15, 3, 8, 8, DAISY::NRM_NONE, noArray(), true, true),
  141. 0.1f)
  142. ));
  143. #endif
  144. #ifdef OPENCV_XFEATURES2D_HAS_VGG_DATA
  145. INSTANTIATE_TEST_CASE_P(VGG120, DescriptorScaleInvariance, Values(
  146. make_tuple(IMAGE_BIKES,
  147. KAZE::create(),
  148. VGG::create(VGG::VGG_120, 1.4f, true, true, 48.0f, false),
  149. 0.98f)
  150. ));
  151. INSTANTIATE_TEST_CASE_P(VGG80, DescriptorScaleInvariance, Values(
  152. make_tuple(IMAGE_BIKES,
  153. KAZE::create(),
  154. VGG::create(VGG::VGG_80, 1.4f, true, true, 48.0f, false),
  155. 0.98f)
  156. ));
  157. INSTANTIATE_TEST_CASE_P(VGG64, DescriptorScaleInvariance, Values(
  158. make_tuple(IMAGE_BIKES,
  159. KAZE::create(),
  160. VGG::create(VGG::VGG_64, 1.4f, true, true, 48.0f, false),
  161. 0.97f)
  162. ));
  163. INSTANTIATE_TEST_CASE_P(VGG48, DescriptorScaleInvariance, Values(
  164. make_tuple(IMAGE_BIKES,
  165. KAZE::create(),
  166. VGG::create(VGG::VGG_48, 1.4f, true, true, 48.0f, false),
  167. 0.93f)
  168. ));
  169. #endif // OPENCV_XFEATURES2D_HAS_VGG_DATA
  170. #ifdef OPENCV_ENABLE_NONFREE // SURF detector is used in tests
  171. #ifdef OPENCV_XFEATURES2D_HAS_BOOST_DATA
  172. INSTANTIATE_TEST_CASE_P(BoostDesc_BGM, DescriptorScaleInvariance, Values(
  173. make_tuple(IMAGE_BIKES,
  174. SURF::create(),
  175. BoostDesc::create(BoostDesc::BGM, true, 6.25f),
  176. 0.98f)
  177. ));
  178. INSTANTIATE_TEST_CASE_P(BoostDesc_BGM_HARD, DescriptorScaleInvariance, Values(
  179. make_tuple(IMAGE_BIKES,
  180. SURF::create(),
  181. BoostDesc::create(BoostDesc::BGM_HARD, true, 6.25f),
  182. 0.75f)
  183. ));
  184. INSTANTIATE_TEST_CASE_P(BoostDesc_BGM_BILINEAR, DescriptorScaleInvariance, Values(
  185. make_tuple(IMAGE_BIKES,
  186. SURF::create(),
  187. BoostDesc::create(BoostDesc::BGM_BILINEAR, true, 6.25f),
  188. 0.95f)
  189. ));
  190. INSTANTIATE_TEST_CASE_P(BoostDesc_LBGM, DescriptorScaleInvariance, Values(
  191. make_tuple(IMAGE_BIKES,
  192. SURF::create(),
  193. BoostDesc::create(BoostDesc::LBGM, true, 6.25f),
  194. 0.95f)
  195. ));
  196. INSTANTIATE_TEST_CASE_P(BoostDesc_BINBOOST_64, DescriptorScaleInvariance, Values(
  197. make_tuple(IMAGE_BIKES,
  198. SURF::create(),
  199. BoostDesc::create(BoostDesc::BINBOOST_64, true, 6.25f),
  200. 0.75f)
  201. ));
  202. INSTANTIATE_TEST_CASE_P(BoostDesc_BINBOOST_128, DescriptorScaleInvariance, Values(
  203. make_tuple(IMAGE_BIKES,
  204. SURF::create(),
  205. BoostDesc::create(BoostDesc::BINBOOST_128, true, 6.25f),
  206. 0.95f)
  207. ));
  208. INSTANTIATE_TEST_CASE_P(BoostDesc_BINBOOST_256, DescriptorScaleInvariance, Values(
  209. make_tuple(IMAGE_BIKES,
  210. SURF::create(),
  211. BoostDesc::create(BoostDesc::BINBOOST_256, true, 6.25f),
  212. 0.98f)
  213. ));
  214. #endif // OPENCV_XFEATURES2D_HAS_BOOST_DATA
  215. #endif // NONFREE
  216. // ============================== OTHER TESTS =================================
  217. #ifdef OPENCV_ENABLE_NONFREE
  218. TEST(Features2d_RotationInvariance2_Detector_SURF, regression)
  219. {
  220. Mat cross(100, 100, CV_8UC1, Scalar(255));
  221. line(cross, Point(30, 50), Point(69, 50), Scalar(100), 3);
  222. line(cross, Point(50, 30), Point(50, 69), Scalar(100), 3);
  223. Ptr<SURF> surf = SURF::create(8000., 3, 4, true, false);
  224. vector<KeyPoint> keypoints;
  225. surf->detect(cross, keypoints);
  226. // Expect 5 keypoints. One keypoint has coordinates (50.0, 50.0).
  227. // The other 4 keypoints should have the same response.
  228. // The order of the keypoints is indeterminate.
  229. ASSERT_EQ(keypoints.size(), (vector<KeyPoint>::size_type) 5);
  230. int i1 = -1;
  231. for(int i = 0; i < 5; i++)
  232. {
  233. if(keypoints[i].pt.x == 50.0f)
  234. ;
  235. else if(i1 == -1)
  236. i1 = i;
  237. else
  238. ASSERT_LT(fabs(keypoints[i1].response - keypoints[i].response) / keypoints[i1].response, 1e-6);
  239. }
  240. }
  241. #endif // NONFREE
  242. }} // namespace