Path: blob/master/modules/stitching/perf/opencl/perf_stitch.cpp
16348 views
// This file is part of OpenCV project.1// It is subject to the license terms in the LICENSE file found in the top-level directory2// of this distribution and at http://opencv.org/license.html.3//4// Copyright (C) 2014, Itseez, Inc, all rights reserved.56#include "../perf_precomp.hpp"7#include "opencv2/ts/ocl_perf.hpp"89#ifdef HAVE_OPENCL1011namespace opencv_test {12using namespace perf;13namespace ocl {1415#define SURF_MATCH_CONFIDENCE 0.65f16#define ORB_MATCH_CONFIDENCE 0.3f17#define WORK_MEGAPIX 0.61819typedef TestBaseWithParam<string> stitch;2021#ifdef HAVE_OPENCV_XFEATURES2D22#define TEST_DETECTORS testing::Values("surf", "orb", "akaze")23#else24#define TEST_DETECTORS testing::Values("orb", "akaze")25#endif2627OCL_PERF_TEST_P(stitch, a123, TEST_DETECTORS)28{29UMat pano;3031vector<Mat> _imgs;32_imgs.push_back( imread( getDataPath("stitching/a1.png") ) );33_imgs.push_back( imread( getDataPath("stitching/a2.png") ) );34_imgs.push_back( imread( getDataPath("stitching/a3.png") ) );35vector<UMat> imgs = ToUMat(_imgs);3637Ptr<detail::FeaturesFinder> featuresFinder = getFeatureFinder(GetParam());38Ptr<detail::FeaturesMatcher> featuresMatcher = GetParam() == "orb"39? makePtr<detail::BestOf2NearestMatcher>(false, ORB_MATCH_CONFIDENCE)40: makePtr<detail::BestOf2NearestMatcher>(false, SURF_MATCH_CONFIDENCE);4142declare.iterations(20);4344while(next())45{46Stitcher stitcher = Stitcher::createDefault();47stitcher.setFeaturesFinder(featuresFinder);48stitcher.setFeaturesMatcher(featuresMatcher);49stitcher.setWarper(makePtr<SphericalWarper>());50stitcher.setRegistrationResol(WORK_MEGAPIX);5152startTimer();53stitcher.stitch(imgs, pano);54stopTimer();55}5657EXPECT_NEAR(pano.size().width, 1182, 50);58EXPECT_NEAR(pano.size().height, 682, 30);5960SANITY_CHECK_NOTHING();61}6263OCL_PERF_TEST_P(stitch, b12, TEST_DETECTORS)64{65UMat pano;6667vector<Mat> imgs;68imgs.push_back( imread( getDataPath("stitching/b1.png") ) );69imgs.push_back( imread( getDataPath("stitching/b2.png") ) );7071Ptr<detail::FeaturesFinder> featuresFinder = getFeatureFinder(GetParam());72Ptr<detail::FeaturesMatcher> featuresMatcher = GetParam() == "orb"73? makePtr<detail::BestOf2NearestMatcher>(false, ORB_MATCH_CONFIDENCE)74: makePtr<detail::BestOf2NearestMatcher>(false, SURF_MATCH_CONFIDENCE);7576declare.iterations(20);7778while(next())79{80Stitcher stitcher = Stitcher::createDefault();81stitcher.setFeaturesFinder(featuresFinder);82stitcher.setFeaturesMatcher(featuresMatcher);83stitcher.setWarper(makePtr<SphericalWarper>());84stitcher.setRegistrationResol(WORK_MEGAPIX);8586startTimer();87stitcher.stitch(imgs, pano);88stopTimer();89}9091EXPECT_NEAR(pano.size().width, 1124, GetParam() == "surf" ? 100 : 50);92EXPECT_NEAR(pano.size().height, 644, GetParam() == "surf" ? 60 : 30);9394SANITY_CHECK_NOTHING();95}9697OCL_PERF_TEST_P(stitch, boat, TEST_DETECTORS)98{99Size expected_dst_size(10789, 2663);100checkDeviceMaxMemoryAllocSize(expected_dst_size, CV_16SC3, 4);101102#if defined(_WIN32) && !defined(_WIN64)103if (cv::ocl::useOpenCL())104throw ::perf::TestBase::PerfSkipTestException();105#endif106107UMat pano;108109vector<Mat> _imgs;110_imgs.push_back( imread( getDataPath("stitching/boat1.jpg") ) );111_imgs.push_back( imread( getDataPath("stitching/boat2.jpg") ) );112_imgs.push_back( imread( getDataPath("stitching/boat3.jpg") ) );113_imgs.push_back( imread( getDataPath("stitching/boat4.jpg") ) );114_imgs.push_back( imread( getDataPath("stitching/boat5.jpg") ) );115_imgs.push_back( imread( getDataPath("stitching/boat6.jpg") ) );116vector<UMat> imgs = ToUMat(_imgs);117118Ptr<detail::FeaturesFinder> featuresFinder = getFeatureFinder(GetParam());119Ptr<detail::FeaturesMatcher> featuresMatcher = GetParam() == "orb"120? makePtr<detail::BestOf2NearestMatcher>(false, ORB_MATCH_CONFIDENCE)121: makePtr<detail::BestOf2NearestMatcher>(false, SURF_MATCH_CONFIDENCE);122123declare.iterations(20);124125while(next())126{127Stitcher stitcher = Stitcher::createDefault();128stitcher.setFeaturesFinder(featuresFinder);129stitcher.setFeaturesMatcher(featuresMatcher);130stitcher.setWarper(makePtr<SphericalWarper>());131stitcher.setRegistrationResol(WORK_MEGAPIX);132133startTimer();134stitcher.stitch(imgs, pano);135stopTimer();136}137138EXPECT_NEAR(pano.size().width, expected_dst_size.width, 200);139EXPECT_NEAR(pano.size().height, expected_dst_size.height, 100);140141SANITY_CHECK_NOTHING();142}143144} } // namespace opencv_test::ocl145146#endif // HAVE_OPENCL147148149