Home | History | Annotate | Download | only in opencl
      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 
      7 #include "../perf_precomp.hpp"
      8 #include "opencv2/ts/ocl_perf.hpp"
      9 
     10 using namespace cv;
     11 using namespace perf;
     12 using namespace cvtest::ocl;
     13 using namespace std;
     14 using namespace std::tr1;
     15 
     16 #define SURF_MATCH_CONFIDENCE 0.65f
     17 #define ORB_MATCH_CONFIDENCE  0.3f
     18 #define WORK_MEGAPIX 0.6
     19 
     20 typedef TestBaseWithParam<string> stitch;
     21 
     22 #ifdef HAVE_OPENCV_NONFREE_TODO_FIND_WHY_SURF_IS_NOT_ABLE_TO_STITCH_PANOS
     23 #define TEST_DETECTORS testing::Values("surf", "orb")
     24 #else
     25 #define TEST_DETECTORS testing::Values<string>("orb")
     26 #endif
     27 
     28 OCL_PERF_TEST_P(stitch, a123, TEST_DETECTORS)
     29 {
     30     UMat pano;
     31 
     32     vector<Mat> _imgs;
     33     _imgs.push_back( imread( getDataPath("stitching/a1.png") ) );
     34     _imgs.push_back( imread( getDataPath("stitching/a2.png") ) );
     35     _imgs.push_back( imread( getDataPath("stitching/a3.png") ) );
     36     vector<UMat> imgs = ToUMat(_imgs);
     37 
     38     Ptr<detail::FeaturesFinder> featuresFinder = GetParam() == "orb"
     39             ? Ptr<detail::FeaturesFinder>(new detail::OrbFeaturesFinder())
     40             : Ptr<detail::FeaturesFinder>(new detail::SurfFeaturesFinder());
     41 
     42     Ptr<detail::FeaturesMatcher> featuresMatcher = GetParam() == "orb"
     43             ? makePtr<detail::BestOf2NearestMatcher>(false, ORB_MATCH_CONFIDENCE)
     44             : makePtr<detail::BestOf2NearestMatcher>(false, SURF_MATCH_CONFIDENCE);
     45 
     46     declare.iterations(20);
     47 
     48     while(next())
     49     {
     50         Stitcher stitcher = Stitcher::createDefault();
     51         stitcher.setFeaturesFinder(featuresFinder);
     52         stitcher.setFeaturesMatcher(featuresMatcher);
     53         stitcher.setWarper(makePtr<SphericalWarper>());
     54         stitcher.setRegistrationResol(WORK_MEGAPIX);
     55 
     56         startTimer();
     57         stitcher.stitch(imgs, pano);
     58         stopTimer();
     59     }
     60 
     61     EXPECT_NEAR(pano.size().width, 1182, 50);
     62     EXPECT_NEAR(pano.size().height, 682, 30);
     63 
     64     SANITY_CHECK_NOTHING();
     65 }
     66 
     67 OCL_PERF_TEST_P(stitch, b12, TEST_DETECTORS)
     68 {
     69     UMat pano;
     70 
     71     vector<Mat> imgs;
     72     imgs.push_back( imread( getDataPath("stitching/b1.png") ) );
     73     imgs.push_back( imread( getDataPath("stitching/b2.png") ) );
     74 
     75     Ptr<detail::FeaturesFinder> featuresFinder = GetParam() == "orb"
     76             ? Ptr<detail::FeaturesFinder>(new detail::OrbFeaturesFinder())
     77             : Ptr<detail::FeaturesFinder>(new detail::SurfFeaturesFinder());
     78 
     79     Ptr<detail::FeaturesMatcher> featuresMatcher = GetParam() == "orb"
     80             ? makePtr<detail::BestOf2NearestMatcher>(false, ORB_MATCH_CONFIDENCE)
     81             : makePtr<detail::BestOf2NearestMatcher>(false, SURF_MATCH_CONFIDENCE);
     82 
     83     declare.iterations(20);
     84 
     85     while(next())
     86     {
     87         Stitcher stitcher = Stitcher::createDefault();
     88         stitcher.setFeaturesFinder(featuresFinder);
     89         stitcher.setFeaturesMatcher(featuresMatcher);
     90         stitcher.setWarper(makePtr<SphericalWarper>());
     91         stitcher.setRegistrationResol(WORK_MEGAPIX);
     92 
     93         startTimer();
     94         stitcher.stitch(imgs, pano);
     95         stopTimer();
     96     }
     97 
     98     EXPECT_NEAR(pano.size().width, 1124, 50);
     99     EXPECT_NEAR(pano.size().height, 644, 30);
    100 
    101     SANITY_CHECK_NOTHING();
    102 }
    103 
    104 OCL_PERF_TEST_P(stitch, boat, TEST_DETECTORS)
    105 {
    106     UMat pano;
    107 
    108     vector<Mat> _imgs;
    109     _imgs.push_back( imread( getDataPath("stitching/boat1.jpg") ) );
    110     _imgs.push_back( imread( getDataPath("stitching/boat2.jpg") ) );
    111     _imgs.push_back( imread( getDataPath("stitching/boat3.jpg") ) );
    112     _imgs.push_back( imread( getDataPath("stitching/boat4.jpg") ) );
    113     _imgs.push_back( imread( getDataPath("stitching/boat5.jpg") ) );
    114     _imgs.push_back( imread( getDataPath("stitching/boat6.jpg") ) );
    115     vector<UMat> imgs = ToUMat(_imgs);
    116 
    117     Ptr<detail::FeaturesFinder> featuresFinder = GetParam() == "orb"
    118             ? Ptr<detail::FeaturesFinder>(new detail::OrbFeaturesFinder())
    119             : Ptr<detail::FeaturesFinder>(new detail::SurfFeaturesFinder());
    120 
    121     Ptr<detail::FeaturesMatcher> featuresMatcher = GetParam() == "orb"
    122             ? makePtr<detail::BestOf2NearestMatcher>(false, ORB_MATCH_CONFIDENCE)
    123             : makePtr<detail::BestOf2NearestMatcher>(false, SURF_MATCH_CONFIDENCE);
    124 
    125     declare.iterations(20);
    126 
    127     while(next())
    128     {
    129         Stitcher stitcher = Stitcher::createDefault();
    130         stitcher.setFeaturesFinder(featuresFinder);
    131         stitcher.setFeaturesMatcher(featuresMatcher);
    132         stitcher.setWarper(makePtr<SphericalWarper>());
    133         stitcher.setRegistrationResol(WORK_MEGAPIX);
    134 
    135         startTimer();
    136         stitcher.stitch(imgs, pano);
    137         stopTimer();
    138     }
    139 
    140     EXPECT_NEAR(pano.size().width, 10789, 200);
    141     EXPECT_NEAR(pano.size().height, 2663, 100);
    142 
    143     SANITY_CHECK_NOTHING();
    144 }
    145