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// Third party copyrights are property of their respective owners.
16//
17// Redistribution and use in source and binary forms, with or without modification,
18// are permitted provided that the following conditions are met:
19//
20//   * Redistribution's of source code must retain the above copyright notice,
21//     this list of conditions and the following disclaimer.
22//
23//   * Redistribution's in binary form must reproduce the above copyright notice,
24//     this list of conditions and the following disclaimer in the documentation
25//     and/or other materials provided with the distribution.
26//
27//   * The name of the copyright holders may not be used to endorse or promote products
28//     derived from this software without specific prior written permission.
29//
30// This software is provided by the copyright holders and contributors "as is" and
31// any express or implied warranties, including, but not limited to, the implied
32// warranties of merchantability and fitness for a particular purpose are disclaimed.
33// In no event shall the Intel Corporation or contributors be liable for any direct,
34// indirect, incidental, special, exemplary, or consequential damages
35// (including, but not limited to, procurement of substitute goods or services;
36// loss of use, data, or profits; or business interruption) however caused
37// and on any theory of liability, whether in contract, strict liability,
38// or tort (including negligence or otherwise) arising in any way out of
39// the use of this software, even if advised of the possibility of such damage.
40//
41//M*/
42
43#ifndef __OPENCV_CUDAARITHM_HPP__
44#define __OPENCV_CUDAARITHM_HPP__
45
46#ifndef __cplusplus
47#  error cudaarithm.hpp header must be compiled as C++
48#endif
49
50#include "opencv2/core/cuda.hpp"
51
52/**
53  @addtogroup cuda
54  @{
55    @defgroup cudaarithm Operations on Matrices
56    @{
57        @defgroup cudaarithm_core Core Operations on Matrices
58        @defgroup cudaarithm_elem Per-element Operations
59        @defgroup cudaarithm_reduce Matrix Reductions
60        @defgroup cudaarithm_arithm Arithm Operations on Matrices
61    @}
62  @}
63 */
64
65namespace cv { namespace cuda {
66
67//! @addtogroup cudaarithm
68//! @{
69
70//! @addtogroup cudaarithm_elem
71//! @{
72
73/** @brief Computes a matrix-matrix or matrix-scalar sum.
74
75@param src1 First source matrix or scalar.
76@param src2 Second source matrix or scalar. Matrix should have the same size and type as src1 .
77@param dst Destination matrix that has the same size and number of channels as the input array(s).
78The depth is defined by dtype or src1 depth.
79@param mask Optional operation mask, 8-bit single channel array, that specifies elements of the
80destination array to be changed.
81@param dtype Optional depth of the output array.
82@param stream Stream for the asynchronous version.
83
84@sa add
85 */
86CV_EXPORTS void add(InputArray src1, InputArray src2, OutputArray dst, InputArray mask = noArray(), int dtype = -1, Stream& stream = Stream::Null());
87
88/** @brief Computes a matrix-matrix or matrix-scalar difference.
89
90@param src1 First source matrix or scalar.
91@param src2 Second source matrix or scalar. Matrix should have the same size and type as src1 .
92@param dst Destination matrix that has the same size and number of channels as the input array(s).
93The depth is defined by dtype or src1 depth.
94@param mask Optional operation mask, 8-bit single channel array, that specifies elements of the
95destination array to be changed.
96@param dtype Optional depth of the output array.
97@param stream Stream for the asynchronous version.
98
99@sa subtract
100 */
101CV_EXPORTS void subtract(InputArray src1, InputArray src2, OutputArray dst, InputArray mask = noArray(), int dtype = -1, Stream& stream = Stream::Null());
102
103/** @brief Computes a matrix-matrix or matrix-scalar per-element product.
104
105@param src1 First source matrix or scalar.
106@param src2 Second source matrix or scalar.
107@param dst Destination matrix that has the same size and number of channels as the input array(s).
108The depth is defined by dtype or src1 depth.
109@param scale Optional scale factor.
110@param dtype Optional depth of the output array.
111@param stream Stream for the asynchronous version.
112
113@sa multiply
114 */
115CV_EXPORTS void multiply(InputArray src1, InputArray src2, OutputArray dst, double scale = 1, int dtype = -1, Stream& stream = Stream::Null());
116
117/** @brief Computes a matrix-matrix or matrix-scalar division.
118
119@param src1 First source matrix or a scalar.
120@param src2 Second source matrix or scalar.
121@param dst Destination matrix that has the same size and number of channels as the input array(s).
122The depth is defined by dtype or src1 depth.
123@param scale Optional scale factor.
124@param dtype Optional depth of the output array.
125@param stream Stream for the asynchronous version.
126
127This function, in contrast to divide, uses a round-down rounding mode.
128
129@sa divide
130 */
131CV_EXPORTS void divide(InputArray src1, InputArray src2, OutputArray dst, double scale = 1, int dtype = -1, Stream& stream = Stream::Null());
132
133/** @brief Computes per-element absolute difference of two matrices (or of a matrix and scalar).
134
135@param src1 First source matrix or scalar.
136@param src2 Second source matrix or scalar.
137@param dst Destination matrix that has the same size and type as the input array(s).
138@param stream Stream for the asynchronous version.
139
140@sa absdiff
141 */
142CV_EXPORTS void absdiff(InputArray src1, InputArray src2, OutputArray dst, Stream& stream = Stream::Null());
143
144/** @brief Computes an absolute value of each matrix element.
145
146@param src Source matrix.
147@param dst Destination matrix with the same size and type as src .
148@param stream Stream for the asynchronous version.
149
150@sa abs
151 */
152CV_EXPORTS void abs(InputArray src, OutputArray dst, Stream& stream = Stream::Null());
153
154/** @brief Computes a square value of each matrix element.
155
156@param src Source matrix.
157@param dst Destination matrix with the same size and type as src .
158@param stream Stream for the asynchronous version.
159 */
160CV_EXPORTS void sqr(InputArray src, OutputArray dst, Stream& stream = Stream::Null());
161
162/** @brief Computes a square root of each matrix element.
163
164@param src Source matrix.
165@param dst Destination matrix with the same size and type as src .
166@param stream Stream for the asynchronous version.
167
168@sa sqrt
169 */
170CV_EXPORTS void sqrt(InputArray src, OutputArray dst, Stream& stream = Stream::Null());
171
172/** @brief Computes an exponent of each matrix element.
173
174@param src Source matrix.
175@param dst Destination matrix with the same size and type as src .
176@param stream Stream for the asynchronous version.
177
178@sa exp
179 */
180CV_EXPORTS void exp(InputArray src, OutputArray dst, Stream& stream = Stream::Null());
181
182/** @brief Computes a natural logarithm of absolute value of each matrix element.
183
184@param src Source matrix.
185@param dst Destination matrix with the same size and type as src .
186@param stream Stream for the asynchronous version.
187
188@sa log
189 */
190CV_EXPORTS void log(InputArray src, OutputArray dst, Stream& stream = Stream::Null());
191
192/** @brief Raises every matrix element to a power.
193
194@param src Source matrix.
195@param power Exponent of power.
196@param dst Destination matrix with the same size and type as src .
197@param stream Stream for the asynchronous version.
198
199The function pow raises every element of the input matrix to power :
200
201\f[\texttt{dst} (I) =  \fork{\texttt{src}(I)^power}{if \texttt{power} is integer}{|\texttt{src}(I)|^power}{otherwise}\f]
202
203@sa pow
204 */
205CV_EXPORTS void pow(InputArray src, double power, OutputArray dst, Stream& stream = Stream::Null());
206
207/** @brief Compares elements of two matrices (or of a matrix and scalar).
208
209@param src1 First source matrix or scalar.
210@param src2 Second source matrix or scalar.
211@param dst Destination matrix that has the same size and type as the input array(s).
212@param cmpop Flag specifying the relation between the elements to be checked:
213-   **CMP_EQ:** a(.) == b(.)
214-   **CMP_GT:** a(.) \> b(.)
215-   **CMP_GE:** a(.) \>= b(.)
216-   **CMP_LT:** a(.) \< b(.)
217-   **CMP_LE:** a(.) \<= b(.)
218-   **CMP_NE:** a(.) != b(.)
219@param stream Stream for the asynchronous version.
220
221@sa compare
222 */
223CV_EXPORTS void compare(InputArray src1, InputArray src2, OutputArray dst, int cmpop, Stream& stream = Stream::Null());
224
225/** @brief Performs a per-element bitwise inversion.
226
227@param src Source matrix.
228@param dst Destination matrix with the same size and type as src .
229@param mask Optional operation mask. 8-bit single channel image.
230@param stream Stream for the asynchronous version.
231 */
232CV_EXPORTS void bitwise_not(InputArray src, OutputArray dst, InputArray mask = noArray(), Stream& stream = Stream::Null());
233
234/** @brief Performs a per-element bitwise disjunction of two matrices (or of matrix and scalar).
235
236@param src1 First source matrix or scalar.
237@param src2 Second source matrix or scalar.
238@param dst Destination matrix that has the same size and type as the input array(s).
239@param mask Optional operation mask. 8-bit single channel image.
240@param stream Stream for the asynchronous version.
241 */
242CV_EXPORTS void bitwise_or(InputArray src1, InputArray src2, OutputArray dst, InputArray mask = noArray(), Stream& stream = Stream::Null());
243
244/** @brief Performs a per-element bitwise conjunction of two matrices (or of matrix and scalar).
245
246@param src1 First source matrix or scalar.
247@param src2 Second source matrix or scalar.
248@param dst Destination matrix that has the same size and type as the input array(s).
249@param mask Optional operation mask. 8-bit single channel image.
250@param stream Stream for the asynchronous version.
251 */
252CV_EXPORTS void bitwise_and(InputArray src1, InputArray src2, OutputArray dst, InputArray mask = noArray(), Stream& stream = Stream::Null());
253
254/** @brief Performs a per-element bitwise exclusive or operation of two matrices (or of matrix and scalar).
255
256@param src1 First source matrix or scalar.
257@param src2 Second source matrix or scalar.
258@param dst Destination matrix that has the same size and type as the input array(s).
259@param mask Optional operation mask. 8-bit single channel image.
260@param stream Stream for the asynchronous version.
261 */
262CV_EXPORTS void bitwise_xor(InputArray src1, InputArray src2, OutputArray dst, InputArray mask = noArray(), Stream& stream = Stream::Null());
263
264/** @brief Performs pixel by pixel right shift of an image by a constant value.
265
266@param src Source matrix. Supports 1, 3 and 4 channels images with integers elements.
267@param val Constant values, one per channel.
268@param dst Destination matrix with the same size and type as src .
269@param stream Stream for the asynchronous version.
270 */
271CV_EXPORTS void rshift(InputArray src, Scalar_<int> val, OutputArray dst, Stream& stream = Stream::Null());
272
273/** @brief Performs pixel by pixel right left of an image by a constant value.
274
275@param src Source matrix. Supports 1, 3 and 4 channels images with CV_8U , CV_16U or CV_32S
276depth.
277@param val Constant values, one per channel.
278@param dst Destination matrix with the same size and type as src .
279@param stream Stream for the asynchronous version.
280 */
281CV_EXPORTS void lshift(InputArray src, Scalar_<int> val, OutputArray dst, Stream& stream = Stream::Null());
282
283/** @brief Computes the per-element minimum of two matrices (or a matrix and a scalar).
284
285@param src1 First source matrix or scalar.
286@param src2 Second source matrix or scalar.
287@param dst Destination matrix that has the same size and type as the input array(s).
288@param stream Stream for the asynchronous version.
289
290@sa min
291 */
292CV_EXPORTS void min(InputArray src1, InputArray src2, OutputArray dst, Stream& stream = Stream::Null());
293
294/** @brief Computes the per-element maximum of two matrices (or a matrix and a scalar).
295
296@param src1 First source matrix or scalar.
297@param src2 Second source matrix or scalar.
298@param dst Destination matrix that has the same size and type as the input array(s).
299@param stream Stream for the asynchronous version.
300
301@sa max
302 */
303CV_EXPORTS void max(InputArray src1, InputArray src2, OutputArray dst, Stream& stream = Stream::Null());
304
305/** @brief Computes the weighted sum of two arrays.
306
307@param src1 First source array.
308@param alpha Weight for the first array elements.
309@param src2 Second source array of the same size and channel number as src1 .
310@param beta Weight for the second array elements.
311@param dst Destination array that has the same size and number of channels as the input arrays.
312@param gamma Scalar added to each sum.
313@param dtype Optional depth of the destination array. When both input arrays have the same depth,
314dtype can be set to -1, which will be equivalent to src1.depth().
315@param stream Stream for the asynchronous version.
316
317The function addWeighted calculates the weighted sum of two arrays as follows:
318
319\f[\texttt{dst} (I)= \texttt{saturate} ( \texttt{src1} (I)* \texttt{alpha} +  \texttt{src2} (I)* \texttt{beta} +  \texttt{gamma} )\f]
320
321where I is a multi-dimensional index of array elements. In case of multi-channel arrays, each
322channel is processed independently.
323
324@sa addWeighted
325 */
326CV_EXPORTS void addWeighted(InputArray src1, double alpha, InputArray src2, double beta, double gamma, OutputArray dst,
327                            int dtype = -1, Stream& stream = Stream::Null());
328
329//! adds scaled array to another one (dst = alpha*src1 + src2)
330static inline void scaleAdd(InputArray src1, double alpha, InputArray src2, OutputArray dst, Stream& stream = Stream::Null())
331{
332    addWeighted(src1, alpha, src2, 1.0, 0.0, dst, -1, stream);
333}
334
335/** @brief Applies a fixed-level threshold to each array element.
336
337@param src Source array (single-channel).
338@param dst Destination array with the same size and type as src .
339@param thresh Threshold value.
340@param maxval Maximum value to use with THRESH_BINARY and THRESH_BINARY_INV threshold types.
341@param type Threshold type. For details, see threshold . The THRESH_OTSU and THRESH_TRIANGLE
342threshold types are not supported.
343@param stream Stream for the asynchronous version.
344
345@sa threshold
346 */
347CV_EXPORTS double threshold(InputArray src, OutputArray dst, double thresh, double maxval, int type, Stream& stream = Stream::Null());
348
349/** @brief Computes magnitudes of complex matrix elements.
350
351@param xy Source complex matrix in the interleaved format ( CV_32FC2 ).
352@param magnitude Destination matrix of float magnitudes ( CV_32FC1 ).
353@param stream Stream for the asynchronous version.
354
355@sa magnitude
356 */
357CV_EXPORTS void magnitude(InputArray xy, OutputArray magnitude, Stream& stream = Stream::Null());
358
359/** @brief Computes squared magnitudes of complex matrix elements.
360
361@param xy Source complex matrix in the interleaved format ( CV_32FC2 ).
362@param magnitude Destination matrix of float magnitude squares ( CV_32FC1 ).
363@param stream Stream for the asynchronous version.
364 */
365CV_EXPORTS void magnitudeSqr(InputArray xy, OutputArray magnitude, Stream& stream = Stream::Null());
366
367/** @overload
368 computes magnitude of each (x(i), y(i)) vector
369 supports only floating-point source
370@param x Source matrix containing real components ( CV_32FC1 ).
371@param y Source matrix containing imaginary components ( CV_32FC1 ).
372@param magnitude Destination matrix of float magnitudes ( CV_32FC1 ).
373@param stream Stream for the asynchronous version.
374 */
375CV_EXPORTS void magnitude(InputArray x, InputArray y, OutputArray magnitude, Stream& stream = Stream::Null());
376
377/** @overload
378 computes squared magnitude of each (x(i), y(i)) vector
379 supports only floating-point source
380@param x Source matrix containing real components ( CV_32FC1 ).
381@param y Source matrix containing imaginary components ( CV_32FC1 ).
382@param magnitude Destination matrix of float magnitude squares ( CV_32FC1 ).
383@param stream Stream for the asynchronous version.
384*/
385CV_EXPORTS void magnitudeSqr(InputArray x, InputArray y, OutputArray magnitude, Stream& stream = Stream::Null());
386
387/** @brief Computes polar angles of complex matrix elements.
388
389@param x Source matrix containing real components ( CV_32FC1 ).
390@param y Source matrix containing imaginary components ( CV_32FC1 ).
391@param angle Destination matrix of angles ( CV_32FC1 ).
392@param angleInDegrees Flag for angles that must be evaluated in degrees.
393@param stream Stream for the asynchronous version.
394
395@sa phase
396 */
397CV_EXPORTS void phase(InputArray x, InputArray y, OutputArray angle, bool angleInDegrees = false, Stream& stream = Stream::Null());
398
399/** @brief Converts Cartesian coordinates into polar.
400
401@param x Source matrix containing real components ( CV_32FC1 ).
402@param y Source matrix containing imaginary components ( CV_32FC1 ).
403@param magnitude Destination matrix of float magnitudes ( CV_32FC1 ).
404@param angle Destination matrix of angles ( CV_32FC1 ).
405@param angleInDegrees Flag for angles that must be evaluated in degrees.
406@param stream Stream for the asynchronous version.
407
408@sa cartToPolar
409 */
410CV_EXPORTS void cartToPolar(InputArray x, InputArray y, OutputArray magnitude, OutputArray angle, bool angleInDegrees = false, Stream& stream = Stream::Null());
411
412/** @brief Converts polar coordinates into Cartesian.
413
414@param magnitude Source matrix containing magnitudes ( CV_32FC1 ).
415@param angle Source matrix containing angles ( CV_32FC1 ).
416@param x Destination matrix of real components ( CV_32FC1 ).
417@param y Destination matrix of imaginary components ( CV_32FC1 ).
418@param angleInDegrees Flag that indicates angles in degrees.
419@param stream Stream for the asynchronous version.
420 */
421CV_EXPORTS void polarToCart(InputArray magnitude, InputArray angle, OutputArray x, OutputArray y, bool angleInDegrees = false, Stream& stream = Stream::Null());
422
423//! @} cudaarithm_elem
424
425//! @addtogroup cudaarithm_core
426//! @{
427
428/** @brief Makes a multi-channel matrix out of several single-channel matrices.
429
430@param src Array/vector of source matrices.
431@param n Number of source matrices.
432@param dst Destination matrix.
433@param stream Stream for the asynchronous version.
434
435@sa merge
436 */
437CV_EXPORTS void merge(const GpuMat* src, size_t n, OutputArray dst, Stream& stream = Stream::Null());
438/** @overload */
439CV_EXPORTS void merge(const std::vector<GpuMat>& src, OutputArray dst, Stream& stream = Stream::Null());
440
441/** @brief Copies each plane of a multi-channel matrix into an array.
442
443@param src Source matrix.
444@param dst Destination array/vector of single-channel matrices.
445@param stream Stream for the asynchronous version.
446
447@sa split
448 */
449CV_EXPORTS void split(InputArray src, GpuMat* dst, Stream& stream = Stream::Null());
450/** @overload */
451CV_EXPORTS void split(InputArray src, std::vector<GpuMat>& dst, Stream& stream = Stream::Null());
452
453/** @brief Transposes a matrix.
454
455@param src1 Source matrix. 1-, 4-, 8-byte element sizes are supported for now.
456@param dst Destination matrix.
457@param stream Stream for the asynchronous version.
458
459@sa transpose
460 */
461CV_EXPORTS void transpose(InputArray src1, OutputArray dst, Stream& stream = Stream::Null());
462
463/** @brief Flips a 2D matrix around vertical, horizontal, or both axes.
464
465@param src Source matrix. Supports 1, 3 and 4 channels images with CV_8U, CV_16U, CV_32S or
466CV_32F depth.
467@param dst Destination matrix.
468@param flipCode Flip mode for the source:
469-   0 Flips around x-axis.
470-   \> 0 Flips around y-axis.
471-   \< 0 Flips around both axes.
472@param stream Stream for the asynchronous version.
473
474@sa flip
475 */
476CV_EXPORTS void flip(InputArray src, OutputArray dst, int flipCode, Stream& stream = Stream::Null());
477
478/** @brief Base class for transform using lookup table.
479 */
480class CV_EXPORTS LookUpTable : public Algorithm
481{
482public:
483    /** @brief Transforms the source matrix into the destination matrix using the given look-up table:
484    dst(I) = lut(src(I)) .
485
486    @param src Source matrix. CV_8UC1 and CV_8UC3 matrices are supported for now.
487    @param dst Destination matrix.
488    @param stream Stream for the asynchronous version.
489     */
490    virtual void transform(InputArray src, OutputArray dst, Stream& stream = Stream::Null()) = 0;
491};
492
493/** @brief Creates implementation for cuda::LookUpTable .
494
495@param lut Look-up table of 256 elements. It is a continuous CV_8U matrix.
496 */
497CV_EXPORTS Ptr<LookUpTable> createLookUpTable(InputArray lut);
498
499/** @brief Forms a border around an image.
500
501@param src Source image. CV_8UC1 , CV_8UC4 , CV_32SC1 , and CV_32FC1 types are supported.
502@param dst Destination image with the same type as src. The size is
503Size(src.cols+left+right, src.rows+top+bottom) .
504@param top
505@param bottom
506@param left
507@param right Number of pixels in each direction from the source image rectangle to extrapolate.
508For example: top=1, bottom=1, left=1, right=1 mean that 1 pixel-wide border needs to be built.
509@param borderType Border type. See borderInterpolate for details. BORDER_REFLECT101 ,
510BORDER_REPLICATE , BORDER_CONSTANT , BORDER_REFLECT and BORDER_WRAP are supported for now.
511@param value Border value.
512@param stream Stream for the asynchronous version.
513 */
514CV_EXPORTS void copyMakeBorder(InputArray src, OutputArray dst, int top, int bottom, int left, int right, int borderType,
515                               Scalar value = Scalar(), Stream& stream = Stream::Null());
516
517//! @} cudaarithm_core
518
519//! @addtogroup cudaarithm_reduce
520//! @{
521
522/** @brief Returns the norm of a matrix (or difference of two matrices).
523
524@param src1 Source matrix. Any matrices except 64F are supported.
525@param normType Norm type. NORM_L1 , NORM_L2 , and NORM_INF are supported for now.
526@param mask optional operation mask; it must have the same size as src1 and CV_8UC1 type.
527
528@sa norm
529 */
530CV_EXPORTS double norm(InputArray src1, int normType, InputArray mask = noArray());
531/** @overload */
532CV_EXPORTS void calcNorm(InputArray src, OutputArray dst, int normType, InputArray mask = noArray(), Stream& stream = Stream::Null());
533
534/** @brief Returns the difference of two matrices.
535
536@param src1 Source matrix. Any matrices except 64F are supported.
537@param src2 Second source matrix (if any) with the same size and type as src1.
538@param normType Norm type. NORM_L1 , NORM_L2 , and NORM_INF are supported for now.
539
540@sa norm
541 */
542CV_EXPORTS double norm(InputArray src1, InputArray src2, int normType=NORM_L2);
543/** @overload */
544CV_EXPORTS void calcNormDiff(InputArray src1, InputArray src2, OutputArray dst, int normType=NORM_L2, Stream& stream = Stream::Null());
545
546/** @brief Returns the sum of matrix elements.
547
548@param src Source image of any depth except for CV_64F .
549@param mask optional operation mask; it must have the same size as src1 and CV_8UC1 type.
550
551@sa sum
552 */
553CV_EXPORTS Scalar sum(InputArray src, InputArray mask = noArray());
554/** @overload */
555CV_EXPORTS void calcSum(InputArray src, OutputArray dst, InputArray mask = noArray(), Stream& stream = Stream::Null());
556
557/** @brief Returns the sum of absolute values for matrix elements.
558
559@param src Source image of any depth except for CV_64F .
560@param mask optional operation mask; it must have the same size as src1 and CV_8UC1 type.
561 */
562CV_EXPORTS Scalar absSum(InputArray src, InputArray mask = noArray());
563/** @overload */
564CV_EXPORTS void calcAbsSum(InputArray src, OutputArray dst, InputArray mask = noArray(), Stream& stream = Stream::Null());
565
566/** @brief Returns the squared sum of matrix elements.
567
568@param src Source image of any depth except for CV_64F .
569@param mask optional operation mask; it must have the same size as src1 and CV_8UC1 type.
570 */
571CV_EXPORTS Scalar sqrSum(InputArray src, InputArray mask = noArray());
572/** @overload */
573CV_EXPORTS void calcSqrSum(InputArray src, OutputArray dst, InputArray mask = noArray(), Stream& stream = Stream::Null());
574
575/** @brief Finds global minimum and maximum matrix elements and returns their values.
576
577@param src Single-channel source image.
578@param minVal Pointer to the returned minimum value. Use NULL if not required.
579@param maxVal Pointer to the returned maximum value. Use NULL if not required.
580@param mask Optional mask to select a sub-matrix.
581
582The function does not work with CV_64F images on GPUs with the compute capability \< 1.3.
583
584@sa minMaxLoc
585 */
586CV_EXPORTS void minMax(InputArray src, double* minVal, double* maxVal, InputArray mask = noArray());
587/** @overload */
588CV_EXPORTS void findMinMax(InputArray src, OutputArray dst, InputArray mask = noArray(), Stream& stream = Stream::Null());
589
590/** @brief Finds global minimum and maximum matrix elements and returns their values with locations.
591
592@param src Single-channel source image.
593@param minVal Pointer to the returned minimum value. Use NULL if not required.
594@param maxVal Pointer to the returned maximum value. Use NULL if not required.
595@param minLoc Pointer to the returned minimum location. Use NULL if not required.
596@param maxLoc Pointer to the returned maximum location. Use NULL if not required.
597@param mask Optional mask to select a sub-matrix.
598
599The function does not work with CV_64F images on GPU with the compute capability \< 1.3.
600
601@sa minMaxLoc
602 */
603CV_EXPORTS void minMaxLoc(InputArray src, double* minVal, double* maxVal, Point* minLoc, Point* maxLoc,
604                          InputArray mask = noArray());
605/** @overload */
606CV_EXPORTS void findMinMaxLoc(InputArray src, OutputArray minMaxVals, OutputArray loc,
607                              InputArray mask = noArray(), Stream& stream = Stream::Null());
608
609/** @brief Counts non-zero matrix elements.
610
611@param src Single-channel source image.
612
613The function does not work with CV_64F images on GPUs with the compute capability \< 1.3.
614
615@sa countNonZero
616 */
617CV_EXPORTS int countNonZero(InputArray src);
618/** @overload */
619CV_EXPORTS void countNonZero(InputArray src, OutputArray dst, Stream& stream = Stream::Null());
620
621/** @brief Reduces a matrix to a vector.
622
623@param mtx Source 2D matrix.
624@param vec Destination vector. Its size and type is defined by dim and dtype parameters.
625@param dim Dimension index along which the matrix is reduced. 0 means that the matrix is reduced
626to a single row. 1 means that the matrix is reduced to a single column.
627@param reduceOp Reduction operation that could be one of the following:
628-   **CV_REDUCE_SUM** The output is the sum of all rows/columns of the matrix.
629-   **CV_REDUCE_AVG** The output is the mean vector of all rows/columns of the matrix.
630-   **CV_REDUCE_MAX** The output is the maximum (column/row-wise) of all rows/columns of the
631matrix.
632-   **CV_REDUCE_MIN** The output is the minimum (column/row-wise) of all rows/columns of the
633matrix.
634@param dtype When it is negative, the destination vector will have the same type as the source
635matrix. Otherwise, its type will be CV_MAKE_TYPE(CV_MAT_DEPTH(dtype), mtx.channels()) .
636@param stream Stream for the asynchronous version.
637
638The function reduce reduces the matrix to a vector by treating the matrix rows/columns as a set of
6391D vectors and performing the specified operation on the vectors until a single row/column is
640obtained. For example, the function can be used to compute horizontal and vertical projections of a
641raster image. In case of CV_REDUCE_SUM and CV_REDUCE_AVG , the output may have a larger element
642bit-depth to preserve accuracy. And multi-channel arrays are also supported in these two reduction
643modes.
644
645@sa reduce
646 */
647CV_EXPORTS void reduce(InputArray mtx, OutputArray vec, int dim, int reduceOp, int dtype = -1, Stream& stream = Stream::Null());
648
649/** @brief Computes a mean value and a standard deviation of matrix elements.
650
651@param mtx Source matrix. CV_8UC1 matrices are supported for now.
652@param mean Mean value.
653@param stddev Standard deviation value.
654
655@sa meanStdDev
656 */
657CV_EXPORTS void meanStdDev(InputArray mtx, Scalar& mean, Scalar& stddev);
658/** @overload */
659CV_EXPORTS void meanStdDev(InputArray mtx, OutputArray dst, Stream& stream = Stream::Null());
660
661/** @brief Computes a standard deviation of integral images.
662
663@param src Source image. Only the CV_32SC1 type is supported.
664@param sqr Squared source image. Only the CV_32FC1 type is supported.
665@param dst Destination image with the same type and size as src .
666@param rect Rectangular window.
667@param stream Stream for the asynchronous version.
668 */
669CV_EXPORTS void rectStdDev(InputArray src, InputArray sqr, OutputArray dst, Rect rect, Stream& stream = Stream::Null());
670
671/** @brief Normalizes the norm or value range of an array.
672
673@param src Input array.
674@param dst Output array of the same size as src .
675@param alpha Norm value to normalize to or the lower range boundary in case of the range
676normalization.
677@param beta Upper range boundary in case of the range normalization; it is not used for the norm
678normalization.
679@param norm_type Normalization type ( NORM_MINMAX , NORM_L2 , NORM_L1 or NORM_INF ).
680@param dtype When negative, the output array has the same type as src; otherwise, it has the same
681number of channels as src and the depth =CV_MAT_DEPTH(dtype).
682@param mask Optional operation mask.
683@param stream Stream for the asynchronous version.
684
685@sa normalize
686 */
687CV_EXPORTS void normalize(InputArray src, OutputArray dst, double alpha, double beta,
688                          int norm_type, int dtype, InputArray mask = noArray(),
689                          Stream& stream = Stream::Null());
690
691/** @brief Computes an integral image.
692
693@param src Source image. Only CV_8UC1 images are supported for now.
694@param sum Integral image containing 32-bit unsigned integer values packed into CV_32SC1 .
695@param stream Stream for the asynchronous version.
696
697@sa integral
698 */
699CV_EXPORTS void integral(InputArray src, OutputArray sum, Stream& stream = Stream::Null());
700
701/** @brief Computes a squared integral image.
702
703@param src Source image. Only CV_8UC1 images are supported for now.
704@param sqsum Squared integral image containing 64-bit unsigned integer values packed into
705CV_64FC1 .
706@param stream Stream for the asynchronous version.
707 */
708CV_EXPORTS void sqrIntegral(InputArray src, OutputArray sqsum, Stream& stream = Stream::Null());
709
710//! @} cudaarithm_reduce
711
712//! @addtogroup cudaarithm_arithm
713//! @{
714
715/** @brief Performs generalized matrix multiplication.
716
717@param src1 First multiplied input matrix that should have CV_32FC1 , CV_64FC1 , CV_32FC2 , or
718CV_64FC2 type.
719@param src2 Second multiplied input matrix of the same type as src1 .
720@param alpha Weight of the matrix product.
721@param src3 Third optional delta matrix added to the matrix product. It should have the same type
722as src1 and src2 .
723@param beta Weight of src3 .
724@param dst Destination matrix. It has the proper size and the same type as input matrices.
725@param flags Operation flags:
726-   **GEMM_1_T** transpose src1
727-   **GEMM_2_T** transpose src2
728-   **GEMM_3_T** transpose src3
729@param stream Stream for the asynchronous version.
730
731The function performs generalized matrix multiplication similar to the gemm functions in BLAS level
7323. For example, gemm(src1, src2, alpha, src3, beta, dst, GEMM_1_T + GEMM_3_T) corresponds to
733
734\f[\texttt{dst} =  \texttt{alpha} \cdot \texttt{src1} ^T  \cdot \texttt{src2} +  \texttt{beta} \cdot \texttt{src3} ^T\f]
735
736@note Transposition operation doesn't support CV_64FC2 input type.
737
738@sa gemm
739 */
740CV_EXPORTS void gemm(InputArray src1, InputArray src2, double alpha,
741                     InputArray src3, double beta, OutputArray dst, int flags = 0, Stream& stream = Stream::Null());
742
743/** @brief Performs a per-element multiplication of two Fourier spectrums.
744
745@param src1 First spectrum.
746@param src2 Second spectrum with the same size and type as a .
747@param dst Destination spectrum.
748@param flags Mock parameter used for CPU/CUDA interfaces similarity.
749@param conjB Optional flag to specify if the second spectrum needs to be conjugated before the
750multiplication.
751@param stream Stream for the asynchronous version.
752
753Only full (not packed) CV_32FC2 complex spectrums in the interleaved format are supported for now.
754
755@sa mulSpectrums
756 */
757CV_EXPORTS void mulSpectrums(InputArray src1, InputArray src2, OutputArray dst, int flags, bool conjB=false, Stream& stream = Stream::Null());
758
759/** @brief Performs a per-element multiplication of two Fourier spectrums and scales the result.
760
761@param src1 First spectrum.
762@param src2 Second spectrum with the same size and type as a .
763@param dst Destination spectrum.
764@param flags Mock parameter used for CPU/CUDA interfaces similarity, simply add a `0` value.
765@param scale Scale constant.
766@param conjB Optional flag to specify if the second spectrum needs to be conjugated before the
767multiplication.
768@param stream Stream for the asynchronous version.
769
770Only full (not packed) CV_32FC2 complex spectrums in the interleaved format are supported for now.
771
772@sa mulSpectrums
773 */
774CV_EXPORTS void mulAndScaleSpectrums(InputArray src1, InputArray src2, OutputArray dst, int flags, float scale, bool conjB=false, Stream& stream = Stream::Null());
775
776/** @brief Performs a forward or inverse discrete Fourier transform (1D or 2D) of the floating point matrix.
777
778@param src Source matrix (real or complex).
779@param dst Destination matrix (real or complex).
780@param dft_size Size of a discrete Fourier transform.
781@param flags Optional flags:
782-   **DFT_ROWS** transforms each individual row of the source matrix.
783-   **DFT_SCALE** scales the result: divide it by the number of elements in the transform
784(obtained from dft_size ).
785-   **DFT_INVERSE** inverts DFT. Use for complex-complex cases (real-complex and complex-real
786cases are always forward and inverse, respectively).
787-   **DFT_REAL_OUTPUT** specifies the output as real. The source matrix is the result of
788real-complex transform, so the destination matrix must be real.
789@param stream Stream for the asynchronous version.
790
791Use to handle real matrices ( CV32FC1 ) and complex matrices in the interleaved format ( CV32FC2 ).
792
793The source matrix should be continuous, otherwise reallocation and data copying is performed. The
794function chooses an operation mode depending on the flags, size, and channel count of the source
795matrix:
796
797-   If the source matrix is complex and the output is not specified as real, the destination
798matrix is complex and has the dft_size size and CV_32FC2 type. The destination matrix
799contains a full result of the DFT (forward or inverse).
800-   If the source matrix is complex and the output is specified as real, the function assumes that
801its input is the result of the forward transform (see the next item). The destination matrix
802has the dft_size size and CV_32FC1 type. It contains the result of the inverse DFT.
803-   If the source matrix is real (its type is CV_32FC1 ), forward DFT is performed. The result of
804the DFT is packed into complex ( CV_32FC2 ) matrix. So, the width of the destination matrix
805is dft_size.width / 2 + 1 . But if the source is a single column, the height is reduced
806instead of the width.
807
808@sa dft
809 */
810CV_EXPORTS void dft(InputArray src, OutputArray dst, Size dft_size, int flags=0, Stream& stream = Stream::Null());
811
812/** @brief Base class for convolution (or cross-correlation) operator. :
813 */
814class CV_EXPORTS Convolution : public Algorithm
815{
816public:
817    /** @brief Computes a convolution (or cross-correlation) of two images.
818
819    @param image Source image. Only CV_32FC1 images are supported for now.
820    @param templ Template image. The size is not greater than the image size. The type is the same as
821    image .
822    @param result Result image. If image is *W x H* and templ is *w x h*, then result must be *W-w+1 x
823    H-h+1*.
824    @param ccorr Flags to evaluate cross-correlation instead of convolution.
825    @param stream Stream for the asynchronous version.
826     */
827    virtual void convolve(InputArray image, InputArray templ, OutputArray result, bool ccorr = false, Stream& stream = Stream::Null()) = 0;
828};
829
830/** @brief Creates implementation for cuda::Convolution .
831
832@param user_block_size Block size. If you leave default value Size(0,0) then automatic
833estimation of block size will be used (which is optimized for speed). By varying user_block_size
834you can reduce memory requirements at the cost of speed.
835 */
836CV_EXPORTS Ptr<Convolution> createConvolution(Size user_block_size = Size());
837
838//! @} cudaarithm_arithm
839
840//! @} cudaarithm
841
842}} // namespace cv { namespace cuda {
843
844#endif /* __OPENCV_CUDAARITHM_HPP__ */
845