test_dft.cpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*M///////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
  4. //
  5. // By downloading, copying, installing or using the software you agree to this license.
  6. // If you do not agree to this license, do not download, install,
  7. // copy or use the software.
  8. //
  9. //
  10. // License Agreement
  11. // For Open Source Computer Vision Library
  12. //
  13. // Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.
  14. // Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
  15. // Third party copyrights are property of their respective owners.
  16. //
  17. // @Authors
  18. // Peng Xiao, pengxiao@multicorewareinc.com
  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 documentation
  28. // and/or other materials provided with the distribution.
  29. //
  30. // * The name of the copyright holders may not be used to endorse or promote products
  31. // derived from this software without specific prior written permission.
  32. //
  33. // This software is provided by the copyright holders and contributors as is and
  34. // any express or implied warranties, including, but not limited to, the implied
  35. // 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 damages
  38. // (including, but not limited to, procurement of substitute goods or services;
  39. // loss of use, data, or profits; or business interruption) however caused
  40. // and on any theory of liability, whether in contract, strict liability,
  41. // or tort (including negligence or otherwise) arising in any way out of
  42. // the use of this software, even if advised of the possibility of such damage.
  43. //
  44. //M*/
  45. #include "../test_precomp.hpp"
  46. #include "opencv2/ts/ocl_test.hpp"
  47. #ifdef HAVE_OPENCL
  48. enum OCL_FFT_TYPE
  49. {
  50. R2R = 0,
  51. C2R = 1,
  52. R2C = 2,
  53. C2C = 3
  54. };
  55. namespace opencv_test {
  56. namespace ocl {
  57. ////////////////////////////////////////////////////////////////////////////
  58. // Dft
  59. PARAM_TEST_CASE(Dft, cv::Size, OCL_FFT_TYPE, MatDepth, bool, bool, bool, bool)
  60. {
  61. cv::Size dft_size;
  62. int dft_flags, depth, cn, dft_type;
  63. bool hint;
  64. bool is1d;
  65. TEST_DECLARE_INPUT_PARAMETER(src);
  66. TEST_DECLARE_OUTPUT_PARAMETER(dst);
  67. virtual void SetUp()
  68. {
  69. dft_size = GET_PARAM(0);
  70. dft_type = GET_PARAM(1);
  71. depth = GET_PARAM(2);
  72. dft_flags = 0;
  73. switch (dft_type)
  74. {
  75. case R2R: dft_flags |= cv::DFT_REAL_OUTPUT; cn = 1; break;
  76. case C2R: dft_flags |= cv::DFT_REAL_OUTPUT; cn = 2; break;
  77. case R2C: dft_flags |= cv::DFT_COMPLEX_OUTPUT; cn = 1; break;
  78. case C2C: dft_flags |= cv::DFT_COMPLEX_OUTPUT; cn = 2; break;
  79. }
  80. if (GET_PARAM(3))
  81. dft_flags |= cv::DFT_INVERSE;
  82. if (GET_PARAM(4))
  83. dft_flags |= cv::DFT_ROWS;
  84. if (GET_PARAM(5))
  85. dft_flags |= cv::DFT_SCALE;
  86. hint = GET_PARAM(6);
  87. is1d = (dft_flags & DFT_ROWS) != 0 || dft_size.height == 1;
  88. }
  89. void generateTestData()
  90. {
  91. src = randomMat(dft_size, CV_MAKE_TYPE(depth, cn), 0.0, 100.0);
  92. usrc = src.getUMat(ACCESS_READ);
  93. }
  94. };
  95. OCL_TEST_P(Dft, Mat)
  96. {
  97. generateTestData();
  98. int nonzero_rows = hint ? src.rows - randomInt(1, src.rows-1) : 0;
  99. OCL_OFF(cv::dft(src, dst, dft_flags, nonzero_rows));
  100. OCL_ON(cv::dft(usrc, udst, dft_flags, nonzero_rows));
  101. // In case forward R2C 1d transform dst contains only half of output
  102. // without complex conjugate
  103. if (dft_type == R2C && is1d && (dft_flags & cv::DFT_INVERSE) == 0)
  104. {
  105. dst = dst(cv::Range(0, dst.rows), cv::Range(0, dst.cols/2 + 1));
  106. udst = udst(cv::Range(0, udst.rows), cv::Range(0, udst.cols/2 + 1));
  107. }
  108. double eps = src.size().area() * 1e-4;
  109. EXPECT_MAT_NEAR(dst, udst, eps);
  110. }
  111. ////////////////////////////////////////////////////////////////////////////
  112. // MulSpectrums
  113. PARAM_TEST_CASE(MulSpectrums, bool, bool)
  114. {
  115. bool ccorr, useRoi;
  116. TEST_DECLARE_INPUT_PARAMETER(src1);
  117. TEST_DECLARE_INPUT_PARAMETER(src2);
  118. TEST_DECLARE_OUTPUT_PARAMETER(dst);
  119. virtual void SetUp()
  120. {
  121. ccorr = GET_PARAM(0);
  122. useRoi = GET_PARAM(1);
  123. }
  124. void generateTestData()
  125. {
  126. Size srcRoiSize = randomSize(1, MAX_VALUE);
  127. Border src1Border = randomBorder(0, useRoi ? MAX_VALUE : 0);
  128. randomSubMat(src1, src1_roi, srcRoiSize, src1Border, CV_32FC2, -11, 11);
  129. Border src2Border = randomBorder(0, useRoi ? MAX_VALUE : 0);
  130. randomSubMat(src2, src2_roi, srcRoiSize, src2Border, CV_32FC2, -11, 11);
  131. Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
  132. randomSubMat(dst, dst_roi, srcRoiSize, dstBorder, CV_32FC2, 5, 16);
  133. UMAT_UPLOAD_INPUT_PARAMETER(src1);
  134. UMAT_UPLOAD_INPUT_PARAMETER(src2);
  135. UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
  136. }
  137. };
  138. OCL_TEST_P(MulSpectrums, Mat)
  139. {
  140. for (int i = 0; i < test_loop_times; ++i)
  141. {
  142. generateTestData();
  143. OCL_OFF(cv::mulSpectrums(src1_roi, src2_roi, dst_roi, 0, ccorr));
  144. OCL_ON(cv::mulSpectrums(usrc1_roi, usrc2_roi, udst_roi, 0, ccorr));
  145. OCL_EXPECT_MATS_NEAR_RELATIVE(dst, 1e-6);
  146. }
  147. }
  148. OCL_INSTANTIATE_TEST_CASE_P(OCL_ImgProc, MulSpectrums, testing::Combine(Bool(), Bool()));
  149. OCL_INSTANTIATE_TEST_CASE_P(Core, Dft, Combine(Values(cv::Size(45, 72), cv::Size(36, 36), cv::Size(512, 1), cv::Size(1280, 768)),
  150. Values((OCL_FFT_TYPE) R2C, (OCL_FFT_TYPE) C2C, (OCL_FFT_TYPE) R2R, (OCL_FFT_TYPE) C2R),
  151. Values(CV_32F, CV_64F),
  152. Bool(), // DFT_INVERSE
  153. Bool(), // DFT_ROWS
  154. Bool(), // DFT_SCALE
  155. Bool() // hint
  156. )
  157. );
  158. } } // namespace opencv_test::ocl
  159. #endif // HAVE_OPENCL