Path: blob/master/modules/stitching/perf/perf_stich.cpp
16344 views
#include "perf_precomp.hpp"1#include "opencv2/imgcodecs.hpp"2#include "opencv2/opencv_modules.hpp"34#include "opencv2/core/ocl.hpp"56namespace opencv_test7{8using namespace perf;910#define SURF_MATCH_CONFIDENCE 0.65f11#define ORB_MATCH_CONFIDENCE 0.3f12#define WORK_MEGAPIX 0.61314typedef TestBaseWithParam<string> stitch;15typedef TestBaseWithParam<tuple<string, string> > stitchDatasets;1617#ifdef HAVE_OPENCV_XFEATURES2D18#define TEST_DETECTORS testing::Values("surf", "orb", "akaze")19#else20#define TEST_DETECTORS testing::Values("orb", "akaze")21#endif22#define AFFINE_DATASETS testing::Values("s", "budapest", "newspaper", "prague")2324PERF_TEST_P(stitch, a123, TEST_DETECTORS)25{26Mat pano;2728vector<Mat> imgs;29imgs.push_back( imread( getDataPath("stitching/a1.png") ) );30imgs.push_back( imread( getDataPath("stitching/a2.png") ) );31imgs.push_back( imread( getDataPath("stitching/a3.png") ) );3233Ptr<detail::FeaturesFinder> featuresFinder = getFeatureFinder(GetParam());3435Ptr<detail::FeaturesMatcher> featuresMatcher = GetParam() == "orb"36? makePtr<detail::BestOf2NearestMatcher>(false, ORB_MATCH_CONFIDENCE)37: makePtr<detail::BestOf2NearestMatcher>(false, SURF_MATCH_CONFIDENCE);3839declare.time(30 * 20).iterations(20);4041while(next())42{43Stitcher stitcher = Stitcher::createDefault();44stitcher.setFeaturesFinder(featuresFinder);45stitcher.setFeaturesMatcher(featuresMatcher);46stitcher.setWarper(makePtr<SphericalWarper>());47stitcher.setRegistrationResol(WORK_MEGAPIX);4849startTimer();50stitcher.stitch(imgs, pano);51stopTimer();52}5354EXPECT_NEAR(pano.size().width, 1182, 50);55EXPECT_NEAR(pano.size().height, 682, 30);5657SANITY_CHECK_NOTHING();58}5960PERF_TEST_P(stitch, b12, TEST_DETECTORS)61{62Mat pano;6364vector<Mat> imgs;65imgs.push_back( imread( getDataPath("stitching/b1.png") ) );66imgs.push_back( imread( getDataPath("stitching/b2.png") ) );6768Ptr<detail::FeaturesFinder> featuresFinder = getFeatureFinder(GetParam());6970Ptr<detail::FeaturesMatcher> featuresMatcher = GetParam() == "orb"71? makePtr<detail::BestOf2NearestMatcher>(false, ORB_MATCH_CONFIDENCE)72: makePtr<detail::BestOf2NearestMatcher>(false, SURF_MATCH_CONFIDENCE);7374declare.time(30 * 20).iterations(20);7576while(next())77{78Stitcher stitcher = Stitcher::createDefault();79stitcher.setFeaturesFinder(featuresFinder);80stitcher.setFeaturesMatcher(featuresMatcher);81stitcher.setWarper(makePtr<SphericalWarper>());82stitcher.setRegistrationResol(WORK_MEGAPIX);8384startTimer();85stitcher.stitch(imgs, pano);86stopTimer();87}8889EXPECT_NEAR(pano.size().width, 1117, GetParam() == "surf" ? 100 : 50);90EXPECT_NEAR(pano.size().height, 642, GetParam() == "surf" ? 60 : 30);9192SANITY_CHECK_NOTHING();93}9495PERF_TEST_P(stitchDatasets, affine, testing::Combine(AFFINE_DATASETS, TEST_DETECTORS))96{97string dataset = get<0>(GetParam());98string detector = get<1>(GetParam());99100Mat pano;101vector<Mat> imgs;102int width, height, allowed_diff = 20;103Ptr<detail::FeaturesFinder> featuresFinder = getFeatureFinder(detector);104105if(dataset == "budapest")106{107imgs.push_back(imread(getDataPath("stitching/budapest1.jpg")));108imgs.push_back(imread(getDataPath("stitching/budapest2.jpg")));109imgs.push_back(imread(getDataPath("stitching/budapest3.jpg")));110imgs.push_back(imread(getDataPath("stitching/budapest4.jpg")));111imgs.push_back(imread(getDataPath("stitching/budapest5.jpg")));112imgs.push_back(imread(getDataPath("stitching/budapest6.jpg")));113width = 2313;114height = 1158;115// this dataset is big, the results between surf and orb differ slightly,116// but both are still good117allowed_diff = 50;118}119else if (dataset == "newspaper")120{121imgs.push_back(imread(getDataPath("stitching/newspaper1.jpg")));122imgs.push_back(imread(getDataPath("stitching/newspaper2.jpg")));123imgs.push_back(imread(getDataPath("stitching/newspaper3.jpg")));124imgs.push_back(imread(getDataPath("stitching/newspaper4.jpg")));125width = 1791;126height = 1136;127// we need to boost ORB number of features to be able to stitch this dataset128// SURF works just fine with default settings129if(detector == "orb")130featuresFinder = makePtr<detail::OrbFeaturesFinder>(Size(3,1), 3000);131}132else if (dataset == "prague")133{134imgs.push_back(imread(getDataPath("stitching/prague1.jpg")));135imgs.push_back(imread(getDataPath("stitching/prague2.jpg")));136width = 983;137height = 1759;138}139else // dataset == "s"140{141imgs.push_back(imread(getDataPath("stitching/s1.jpg")));142imgs.push_back(imread(getDataPath("stitching/s2.jpg")));143width = 1815;144height = 700;145}146147declare.time(30 * 20).iterations(20);148149while(next())150{151Ptr<Stitcher> stitcher = Stitcher::create(Stitcher::SCANS, false);152stitcher->setFeaturesFinder(featuresFinder);153154if (cv::ocl::useOpenCL())155cv::theRNG() = cv::RNG(12345); // prevent fails of Windows OpenCL builds (see #8294)156157startTimer();158stitcher->stitch(imgs, pano);159stopTimer();160}161162EXPECT_NEAR(pano.size().width, width, allowed_diff);163EXPECT_NEAR(pano.size().height, height, allowed_diff);164165SANITY_CHECK_NOTHING();166}167168} // namespace169170171