perf_stitch.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. //
  5. // Copyright (C) 2014, Itseez, Inc, all rights reserved.
  6. #include "../perf_precomp.hpp"
  7. #include "opencv2/ts/ocl_perf.hpp"
  8. #ifdef HAVE_OPENCL
  9. namespace opencv_test {
  10. using namespace perf;
  11. namespace ocl {
  12. #define SURF_MATCH_CONFIDENCE 0.65f
  13. #define ORB_MATCH_CONFIDENCE 0.3f
  14. #define WORK_MEGAPIX 0.6
  15. typedef TestBaseWithParam<string> stitch;
  16. #if defined(HAVE_OPENCV_XFEATURES2D) && defined(OPENCV_ENABLE_NONFREE)
  17. #define TEST_DETECTORS testing::Values("surf", "orb", "akaze")
  18. #else
  19. #define TEST_DETECTORS testing::Values("orb", "akaze")
  20. #endif
  21. OCL_PERF_TEST_P(stitch, a123, TEST_DETECTORS)
  22. {
  23. UMat pano;
  24. vector<Mat> _imgs;
  25. _imgs.push_back( imread( getDataPath("stitching/a1.png") ) );
  26. _imgs.push_back( imread( getDataPath("stitching/a2.png") ) );
  27. _imgs.push_back( imread( getDataPath("stitching/a3.png") ) );
  28. vector<UMat> imgs = ToUMat(_imgs);
  29. Ptr<Feature2D> featuresFinder = getFeatureFinder(GetParam());
  30. Ptr<detail::FeaturesMatcher> featuresMatcher = GetParam() == "orb"
  31. ? makePtr<detail::BestOf2NearestMatcher>(false, ORB_MATCH_CONFIDENCE)
  32. : makePtr<detail::BestOf2NearestMatcher>(false, SURF_MATCH_CONFIDENCE);
  33. declare.iterations(20);
  34. while(next())
  35. {
  36. Ptr<Stitcher> stitcher = Stitcher::create();
  37. stitcher->setFeaturesFinder(featuresFinder);
  38. stitcher->setFeaturesMatcher(featuresMatcher);
  39. stitcher->setWarper(makePtr<SphericalWarper>());
  40. stitcher->setRegistrationResol(WORK_MEGAPIX);
  41. startTimer();
  42. stitcher->stitch(imgs, pano);
  43. stopTimer();
  44. }
  45. EXPECT_NEAR(pano.size().width, 1182, 50);
  46. EXPECT_NEAR(pano.size().height, 682, 30);
  47. SANITY_CHECK_NOTHING();
  48. }
  49. OCL_PERF_TEST_P(stitch, b12, TEST_DETECTORS)
  50. {
  51. UMat pano;
  52. vector<Mat> imgs;
  53. imgs.push_back( imread( getDataPath("stitching/b1.png") ) );
  54. imgs.push_back( imread( getDataPath("stitching/b2.png") ) );
  55. Ptr<Feature2D> featuresFinder = getFeatureFinder(GetParam());
  56. Ptr<detail::FeaturesMatcher> featuresMatcher = GetParam() == "orb"
  57. ? makePtr<detail::BestOf2NearestMatcher>(false, ORB_MATCH_CONFIDENCE)
  58. : makePtr<detail::BestOf2NearestMatcher>(false, SURF_MATCH_CONFIDENCE);
  59. declare.iterations(20);
  60. while(next())
  61. {
  62. Ptr<Stitcher> stitcher = Stitcher::create();
  63. stitcher->setFeaturesFinder(featuresFinder);
  64. stitcher->setFeaturesMatcher(featuresMatcher);
  65. stitcher->setWarper(makePtr<SphericalWarper>());
  66. stitcher->setRegistrationResol(WORK_MEGAPIX);
  67. startTimer();
  68. stitcher->stitch(imgs, pano);
  69. stopTimer();
  70. }
  71. EXPECT_NEAR(pano.size().width, 1124, GetParam() == "surf" ? 100 : 50);
  72. EXPECT_NEAR(pano.size().height, 644, GetParam() == "surf" ? 60 : 30);
  73. SANITY_CHECK_NOTHING();
  74. }
  75. OCL_PERF_TEST_P(stitch, boat, TEST_DETECTORS)
  76. {
  77. Size expected_dst_size(10789, 2663);
  78. checkDeviceMaxMemoryAllocSize(expected_dst_size, CV_16SC3, 4);
  79. #if defined(_WIN32) && !defined(_WIN64)
  80. if (cv::ocl::useOpenCL())
  81. throw ::perf::TestBase::PerfSkipTestException();
  82. #endif
  83. UMat pano;
  84. vector<Mat> _imgs;
  85. _imgs.push_back( imread( getDataPath("stitching/boat1.jpg") ) );
  86. _imgs.push_back( imread( getDataPath("stitching/boat2.jpg") ) );
  87. _imgs.push_back( imread( getDataPath("stitching/boat3.jpg") ) );
  88. _imgs.push_back( imread( getDataPath("stitching/boat4.jpg") ) );
  89. _imgs.push_back( imread( getDataPath("stitching/boat5.jpg") ) );
  90. _imgs.push_back( imread( getDataPath("stitching/boat6.jpg") ) );
  91. vector<UMat> imgs = ToUMat(_imgs);
  92. Ptr<Feature2D> featuresFinder = getFeatureFinder(GetParam());
  93. Ptr<detail::FeaturesMatcher> featuresMatcher = GetParam() == "orb"
  94. ? makePtr<detail::BestOf2NearestMatcher>(false, ORB_MATCH_CONFIDENCE)
  95. : makePtr<detail::BestOf2NearestMatcher>(false, SURF_MATCH_CONFIDENCE);
  96. declare.iterations(20);
  97. while(next())
  98. {
  99. Ptr<Stitcher> stitcher = Stitcher::create();
  100. stitcher->setFeaturesFinder(featuresFinder);
  101. stitcher->setFeaturesMatcher(featuresMatcher);
  102. stitcher->setWarper(makePtr<SphericalWarper>());
  103. stitcher->setRegistrationResol(WORK_MEGAPIX);
  104. startTimer();
  105. stitcher->stitch(imgs, pano);
  106. stopTimer();
  107. }
  108. EXPECT_NEAR(pano.size().width, expected_dst_size.width, 200);
  109. EXPECT_NEAR(pano.size().height, expected_dst_size.height, 100);
  110. SANITY_CHECK_NOTHING();
  111. }
  112. } } // namespace opencv_test::ocl
  113. #endif // HAVE_OPENCL