Path: blob/master/modules/stitching/perf/opencl/perf_warpers.cpp
16348 views
/*M///////////////////////////////////////////////////////////////////////////////////////1//2// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.3//4// By downloading, copying, installing or using the software you agree to this license.5// If you do not agree to this license, do not download, install,6// copy or use the software.7//8//9// License Agreement10// For Open Source Computer Vision Library11//12// Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved.13// Third party copyrights are property of their respective owners.14//15// Redistribution and use in source and binary forms, with or without modification,16// are permitted provided that the following conditions are met:17//18// * Redistribution's of source code must retain the above copyright notice,19// this list of conditions and the following disclaimer.20//21// * Redistribution's in binary form must reproduce the above copyright notice,22// this list of conditions and the following disclaimer in the documentation23// and/or other materials provided with the distribution.24//25// * The name of the copyright holders may not be used to endorse or promote products26// derived from this software without specific prior written permission.27//28// This software is provided by the copyright holders and contributors "as is" and29// any express or implied warranties, including, but not limited to, the implied30// warranties of merchantability and fitness for a particular purpose are disclaimed.31// In no event shall the OpenCV Foundation or contributors be liable for any direct,32// indirect, incidental, special, exemplary, or consequential damages33// (including, but not limited to, procurement of substitute goods or services;34// loss of use, data, or profits; or business interruption) however caused35// and on any theory of liability, whether in contract, strict liability,36// or tort (including negligence or otherwise) arising in any way out of37// the use of this software, even if advised of the possibility of such damage.38//39//M*/4041#include "../perf_precomp.hpp"42#include "opencv2/stitching/warpers.hpp"43#include "opencv2/ts/ocl_perf.hpp"4445#ifdef HAVE_OPENCL4647namespace opencv_test {48namespace ocl {4950///////////////////////// Stitching Warpers ///////////////////////////5152enum53{54SphericalWarperType = 0,55CylindricalWarperType = 1,56PlaneWarperType = 2,57AffineWarperType = 3,58};5960class WarperBase61{62public:63explicit WarperBase(int type, Size srcSize)64{65Ptr<WarperCreator> creator;66if (type == SphericalWarperType)67creator = makePtr<SphericalWarper>();68else if (type == CylindricalWarperType)69creator = makePtr<CylindricalWarper>();70else if (type == PlaneWarperType)71creator = makePtr<PlaneWarper>();72else if (type == AffineWarperType)73creator = makePtr<AffineWarper>();74CV_Assert(!creator.empty());7576K = Mat::eye(3, 3, CV_32FC1);77K.at<float>(0,0) = (float)srcSize.width;78K.at<float>(0,2) = (float)srcSize.width/2;79K.at<float>(1,1) = (float)srcSize.height;80K.at<float>(1,2) = (float)srcSize.height/2;81K.at<float>(2,2) = 1.0f;82R = Mat::eye(3, 3, CV_32FC1);83float scale = (float)srcSize.width;8485warper = creator->create(scale);86}8788Rect buildMaps(Size src_size, OutputArray xmap, OutputArray ymap) const89{90return warper->buildMaps(src_size, K, R, xmap, ymap);91}9293Point warp(InputArray src, int interp_mode, int border_mode, OutputArray dst) const94{95return warper->warp(src, K, R, interp_mode, border_mode, dst);96}9798private:99Ptr<detail::RotationWarper> warper;100Mat K, R;101};102103CV_ENUM(WarperType, SphericalWarperType, CylindricalWarperType, PlaneWarperType, AffineWarperType)104105typedef tuple<Size, WarperType> StitchingWarpersParams;106typedef TestBaseWithParam<StitchingWarpersParams> StitchingWarpersFixture;107108static void prepareWarperSrc(InputOutputArray src, Size srcSize)109{110src.create(srcSize, CV_8UC1);111src.setTo(Scalar::all(64));112ellipse(src, Point(srcSize.width/2, srcSize.height/2), Size(srcSize.width/2, srcSize.height/2),113360, 0, 360, Scalar::all(255), 2);114ellipse(src, Point(srcSize.width/2, srcSize.height/2), Size(srcSize.width/3, srcSize.height/3),115360, 0, 360, Scalar::all(128), 2);116rectangle(src, Point(10, 10), Point(srcSize.width - 10, srcSize.height - 10), Scalar::all(128), 2);117}118119OCL_PERF_TEST_P(StitchingWarpersFixture, StitchingWarpers_BuildMaps,120::testing::Combine(OCL_TEST_SIZES, WarperType::all()))121{122const StitchingWarpersParams params = GetParam();123const Size srcSize = get<0>(params);124const WarperBase warper(get<1>(params), srcSize);125126UMat xmap, ymap;127128OCL_TEST_CYCLE() warper.buildMaps(srcSize, xmap, ymap);129130SANITY_CHECK(xmap, 1e-3);131SANITY_CHECK(ymap, 1e-3);132}133134OCL_PERF_TEST_P(StitchingWarpersFixture, StitchingWarpers_Warp,135::testing::Combine(OCL_TEST_SIZES, WarperType::all()))136{137const StitchingWarpersParams params = GetParam();138const Size srcSize = get<0>(params);139const WarperBase warper(get<1>(params), srcSize);140141UMat src, dst;142prepareWarperSrc(src, srcSize);143declare.in(src, WARMUP_READ);144145OCL_TEST_CYCLE() warper.warp(src, INTER_LINEAR, BORDER_REPLICATE, dst);146147#if 0148namedWindow("src", WINDOW_NORMAL);149namedWindow("dst", WINDOW_NORMAL);150imshow("src", src);151imshow("dst", dst);152std::cout << dst.size() << " " << dst.size().area() << std::endl;153cv::waitKey();154#endif155156SANITY_CHECK(dst, 1e-5);157}158159} } // namespace opencv_test::ocl160161#endif // HAVE_OPENCL162163164