From 8b6c5ade0e527db9935fb7485f12be5c2295abf9 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Thu, 13 Feb 2014 18:10:37 +0400 Subject: [PATCH] TAPI: added perf test for stitching --- modules/stitching/perf/opencl/perf_stitch.cpp | 144 ++++++++++++++++++++++++++ modules/ts/include/opencv2/ts/ocl_test.hpp | 25 +++++ 2 files changed, 169 insertions(+) create mode 100644 modules/stitching/perf/opencl/perf_stitch.cpp diff --git a/modules/stitching/perf/opencl/perf_stitch.cpp b/modules/stitching/perf/opencl/perf_stitch.cpp new file mode 100644 index 0000000..3434726 --- /dev/null +++ b/modules/stitching/perf/opencl/perf_stitch.cpp @@ -0,0 +1,144 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2014, Itseez, Inc, all rights reserved. + +#include "perf_precomp.hpp" +#include "opencv2/ts/ocl_perf.hpp" + +using namespace cv; +using namespace perf; +using namespace cvtest::ocl; +using namespace std; +using namespace std::tr1; + +#define SURF_MATCH_CONFIDENCE 0.65f +#define ORB_MATCH_CONFIDENCE 0.3f +#define WORK_MEGAPIX 0.6 + +typedef TestBaseWithParam stitch; + +#ifdef HAVE_OPENCV_NONFREE_TODO_FIND_WHY_SURF_IS_NOT_ABLE_TO_STITCH_PANOS +#define TEST_DETECTORS testing::Values("surf", "orb") +#else +#define TEST_DETECTORS testing::Values("orb") +#endif + +OCL_PERF_TEST_P(stitch, a123, TEST_DETECTORS) +{ + UMat pano; + + vector _imgs; + _imgs.push_back( imread( getDataPath("stitching/a1.png") ) ); + _imgs.push_back( imread( getDataPath("stitching/a2.png") ) ); + _imgs.push_back( imread( getDataPath("stitching/a3.png") ) ); + vector imgs = ToUMat(_imgs); + + Ptr featuresFinder = GetParam() == "orb" + ? Ptr(new detail::OrbFeaturesFinder()) + : Ptr(new detail::SurfFeaturesFinder()); + + Ptr featuresMatcher = GetParam() == "orb" + ? makePtr(false, ORB_MATCH_CONFIDENCE) + : makePtr(false, SURF_MATCH_CONFIDENCE); + + declare.iterations(20); + + while(next()) + { + Stitcher stitcher = Stitcher::createDefault(); + stitcher.setFeaturesFinder(featuresFinder); + stitcher.setFeaturesMatcher(featuresMatcher); + stitcher.setWarper(makePtr()); + stitcher.setRegistrationResol(WORK_MEGAPIX); + + startTimer(); + stitcher.stitch(imgs, pano); + stopTimer(); + } + + EXPECT_NEAR(pano.size().width, 1182, 50); + EXPECT_NEAR(pano.size().height, 682, 30); + + SANITY_CHECK_NOTHING(); +} + +OCL_PERF_TEST_P(stitch, b12, TEST_DETECTORS) +{ + UMat pano; + + vector imgs; + imgs.push_back( imread( getDataPath("stitching/b1.png") ) ); + imgs.push_back( imread( getDataPath("stitching/b2.png") ) ); + + Ptr featuresFinder = GetParam() == "orb" + ? Ptr(new detail::OrbFeaturesFinder()) + : Ptr(new detail::SurfFeaturesFinder()); + + Ptr featuresMatcher = GetParam() == "orb" + ? makePtr(false, ORB_MATCH_CONFIDENCE) + : makePtr(false, SURF_MATCH_CONFIDENCE); + + declare.iterations(20); + + while(next()) + { + Stitcher stitcher = Stitcher::createDefault(); + stitcher.setFeaturesFinder(featuresFinder); + stitcher.setFeaturesMatcher(featuresMatcher); + stitcher.setWarper(makePtr()); + stitcher.setRegistrationResol(WORK_MEGAPIX); + + startTimer(); + stitcher.stitch(imgs, pano); + stopTimer(); + } + + EXPECT_NEAR(pano.size().width, 1124, 50); + EXPECT_NEAR(pano.size().height, 644, 30); + + SANITY_CHECK_NOTHING(); +} + +OCL_PERF_TEST_P(stitch, boat, TEST_DETECTORS) +{ + UMat pano; + + vector _imgs; + _imgs.push_back( imread( getDataPath("stitching/boat1.jpg") ) ); + _imgs.push_back( imread( getDataPath("stitching/boat2.jpg") ) ); + _imgs.push_back( imread( getDataPath("stitching/boat3.jpg") ) ); + _imgs.push_back( imread( getDataPath("stitching/boat4.jpg") ) ); + _imgs.push_back( imread( getDataPath("stitching/boat5.jpg") ) ); + _imgs.push_back( imread( getDataPath("stitching/boat6.jpg") ) ); + vector imgs = ToUMat(_imgs); + + Ptr featuresFinder = GetParam() == "orb" + ? Ptr(new detail::OrbFeaturesFinder()) + : Ptr(new detail::SurfFeaturesFinder()); + + Ptr featuresMatcher = GetParam() == "orb" + ? makePtr(false, ORB_MATCH_CONFIDENCE) + : makePtr(false, SURF_MATCH_CONFIDENCE); + + declare.iterations(20); + + while(next()) + { + Stitcher stitcher = Stitcher::createDefault(); + stitcher.setFeaturesFinder(featuresFinder); + stitcher.setFeaturesMatcher(featuresMatcher); + stitcher.setWarper(makePtr()); + stitcher.setRegistrationResol(WORK_MEGAPIX); + + startTimer(); + stitcher.stitch(imgs, pano); + stopTimer(); + } + + EXPECT_NEAR(pano.size().width, 10789, 200); + EXPECT_NEAR(pano.size().height, 2663, 100); + + SANITY_CHECK_NOTHING(); +} diff --git a/modules/ts/include/opencv2/ts/ocl_test.hpp b/modules/ts/include/opencv2/ts/ocl_test.hpp index 5dd25db..43c01b2 100644 --- a/modules/ts/include/opencv2/ts/ocl_test.hpp +++ b/modules/ts/include/opencv2/ts/ocl_test.hpp @@ -57,6 +57,31 @@ namespace ocl { using namespace cv; using namespace testing; +inline std::vector ToUMat(const std::vector& src) +{ + std::vector dst; + dst.resize(src.size()); + for (size_t i = 0; i < src.size(); ++i) + { + src[i].copyTo(dst[i]); + } + return dst; +} + +inline UMat ToUMat(const Mat& src) +{ + UMat dst; + src.copyTo(dst); + return dst; +} + +inline UMat ToUMat(InputArray src) +{ + UMat dst; + src.getMat().copyTo(dst); + return dst; +} + extern int test_loop_times; #define MAX_VALUE 357 -- 2.7.4