Path: blob/master/modules/imgproc/test/ocl/test_blend.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// Nathan, [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*/4445#include "../test_precomp.hpp"46#include "opencv2/ts/ocl_test.hpp"4748#ifdef HAVE_OPENCL4950namespace opencv_test {51namespace ocl {5253PARAM_TEST_CASE(BlendLinear, MatDepth, Channels, bool)54{55int depth, channels;56bool useRoi;5758TEST_DECLARE_INPUT_PARAMETER(src1);59TEST_DECLARE_INPUT_PARAMETER(src2);60TEST_DECLARE_INPUT_PARAMETER(weights2);61TEST_DECLARE_INPUT_PARAMETER(weights1);62TEST_DECLARE_OUTPUT_PARAMETER(dst);6364virtual void SetUp()65{66depth = GET_PARAM(0);67channels = GET_PARAM(1);68useRoi = GET_PARAM(2);69}7071void random_roi()72{73const int type = CV_MAKE_TYPE(depth, channels);74const double upValue = 256;7576Size roiSize = randomSize(1, MAX_VALUE);77Border src1Border = randomBorder(0, useRoi ? MAX_VALUE : 0);78randomSubMat(src1, src1_roi, roiSize, src1Border, type, -upValue, upValue);7980Border src2Border = randomBorder(0, useRoi ? MAX_VALUE : 0);81randomSubMat(src2, src2_roi, roiSize, src2Border, type, -upValue, upValue);8283Border weights1Border = randomBorder(0, useRoi ? MAX_VALUE : 0);84randomSubMat(weights1, weights1_roi, roiSize, weights1Border, CV_32FC1, -upValue, upValue);8586Border weights2Border = randomBorder(0, useRoi ? MAX_VALUE : 0);87randomSubMat(weights2, weights2_roi, roiSize, weights2Border, CV_32FC1, 1e-2, upValue);8889weights2_roi -= weights1_roi;90CV_Assert(checkNorm2(weights2_roi, weights2(Rect(weights2Border.lef, weights2Border.top,91roiSize.width, roiSize.height))) < 1e-6);9293Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);94randomSubMat(dst, dst_roi, roiSize, dstBorder, type, 5, 16);9596UMAT_UPLOAD_INPUT_PARAMETER(src1);97UMAT_UPLOAD_INPUT_PARAMETER(src2);98UMAT_UPLOAD_INPUT_PARAMETER(weights1);99UMAT_UPLOAD_INPUT_PARAMETER(weights2);100UMAT_UPLOAD_OUTPUT_PARAMETER(dst);101}102103void Near(double eps = 0.0)104{105OCL_EXPECT_MATS_NEAR(dst, eps);106}107};108109OCL_TEST_P(BlendLinear, Accuracy)110{111for (int i = 0; i < test_loop_times; ++i)112{113random_roi();114115OCL_OFF(cv::blendLinear(src1_roi, src2_roi, weights1_roi, weights2_roi, dst_roi));116OCL_ON(cv::blendLinear(usrc1_roi, usrc2_roi, uweights1_roi, uweights2_roi, udst_roi));117118Near(depth <= CV_32S ? 1.0 : 0.5);119}120}121122OCL_INSTANTIATE_TEST_CASE_P(ImgProc, BlendLinear, Combine(testing::Values(CV_8U, CV_32F), OCL_ALL_CHANNELS, Bool()));123124} } // namespace opencv_test::ocl125126#endif127128129