test_matchers.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. // Intel License Agreement
  11. // For Open Source Computer Vision Library
  12. //
  13. // Copyright (C) 2000, Intel Corporation, all rights reserved.
  14. // Third party copyrights are property of their respective owners.
  15. //
  16. // Redistribution and use in source and binary forms, with or without modification,
  17. // are permitted provided that the following conditions are met:
  18. //
  19. // * Redistribution's of source code must retain the above copyright notice,
  20. // this list of conditions and the following disclaimer.
  21. //
  22. // * Redistribution's in binary form must reproduce the above copyright notice,
  23. // this list of conditions and the following disclaimer in the documentation
  24. // and/or other materials provided with the distribution.
  25. //
  26. // * The name of Intel Corporation may not be used to endorse or promote products
  27. // derived from this software 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 the Intel Corporation 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 "test_precomp.hpp"
  42. namespace opencv_test { namespace {
  43. #if defined(HAVE_OPENCV_XFEATURES2D) && defined(OPENCV_ENABLE_NONFREE)
  44. TEST(SurfFeaturesFinder, CanFindInROIs)
  45. {
  46. Ptr<Feature2D> finder = xfeatures2d::SURF::create();
  47. Mat img = imread(string(cvtest::TS::ptr()->get_data_path()) + "cv/shared/lena.png");
  48. vector<Rect> rois;
  49. rois.push_back(Rect(0, 0, img.cols / 2, img.rows / 2));
  50. rois.push_back(Rect(img.cols / 2, img.rows / 2, img.cols - img.cols / 2, img.rows - img.rows / 2));
  51. // construct mask
  52. Mat mask = Mat::zeros(img.size(), CV_8U);
  53. for (const Rect &roi : rois)
  54. {
  55. Mat(mask, roi) = 1;
  56. }
  57. detail::ImageFeatures roi_features;
  58. detail::computeImageFeatures(finder, img, roi_features, mask);
  59. int tl_rect_count = 0, br_rect_count = 0, bad_count = 0;
  60. for (const auto &keypoint : roi_features.keypoints)
  61. {
  62. if (rois[0].contains(keypoint.pt))
  63. tl_rect_count++;
  64. else if (rois[1].contains(keypoint.pt))
  65. br_rect_count++;
  66. else
  67. bad_count++;
  68. }
  69. EXPECT_GT(tl_rect_count, 0);
  70. EXPECT_GT(br_rect_count, 0);
  71. EXPECT_EQ(bad_count, 0);
  72. }
  73. #endif // HAVE_OPENCV_XFEATURES2D && OPENCV_ENABLE_NONFREE
  74. TEST(ParallelFeaturesFinder, IsSameWithSerial)
  75. {
  76. Ptr<Feature2D> para_finder = ORB::create();
  77. Ptr<Feature2D> serial_finder = ORB::create();
  78. Mat img = imread(string(cvtest::TS::ptr()->get_data_path()) + "stitching/a3.png", IMREAD_GRAYSCALE);
  79. detail::ImageFeatures serial_features;
  80. detail::computeImageFeatures(serial_finder, img, serial_features);
  81. vector<Mat> imgs(50, img);
  82. vector<detail::ImageFeatures> para_features(imgs.size());
  83. detail::computeImageFeatures(para_finder, imgs, para_features); // FIXIT This call doesn't use parallel_for_()
  84. // results must be the same
  85. Mat serial_descriptors;
  86. serial_features.descriptors.copyTo(serial_descriptors);
  87. for(size_t i = 0; i < para_features.size(); ++i)
  88. {
  89. SCOPED_TRACE(cv::format("i=%zu", i));
  90. EXPECT_EQ(serial_descriptors.size(), para_features[i].descriptors.size());
  91. #if 0 // FIXIT ORB descriptors are not bit-exact (perhaps due internal parallel_for usage)
  92. ASSERT_EQ(0, cv::norm(u_serial_descriptors, para_features[i].descriptors, NORM_L1))
  93. << "serial_size=" << u_serial_descriptors.size()
  94. << " par_size=" << para_features[i].descriptors.size()
  95. << endl << u_serial_descriptors.getMat(ACCESS_READ)
  96. << endl << endl << para_features[i].descriptors.getMat(ACCESS_READ);
  97. #endif
  98. EXPECT_EQ(serial_features.img_size, para_features[i].img_size);
  99. EXPECT_EQ(serial_features.keypoints.size(), para_features[i].keypoints.size());
  100. }
  101. }
  102. }} // namespace