1/*M/////////////////////////////////////////////////////////////////////////////////////// 2// 3// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 4// 5// By downloading, copying, installing or using the software you agree to this license. 6// If you do not agree to this license, do not download, install, 7// copy or use the software. 8// 9// 10// License Agreement 11// For Open Source Computer Vision Library 12// 13// Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved. 14// Third party copyrights are property of their respective owners. 15// 16// Redistribution and use in source and binary forms, with or without modification, 17// are permitted provided that the following conditions are met: 18// 19// * Redistribution's of source code must retain the above copyright notice, 20// this list of conditions and the following disclaimer. 21// 22// * Redistribution's in binary form must reproduce the above copyright notice, 23// this list of conditions and the following disclaimer in the documentation 24// and/or other materials provided with the distribution. 25// 26// * The name of the copyright holders may not be used to endorse or promote products 27// derived from this software without specific prior written permission. 28// 29// This software is provided by the copyright holders and contributors "as is" and 30// any express or implied warranties, including, but not limited to, the implied 31// warranties of merchantability and fitness for a particular purpose are disclaimed. 32// In no event shall the OpenCV Foundation or contributors be liable for any direct, 33// indirect, incidental, special, exemplary, or consequential damages 34// (including, but not limited to, procurement of substitute goods or services; 35// loss of use, data, or profits; or business interruption) however caused 36// and on any theory of liability, whether in contract, strict liability, 37// or tort (including negligence or otherwise) arising in any way out of 38// the use of this software, even if advised of the possibility of such damage. 39// 40//M*/ 41 42#include "../perf_precomp.hpp" 43#include "opencv2/stitching/warpers.hpp" 44#include "opencv2/ts/ocl_perf.hpp" 45 46#ifdef HAVE_OPENCL 47 48namespace cvtest { 49namespace ocl { 50 51///////////////////////// Stitching Warpers /////////////////////////// 52 53enum 54{ 55 SphericalWarperType = 0, 56 CylindricalWarperType = 1, 57 PlaneWarperType = 2 58}; 59 60class WarperBase 61{ 62public: 63 explicit WarperBase(int type, Size srcSize) 64 { 65 Ptr<WarperCreator> creator; 66 if (type == SphericalWarperType) 67 creator = makePtr<SphericalWarper>(); 68 else if (type == CylindricalWarperType) 69 creator = makePtr<CylindricalWarper>(); 70 else if (type == PlaneWarperType) 71 creator = makePtr<PlaneWarper>(); 72 CV_Assert(!creator.empty()); 73 74 K = Mat::eye(3, 3, CV_32FC1); 75 K.at<float>(0,0) = (float)srcSize.width; 76 K.at<float>(0,2) = (float)srcSize.width/2; 77 K.at<float>(1,1) = (float)srcSize.height; 78 K.at<float>(1,2) = (float)srcSize.height/2; 79 K.at<float>(2,2) = 1.0f; 80 R = Mat::eye(3, 3, CV_32FC1); 81 float scale = (float)srcSize.width; 82 83 warper = creator->create(scale); 84 } 85 86 Rect buildMaps(Size src_size, OutputArray xmap, OutputArray ymap) const 87 { 88 return warper->buildMaps(src_size, K, R, xmap, ymap); 89 } 90 91 Point warp(InputArray src, int interp_mode, int border_mode, OutputArray dst) const 92 { 93 return warper->warp(src, K, R, interp_mode, border_mode, dst); 94 } 95 96private: 97 Ptr<detail::RotationWarper> warper; 98 Mat K, R; 99}; 100 101CV_ENUM(WarperType, SphericalWarperType, CylindricalWarperType, PlaneWarperType) 102 103typedef tuple<Size, WarperType> StitchingWarpersParams; 104typedef TestBaseWithParam<StitchingWarpersParams> StitchingWarpersFixture; 105 106static void prepareWarperSrc(InputOutputArray src, Size srcSize) 107{ 108 src.create(srcSize, CV_8UC1); 109 src.setTo(Scalar::all(64)); 110 ellipse(src, Point(srcSize.width/2, srcSize.height/2), Size(srcSize.width/2, srcSize.height/2), 111 360, 0, 360, Scalar::all(255), 2); 112 ellipse(src, Point(srcSize.width/2, srcSize.height/2), Size(srcSize.width/3, srcSize.height/3), 113 360, 0, 360, Scalar::all(128), 2); 114 rectangle(src, Point(10, 10), Point(srcSize.width - 10, srcSize.height - 10), Scalar::all(128), 2); 115} 116 117OCL_PERF_TEST_P(StitchingWarpersFixture, StitchingWarpers_BuildMaps, 118 ::testing::Combine(OCL_TEST_SIZES, WarperType::all())) 119{ 120 const StitchingWarpersParams params = GetParam(); 121 const Size srcSize = get<0>(params); 122 const WarperBase warper(get<1>(params), srcSize); 123 124 UMat xmap, ymap; 125 126 OCL_TEST_CYCLE() warper.buildMaps(srcSize, xmap, ymap); 127 128 SANITY_CHECK(xmap, 1e-3); 129 SANITY_CHECK(ymap, 1e-3); 130} 131 132OCL_PERF_TEST_P(StitchingWarpersFixture, StitchingWarpers_Warp, 133 ::testing::Combine(OCL_TEST_SIZES, WarperType::all())) 134{ 135 const StitchingWarpersParams params = GetParam(); 136 const Size srcSize = get<0>(params); 137 const WarperBase warper(get<1>(params), srcSize); 138 139 UMat src, dst; 140 prepareWarperSrc(src, srcSize); 141 declare.in(src, WARMUP_READ); 142 143 OCL_TEST_CYCLE() warper.warp(src, INTER_LINEAR, BORDER_REPLICATE, dst); 144 145#if 0 146 namedWindow("src", WINDOW_NORMAL); 147 namedWindow("dst", WINDOW_NORMAL); 148 imshow("src", src); 149 imshow("dst", dst); 150 std::cout << dst.size() << " " << dst.size().area() << std::endl; 151 cv::waitKey(); 152#endif 153 154 SANITY_CHECK(dst, 1e-5); 155} 156 157} } // namespace cvtest::ocl 158 159#endif // HAVE_OPENCL 160