Path: blob/master/modules/imgproc/test/ocl/test_pyramids.cpp
16344 views
///////////////////////////////////////////////////////////////////////////////////////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// Third party copyrights are property of their respective owners.15//16// @Authors17// Yao Wang [email protected]18//19// Redistribution and use in source and binary forms, with or without modification,20// are permitted provided that the following conditions are met:21//22// * Redistribution's of source code must retain the above copyright notice,23// this list of conditions and the following disclaimer.24//25// * Redistribution's in binary form must reproduce the above copyright notice,26// this list of conditions and the following disclaimer in the documentation27// and/or other materials provided with the distribution.28//29// * The name of the copyright holders may not be used to endorse or promote products30// derived from this software without specific prior written permission.31//32// This software is provided by the copyright holders and contributors "as is" and33// any express or implied warranties, including, but not limited to, the implied34// warranties of merchantability and fitness for a particular purpose are disclaimed.35// In no event shall the Intel Corporation or contributors be liable for any direct,36// indirect, incidental, special, exemplary, or consequential damages37// (including, but not limited to, procurement of substitute goods or services;38// loss of use, data, or profits; or business interruption) however caused39// and on any theory of liability, whether in contract, strict liability,40// or tort (including negligence or otherwise) arising in any way out of41// the use of this software, even if advised of the possibility of such damage.42//43//M*/444546#include "../test_precomp.hpp"47#include "opencv2/ts/ocl_test.hpp"4849#ifdef HAVE_OPENCL5051namespace opencv_test {52namespace ocl {5354PARAM_TEST_CASE(PyrTestBase, MatDepth, Channels, BorderType, bool)55{56int depth, channels, borderType;57bool use_roi;5859TEST_DECLARE_INPUT_PARAMETER(src);60TEST_DECLARE_OUTPUT_PARAMETER(dst);6162virtual void SetUp()63{64depth = GET_PARAM(0);65channels = GET_PARAM(1);66borderType = GET_PARAM(2);67use_roi = GET_PARAM(3);68}6970void generateTestData(Size src_roiSize, Size dst_roiSize)71{72Border srcBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);73randomSubMat(src, src_roi, src_roiSize, srcBorder, CV_MAKETYPE(depth, channels), -MAX_VALUE, MAX_VALUE);7475Border dstBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);76randomSubMat(dst, dst_roi, dst_roiSize, dstBorder, CV_MAKETYPE(depth, channels), -MAX_VALUE, MAX_VALUE);7778UMAT_UPLOAD_INPUT_PARAMETER(src);79UMAT_UPLOAD_OUTPUT_PARAMETER(dst);80}8182void Near(double threshold = 0.0)83{84OCL_EXPECT_MATS_NEAR(dst, threshold);85}86};8788/////////////////////// PyrDown //////////////////////////8990typedef PyrTestBase PyrDown;9192OCL_TEST_P(PyrDown, Mat)93{94for (int j = 0; j < test_loop_times; j++)95{96Size src_roiSize = randomSize(1, MAX_VALUE);97Size dst_roiSize = Size(randomInt((src_roiSize.width - 1) / 2, (src_roiSize.width + 3) / 2),98randomInt((src_roiSize.height - 1) / 2, (src_roiSize.height + 3) / 2));99dst_roiSize = dst_roiSize.empty() ? Size((src_roiSize.width + 1) / 2, (src_roiSize.height + 1) / 2) : dst_roiSize;100generateTestData(src_roiSize, dst_roiSize);101102OCL_OFF(pyrDown(src_roi, dst_roi, dst_roiSize, borderType));103OCL_ON(pyrDown(usrc_roi, udst_roi, dst_roiSize, borderType));104105Near(depth == CV_32F ? 1e-4f : 1.0f);106}107}108109OCL_INSTANTIATE_TEST_CASE_P(ImgprocPyr, PyrDown, Combine(110Values(CV_8U, CV_16U, CV_16S, CV_32F, CV_64F),111Values(1, 2, 3, 4),112Values((BorderType)BORDER_REPLICATE,113(BorderType)BORDER_REFLECT, (BorderType)BORDER_REFLECT_101),114Bool()115));116117/////////////////////// PyrUp //////////////////////////118119typedef PyrTestBase PyrUp;120121OCL_TEST_P(PyrUp, Mat)122{123for (int j = 0; j < test_loop_times; j++)124{125Size src_roiSize = randomSize(1, MAX_VALUE);126Size dst_roiSize = Size(2 * src_roiSize.width, 2 * src_roiSize.height);127generateTestData(src_roiSize, dst_roiSize);128129OCL_OFF(pyrUp(src_roi, dst_roi, dst_roiSize, borderType));130OCL_ON(pyrUp(usrc_roi, udst_roi, dst_roiSize, borderType));131132Near(depth == CV_32F ? 1e-4f : 1.0f);133}134}135136typedef PyrTestBase PyrUp_cols2;137138OCL_TEST_P(PyrUp_cols2, Mat)139{140for (int j = 0; j < test_loop_times; j++)141{142Size src_roiSize = randomSize(1, MAX_VALUE);143src_roiSize.width += (src_roiSize.width % 2);144Size dst_roiSize = Size(2 * src_roiSize.width, 2 * src_roiSize.height);145generateTestData(src_roiSize, dst_roiSize);146147OCL_OFF(pyrUp(src_roi, dst_roi, dst_roiSize, borderType));148OCL_ON(pyrUp(usrc_roi, udst_roi, dst_roiSize, borderType));149150Near(depth == CV_32F ? 1e-4f : 1.0f);151}152}153154OCL_INSTANTIATE_TEST_CASE_P(ImgprocPyr, PyrUp, Combine(155Values(CV_8U, CV_16U, CV_16S, CV_32F, CV_64F),156Values(1, 2, 3, 4),157Values((BorderType)BORDER_REFLECT_101),158Bool()159));160161OCL_INSTANTIATE_TEST_CASE_P(ImgprocPyr, PyrUp_cols2, Combine(162Values((MatDepth)CV_8U),163Values((Channels)1),164Values((BorderType)BORDER_REFLECT_101),165Bool()166));167168} } // namespace opencv_test::ocl169170#endif // HAVE_OPENCL171172173