Path: blob/master/modules/imgproc/test/ocl/test_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, Institute Of Software Chinese Academy Of Science, all rights reserved.13// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.14// Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.15// Third party copyrights are property of their respective owners.16//17// @Authors18// Niko Li, [email protected]19// Jia Haipeng, [email protected]20// Shengen Yan, [email protected]21// Jiang Liyuan, [email protected]22// Rock Li, [email protected]23// Wu Zailong, [email protected]24// Xu Pang, [email protected]25// Sen Liu, [email protected]26//27// Redistribution and use in source and binary forms, with or without modification,28// are permitted provided that the following conditions are met:29//30// * Redistribution's of source code must retain the above copyright notice,31// this list of conditions and the following disclaimer.32//33// * Redistribution's in binary form must reproduce the above copyright notice,34// this list of conditions and the following disclaimer in the documentation35// and/or other materials provided with the distribution.36//37// * The name of the copyright holders may not be used to endorse or promote products38// derived from this software without specific prior written permission.39//40// This software is provided by the copyright holders and contributors "as is" and41// any express or implied warranties, including, but not limited to, the implied42// warranties of merchantability and fitness for a particular purpose are disclaimed.43// In no event shall the Intel Corporation or contributors be liable for any direct,44// indirect, incidental, special, exemplary, or consequential damages45// (including, but not limited to, procurement of substitute goods or services;46// loss of use, data, or profits; or business interruption) however caused47// and on any theory of liability, whether in contract, strict liability,48// or tort (including negligence or otherwise) arising in any way out of49// the use of this software, even if advised of the possibility of such damage.50//51//M*/5253#include "../test_precomp.hpp"54#include "opencv2/ts/ocl_test.hpp"5556#ifdef HAVE_OPENCL5758namespace opencv_test {59namespace ocl {6061///////////////////////////////////////////////////////////////////////////////6263PARAM_TEST_CASE(ImgprocTestBase, MatType,64int, // blockSize65int, // border type66bool) // roi or not67{68int type, borderType, blockSize;69bool useRoi;7071TEST_DECLARE_INPUT_PARAMETER(src);72TEST_DECLARE_OUTPUT_PARAMETER(dst);7374virtual void SetUp()75{76type = GET_PARAM(0);77blockSize = GET_PARAM(1);78borderType = GET_PARAM(2);79useRoi = GET_PARAM(3);80}8182void random_roi()83{84Size roiSize = randomSize(1, MAX_VALUE);85Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);86randomSubMat(src, src_roi, roiSize, srcBorder, type, 5, 256);8788Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);89randomSubMat(dst, dst_roi, roiSize, dstBorder, type, 5, 16);9091UMAT_UPLOAD_INPUT_PARAMETER(src);92UMAT_UPLOAD_OUTPUT_PARAMETER(dst);93}9495void Near(double threshold = 0.0, bool relative = false)96{97if (relative)98OCL_EXPECT_MATS_NEAR_RELATIVE(dst, threshold);99else100OCL_EXPECT_MATS_NEAR(dst, threshold);101}102};103104//////////////////////////////// copyMakeBorder ////////////////////////////////////////////105106PARAM_TEST_CASE(CopyMakeBorder, MatDepth, // depth107Channels, // channels108bool, // isolated or not109BorderType, // border type110bool) // roi or not111{112int type, borderType;113bool useRoi;114115TestUtils::Border border;116Scalar val;117118TEST_DECLARE_INPUT_PARAMETER(src);119TEST_DECLARE_OUTPUT_PARAMETER(dst);120121virtual void SetUp()122{123type = CV_MAKE_TYPE(GET_PARAM(0), GET_PARAM(1));124borderType = GET_PARAM(3);125126if (GET_PARAM(2))127borderType |= BORDER_ISOLATED;128129useRoi = GET_PARAM(4);130}131132void random_roi()133{134border = randomBorder(0, MAX_VALUE << 2);135val = randomScalar(-MAX_VALUE, MAX_VALUE);136137Size roiSize = randomSize(1, MAX_VALUE);138Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);139randomSubMat(src, src_roi, roiSize, srcBorder, type, -MAX_VALUE, MAX_VALUE);140141Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);142dstBorder.top += border.top;143dstBorder.lef += border.lef;144dstBorder.rig += border.rig;145dstBorder.bot += border.bot;146147randomSubMat(dst, dst_roi, roiSize, dstBorder, type, -MAX_VALUE, MAX_VALUE);148149UMAT_UPLOAD_INPUT_PARAMETER(src);150UMAT_UPLOAD_OUTPUT_PARAMETER(dst);151}152153void Near()154{155OCL_EXPECT_MATS_NEAR(dst, 0);156}157};158159OCL_TEST_P(CopyMakeBorder, Mat)160{161for (int i = 0; i < test_loop_times; ++i)162{163random_roi();164165OCL_OFF(cv::copyMakeBorder(src_roi, dst_roi, border.top, border.bot, border.lef, border.rig, borderType, val));166OCL_ON(cv::copyMakeBorder(usrc_roi, udst_roi, border.top, border.bot, border.lef, border.rig, borderType, val));167168Near();169}170}171172//////////////////////////////// equalizeHist //////////////////////////////////////////////173174typedef ImgprocTestBase EqualizeHist;175176OCL_TEST_P(EqualizeHist, Mat)177{178for (int j = 0; j < test_loop_times; j++)179{180random_roi();181182OCL_OFF(cv::equalizeHist(src_roi, dst_roi));183OCL_ON(cv::equalizeHist(usrc_roi, udst_roi));184185Near(1);186}187}188189//////////////////////////////// Corners test //////////////////////////////////////////190191struct CornerTestBase :192public ImgprocTestBase193{194void random_roi()195{196Mat image = readImageType("../gpu/stereobm/aloe-L.png", type);197ASSERT_FALSE(image.empty());198199bool isFP = CV_MAT_DEPTH(type) >= CV_32F;200float val = 255.0f;201if (isFP)202{203image.convertTo(image, -1, 1.0 / 255);204val /= 255.0f;205}206207Size roiSize = image.size();208Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);209210Size wholeSize = Size(roiSize.width + srcBorder.lef + srcBorder.rig, roiSize.height + srcBorder.top + srcBorder.bot);211src = randomMat(wholeSize, type, -val, val, false);212src_roi = src(Rect(srcBorder.lef, srcBorder.top, roiSize.width, roiSize.height));213image.copyTo(src_roi);214215Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);216randomSubMat(dst, dst_roi, roiSize, dstBorder, CV_32FC1, 5, 16);217218UMAT_UPLOAD_INPUT_PARAMETER(src);219UMAT_UPLOAD_OUTPUT_PARAMETER(dst);220}221};222223typedef CornerTestBase CornerMinEigenVal;224225OCL_TEST_P(CornerMinEigenVal, Mat)226{227for (int j = 0; j < test_loop_times; j++)228{229random_roi();230231int apertureSize = 3;232233OCL_OFF(cv::cornerMinEigenVal(src_roi, dst_roi, blockSize, apertureSize, borderType));234OCL_ON(cv::cornerMinEigenVal(usrc_roi, udst_roi, blockSize, apertureSize, borderType));235236Near(1e-5, true);237}238}239240//////////////////////////////// cornerHarris //////////////////////////////////////////241242typedef CornerTestBase CornerHarris;243244OCL_TEST_P(CornerHarris, Mat)245{246for (int j = 0; j < test_loop_times; j++)247{248random_roi();249250int apertureSize = 3;251double k = randomDouble(0.01, 0.9);252253OCL_OFF(cv::cornerHarris(src_roi, dst_roi, blockSize, apertureSize, k, borderType));254OCL_ON(cv::cornerHarris(usrc_roi, udst_roi, blockSize, apertureSize, k, borderType));255256Near(1e-6, true);257}258}259260//////////////////////////////// preCornerDetect //////////////////////////////////////////261262typedef ImgprocTestBase PreCornerDetect;263264OCL_TEST_P(PreCornerDetect, Mat)265{266for (int j = 0; j < test_loop_times; j++)267{268random_roi();269270const int apertureSize = blockSize;271272OCL_OFF(cv::preCornerDetect(src_roi, dst_roi, apertureSize, borderType));273OCL_ON(cv::preCornerDetect(usrc_roi, udst_roi, apertureSize, borderType));274275Near(1e-6, true);276}277}278279280////////////////////////////////// integral /////////////////////////////////////////////////281282struct Integral :283public ImgprocTestBase284{285int sdepth, sqdepth;286287TEST_DECLARE_OUTPUT_PARAMETER(dst2);288289virtual void SetUp()290{291type = GET_PARAM(0);292sdepth = GET_PARAM(1);293sqdepth = GET_PARAM(2);294useRoi = GET_PARAM(3);295}296297void random_roi()298{299ASSERT_EQ(CV_MAT_CN(type), 1);300301Size roiSize = randomSize(1, MAX_VALUE), isize = Size(roiSize.width + 1, roiSize.height + 1);302Border srcBorder = randomBorder(0, useRoi ? 2 : 0);303randomSubMat(src, src_roi, roiSize, srcBorder, type, 5, 256);304305Border dstBorder = randomBorder(0, useRoi ? 2 : 0);306randomSubMat(dst, dst_roi, isize, dstBorder, sdepth, 5, 16);307308Border dst2Border = randomBorder(0, useRoi ? 2 : 0);309randomSubMat(dst2, dst2_roi, isize, dst2Border, sqdepth, 5, 16);310311UMAT_UPLOAD_INPUT_PARAMETER(src);312UMAT_UPLOAD_OUTPUT_PARAMETER(dst);313UMAT_UPLOAD_OUTPUT_PARAMETER(dst2);314}315316void Near2(double threshold = 0.0, bool relative = false)317{318if (relative)319OCL_EXPECT_MATS_NEAR_RELATIVE(dst2, threshold);320else321OCL_EXPECT_MATS_NEAR(dst2, threshold);322}323};324325OCL_TEST_P(Integral, Mat1)326{327for (int j = 0; j < test_loop_times; j++)328{329random_roi();330331OCL_OFF(cv::integral(src_roi, dst_roi, sdepth));332OCL_ON(cv::integral(usrc_roi, udst_roi, sdepth));333334Near();335}336}337338OCL_TEST_P(Integral, Mat2)339{340for (int j = 0; j < test_loop_times; j++)341{342random_roi();343344OCL_OFF(cv::integral(src_roi, dst_roi, dst2_roi, sdepth, sqdepth));345OCL_ON(cv::integral(usrc_roi, udst_roi, udst2_roi, sdepth, sqdepth));346347Near();348sqdepth == CV_32F ? Near2(1e-6, true) : Near2();349}350}351352//////////////////////////////////////// threshold //////////////////////////////////////////////353354struct Threshold :355public ImgprocTestBase356{357int thresholdType;358359virtual void SetUp()360{361type = GET_PARAM(0);362thresholdType = GET_PARAM(2);363useRoi = GET_PARAM(3);364}365};366367OCL_TEST_P(Threshold, Mat)368{369for (int j = 0; j < test_loop_times; j++)370{371random_roi();372373double maxVal = randomDouble(20.0, 127.0);374double thresh = randomDouble(0.0, maxVal);375376OCL_OFF(cv::threshold(src_roi, dst_roi, thresh, maxVal, thresholdType));377OCL_ON(cv::threshold(usrc_roi, udst_roi, thresh, maxVal, thresholdType));378379Near(1);380}381}382383/////////////////////////////////////////// CLAHE //////////////////////////////////////////////////384385PARAM_TEST_CASE(CLAHETest, Size, double, bool)386{387Size gridSize;388double clipLimit;389bool useRoi;390391TEST_DECLARE_INPUT_PARAMETER(src);392TEST_DECLARE_OUTPUT_PARAMETER(dst);393394virtual void SetUp()395{396gridSize = GET_PARAM(0);397clipLimit = GET_PARAM(1);398useRoi = GET_PARAM(2);399}400401void random_roi()402{403Size roiSize = randomSize(std::max(gridSize.height, gridSize.width), MAX_VALUE);404Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);405randomSubMat(src, src_roi, roiSize, srcBorder, CV_8UC1, 5, 256);406407Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);408randomSubMat(dst, dst_roi, roiSize, dstBorder, CV_8UC1, 5, 16);409410UMAT_UPLOAD_INPUT_PARAMETER(src);411UMAT_UPLOAD_OUTPUT_PARAMETER(dst);412}413414void Near(double threshold = 0.0)415{416OCL_EXPECT_MATS_NEAR(dst, threshold);417}418};419420OCL_TEST_P(CLAHETest, Accuracy)421{422for (int i = 0; i < test_loop_times; ++i)423{424random_roi();425426Ptr<CLAHE> clahe = cv::createCLAHE(clipLimit, gridSize);427428OCL_OFF(clahe->apply(src_roi, dst_roi));429OCL_ON(clahe->apply(usrc_roi, udst_roi));430431Near(1.0);432}433}434435/////////////////////////////////////////////////////////////////////////////////////436437OCL_INSTANTIATE_TEST_CASE_P(Imgproc, EqualizeHist, Combine(438Values((MatType)CV_8UC1),439Values(0), // not used440Values(0), // not used441Bool()));442443OCL_INSTANTIATE_TEST_CASE_P(Imgproc, CornerMinEigenVal, Combine(444Values((MatType)CV_8UC1, (MatType)CV_32FC1),445Values(3, 5),446Values((BorderType)BORDER_CONSTANT, (BorderType)BORDER_REPLICATE,447(BorderType)BORDER_REFLECT, (BorderType)BORDER_REFLECT101),448Bool()));449450OCL_INSTANTIATE_TEST_CASE_P(Imgproc, CornerHarris, Combine(451Values((MatType)CV_8UC1, CV_32FC1),452Values(3, 5),453Values( (BorderType)BORDER_CONSTANT, (BorderType)BORDER_REPLICATE,454(BorderType)BORDER_REFLECT, (BorderType)BORDER_REFLECT_101),455Bool()));456457OCL_INSTANTIATE_TEST_CASE_P(Imgproc, PreCornerDetect, Combine(458Values((MatType)CV_8UC1, CV_32FC1),459Values(3, 5),460Values( (BorderType)BORDER_CONSTANT, (BorderType)BORDER_REPLICATE,461(BorderType)BORDER_REFLECT, (BorderType)BORDER_REFLECT_101),462Bool()));463464OCL_INSTANTIATE_TEST_CASE_P(Imgproc, Integral, Combine(465Values((MatType)CV_8UC1), // TODO does not work with CV_32F, CV_64F466Values(CV_32SC1, CV_32FC1), // desired sdepth467Values(CV_32FC1, CV_64FC1), // desired sqdepth468Bool()));469470OCL_INSTANTIATE_TEST_CASE_P(Imgproc, Threshold, Combine(471Values(CV_8UC1, CV_8UC2, CV_8UC3, CV_8UC4,472CV_16SC1, CV_16SC2, CV_16SC3, CV_16SC4,473CV_32FC1, CV_32FC2, CV_32FC3, CV_32FC4),474Values(0),475Values(ThreshOp(THRESH_BINARY),476ThreshOp(THRESH_BINARY_INV), ThreshOp(THRESH_TRUNC),477ThreshOp(THRESH_TOZERO), ThreshOp(THRESH_TOZERO_INV)),478Bool()));479480OCL_INSTANTIATE_TEST_CASE_P(Imgproc, CLAHETest, Combine(481Values(Size(4, 4), Size(32, 8), Size(8, 64)),482Values(0.0, 10.0, 62.0, 300.0),483Bool()));484485OCL_INSTANTIATE_TEST_CASE_P(ImgprocTestBase, CopyMakeBorder, Combine(486testing::Values((MatDepth)CV_8U, (MatDepth)CV_16S, (MatDepth)CV_32S, (MatDepth)CV_32F),487testing::Values(Channels(1), Channels(3), (Channels)4),488Bool(), // border isolated or not489Values((BorderType)BORDER_CONSTANT, (BorderType)BORDER_REPLICATE, (BorderType)BORDER_REFLECT,490(BorderType)BORDER_WRAP, (BorderType)BORDER_REFLECT_101),491Bool()));492493} } // namespace opencv_test::ocl494495#endif // HAVE_OPENCL496497498