reduction.hpp 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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) 2000-2008, Intel Corporation, all rights reserved.
  14. // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
  15. // Copyright (C) 2013, OpenCV Foundation, all rights reserved.
  16. // Third party copyrights are property of their respective owners.
  17. //
  18. // Redistribution and use in source and binary forms, with or without modification,
  19. // are permitted provided that the following conditions are met:
  20. //
  21. // * Redistribution's of source code must retain the above copyright notice,
  22. // this list of conditions and the following disclaimer.
  23. //
  24. // * Redistribution's in binary form must reproduce the above copyright notice,
  25. // this list of conditions and the following disclaimer in the documentation
  26. // and/or other materials provided with the distribution.
  27. //
  28. // * The name of the copyright holders may not be used to endorse or promote products
  29. // derived from this software without specific prior written permission.
  30. //
  31. // This software is provided by the copyright holders and contributors "as is" and
  32. // any express or implied warranties, including, but not limited to, the implied
  33. // warranties of merchantability and fitness for a particular purpose are disclaimed.
  34. // In no event shall the Intel Corporation or contributors be liable for any direct,
  35. // indirect, incidental, special, exemplary, or consequential damages
  36. // (including, but not limited to, procurement of substitute goods or services;
  37. // loss of use, data, or profits; or business interruption) however caused
  38. // and on any theory of liability, whether in contract, strict liability,
  39. // or tort (including negligence or otherwise) arising in any way out of
  40. // the use of this software, even if advised of the possibility of such damage.
  41. //
  42. //M*/
  43. #pragma once
  44. #ifndef OPENCV_CUDEV_EXPR_REDUCTION_HPP
  45. #define OPENCV_CUDEV_EXPR_REDUCTION_HPP
  46. #include "../common.hpp"
  47. #include "../grid/reduce.hpp"
  48. #include "../grid/histogram.hpp"
  49. #include "../grid/integral.hpp"
  50. #include "../grid/reduce_to_vec.hpp"
  51. #include "../ptr2d/traits.hpp"
  52. #include "expr.hpp"
  53. namespace cv { namespace cudev {
  54. //! @addtogroup cudev
  55. //! @{
  56. // sum
  57. template <class SrcPtr> struct SumExprBody
  58. {
  59. SrcPtr src;
  60. template <typename T>
  61. __host__ void assignTo(GpuMat_<T>& dst, Stream& stream = Stream::Null()) const
  62. {
  63. gridCalcSum(src, dst, stream);
  64. }
  65. };
  66. template <class SrcPtr>
  67. __host__ Expr<SumExprBody<SrcPtr> >
  68. sum_(const SrcPtr& src)
  69. {
  70. SumExprBody<SrcPtr> body;
  71. body.src = src;
  72. return makeExpr(body);
  73. }
  74. // minVal
  75. template <class SrcPtr> struct FindMinValExprBody
  76. {
  77. SrcPtr src;
  78. template <typename T>
  79. __host__ void assignTo(GpuMat_<T>& dst, Stream& stream = Stream::Null()) const
  80. {
  81. gridFindMinVal(src, dst, stream);
  82. }
  83. };
  84. template <class SrcPtr>
  85. __host__ Expr<FindMinValExprBody<SrcPtr> >
  86. minVal_(const SrcPtr& src)
  87. {
  88. FindMinValExprBody<SrcPtr> body;
  89. body.src = src;
  90. return makeExpr(body);
  91. }
  92. // maxVal
  93. template <class SrcPtr> struct FindMaxValExprBody
  94. {
  95. SrcPtr src;
  96. template <typename T>
  97. __host__ void assignTo(GpuMat_<T>& dst, Stream& stream = Stream::Null()) const
  98. {
  99. gridFindMaxVal(src, dst, stream);
  100. }
  101. };
  102. template <class SrcPtr>
  103. __host__ Expr<FindMaxValExprBody<SrcPtr> >
  104. maxVal_(const SrcPtr& src)
  105. {
  106. FindMaxValExprBody<SrcPtr> body;
  107. body.src = src;
  108. return makeExpr(body);
  109. }
  110. // minMaxVal
  111. template <class SrcPtr> struct FindMinMaxValExprBody
  112. {
  113. SrcPtr src;
  114. template <typename T>
  115. __host__ void assignTo(GpuMat_<T>& dst, Stream& stream = Stream::Null()) const
  116. {
  117. gridFindMinMaxVal(src, dst, stream);
  118. }
  119. };
  120. template <class SrcPtr>
  121. __host__ Expr<FindMinMaxValExprBody<SrcPtr> >
  122. minMaxVal_(const SrcPtr& src)
  123. {
  124. FindMinMaxValExprBody<SrcPtr> body;
  125. body.src = src;
  126. return makeExpr(body);
  127. }
  128. // countNonZero
  129. template <class SrcPtr> struct CountNonZeroExprBody
  130. {
  131. SrcPtr src;
  132. template <typename T>
  133. __host__ void assignTo(GpuMat_<T>& dst, Stream& stream = Stream::Null()) const
  134. {
  135. gridCountNonZero(src, dst, stream);
  136. }
  137. };
  138. template <class SrcPtr>
  139. __host__ Expr<CountNonZeroExprBody<SrcPtr> >
  140. countNonZero_(const SrcPtr& src)
  141. {
  142. CountNonZeroExprBody<SrcPtr> body;
  143. body.src = src;
  144. return makeExpr(body);
  145. }
  146. // reduceToRow
  147. template <class Reductor, class SrcPtr> struct ReduceToRowBody
  148. {
  149. SrcPtr src;
  150. template <typename T>
  151. __host__ void assignTo(GpuMat_<T>& dst, Stream& stream = Stream::Null()) const
  152. {
  153. gridReduceToRow<Reductor>(src, dst, stream);
  154. }
  155. };
  156. template <class Reductor, class SrcPtr>
  157. __host__ Expr<ReduceToRowBody<Reductor, SrcPtr> >
  158. reduceToRow_(const SrcPtr& src)
  159. {
  160. ReduceToRowBody<Reductor, SrcPtr> body;
  161. body.src = src;
  162. return makeExpr(body);
  163. }
  164. // reduceToColumn
  165. template <class Reductor, class SrcPtr> struct ReduceToColumnBody
  166. {
  167. SrcPtr src;
  168. template <typename T>
  169. __host__ void assignTo(GpuMat_<T>& dst, Stream& stream = Stream::Null()) const
  170. {
  171. gridReduceToColumn<Reductor>(src, dst, stream);
  172. }
  173. };
  174. template <class Reductor, class SrcPtr>
  175. __host__ Expr<ReduceToColumnBody<Reductor, SrcPtr> >
  176. reduceToColumn_(const SrcPtr& src)
  177. {
  178. ReduceToColumnBody<Reductor, SrcPtr> body;
  179. body.src = src;
  180. return makeExpr(body);
  181. }
  182. // histogram
  183. template <int BIN_COUNT, class SrcPtr> struct HistogramBody
  184. {
  185. SrcPtr src;
  186. template <typename T>
  187. __host__ void assignTo(GpuMat_<T>& dst, Stream& stream = Stream::Null()) const
  188. {
  189. gridHistogram<BIN_COUNT>(src, dst, stream);
  190. }
  191. };
  192. template <int BIN_COUNT, class SrcPtr>
  193. __host__ Expr<HistogramBody<BIN_COUNT, SrcPtr> >
  194. histogram_(const SrcPtr& src)
  195. {
  196. HistogramBody<BIN_COUNT, SrcPtr> body;
  197. body.src = src;
  198. return makeExpr(body);
  199. }
  200. // integral
  201. template <class SrcPtr> struct IntegralBody
  202. {
  203. SrcPtr src;
  204. template <typename T>
  205. __host__ void assignTo(GpuMat_<T>& dst, Stream& stream = Stream::Null()) const
  206. {
  207. gridIntegral(src, dst, stream);
  208. }
  209. };
  210. template <class SrcPtr>
  211. __host__ Expr<IntegralBody<SrcPtr> >
  212. integral_(const SrcPtr& src)
  213. {
  214. IntegralBody<SrcPtr> body;
  215. body.src = src;
  216. return makeExpr(body);
  217. }
  218. //! @}
  219. }}
  220. #endif