test_descriptors_regression.cpp 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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. namespace opencv_test { namespace {
  6. const string FEATURES2D_DIR = "features2d";
  7. const string IMAGE_FILENAME = "tsukuba.png";
  8. const string DESCRIPTOR_DIR = FEATURES2D_DIR + "/descriptor_extractors";
  9. }} // namespace
  10. #include "test_descriptors_regression.impl.hpp"
  11. namespace opencv_test { namespace {
  12. /****************************************************************************************\
  13. * Tests registrations *
  14. \****************************************************************************************/
  15. TEST( Features2d_DescriptorExtractor_SIFT, regression )
  16. {
  17. CV_DescriptorExtractorTest<L1<float> > test( "descriptor-sift", 1.0f,
  18. SIFT::create() );
  19. test.safe_run();
  20. }
  21. TEST( Features2d_DescriptorExtractor_BRISK, regression )
  22. {
  23. CV_DescriptorExtractorTest<Hamming> test( "descriptor-brisk",
  24. (CV_DescriptorExtractorTest<Hamming>::DistanceType)2.f,
  25. BRISK::create() );
  26. test.safe_run();
  27. }
  28. TEST( Features2d_DescriptorExtractor_ORB, regression )
  29. {
  30. // TODO adjust the parameters below
  31. CV_DescriptorExtractorTest<Hamming> test( "descriptor-orb",
  32. #if CV_NEON
  33. (CV_DescriptorExtractorTest<Hamming>::DistanceType)25.f,
  34. #else
  35. (CV_DescriptorExtractorTest<Hamming>::DistanceType)12.f,
  36. #endif
  37. ORB::create() );
  38. test.safe_run();
  39. }
  40. TEST( Features2d_DescriptorExtractor_KAZE, regression )
  41. {
  42. CV_DescriptorExtractorTest< L2<float> > test( "descriptor-kaze", 0.03f,
  43. KAZE::create(),
  44. L2<float>(), KAZE::create() );
  45. test.safe_run();
  46. }
  47. TEST( Features2d_DescriptorExtractor_AKAZE, regression )
  48. {
  49. CV_DescriptorExtractorTest<Hamming> test( "descriptor-akaze",
  50. (CV_DescriptorExtractorTest<Hamming>::DistanceType)(486*0.05f),
  51. AKAZE::create(),
  52. Hamming(), AKAZE::create());
  53. test.safe_run();
  54. }
  55. TEST( Features2d_DescriptorExtractor_AKAZE_DESCRIPTOR_KAZE, regression )
  56. {
  57. CV_DescriptorExtractorTest< L2<float> > test( "descriptor-akaze-with-kaze-desc", 0.03f,
  58. AKAZE::create(AKAZE::DESCRIPTOR_KAZE),
  59. L2<float>(), AKAZE::create(AKAZE::DESCRIPTOR_KAZE));
  60. test.safe_run();
  61. }
  62. TEST( Features2d_DescriptorExtractor, batch_ORB )
  63. {
  64. string path = string(cvtest::TS::ptr()->get_data_path() + "detectors_descriptors_evaluation/images_datasets/graf");
  65. vector<Mat> imgs, descriptors;
  66. vector<vector<KeyPoint> > keypoints;
  67. int i, n = 6;
  68. Ptr<ORB> orb = ORB::create();
  69. for( i = 0; i < n; i++ )
  70. {
  71. string imgname = format("%s/img%d.png", path.c_str(), i+1);
  72. Mat img = imread(imgname, 0);
  73. imgs.push_back(img);
  74. }
  75. orb->detect(imgs, keypoints);
  76. orb->compute(imgs, keypoints, descriptors);
  77. ASSERT_EQ((int)keypoints.size(), n);
  78. ASSERT_EQ((int)descriptors.size(), n);
  79. for( i = 0; i < n; i++ )
  80. {
  81. EXPECT_GT((int)keypoints[i].size(), 100);
  82. EXPECT_GT(descriptors[i].rows, 100);
  83. }
  84. }
  85. TEST( Features2d_DescriptorExtractor, batch_SIFT )
  86. {
  87. string path = string(cvtest::TS::ptr()->get_data_path() + "detectors_descriptors_evaluation/images_datasets/graf");
  88. vector<Mat> imgs, descriptors;
  89. vector<vector<KeyPoint> > keypoints;
  90. int i, n = 6;
  91. Ptr<SIFT> sift = SIFT::create();
  92. for( i = 0; i < n; i++ )
  93. {
  94. string imgname = format("%s/img%d.png", path.c_str(), i+1);
  95. Mat img = imread(imgname, 0);
  96. imgs.push_back(img);
  97. }
  98. sift->detect(imgs, keypoints);
  99. sift->compute(imgs, keypoints, descriptors);
  100. ASSERT_EQ((int)keypoints.size(), n);
  101. ASSERT_EQ((int)descriptors.size(), n);
  102. for( i = 0; i < n; i++ )
  103. {
  104. EXPECT_GT((int)keypoints[i].size(), 100);
  105. EXPECT_GT(descriptors[i].rows, 100);
  106. }
  107. }
  108. class DescriptorImage : public TestWithParam<std::string>
  109. {
  110. protected:
  111. virtual void SetUp() {
  112. pattern = GetParam();
  113. }
  114. std::string pattern;
  115. };
  116. TEST_P(DescriptorImage, no_crash)
  117. {
  118. vector<String> fnames;
  119. glob(cvtest::TS::ptr()->get_data_path() + pattern, fnames, false);
  120. sort(fnames.begin(), fnames.end());
  121. Ptr<AKAZE> akaze_mldb = AKAZE::create(AKAZE::DESCRIPTOR_MLDB);
  122. Ptr<AKAZE> akaze_mldb_upright = AKAZE::create(AKAZE::DESCRIPTOR_MLDB_UPRIGHT);
  123. Ptr<AKAZE> akaze_mldb_256 = AKAZE::create(AKAZE::DESCRIPTOR_MLDB, 256);
  124. Ptr<AKAZE> akaze_mldb_upright_256 = AKAZE::create(AKAZE::DESCRIPTOR_MLDB_UPRIGHT, 256);
  125. Ptr<AKAZE> akaze_kaze = AKAZE::create(AKAZE::DESCRIPTOR_KAZE);
  126. Ptr<AKAZE> akaze_kaze_upright = AKAZE::create(AKAZE::DESCRIPTOR_KAZE_UPRIGHT);
  127. Ptr<ORB> orb = ORB::create();
  128. Ptr<KAZE> kaze = KAZE::create();
  129. Ptr<BRISK> brisk = BRISK::create();
  130. size_t n = fnames.size();
  131. vector<KeyPoint> keypoints;
  132. Mat descriptors;
  133. orb->setMaxFeatures(5000);
  134. for(size_t i = 0; i < n; i++ )
  135. {
  136. printf("%d. image: %s:\n", (int)i, fnames[i].c_str());
  137. if( strstr(fnames[i].c_str(), "MP.png") != 0 )
  138. {
  139. printf("\tskip\n");
  140. continue;
  141. }
  142. bool checkCount = strstr(fnames[i].c_str(), "templ.png") == 0;
  143. Mat img = imread(fnames[i], -1);
  144. printf("\t%dx%d\n", img.cols, img.rows);
  145. #define TEST_DETECTOR(name, descriptor) \
  146. keypoints.clear(); descriptors.release(); \
  147. printf("\t" name "\n"); fflush(stdout); \
  148. descriptor->detectAndCompute(img, noArray(), keypoints, descriptors); \
  149. printf("\t\t\t(%d keypoints, descriptor size = %d)\n", (int)keypoints.size(), descriptors.cols); fflush(stdout); \
  150. if (checkCount) \
  151. { \
  152. EXPECT_GT((int)keypoints.size(), 0); \
  153. } \
  154. ASSERT_EQ(descriptors.rows, (int)keypoints.size());
  155. TEST_DETECTOR("AKAZE:MLDB", akaze_mldb);
  156. TEST_DETECTOR("AKAZE:MLDB_UPRIGHT", akaze_mldb_upright);
  157. TEST_DETECTOR("AKAZE:MLDB_256", akaze_mldb_256);
  158. TEST_DETECTOR("AKAZE:MLDB_UPRIGHT_256", akaze_mldb_upright_256);
  159. TEST_DETECTOR("AKAZE:KAZE", akaze_kaze);
  160. TEST_DETECTOR("AKAZE:KAZE_UPRIGHT", akaze_kaze_upright);
  161. TEST_DETECTOR("KAZE", kaze);
  162. TEST_DETECTOR("ORB", orb);
  163. TEST_DETECTOR("BRISK", brisk);
  164. }
  165. }
  166. INSTANTIATE_TEST_CASE_P(Features2d, DescriptorImage,
  167. testing::Values(
  168. "shared/lena.png",
  169. "shared/box*.png",
  170. "shared/fruits*.png",
  171. "shared/airplane.png",
  172. "shared/graffiti.png",
  173. "shared/1_itseez-0001*.png",
  174. "shared/pic*.png",
  175. "shared/templ.png"
  176. )
  177. );
  178. }} // namespace