Path: blob/master/modules/imgproc/perf/opencl/perf_imgwarp.cpp
16350 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-2012, Multicoreware, Inc., all rights reserved.13// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.14// Third party copyrights are property of their respective owners.15//16// @Authors17// Fangfang Bai, [email protected]18// Jin Ma, [email protected]19//20// Redistribution and use in source and binary forms, with or without modification,21// are permitted provided that the following conditions are met:22//23// * Redistribution's of source code must retain the above copyright notice,24// this list of conditions and the following disclaimer.25//26// * Redistribution's in binary form must reproduce the above copyright notice,27// this list of conditions and the following disclaimer in the documentation28// and/or other materials provided with the distribution.29//30// * The name of the copyright holders may not be used to endorse or promote products31// derived from this software without specific prior written permission.32//33// This software is provided by the copyright holders and contributors as is and34// any express or implied warranties, including, but not limited to, the implied35// warranties of merchantability and fitness for a particular purpose are disclaimed.36// In no event shall the Intel Corporation or contributors be liable for any direct,37// indirect, incidental, special, exemplary, or consequential damages38// (including, but not limited to, procurement of substitute goods or services;39// loss of use, data, or profits; or business interruption) however caused40// and on any theory of liability, whether in contract, strict liability,41// or tort (including negligence or otherwise) arising in any way out of42// the use of this software, even if advised of the possibility of such damage.43//44//M*/4546#include "../perf_precomp.hpp"47#include "opencv2/ts/ocl_perf.hpp"4849#ifdef HAVE_OPENCL5051namespace opencv_test {52namespace ocl {5354///////////// WarpAffine ////////////////////////5556CV_ENUM(InterType, INTER_NEAREST, INTER_LINEAR, INTER_CUBIC)5758typedef tuple<Size, MatType, InterType> WarpAffineParams;59typedef TestBaseWithParam<WarpAffineParams> WarpAffineFixture;6061OCL_PERF_TEST_P(WarpAffineFixture, WarpAffine,62::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134, InterType::all()))63{64static const double coeffs[2][3] =65{66{ cos(CV_PI / 6), -sin(CV_PI / 6), 100.0 },67{ sin(CV_PI / 6), cos(CV_PI / 6) , -100.0 }68};69Mat M(2, 3, CV_64F, (void *)coeffs);7071const WarpAffineParams params = GetParam();72const Size srcSize = get<0>(params);73const int type = get<1>(params), interpolation = get<2>(params);74const double eps = CV_MAT_DEPTH(type) <= CV_32S ? 1 : interpolation == INTER_CUBIC ? 2e-3 : 1e-4;7576checkDeviceMaxMemoryAllocSize(srcSize, type);7778UMat src(srcSize, type), dst(srcSize, type);79declare.in(src, WARMUP_RNG).out(dst);8081OCL_TEST_CYCLE() cv::warpAffine(src, dst, M, srcSize, interpolation);8283SANITY_CHECK(dst, eps);84}8586///////////// WarpPerspective ////////////////////////8788typedef WarpAffineParams WarpPerspectiveParams;89typedef TestBaseWithParam<WarpPerspectiveParams> WarpPerspectiveFixture;9091OCL_PERF_TEST_P(WarpPerspectiveFixture, WarpPerspective,92::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134,93OCL_PERF_ENUM(InterType(INTER_NEAREST), InterType(INTER_LINEAR))))94{95static const double coeffs[3][3] =96{97{cos(CV_PI / 6), -sin(CV_PI / 6), 100.0},98{sin(CV_PI / 6), cos(CV_PI / 6), -100.0},99{0.0, 0.0, 1.0}100};101Mat M(3, 3, CV_64F, (void *)coeffs);102103const WarpPerspectiveParams params = GetParam();104const Size srcSize = get<0>(params);105const int type = get<1>(params), interpolation = get<2>(params);106const double eps = CV_MAT_DEPTH(type) <= CV_32S ? 1 : 1e-4;107108checkDeviceMaxMemoryAllocSize(srcSize, type);109110UMat src(srcSize, type), dst(srcSize, type);111declare.in(src, WARMUP_RNG).out(dst);112113OCL_TEST_CYCLE() cv::warpPerspective(src, dst, M, srcSize, interpolation);114115SANITY_CHECK(dst, eps);116}117118///////////// Resize ////////////////////////119120typedef tuple<Size, MatType, InterType, double> ResizeParams;121typedef TestBaseWithParam<ResizeParams> ResizeFixture;122123OCL_PERF_TEST_P(ResizeFixture, Resize,124::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134,125OCL_PERF_ENUM(InterType(INTER_NEAREST), InterType(INTER_LINEAR)),126::testing::Values(0.5, 2.0)))127{128const ResizeParams params = GetParam();129const Size srcSize = get<0>(params);130const int type = get<1>(params), interType = get<2>(params);131double scale = get<3>(params);132const Size dstSize(cvRound(srcSize.width * scale), cvRound(srcSize.height * scale));133const double eps = CV_MAT_DEPTH(type) <= CV_32S ? 1 : 1e-4;134135checkDeviceMaxMemoryAllocSize(srcSize, type);136checkDeviceMaxMemoryAllocSize(dstSize, type);137138UMat src(srcSize, type), dst(dstSize, type);139declare.in(src, WARMUP_RNG).out(dst);140141OCL_TEST_CYCLE() cv::resize(src, dst, Size(), scale, scale, interType);142143SANITY_CHECK(dst, eps);144}145146typedef tuple<Size, MatType, double> ResizeAreaParams;147typedef TestBaseWithParam<ResizeAreaParams> ResizeAreaFixture;148149OCL_PERF_TEST_P(ResizeAreaFixture, Resize,150::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134, ::testing::Values(0.3, 0.5, 0.6)))151{152const ResizeAreaParams params = GetParam();153const Size srcSize = get<0>(params);154const int type = get<1>(params);155double scale = get<2>(params);156const Size dstSize(cvRound(srcSize.width * scale), cvRound(srcSize.height * scale));157const double eps = CV_MAT_DEPTH(type) <= CV_32S ? 1 : 1e-4;158159checkDeviceMaxMemoryAllocSize(srcSize, type);160checkDeviceMaxMemoryAllocSize(dstSize, type);161162UMat src(srcSize, type), dst(dstSize, type);163declare.in(src, WARMUP_RNG).out(dst);164165OCL_TEST_CYCLE() cv::resize(src, dst, Size(), scale, scale, cv::INTER_AREA);166167SANITY_CHECK(dst, eps);168}169170typedef ResizeAreaParams ResizeLinearExactParams;171typedef TestBaseWithParam<ResizeLinearExactParams> ResizeLinearExactFixture;172173OCL_PERF_TEST_P(ResizeLinearExactFixture, Resize,174::testing::Combine(OCL_TEST_SIZES, ::testing::Values(CV_8UC1, CV_8UC3, CV_8UC4), ::testing::Values(0.5, 2.0)))175{176const ResizeAreaParams params = GetParam();177const Size srcSize = get<0>(params);178const int type = get<1>(params);179double scale = get<2>(params);180const Size dstSize(cvRound(srcSize.width * scale), cvRound(srcSize.height * scale));181const double eps = 1e-4;182183checkDeviceMaxMemoryAllocSize(srcSize, type);184checkDeviceMaxMemoryAllocSize(dstSize, type);185186UMat src(srcSize, type), dst(dstSize, type);187declare.in(src, WARMUP_RNG).out(dst);188189OCL_TEST_CYCLE() cv::resize(src, dst, Size(), scale, scale, cv::INTER_LINEAR_EXACT);190191SANITY_CHECK(dst, eps);192}193194///////////// Remap ////////////////////////195196typedef tuple<Size, MatType, InterType> RemapParams;197typedef TestBaseWithParam<RemapParams> RemapFixture;198199OCL_PERF_TEST_P(RemapFixture, Remap,200::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134,201OCL_PERF_ENUM(InterType(INTER_NEAREST), InterType(INTER_LINEAR))))202{203const RemapParams params = GetParam();204const Size srcSize = get<0>(params);205const int type = get<1>(params), interpolation = get<2>(params), borderMode = BORDER_CONSTANT;206//const double eps = CV_MAT_DEPTH(type) <= CV_32S ? 1 : 1e-4;207208checkDeviceMaxMemoryAllocSize(srcSize, type);209210UMat src(srcSize, type), dst(srcSize, type);211UMat xmap(srcSize, CV_32FC1), ymap(srcSize, CV_32FC1);212213{214Mat _xmap = xmap.getMat(ACCESS_WRITE), _ymap = ymap.getMat(ACCESS_WRITE);215for (int i = 0; i < srcSize.height; ++i)216{217float * const xmap_row = _xmap.ptr<float>(i);218float * const ymap_row = _ymap.ptr<float>(i);219220for (int j = 0; j < srcSize.width; ++j)221{222xmap_row[j] = (j - srcSize.width * 0.5f) * 0.75f + srcSize.width * 0.5f;223ymap_row[j] = (i - srcSize.height * 0.5f) * 0.75f + srcSize.height * 0.5f;224}225}226}227declare.in(src, WARMUP_RNG).in(xmap, ymap, WARMUP_READ).out(dst);228229OCL_TEST_CYCLE() cv::remap(src, dst, xmap, ymap, interpolation, borderMode);230231SANITY_CHECK_NOTHING();232}233234} } // namespace opencv_test::ocl235236#endif // HAVE_OPENCL237238239