test_accumulate.cpp 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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. // Nathan, liujun@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(AccumulateBase, std::pair<MatDepth, MatDepth>, Channels, bool)
  51. {
  52. int sdepth, ddepth, channels;
  53. bool useRoi;
  54. double alpha;
  55. TEST_DECLARE_INPUT_PARAMETER(src);
  56. TEST_DECLARE_INPUT_PARAMETER(mask);
  57. TEST_DECLARE_INPUT_PARAMETER(src2);
  58. TEST_DECLARE_OUTPUT_PARAMETER(dst);
  59. virtual void SetUp()
  60. {
  61. const std::pair<MatDepth, MatDepth> depths = GET_PARAM(0);
  62. sdepth = depths.first, ddepth = depths.second;
  63. channels = GET_PARAM(1);
  64. useRoi = GET_PARAM(2);
  65. }
  66. void random_roi()
  67. {
  68. const int stype = CV_MAKE_TYPE(sdepth, channels),
  69. dtype = CV_MAKE_TYPE(ddepth, channels);
  70. Size roiSize = randomSize(1, 10);
  71. Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
  72. randomSubMat(src, src_roi, roiSize, srcBorder, stype, -MAX_VALUE, MAX_VALUE);
  73. Border maskBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
  74. randomSubMat(mask, mask_roi, roiSize, maskBorder, CV_8UC1, -MAX_VALUE, MAX_VALUE);
  75. cvtest::threshold(mask, mask, 80, 255, THRESH_BINARY);
  76. Border src2Border = randomBorder(0, useRoi ? MAX_VALUE : 0);
  77. randomSubMat(src2, src2_roi, roiSize, src2Border, stype, -MAX_VALUE, MAX_VALUE);
  78. Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
  79. randomSubMat(dst, dst_roi, roiSize, dstBorder, dtype, -MAX_VALUE, MAX_VALUE);
  80. UMAT_UPLOAD_INPUT_PARAMETER(src);
  81. UMAT_UPLOAD_INPUT_PARAMETER(mask);
  82. UMAT_UPLOAD_INPUT_PARAMETER(src2);
  83. UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
  84. alpha = randomDouble(-5, 5);
  85. }
  86. };
  87. /////////////////////////////////// Accumulate ///////////////////////////////////
  88. typedef AccumulateBase Accumulate;
  89. OCL_TEST_P(Accumulate, Mat)
  90. {
  91. for (int i = 0; i < test_loop_times; ++i)
  92. {
  93. random_roi();
  94. OCL_OFF(cv::accumulate(src_roi, dst_roi));
  95. OCL_ON(cv::accumulate(usrc_roi, udst_roi));
  96. OCL_EXPECT_MATS_NEAR(dst, 1e-6);
  97. }
  98. }
  99. OCL_TEST_P(Accumulate, Mask)
  100. {
  101. for (int i = 0; i < test_loop_times; ++i)
  102. {
  103. random_roi();
  104. OCL_OFF(cv::accumulate(src_roi, dst_roi, mask_roi));
  105. OCL_ON(cv::accumulate(usrc_roi, udst_roi, umask_roi));
  106. OCL_EXPECT_MATS_NEAR(dst, 1e-6);
  107. }
  108. }
  109. /////////////////////////////////// AccumulateSquare ///////////////////////////////////
  110. typedef AccumulateBase AccumulateSquare;
  111. OCL_TEST_P(AccumulateSquare, Mat)
  112. {
  113. for (int i = 0; i < test_loop_times; ++i)
  114. {
  115. random_roi();
  116. OCL_OFF(cv::accumulateSquare(src_roi, dst_roi));
  117. OCL_ON(cv::accumulateSquare(usrc_roi, udst_roi));
  118. OCL_EXPECT_MATS_NEAR(dst, 1e-2);
  119. }
  120. }
  121. OCL_TEST_P(AccumulateSquare, Mask)
  122. {
  123. for (int i = 0; i < test_loop_times; ++i)
  124. {
  125. random_roi();
  126. OCL_OFF(cv::accumulateSquare(src_roi, dst_roi, mask_roi));
  127. OCL_ON(cv::accumulateSquare(usrc_roi, udst_roi, umask_roi));
  128. OCL_EXPECT_MATS_NEAR(dst, 1e-2);
  129. }
  130. }
  131. /////////////////////////////////// AccumulateProduct ///////////////////////////////////
  132. typedef AccumulateBase AccumulateProduct;
  133. OCL_TEST_P(AccumulateProduct, Mat)
  134. {
  135. for (int i = 0; i < test_loop_times; ++i)
  136. {
  137. random_roi();
  138. OCL_OFF(cv::accumulateProduct(src_roi, src2_roi, dst_roi));
  139. OCL_ON(cv::accumulateProduct(usrc_roi, usrc2_roi, udst_roi));
  140. OCL_EXPECT_MATS_NEAR(dst, 1e-2);
  141. }
  142. }
  143. OCL_TEST_P(AccumulateProduct, Mask)
  144. {
  145. for (int i = 0; i < test_loop_times; ++i)
  146. {
  147. random_roi();
  148. OCL_OFF(cv::accumulateProduct(src_roi, src2_roi, dst_roi, mask_roi));
  149. OCL_ON(cv::accumulateProduct(usrc_roi, usrc2_roi, udst_roi, umask_roi));
  150. OCL_EXPECT_MATS_NEAR(dst, 1e-2);
  151. }
  152. }
  153. /////////////////////////////////// AccumulateWeighted ///////////////////////////////////
  154. typedef AccumulateBase AccumulateWeighted;
  155. OCL_TEST_P(AccumulateWeighted, Mat)
  156. {
  157. for (int i = 0; i < test_loop_times; ++i)
  158. {
  159. random_roi();
  160. OCL_OFF(cv::accumulateWeighted(src_roi, dst_roi, alpha));
  161. OCL_ON(cv::accumulateWeighted(usrc_roi, udst_roi, alpha));
  162. OCL_EXPECT_MATS_NEAR(dst, 1e-2);
  163. }
  164. }
  165. OCL_TEST_P(AccumulateWeighted, Mask)
  166. {
  167. for (int i = 0; i < test_loop_times; ++i)
  168. {
  169. random_roi();
  170. OCL_OFF(cv::accumulateWeighted(src_roi, dst_roi, alpha));
  171. OCL_ON(cv::accumulateWeighted(usrc_roi, udst_roi, alpha));
  172. OCL_EXPECT_MATS_NEAR(dst, 1e-2);
  173. }
  174. }
  175. /////////////////////////////////// Instantiation ///////////////////////////////////
  176. #define OCL_DEPTH_ALL_COMBINATIONS \
  177. testing::Values(std::make_pair<MatDepth, MatDepth>(CV_8U, CV_32F), \
  178. std::make_pair<MatDepth, MatDepth>(CV_16U, CV_32F), \
  179. std::make_pair<MatDepth, MatDepth>(CV_32F, CV_32F), \
  180. std::make_pair<MatDepth, MatDepth>(CV_8U, CV_64F), \
  181. std::make_pair<MatDepth, MatDepth>(CV_16U, CV_64F), \
  182. std::make_pair<MatDepth, MatDepth>(CV_32F, CV_64F), \
  183. std::make_pair<MatDepth, MatDepth>(CV_64F, CV_64F))
  184. OCL_INSTANTIATE_TEST_CASE_P(ImgProc, Accumulate, Combine(OCL_DEPTH_ALL_COMBINATIONS, OCL_ALL_CHANNELS, Bool()));
  185. OCL_INSTANTIATE_TEST_CASE_P(ImgProc, AccumulateSquare, Combine(OCL_DEPTH_ALL_COMBINATIONS, OCL_ALL_CHANNELS, Bool()));
  186. OCL_INSTANTIATE_TEST_CASE_P(ImgProc, AccumulateProduct, Combine(OCL_DEPTH_ALL_COMBINATIONS, OCL_ALL_CHANNELS, Bool()));
  187. OCL_INSTANTIATE_TEST_CASE_P(ImgProc, AccumulateWeighted, Combine(OCL_DEPTH_ALL_COMBINATIONS, OCL_ALL_CHANNELS, Bool()));
  188. } } // namespace opencv_test::ocl
  189. #endif