test_pyramids.cpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. ///////////////////////////////////////////////////////////////////////////////////////
  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, Institute Of Software Chinese Academy Of Science, 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. // Yao Wang yao@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. namespace opencv_test {
  49. namespace ocl {
  50. PARAM_TEST_CASE(PyrTestBase, MatDepth, Channels, BorderType, bool)
  51. {
  52. int depth, channels, borderType;
  53. bool use_roi;
  54. TEST_DECLARE_INPUT_PARAMETER(src);
  55. TEST_DECLARE_OUTPUT_PARAMETER(dst);
  56. virtual void SetUp()
  57. {
  58. depth = GET_PARAM(0);
  59. channels = GET_PARAM(1);
  60. borderType = GET_PARAM(2);
  61. use_roi = GET_PARAM(3);
  62. }
  63. void generateTestData(Size src_roiSize, Size dst_roiSize)
  64. {
  65. Border srcBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
  66. randomSubMat(src, src_roi, src_roiSize, srcBorder, CV_MAKETYPE(depth, channels), -MAX_VALUE, MAX_VALUE);
  67. Border dstBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
  68. randomSubMat(dst, dst_roi, dst_roiSize, dstBorder, CV_MAKETYPE(depth, channels), -MAX_VALUE, MAX_VALUE);
  69. UMAT_UPLOAD_INPUT_PARAMETER(src);
  70. UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
  71. }
  72. void Near(double threshold = 0.0)
  73. {
  74. OCL_EXPECT_MATS_NEAR(dst, threshold);
  75. }
  76. };
  77. /////////////////////// PyrDown //////////////////////////
  78. typedef PyrTestBase PyrDown;
  79. OCL_TEST_P(PyrDown, Mat)
  80. {
  81. for (int j = 0; j < test_loop_times; j++)
  82. {
  83. Size src_roiSize = randomSize(1, MAX_VALUE);
  84. Size dst_roiSize = Size(randomInt((src_roiSize.width - 1) / 2, (src_roiSize.width + 3) / 2),
  85. randomInt((src_roiSize.height - 1) / 2, (src_roiSize.height + 3) / 2));
  86. dst_roiSize = dst_roiSize.empty() ? Size((src_roiSize.width + 1) / 2, (src_roiSize.height + 1) / 2) : dst_roiSize;
  87. generateTestData(src_roiSize, dst_roiSize);
  88. OCL_OFF(pyrDown(src_roi, dst_roi, dst_roiSize, borderType));
  89. OCL_ON(pyrDown(usrc_roi, udst_roi, dst_roiSize, borderType));
  90. Near(depth == CV_32F ? 1e-4f : 1.0f);
  91. }
  92. }
  93. OCL_INSTANTIATE_TEST_CASE_P(ImgprocPyr, PyrDown, Combine(
  94. Values(CV_8U, CV_16U, CV_16S, CV_32F, CV_64F),
  95. Values(1, 2, 3, 4),
  96. Values((BorderType)BORDER_REPLICATE,
  97. (BorderType)BORDER_REFLECT, (BorderType)BORDER_REFLECT_101),
  98. Bool()
  99. ));
  100. /////////////////////// PyrUp //////////////////////////
  101. typedef PyrTestBase PyrUp;
  102. OCL_TEST_P(PyrUp, Mat)
  103. {
  104. for (int j = 0; j < test_loop_times; j++)
  105. {
  106. Size src_roiSize = randomSize(1, MAX_VALUE);
  107. Size dst_roiSize = Size(2 * src_roiSize.width, 2 * src_roiSize.height);
  108. generateTestData(src_roiSize, dst_roiSize);
  109. OCL_OFF(pyrUp(src_roi, dst_roi, dst_roiSize, borderType));
  110. OCL_ON(pyrUp(usrc_roi, udst_roi, dst_roiSize, borderType));
  111. Near(depth == CV_32F ? 1e-4f : 1.0f);
  112. }
  113. }
  114. typedef PyrTestBase PyrUp_cols2;
  115. OCL_TEST_P(PyrUp_cols2, Mat)
  116. {
  117. for (int j = 0; j < test_loop_times; j++)
  118. {
  119. Size src_roiSize = randomSize(1, MAX_VALUE);
  120. src_roiSize.width += (src_roiSize.width % 2);
  121. Size dst_roiSize = Size(2 * src_roiSize.width, 2 * src_roiSize.height);
  122. generateTestData(src_roiSize, dst_roiSize);
  123. OCL_OFF(pyrUp(src_roi, dst_roi, dst_roiSize, borderType));
  124. OCL_ON(pyrUp(usrc_roi, udst_roi, dst_roiSize, borderType));
  125. Near(depth == CV_32F ? 1e-4f : 1.0f);
  126. }
  127. }
  128. OCL_INSTANTIATE_TEST_CASE_P(ImgprocPyr, PyrUp, Combine(
  129. Values(CV_8U, CV_16U, CV_16S, CV_32F, CV_64F),
  130. Values(1, 2, 3, 4),
  131. Values((BorderType)BORDER_REFLECT_101),
  132. Bool()
  133. ));
  134. OCL_INSTANTIATE_TEST_CASE_P(ImgprocPyr, PyrUp_cols2, Combine(
  135. Values((MatDepth)CV_8U),
  136. Values((Channels)1),
  137. Values((BorderType)BORDER_REFLECT_101),
  138. Bool()
  139. ));
  140. } } // namespace opencv_test::ocl
  141. #endif // HAVE_OPENCL