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 44 #pragma once 45 46 #ifndef __OPENCV_CUDEV_EXPR_REDUCTION_HPP__ 47 #define __OPENCV_CUDEV_EXPR_REDUCTION_HPP__ 48 49 #include "../common.hpp" 50 #include "../grid/reduce.hpp" 51 #include "../grid/histogram.hpp" 52 #include "../grid/integral.hpp" 53 #include "../grid/reduce_to_vec.hpp" 54 #include "../ptr2d/traits.hpp" 55 #include "expr.hpp" 56 57 namespace cv { namespace cudev { 58 59 //! @addtogroup cudev 60 //! @{ 61 62 // sum 63 64 template <class SrcPtr> struct SumExprBody 65 { 66 SrcPtr src; 67 68 template <typename T> 69 __host__ void assignTo(GpuMat_<T>& dst, Stream& stream = Stream::Null()) const 70 { 71 gridCalcSum(src, dst, stream); 72 } 73 }; 74 75 template <class SrcPtr> 76 __host__ Expr<SumExprBody<SrcPtr> > 77 sum_(const SrcPtr& src) 78 { 79 SumExprBody<SrcPtr> body; 80 body.src = src; 81 return makeExpr(body); 82 } 83 84 // minVal 85 86 template <class SrcPtr> struct FindMinValExprBody 87 { 88 SrcPtr src; 89 90 template <typename T> 91 __host__ void assignTo(GpuMat_<T>& dst, Stream& stream = Stream::Null()) const 92 { 93 gridFindMinVal(src, dst, stream); 94 } 95 }; 96 97 template <class SrcPtr> 98 __host__ Expr<FindMinValExprBody<SrcPtr> > 99 minVal_(const SrcPtr& src) 100 { 101 FindMinValExprBody<SrcPtr> body; 102 body.src = src; 103 return makeExpr(body); 104 } 105 106 // maxVal 107 108 template <class SrcPtr> struct FindMaxValExprBody 109 { 110 SrcPtr src; 111 112 template <typename T> 113 __host__ void assignTo(GpuMat_<T>& dst, Stream& stream = Stream::Null()) const 114 { 115 gridFindMaxVal(src, dst, stream); 116 } 117 }; 118 119 template <class SrcPtr> 120 __host__ Expr<FindMaxValExprBody<SrcPtr> > 121 maxVal_(const SrcPtr& src) 122 { 123 FindMaxValExprBody<SrcPtr> body; 124 body.src = src; 125 return makeExpr(body); 126 } 127 128 // minMaxVal 129 130 template <class SrcPtr> struct FindMinMaxValExprBody 131 { 132 SrcPtr src; 133 134 template <typename T> 135 __host__ void assignTo(GpuMat_<T>& dst, Stream& stream = Stream::Null()) const 136 { 137 gridFindMinMaxVal(src, dst, stream); 138 } 139 }; 140 141 template <class SrcPtr> 142 __host__ Expr<FindMinMaxValExprBody<SrcPtr> > 143 minMaxVal_(const SrcPtr& src) 144 { 145 FindMinMaxValExprBody<SrcPtr> body; 146 body.src = src; 147 return makeExpr(body); 148 } 149 150 // countNonZero 151 152 template <class SrcPtr> struct CountNonZeroExprBody 153 { 154 SrcPtr src; 155 156 template <typename T> 157 __host__ void assignTo(GpuMat_<T>& dst, Stream& stream = Stream::Null()) const 158 { 159 gridCountNonZero(src, dst, stream); 160 } 161 }; 162 163 template <class SrcPtr> 164 __host__ Expr<CountNonZeroExprBody<SrcPtr> > 165 countNonZero_(const SrcPtr& src) 166 { 167 CountNonZeroExprBody<SrcPtr> body; 168 body.src = src; 169 return makeExpr(body); 170 } 171 172 // reduceToRow 173 174 template <class Reductor, class SrcPtr> struct ReduceToRowBody 175 { 176 SrcPtr src; 177 178 template <typename T> 179 __host__ void assignTo(GpuMat_<T>& dst, Stream& stream = Stream::Null()) const 180 { 181 gridReduceToRow<Reductor>(src, dst, stream); 182 } 183 }; 184 185 template <class Reductor, class SrcPtr> 186 __host__ Expr<ReduceToRowBody<Reductor, SrcPtr> > 187 reduceToRow_(const SrcPtr& src) 188 { 189 ReduceToRowBody<Reductor, SrcPtr> body; 190 body.src = src; 191 return makeExpr(body); 192 } 193 194 // reduceToColumn 195 196 template <class Reductor, class SrcPtr> struct ReduceToColumnBody 197 { 198 SrcPtr src; 199 200 template <typename T> 201 __host__ void assignTo(GpuMat_<T>& dst, Stream& stream = Stream::Null()) const 202 { 203 gridReduceToColumn<Reductor>(src, dst, stream); 204 } 205 }; 206 207 template <class Reductor, class SrcPtr> 208 __host__ Expr<ReduceToColumnBody<Reductor, SrcPtr> > 209 reduceToColumn_(const SrcPtr& src) 210 { 211 ReduceToColumnBody<Reductor, SrcPtr> body; 212 body.src = src; 213 return makeExpr(body); 214 } 215 216 // histogram 217 218 template <int BIN_COUNT, class SrcPtr> struct HistogramBody 219 { 220 SrcPtr src; 221 222 template <typename T> 223 __host__ void assignTo(GpuMat_<T>& dst, Stream& stream = Stream::Null()) const 224 { 225 gridHistogram<BIN_COUNT>(src, dst, stream); 226 } 227 }; 228 229 template <int BIN_COUNT, class SrcPtr> 230 __host__ Expr<HistogramBody<BIN_COUNT, SrcPtr> > 231 histogram_(const SrcPtr& src) 232 { 233 HistogramBody<BIN_COUNT, SrcPtr> body; 234 body.src = src; 235 return makeExpr(body); 236 } 237 238 // integral 239 240 template <class SrcPtr> struct IntegralBody 241 { 242 SrcPtr src; 243 244 template <typename T> 245 __host__ void assignTo(GpuMat_<T>& dst, Stream& stream = Stream::Null()) const 246 { 247 gridIntegral(src, dst, stream); 248 } 249 }; 250 251 template <class SrcPtr> 252 __host__ Expr<IntegralBody<SrcPtr> > 253 integral_(const SrcPtr& src) 254 { 255 IntegralBody<SrcPtr> body; 256 body.src = src; 257 return makeExpr(body); 258 } 259 260 //! @} 261 262 }} 263 264 #endif 265