diff --git a/modules/stitching/CMakeLists.txt b/modules/stitching/CMakeLists.txt index b61962ca9f..98410198d7 100644 --- a/modules/stitching/CMakeLists.txt +++ b/modules/stitching/CMakeLists.txt @@ -1,4 +1,3 @@ -include_directories("${OpenCV_SOURCE_DIR}/modules/imgproc/src") # For gcgraph.hpp if(ANDROID) define_opencv_module(stitching opencv_core opencv_imgproc opencv_features2d opencv_calib3d opencv_flann opencv_objdetect) else() diff --git a/modules/stitching/perf/perf_stich.cpp b/modules/stitching/perf/perf_stich.cpp index c31ce27c27..e7bbd400dd 100644 --- a/modules/stitching/perf/perf_stich.cpp +++ b/modules/stitching/perf/perf_stich.cpp @@ -1,12 +1,18 @@ #include "perf_precomp.hpp" #include "opencv2/highgui/highgui.hpp" +#include "opencv2/flann/flann.hpp" using namespace std; using namespace cv; using namespace perf; +#define SURF_MATCH_CONFIDENCE 0.65f +#define ORB_MATCH_CONFIDENCE 0.3f +#define WORK_MEGAPIX 0.6 + typedef TestBaseWithParam stitch; +typedef TestBaseWithParam match; PERF_TEST_P( stitch, a123, testing::Values("surf", "orb")) { @@ -23,8 +29,8 @@ PERF_TEST_P( stitch, a123, testing::Values("surf", "orb")) : (detail::FeaturesFinder*)new detail::SurfFeaturesFinder(); Ptr featuresMatcher = GetParam() == "orb" - ? new detail::BestOf2NearestMatcher(false, 0.3f) - : new detail::BestOf2NearestMatcher(false, 0.65f); + ? new detail::BestOf2NearestMatcher(false, ORB_MATCH_CONFIDENCE) + : new detail::BestOf2NearestMatcher(false, SURF_MATCH_CONFIDENCE); declare.time(30 * 20).iterations(50); @@ -33,6 +39,8 @@ PERF_TEST_P( stitch, a123, testing::Values("surf", "orb")) Stitcher stitcher = Stitcher::createDefault(); stitcher.setFeaturesFinder(featuresFinder); stitcher.setFeaturesMatcher(featuresMatcher); + stitcher.setWarper(new CylindricalWarper()); + stitcher.setRegistrationResol(WORK_MEGAPIX); startTimer(); status = stitcher.stitch(imgs, pano); @@ -54,8 +62,8 @@ PERF_TEST_P( stitch, b12, testing::Values("surf", "orb")) : (detail::FeaturesFinder*)new detail::SurfFeaturesFinder(); Ptr featuresMatcher = GetParam() == "orb" - ? new detail::BestOf2NearestMatcher(false, 0.3f) - : new detail::BestOf2NearestMatcher(false, 0.65f); + ? new detail::BestOf2NearestMatcher(false, ORB_MATCH_CONFIDENCE) + : new detail::BestOf2NearestMatcher(false, SURF_MATCH_CONFIDENCE); declare.time(30 * 20).iterations(50); @@ -64,9 +72,56 @@ PERF_TEST_P( stitch, b12, testing::Values("surf", "orb")) Stitcher stitcher = Stitcher::createDefault(); stitcher.setFeaturesFinder(featuresFinder); stitcher.setFeaturesMatcher(featuresMatcher); + stitcher.setWarper(new CylindricalWarper()); + stitcher.setRegistrationResol(WORK_MEGAPIX); startTimer(); status = stitcher.stitch(imgs, pano); stopTimer(); } } + +PERF_TEST_P( match, bestOf2Nearest, testing::Values("surf", "orb")) +{ + Mat img1, img1_full = imread( getDataPath("stitching/b1.jpg") ); + Mat img2, img2_full = imread( getDataPath("stitching/b2.jpg") ); + float scale1 = std::min(1.0, sqrt(WORK_MEGAPIX * 1e6 / img1_full.total())); + float scale2 = std::min(1.0, sqrt(WORK_MEGAPIX * 1e6 / img2_full.total())); + resize(img1_full, img1, Size(), scale1, scale1); + resize(img2_full, img2, Size(), scale2, scale2); + + Ptr finder; + Ptr matcher; + if (GetParam() == "surf") + { + finder = new detail::SurfFeaturesFinder(); + matcher = new detail::BestOf2NearestMatcher(false, SURF_MATCH_CONFIDENCE); + } + else if (GetParam() == "orb") + { + finder = new detail::OrbFeaturesFinder(); + matcher = new detail::BestOf2NearestMatcher(false, ORB_MATCH_CONFIDENCE); + } + else + { + FAIL() << "Unknown 2D features type: " << GetParam(); + } + + detail::ImageFeatures features1, features2; + (*finder)(img1, features1); + (*finder)(img2, features2); + + detail::MatchesInfo pairwise_matches; + + declare.in(features1.descriptors, features2.descriptors) + .iterations(100); + + while(next()) + { + cvflann::seed_random(42);//for predictive FlannBasedMatcher + startTimer(); + (*matcher)(features1, features2, pairwise_matches); + stopTimer(); + matcher->collectGarbage(); + } +} diff --git a/modules/stitching/src/matchers.cpp b/modules/stitching/src/matchers.cpp index ec6eac5bcd..c32d910b75 100644 --- a/modules/stitching/src/matchers.cpp +++ b/modules/stitching/src/matchers.cpp @@ -147,11 +147,16 @@ private: void CpuMatcher::match(const ImageFeatures &features1, const ImageFeatures &features2, MatchesInfo& matches_info) { - matches_info.matches.clear(); - CV_Assert(features1.descriptors.type() == features2.descriptors.type()); CV_Assert(features2.descriptors.depth() == CV_8U || features2.descriptors.depth() == CV_32F); +#ifdef HAVE_TEGRA_OPTIMIZATION + if (tegra::match2nearest(features1, features2, matches_info, match_conf_)) + return; +#endif + + matches_info.matches.clear(); + Ptr indexParams = new flann::KDTreeIndexParams(); Ptr searchParams = new flann::SearchParams(); diff --git a/modules/stitching/src/precomp.hpp b/modules/stitching/src/precomp.hpp index 343286494f..d84afe4d23 100644 --- a/modules/stitching/src/precomp.hpp +++ b/modules/stitching/src/precomp.hpp @@ -54,6 +54,8 @@ #include #include #include +#include "opencv2/core/core.hpp" +#include "opencv2/core/internal.hpp" #include "opencv2/stitching/stitcher.hpp" #include "opencv2/stitching/detail/autocalib.hpp" #include "opencv2/stitching/detail/blenders.hpp" @@ -64,14 +66,17 @@ #include "opencv2/stitching/detail/seam_finders.hpp" #include "opencv2/stitching/detail/util.hpp" #include "opencv2/stitching/detail/warpers.hpp" -#include "opencv2/core/core.hpp" -#include "opencv2/core/internal.hpp" #include "opencv2/imgproc/imgproc.hpp" #include "opencv2/features2d/features2d.hpp" #include "opencv2/calib3d/calib3d.hpp" #ifndef ANDROID # include "opencv2/gpu/gpu.hpp" #endif -#include "gcgraph.hpp" + +#include "modules/imgproc/src/gcgraph.hpp" + +#ifdef HAVE_TEGRA_OPTIMIZATION +# include "opencv2/stitching/stitching_tegra.hpp" +#endif #endif