Path: blob/master/modules/imgproc/perf/opencl/perf_imgproc.cpp
16344 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"4849namespace opencv_test {50namespace ocl {5152///////////// equalizeHist ////////////////////////5354typedef TestBaseWithParam<Size> EqualizeHistFixture;5556OCL_PERF_TEST_P(EqualizeHistFixture, EqualizeHist, OCL_TEST_SIZES)57{58const Size srcSize = GetParam();59const double eps = 1;6061checkDeviceMaxMemoryAllocSize(srcSize, CV_8UC1);6263UMat src(srcSize, CV_8UC1), dst(srcSize, CV_8UC1);64declare.in(src, WARMUP_RNG).out(dst);6566OCL_TEST_CYCLE() cv::equalizeHist(src, dst);6768SANITY_CHECK(dst, eps);69}7071///////////// calcHist ////////////////////////7273typedef TestBaseWithParam<Size> CalcHistFixture;7475OCL_PERF_TEST_P(CalcHistFixture, CalcHist, OCL_TEST_SIZES)76{77const Size srcSize = GetParam();7879const std::vector<int> channels(1, 0);80std::vector<float> ranges(2);81std::vector<int> histSize(1, 256);82ranges[0] = 0;83ranges[1] = 256;8485checkDeviceMaxMemoryAllocSize(srcSize, CV_8UC1);8687UMat src(srcSize, CV_8UC1), hist(256, 1, CV_32FC1);88declare.in(src, WARMUP_RNG).out(hist);8990OCL_TEST_CYCLE() cv::calcHist(std::vector<UMat>(1, src), channels, noArray(), hist, histSize, ranges, false);9192SANITY_CHECK(hist);93}9495///////////// calcHist ////////////////////////9697typedef TestBaseWithParam<Size> CalcBackProjFixture;9899OCL_PERF_TEST_P(CalcBackProjFixture, CalcBackProj, OCL_TEST_SIZES)100{101const Size srcSize = GetParam();102103const std::vector<int> channels(1, 0);104std::vector<float> ranges(2);105std::vector<int> histSize(1, 256);106ranges[0] = 0;107ranges[1] = 256;108109checkDeviceMaxMemoryAllocSize(srcSize, CV_8UC1);110111UMat src(srcSize, CV_8UC1), hist(256, 1, CV_32FC1), dst(srcSize, CV_8UC1);112declare.in(src, WARMUP_RNG).out(hist);113114cv::calcHist(std::vector<UMat>(1, src), channels, noArray(), hist, histSize, ranges, false);115116declare.in(src, WARMUP_RNG).out(dst);117OCL_TEST_CYCLE() cv::calcBackProject(std::vector<UMat>(1,src), channels, hist, dst, ranges, 1);118119SANITY_CHECK_NOTHING();120}121122123/////////// CopyMakeBorder //////////////////////124125CV_ENUM(Border, BORDER_CONSTANT, BORDER_REPLICATE, BORDER_REFLECT, BORDER_WRAP, BORDER_REFLECT_101)126127typedef tuple<Size, MatType, Border> CopyMakeBorderParamType;128typedef TestBaseWithParam<CopyMakeBorderParamType> CopyMakeBorderFixture;129130OCL_PERF_TEST_P(CopyMakeBorderFixture, CopyMakeBorder,131::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134, Border::all()))132{133const CopyMakeBorderParamType params = GetParam();134const Size srcSize = get<0>(params);135const int type = get<1>(params), borderType = get<2>(params);136137checkDeviceMaxMemoryAllocSize(srcSize, type);138139UMat src(srcSize, type), dst;140const Size dstSize = srcSize + Size(12, 12);141dst.create(dstSize, type);142declare.in(src, WARMUP_RNG).out(dst);143144OCL_TEST_CYCLE() cv::copyMakeBorder(src, dst, 7, 5, 5, 7, borderType, cv::Scalar(1.0));145146SANITY_CHECK(dst);147}148149///////////// CornerMinEigenVal ////////////////////////150151typedef Size_MatType CornerMinEigenValFixture;152153OCL_PERF_TEST_P(CornerMinEigenValFixture, CornerMinEigenVal,154::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_8UC1, CV_32FC1)))155{156const Size_MatType_t params = GetParam();157const Size srcSize = get<0>(params);158const int type = get<1>(params), borderType = BORDER_REFLECT;159const int blockSize = 7, apertureSize = 1 + 2 * 3;160161checkDeviceMaxMemoryAllocSize(srcSize, type);162163UMat src(srcSize, type), dst(srcSize, CV_32FC1);164declare.in(src, WARMUP_RNG).out(dst);165166OCL_TEST_CYCLE() cv::cornerMinEigenVal(src, dst, blockSize, apertureSize, borderType);167168SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);169}170171///////////// CornerHarris ////////////////////////172173typedef Size_MatType CornerHarrisFixture;174175OCL_PERF_TEST_P(CornerHarrisFixture, CornerHarris,176::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_8UC1, CV_32FC1)))177{178const Size_MatType_t params = GetParam();179const Size srcSize = get<0>(params);180const int type = get<1>(params), borderType = BORDER_REFLECT;181182checkDeviceMaxMemoryAllocSize(srcSize, type);183184UMat src(srcSize, type), dst(srcSize, CV_32FC1);185declare.in(src, WARMUP_RNG).out(dst);186187OCL_TEST_CYCLE() cv::cornerHarris(src, dst, 5, 7, 0.1, borderType);188189SANITY_CHECK(dst, 5e-6, ERROR_RELATIVE);190}191192///////////// PreCornerDetect ////////////////////////193194typedef Size_MatType PreCornerDetectFixture;195196OCL_PERF_TEST_P(PreCornerDetectFixture, PreCornerDetect,197::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_8UC1, CV_32FC1)))198{199const Size_MatType_t params = GetParam();200const Size srcSize = get<0>(params);201const int type = get<1>(params), borderType = BORDER_REFLECT;202203checkDeviceMaxMemoryAllocSize(srcSize, type);204205UMat src(srcSize, type), dst(srcSize, CV_32FC1);206declare.in(src, WARMUP_RNG).out(dst);207208OCL_TEST_CYCLE() cv::preCornerDetect(src, dst, 3, borderType);209210SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);211}212213///////////// Integral ////////////////////////214215typedef tuple<Size, MatDepth> IntegralParams;216typedef TestBaseWithParam<IntegralParams> IntegralFixture;217218OCL_PERF_TEST_P(IntegralFixture, Integral1, ::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32S, CV_32F)))219{220const IntegralParams params = GetParam();221const Size srcSize = get<0>(params);222const int ddepth = get<1>(params);223224checkDeviceMaxMemoryAllocSize(srcSize, ddepth);225226UMat src(srcSize, CV_8UC1), dst(srcSize + Size(1, 1), ddepth);227declare.in(src, WARMUP_RNG).out(dst);228229OCL_TEST_CYCLE() cv::integral(src, dst, ddepth);230231SANITY_CHECK(dst, 2e-6, ERROR_RELATIVE);232}233234OCL_PERF_TEST_P(IntegralFixture, Integral2, ::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32S, CV_32F)))235{236const IntegralParams params = GetParam();237const Size srcSize = get<0>(params);238const int ddepth = get<1>(params);239240checkDeviceMaxMemoryAllocSize(srcSize, ddepth);241242UMat src(srcSize, CV_8UC1), sum(srcSize + Size(1, 1), ddepth), sqsum(srcSize + Size(1, 1), CV_32F);243declare.in(src, WARMUP_RNG).out(sum, sqsum);244245OCL_TEST_CYCLE() cv::integral(src, sum, sqsum, ddepth, CV_32F);246247SANITY_CHECK(sum, 2e-4, ERROR_RELATIVE);248SANITY_CHECK(sqsum, 5e-5, ERROR_RELATIVE);249}250251///////////// Threshold ////////////////////////252253CV_ENUM(ThreshType, THRESH_BINARY, THRESH_BINARY_INV, THRESH_TRUNC, THRESH_TOZERO_INV)254255typedef tuple<Size, MatType, ThreshType> ThreshParams;256typedef TestBaseWithParam<ThreshParams> ThreshFixture;257258OCL_PERF_TEST_P(ThreshFixture, Threshold,259::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES, ThreshType::all()))260{261const ThreshParams params = GetParam();262const Size srcSize = get<0>(params);263const int srcType = get<1>(params);264const int threshType = get<2>(params);265const double maxValue = 220.0, threshold = 50;266267checkDeviceMaxMemoryAllocSize(srcSize, srcType);268269UMat src(srcSize, srcType), dst(srcSize, srcType);270declare.in(src, WARMUP_RNG).out(dst);271272OCL_TEST_CYCLE() cv::threshold(src, dst, threshold, maxValue, threshType);273274SANITY_CHECK(dst);275}276277///////////// CLAHE ////////////////////////278279typedef TestBaseWithParam<Size> CLAHEFixture;280281OCL_PERF_TEST_P(CLAHEFixture, CLAHE, OCL_TEST_SIZES)282{283const Size srcSize = GetParam();284285checkDeviceMaxMemoryAllocSize(srcSize, CV_8UC1);286287UMat src(srcSize, CV_8UC1), dst(srcSize, CV_8UC1);288const double clipLimit = 40.0;289declare.in(src, WARMUP_RNG).out(dst);290291cv::Ptr<cv::CLAHE> clahe = cv::createCLAHE(clipLimit);292OCL_TEST_CYCLE() clahe->apply(src, dst);293294SANITY_CHECK(dst);295}296297///////////// Canny ////////////////////////298299typedef tuple<Size, int, bool> CannyParams;300typedef TestBaseWithParam<CannyParams> CannyFixture;301302OCL_PERF_TEST_P(CannyFixture, Canny, ::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(3, 5), Bool()))303{304const CannyParams& params = GetParam();305cv::Size imgSize = get<0>(params);306int apertureSize = get<1>(params);307bool L2Grad = get<2>(params);308309Mat _img = imread(getDataPath("gpu/stereobm/aloe-L.png"), cv::IMREAD_GRAYSCALE);310ASSERT_TRUE(!_img.empty()) << "can't open aloe-L.png";311312UMat img;313cv::resize(_img, img, imgSize, 0, 0, INTER_LINEAR_EXACT);314UMat edges(img.size(), CV_8UC1);315316declare.in(img).out(edges);317318PERF_SAMPLE_BEGIN();319cv::Canny(img, edges, 50.0, 100.0, apertureSize, L2Grad);320PERF_SAMPLE_END();321322SANITY_CHECK_NOTHING();323}324325} } // namespace opencv_test::ocl326327328