Path: blob/master/modules/core/test/ocl/test_dft.cpp
16339 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// Peng Xiao, [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_OPENCL4950enum OCL_FFT_TYPE51{52R2R = 0,53C2R = 1,54R2C = 2,55C2C = 356};5758namespace opencv_test {59namespace ocl {6061////////////////////////////////////////////////////////////////////////////62// Dft6364PARAM_TEST_CASE(Dft, cv::Size, OCL_FFT_TYPE, MatDepth, bool, bool, bool, bool)65{66cv::Size dft_size;67int dft_flags, depth, cn, dft_type;68bool hint;69bool is1d;7071TEST_DECLARE_INPUT_PARAMETER(src);72TEST_DECLARE_OUTPUT_PARAMETER(dst);7374virtual void SetUp()75{76dft_size = GET_PARAM(0);77dft_type = GET_PARAM(1);78depth = GET_PARAM(2);7980dft_flags = 0;81switch (dft_type)82{83case R2R: dft_flags |= cv::DFT_REAL_OUTPUT; cn = 1; break;84case C2R: dft_flags |= cv::DFT_REAL_OUTPUT; cn = 2; break;85case R2C: dft_flags |= cv::DFT_COMPLEX_OUTPUT; cn = 1; break;86case C2C: dft_flags |= cv::DFT_COMPLEX_OUTPUT; cn = 2; break;87}8889if (GET_PARAM(3))90dft_flags |= cv::DFT_INVERSE;91if (GET_PARAM(4))92dft_flags |= cv::DFT_ROWS;93if (GET_PARAM(5))94dft_flags |= cv::DFT_SCALE;95hint = GET_PARAM(6);96is1d = (dft_flags & DFT_ROWS) != 0 || dft_size.height == 1;97}9899void generateTestData()100{101src = randomMat(dft_size, CV_MAKE_TYPE(depth, cn), 0.0, 100.0);102usrc = src.getUMat(ACCESS_READ);103}104};105106OCL_TEST_P(Dft, Mat)107{108generateTestData();109110int nonzero_rows = hint ? src.rows - randomInt(1, src.rows-1) : 0;111OCL_OFF(cv::dft(src, dst, dft_flags, nonzero_rows));112OCL_ON(cv::dft(usrc, udst, dft_flags, nonzero_rows));113114// In case forward R2C 1d transform dst contains only half of output115// without complex conjugate116if (dft_type == R2C && is1d && (dft_flags & cv::DFT_INVERSE) == 0)117{118dst = dst(cv::Range(0, dst.rows), cv::Range(0, dst.cols/2 + 1));119udst = udst(cv::Range(0, udst.rows), cv::Range(0, udst.cols/2 + 1));120}121122double eps = src.size().area() * 1e-4;123EXPECT_MAT_NEAR(dst, udst, eps);124}125126////////////////////////////////////////////////////////////////////////////127// MulSpectrums128129PARAM_TEST_CASE(MulSpectrums, bool, bool)130{131bool ccorr, useRoi;132133TEST_DECLARE_INPUT_PARAMETER(src1);134TEST_DECLARE_INPUT_PARAMETER(src2);135TEST_DECLARE_OUTPUT_PARAMETER(dst);136137virtual void SetUp()138{139ccorr = GET_PARAM(0);140useRoi = GET_PARAM(1);141}142143void generateTestData()144{145Size srcRoiSize = randomSize(1, MAX_VALUE);146Border src1Border = randomBorder(0, useRoi ? MAX_VALUE : 0);147randomSubMat(src1, src1_roi, srcRoiSize, src1Border, CV_32FC2, -11, 11);148149150Border src2Border = randomBorder(0, useRoi ? MAX_VALUE : 0);151randomSubMat(src2, src2_roi, srcRoiSize, src2Border, CV_32FC2, -11, 11);152153Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);154randomSubMat(dst, dst_roi, srcRoiSize, dstBorder, CV_32FC2, 5, 16);155156UMAT_UPLOAD_INPUT_PARAMETER(src1);157UMAT_UPLOAD_INPUT_PARAMETER(src2);158UMAT_UPLOAD_OUTPUT_PARAMETER(dst);159}160};161162OCL_TEST_P(MulSpectrums, Mat)163{164for (int i = 0; i < test_loop_times; ++i)165{166generateTestData();167168OCL_OFF(cv::mulSpectrums(src1_roi, src2_roi, dst_roi, 0, ccorr));169OCL_ON(cv::mulSpectrums(usrc1_roi, usrc2_roi, udst_roi, 0, ccorr));170171OCL_EXPECT_MATS_NEAR_RELATIVE(dst, 1e-6);172}173}174175OCL_INSTANTIATE_TEST_CASE_P(OCL_ImgProc, MulSpectrums, testing::Combine(Bool(), Bool()));176177OCL_INSTANTIATE_TEST_CASE_P(Core, Dft, Combine(Values(cv::Size(45, 72), cv::Size(36, 36), cv::Size(512, 1), cv::Size(1280, 768)),178Values((OCL_FFT_TYPE) R2C, (OCL_FFT_TYPE) C2C, (OCL_FFT_TYPE) R2R, (OCL_FFT_TYPE) C2R),179Values(CV_32F, CV_64F),180Bool(), // DFT_INVERSE181Bool(), // DFT_ROWS182Bool(), // DFT_SCALE183Bool() // hint184)185);186187} } // namespace opencv_test::ocl188189#endif // HAVE_OPENCL190191