cudaarithm.hpp 37.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
/*M///////////////////////////////////////////////////////////////////////////////////////
//
//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
//  By downloading, copying, installing or using the software you agree to this license.
//  If you do not agree to this license, do not download, install,
//  copy or use the software.
//
//
//                           License Agreement
//                For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
//   * Redistribution's of source code must retain the above copyright notice,
//     this list of conditions and the following disclaimer.
//
//   * Redistribution's in binary form must reproduce the above copyright notice,
//     this list of conditions and the following disclaimer in the documentation
//     and/or other materials provided with the distribution.
//
//   * The name of the copyright holders may not be used to endorse or promote products
//     derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/

S
sourin 已提交
43 44
#ifndef OPENCV_CUDAARITHM_HPP
#define OPENCV_CUDAARITHM_HPP
45 46

#ifndef __cplusplus
47
#  error cudaarithm.hpp header must be compiled as C++
48 49
#endif

50
#include "opencv2/core/cuda.hpp"
51

M
Maksim Shabunin 已提交
52 53 54 55 56 57 58 59 60 61 62 63 64
/**
  @addtogroup cuda
  @{
    @defgroup cudaarithm Operations on Matrices
    @{
        @defgroup cudaarithm_core Core Operations on Matrices
        @defgroup cudaarithm_elem Per-element Operations
        @defgroup cudaarithm_reduce Matrix Reductions
        @defgroup cudaarithm_arithm Arithm Operations on Matrices
    @}
  @}
 */

65
namespace cv { namespace cuda {
66

M
Maksim Shabunin 已提交
67 68 69 70 71 72 73 74 75 76 77 78 79
//! @addtogroup cudaarithm
//! @{

//! @addtogroup cudaarithm_elem
//! @{

/** @brief Computes a matrix-matrix or matrix-scalar sum.

@param src1 First source matrix or scalar.
@param src2 Second source matrix or scalar. Matrix should have the same size and type as src1 .
@param dst Destination matrix that has the same size and number of channels as the input array(s).
The depth is defined by dtype or src1 depth.
@param mask Optional operation mask, 8-bit single channel array, that specifies elements of the
80
destination array to be changed. The mask can be used only with single channel images.
M
Maksim Shabunin 已提交
81 82 83 84 85
@param dtype Optional depth of the output array.
@param stream Stream for the asynchronous version.

@sa add
 */
86
CV_EXPORTS void add(InputArray src1, InputArray src2, OutputArray dst, InputArray mask = noArray(), int dtype = -1, Stream& stream = Stream::Null());
87

M
Maksim Shabunin 已提交
88 89 90 91 92 93 94
/** @brief Computes a matrix-matrix or matrix-scalar difference.

@param src1 First source matrix or scalar.
@param src2 Second source matrix or scalar. Matrix should have the same size and type as src1 .
@param dst Destination matrix that has the same size and number of channels as the input array(s).
The depth is defined by dtype or src1 depth.
@param mask Optional operation mask, 8-bit single channel array, that specifies elements of the
95
destination array to be changed. The mask can be used only with single channel images.
M
Maksim Shabunin 已提交
96 97 98 99 100
@param dtype Optional depth of the output array.
@param stream Stream for the asynchronous version.

@sa subtract
 */
101
CV_EXPORTS void subtract(InputArray src1, InputArray src2, OutputArray dst, InputArray mask = noArray(), int dtype = -1, Stream& stream = Stream::Null());
102

M
Maksim Shabunin 已提交
103 104 105 106 107 108 109 110 111 112 113 114
/** @brief Computes a matrix-matrix or matrix-scalar per-element product.

@param src1 First source matrix or scalar.
@param src2 Second source matrix or scalar.
@param dst Destination matrix that has the same size and number of channels as the input array(s).
The depth is defined by dtype or src1 depth.
@param scale Optional scale factor.
@param dtype Optional depth of the output array.
@param stream Stream for the asynchronous version.

@sa multiply
 */
115
CV_EXPORTS void multiply(InputArray src1, InputArray src2, OutputArray dst, double scale = 1, int dtype = -1, Stream& stream = Stream::Null());
116

M
Maksim Shabunin 已提交
117 118 119 120 121 122 123 124 125 126 127 128 129 130
/** @brief Computes a matrix-matrix or matrix-scalar division.

@param src1 First source matrix or a scalar.
@param src2 Second source matrix or scalar.
@param dst Destination matrix that has the same size and number of channels as the input array(s).
The depth is defined by dtype or src1 depth.
@param scale Optional scale factor.
@param dtype Optional depth of the output array.
@param stream Stream for the asynchronous version.

This function, in contrast to divide, uses a round-down rounding mode.

@sa divide
 */
131 132
CV_EXPORTS void divide(InputArray src1, InputArray src2, OutputArray dst, double scale = 1, int dtype = -1, Stream& stream = Stream::Null());

M
Maksim Shabunin 已提交
133 134 135 136 137 138 139 140 141
/** @brief Computes per-element absolute difference of two matrices (or of a matrix and scalar).

@param src1 First source matrix or scalar.
@param src2 Second source matrix or scalar.
@param dst Destination matrix that has the same size and type as the input array(s).
@param stream Stream for the asynchronous version.

@sa absdiff
 */
142 143
CV_EXPORTS void absdiff(InputArray src1, InputArray src2, OutputArray dst, Stream& stream = Stream::Null());

M
Maksim Shabunin 已提交
144 145 146 147 148 149 150 151
/** @brief Computes an absolute value of each matrix element.

@param src Source matrix.
@param dst Destination matrix with the same size and type as src .
@param stream Stream for the asynchronous version.

@sa abs
 */
152
CV_EXPORTS void abs(InputArray src, OutputArray dst, Stream& stream = Stream::Null());
153

M
Maksim Shabunin 已提交
154 155 156 157 158 159
/** @brief Computes a square value of each matrix element.

@param src Source matrix.
@param dst Destination matrix with the same size and type as src .
@param stream Stream for the asynchronous version.
 */
160
CV_EXPORTS void sqr(InputArray src, OutputArray dst, Stream& stream = Stream::Null());
161

M
Maksim Shabunin 已提交
162 163 164 165 166 167 168 169
/** @brief Computes a square root of each matrix element.

@param src Source matrix.
@param dst Destination matrix with the same size and type as src .
@param stream Stream for the asynchronous version.

@sa sqrt
 */
170
CV_EXPORTS void sqrt(InputArray src, OutputArray dst, Stream& stream = Stream::Null());
171

M
Maksim Shabunin 已提交
172 173 174 175 176 177 178 179
/** @brief Computes an exponent of each matrix element.

@param src Source matrix.
@param dst Destination matrix with the same size and type as src .
@param stream Stream for the asynchronous version.

@sa exp
 */
180
CV_EXPORTS void exp(InputArray src, OutputArray dst, Stream& stream = Stream::Null());
181

M
Maksim Shabunin 已提交
182 183 184 185 186 187 188 189
/** @brief Computes a natural logarithm of absolute value of each matrix element.

@param src Source matrix.
@param dst Destination matrix with the same size and type as src .
@param stream Stream for the asynchronous version.

@sa log
 */
190
CV_EXPORTS void log(InputArray src, OutputArray dst, Stream& stream = Stream::Null());
191

M
Maksim Shabunin 已提交
192 193 194 195 196 197 198 199 200 201 202 203 204
/** @brief Raises every matrix element to a power.

@param src Source matrix.
@param power Exponent of power.
@param dst Destination matrix with the same size and type as src .
@param stream Stream for the asynchronous version.

The function pow raises every element of the input matrix to power :

\f[\texttt{dst} (I) =  \fork{\texttt{src}(I)^power}{if \texttt{power} is integer}{|\texttt{src}(I)|^power}{otherwise}\f]

@sa pow
 */
205 206
CV_EXPORTS void pow(InputArray src, double power, OutputArray dst, Stream& stream = Stream::Null());

M
Maksim Shabunin 已提交
207 208 209 210 211 212
/** @brief Compares elements of two matrices (or of a matrix and scalar).

@param src1 First source matrix or scalar.
@param src2 Second source matrix or scalar.
@param dst Destination matrix that has the same size and type as the input array(s).
@param cmpop Flag specifying the relation between the elements to be checked:
213
-   **CMP_EQ:** a(.) == b(.)
214 215
-   **CMP_GT:** a(.) \> b(.)
-   **CMP_GE:** a(.) \>= b(.)
216 217 218
-   **CMP_LT:** a(.) \< b(.)
-   **CMP_LE:** a(.) \<= b(.)
-   **CMP_NE:** a(.) != b(.)
M
Maksim Shabunin 已提交
219 220 221 222
@param stream Stream for the asynchronous version.

@sa compare
 */
223 224
CV_EXPORTS void compare(InputArray src1, InputArray src2, OutputArray dst, int cmpop, Stream& stream = Stream::Null());

M
Maksim Shabunin 已提交
225 226 227 228
/** @brief Performs a per-element bitwise inversion.

@param src Source matrix.
@param dst Destination matrix with the same size and type as src .
229 230
@param mask Optional operation mask, 8-bit single channel array, that specifies elements of the
destination array to be changed. The mask can be used only with single channel images.
M
Maksim Shabunin 已提交
231 232
@param stream Stream for the asynchronous version.
 */
233 234
CV_EXPORTS void bitwise_not(InputArray src, OutputArray dst, InputArray mask = noArray(), Stream& stream = Stream::Null());

M
Maksim Shabunin 已提交
235 236 237 238 239
/** @brief Performs a per-element bitwise disjunction of two matrices (or of matrix and scalar).

@param src1 First source matrix or scalar.
@param src2 Second source matrix or scalar.
@param dst Destination matrix that has the same size and type as the input array(s).
240 241
@param mask Optional operation mask, 8-bit single channel array, that specifies elements of the
destination array to be changed. The mask can be used only with single channel images.
M
Maksim Shabunin 已提交
242 243
@param stream Stream for the asynchronous version.
 */
244 245
CV_EXPORTS void bitwise_or(InputArray src1, InputArray src2, OutputArray dst, InputArray mask = noArray(), Stream& stream = Stream::Null());

M
Maksim Shabunin 已提交
246 247 248 249 250
/** @brief Performs a per-element bitwise conjunction of two matrices (or of matrix and scalar).

@param src1 First source matrix or scalar.
@param src2 Second source matrix or scalar.
@param dst Destination matrix that has the same size and type as the input array(s).
251 252
@param mask Optional operation mask, 8-bit single channel array, that specifies elements of the
destination array to be changed. The mask can be used only with single channel images.
M
Maksim Shabunin 已提交
253 254
@param stream Stream for the asynchronous version.
 */
255 256
CV_EXPORTS void bitwise_and(InputArray src1, InputArray src2, OutputArray dst, InputArray mask = noArray(), Stream& stream = Stream::Null());

M
Maksim Shabunin 已提交
257 258 259 260 261
/** @brief Performs a per-element bitwise exclusive or operation of two matrices (or of matrix and scalar).

@param src1 First source matrix or scalar.
@param src2 Second source matrix or scalar.
@param dst Destination matrix that has the same size and type as the input array(s).
262 263
@param mask Optional operation mask, 8-bit single channel array, that specifies elements of the
destination array to be changed. The mask can be used only with single channel images.
M
Maksim Shabunin 已提交
264 265
@param stream Stream for the asynchronous version.
 */
266 267
CV_EXPORTS void bitwise_xor(InputArray src1, InputArray src2, OutputArray dst, InputArray mask = noArray(), Stream& stream = Stream::Null());

M
Maksim Shabunin 已提交
268 269 270 271 272 273 274
/** @brief Performs pixel by pixel right shift of an image by a constant value.

@param src Source matrix. Supports 1, 3 and 4 channels images with integers elements.
@param val Constant values, one per channel.
@param dst Destination matrix with the same size and type as src .
@param stream Stream for the asynchronous version.
 */
275 276
CV_EXPORTS void rshift(InputArray src, Scalar_<int> val, OutputArray dst, Stream& stream = Stream::Null());

M
Maksim Shabunin 已提交
277 278
/** @brief Performs pixel by pixel right left of an image by a constant value.

279
@param src Source matrix. Supports 1, 3 and 4 channels images with CV_8U , CV_16U or CV_32S
M
Maksim Shabunin 已提交
280 281 282 283 284
depth.
@param val Constant values, one per channel.
@param dst Destination matrix with the same size and type as src .
@param stream Stream for the asynchronous version.
 */
285 286
CV_EXPORTS void lshift(InputArray src, Scalar_<int> val, OutputArray dst, Stream& stream = Stream::Null());

M
Maksim Shabunin 已提交
287 288 289 290 291 292 293 294 295
/** @brief Computes the per-element minimum of two matrices (or a matrix and a scalar).

@param src1 First source matrix or scalar.
@param src2 Second source matrix or scalar.
@param dst Destination matrix that has the same size and type as the input array(s).
@param stream Stream for the asynchronous version.

@sa min
 */
296 297
CV_EXPORTS void min(InputArray src1, InputArray src2, OutputArray dst, Stream& stream = Stream::Null());

M
Maksim Shabunin 已提交
298 299 300 301 302 303 304 305 306
/** @brief Computes the per-element maximum of two matrices (or a matrix and a scalar).

@param src1 First source matrix or scalar.
@param src2 Second source matrix or scalar.
@param dst Destination matrix that has the same size and type as the input array(s).
@param stream Stream for the asynchronous version.

@sa max
 */
307 308
CV_EXPORTS void max(InputArray src1, InputArray src2, OutputArray dst, Stream& stream = Stream::Null());

M
Maksim Shabunin 已提交
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329
/** @brief Computes the weighted sum of two arrays.

@param src1 First source array.
@param alpha Weight for the first array elements.
@param src2 Second source array of the same size and channel number as src1 .
@param beta Weight for the second array elements.
@param dst Destination array that has the same size and number of channels as the input arrays.
@param gamma Scalar added to each sum.
@param dtype Optional depth of the destination array. When both input arrays have the same depth,
dtype can be set to -1, which will be equivalent to src1.depth().
@param stream Stream for the asynchronous version.

The function addWeighted calculates the weighted sum of two arrays as follows:

\f[\texttt{dst} (I)= \texttt{saturate} ( \texttt{src1} (I)* \texttt{alpha} +  \texttt{src2} (I)* \texttt{beta} +  \texttt{gamma} )\f]

where I is a multi-dimensional index of array elements. In case of multi-channel arrays, each
channel is processed independently.

@sa addWeighted
 */
330
CV_EXPORTS void addWeighted(InputArray src1, double alpha, InputArray src2, double beta, double gamma, OutputArray dst,
331 332 333
                            int dtype = -1, Stream& stream = Stream::Null());

//! adds scaled array to another one (dst = alpha*src1 + src2)
334
static inline void scaleAdd(InputArray src1, double alpha, InputArray src2, OutputArray dst, Stream& stream = Stream::Null())
335 336 337
{
    addWeighted(src1, alpha, src2, 1.0, 0.0, dst, -1, stream);
}
338

M
Maksim Shabunin 已提交
339 340 341 342 343
/** @brief Applies a fixed-level threshold to each array element.

@param src Source array (single-channel).
@param dst Destination array with the same size and type as src .
@param thresh Threshold value.
344 345
@param maxval Maximum value to use with THRESH_BINARY and THRESH_BINARY_INV threshold types.
@param type Threshold type. For details, see threshold . The THRESH_OTSU and THRESH_TRIANGLE
M
Maksim Shabunin 已提交
346 347 348 349 350
threshold types are not supported.
@param stream Stream for the asynchronous version.

@sa threshold
 */
351 352
CV_EXPORTS double threshold(InputArray src, OutputArray dst, double thresh, double maxval, int type, Stream& stream = Stream::Null());

M
Maksim Shabunin 已提交
353 354
/** @brief Computes magnitudes of complex matrix elements.

355 356
@param xy Source complex matrix in the interleaved format ( CV_32FC2 ).
@param magnitude Destination matrix of float magnitudes ( CV_32FC1 ).
M
Maksim Shabunin 已提交
357 358 359 360
@param stream Stream for the asynchronous version.

@sa magnitude
 */
361 362
CV_EXPORTS void magnitude(InputArray xy, OutputArray magnitude, Stream& stream = Stream::Null());

M
Maksim Shabunin 已提交
363 364
/** @brief Computes squared magnitudes of complex matrix elements.

365 366
@param xy Source complex matrix in the interleaved format ( CV_32FC2 ).
@param magnitude Destination matrix of float magnitude squares ( CV_32FC1 ).
M
Maksim Shabunin 已提交
367 368
@param stream Stream for the asynchronous version.
 */
369 370
CV_EXPORTS void magnitudeSqr(InputArray xy, OutputArray magnitude, Stream& stream = Stream::Null());

M
Maksim Shabunin 已提交
371 372 373
/** @overload
 computes magnitude of each (x(i), y(i)) vector
 supports only floating-point source
374 375 376
@param x Source matrix containing real components ( CV_32FC1 ).
@param y Source matrix containing imaginary components ( CV_32FC1 ).
@param magnitude Destination matrix of float magnitudes ( CV_32FC1 ).
M
Maksim Shabunin 已提交
377 378
@param stream Stream for the asynchronous version.
 */
379 380
CV_EXPORTS void magnitude(InputArray x, InputArray y, OutputArray magnitude, Stream& stream = Stream::Null());

M
Maksim Shabunin 已提交
381 382 383
/** @overload
 computes squared magnitude of each (x(i), y(i)) vector
 supports only floating-point source
384 385 386
@param x Source matrix containing real components ( CV_32FC1 ).
@param y Source matrix containing imaginary components ( CV_32FC1 ).
@param magnitude Destination matrix of float magnitude squares ( CV_32FC1 ).
M
Maksim Shabunin 已提交
387 388
@param stream Stream for the asynchronous version.
*/
389 390
CV_EXPORTS void magnitudeSqr(InputArray x, InputArray y, OutputArray magnitude, Stream& stream = Stream::Null());

M
Maksim Shabunin 已提交
391 392
/** @brief Computes polar angles of complex matrix elements.

393 394 395
@param x Source matrix containing real components ( CV_32FC1 ).
@param y Source matrix containing imaginary components ( CV_32FC1 ).
@param angle Destination matrix of angles ( CV_32FC1 ).
M
Maksim Shabunin 已提交
396 397 398 399 400
@param angleInDegrees Flag for angles that must be evaluated in degrees.
@param stream Stream for the asynchronous version.

@sa phase
 */
401 402
CV_EXPORTS void phase(InputArray x, InputArray y, OutputArray angle, bool angleInDegrees = false, Stream& stream = Stream::Null());

M
Maksim Shabunin 已提交
403 404
/** @brief Converts Cartesian coordinates into polar.

405 406 407 408
@param x Source matrix containing real components ( CV_32FC1 ).
@param y Source matrix containing imaginary components ( CV_32FC1 ).
@param magnitude Destination matrix of float magnitudes ( CV_32FC1 ).
@param angle Destination matrix of angles ( CV_32FC1 ).
M
Maksim Shabunin 已提交
409 410 411 412 413
@param angleInDegrees Flag for angles that must be evaluated in degrees.
@param stream Stream for the asynchronous version.

@sa cartToPolar
 */
414 415
CV_EXPORTS void cartToPolar(InputArray x, InputArray y, OutputArray magnitude, OutputArray angle, bool angleInDegrees = false, Stream& stream = Stream::Null());

M
Maksim Shabunin 已提交
416 417
/** @brief Converts polar coordinates into Cartesian.

418 419 420 421
@param magnitude Source matrix containing magnitudes ( CV_32FC1 ).
@param angle Source matrix containing angles ( CV_32FC1 ).
@param x Destination matrix of real components ( CV_32FC1 ).
@param y Destination matrix of imaginary components ( CV_32FC1 ).
M
Maksim Shabunin 已提交
422 423 424
@param angleInDegrees Flag that indicates angles in degrees.
@param stream Stream for the asynchronous version.
 */
425 426
CV_EXPORTS void polarToCart(InputArray magnitude, InputArray angle, OutputArray x, OutputArray y, bool angleInDegrees = false, Stream& stream = Stream::Null());

M
Maksim Shabunin 已提交
427 428 429 430 431 432 433 434 435 436 437 438 439 440
//! @} cudaarithm_elem

//! @addtogroup cudaarithm_core
//! @{

/** @brief Makes a multi-channel matrix out of several single-channel matrices.

@param src Array/vector of source matrices.
@param n Number of source matrices.
@param dst Destination matrix.
@param stream Stream for the asynchronous version.

@sa merge
 */
441
CV_EXPORTS void merge(const GpuMat* src, size_t n, OutputArray dst, Stream& stream = Stream::Null());
M
Maksim Shabunin 已提交
442
/** @overload */
443 444
CV_EXPORTS void merge(const std::vector<GpuMat>& src, OutputArray dst, Stream& stream = Stream::Null());

M
Maksim Shabunin 已提交
445 446 447 448 449 450 451 452
/** @brief Copies each plane of a multi-channel matrix into an array.

@param src Source matrix.
@param dst Destination array/vector of single-channel matrices.
@param stream Stream for the asynchronous version.

@sa split
 */
453
CV_EXPORTS void split(InputArray src, GpuMat* dst, Stream& stream = Stream::Null());
M
Maksim Shabunin 已提交
454
/** @overload */
455 456
CV_EXPORTS void split(InputArray src, std::vector<GpuMat>& dst, Stream& stream = Stream::Null());

M
Maksim Shabunin 已提交
457 458 459 460 461 462 463 464
/** @brief Transposes a matrix.

@param src1 Source matrix. 1-, 4-, 8-byte element sizes are supported for now.
@param dst Destination matrix.
@param stream Stream for the asynchronous version.

@sa transpose
 */
465
CV_EXPORTS void transpose(InputArray src1, OutputArray dst, Stream& stream = Stream::Null());
466

M
Maksim Shabunin 已提交
467 468
/** @brief Flips a 2D matrix around vertical, horizontal, or both axes.

469 470
@param src Source matrix. Supports 1, 3 and 4 channels images with CV_8U, CV_16U, CV_32S or
CV_32F depth.
M
Maksim Shabunin 已提交
471 472 473 474 475 476 477 478 479
@param dst Destination matrix.
@param flipCode Flip mode for the source:
-   0 Flips around x-axis.
-   \> 0 Flips around y-axis.
-   \< 0 Flips around both axes.
@param stream Stream for the asynchronous version.

@sa flip
 */
480 481
CV_EXPORTS void flip(InputArray src, OutputArray dst, int flipCode, Stream& stream = Stream::Null());

M
Maksim Shabunin 已提交
482 483
/** @brief Base class for transform using lookup table.
 */
484 485 486
class CV_EXPORTS LookUpTable : public Algorithm
{
public:
M
Maksim Shabunin 已提交
487 488 489
    /** @brief Transforms the source matrix into the destination matrix using the given look-up table:
    dst(I) = lut(src(I)) .

490
    @param src Source matrix. CV_8UC1 and CV_8UC3 matrices are supported for now.
M
Maksim Shabunin 已提交
491 492 493
    @param dst Destination matrix.
    @param stream Stream for the asynchronous version.
     */
494 495 496
    virtual void transform(InputArray src, OutputArray dst, Stream& stream = Stream::Null()) = 0;
};

M
Maksim Shabunin 已提交
497 498
/** @brief Creates implementation for cuda::LookUpTable .

499
@param lut Look-up table of 256 elements. It is a continuous CV_8U matrix.
M
Maksim Shabunin 已提交
500
 */
501
CV_EXPORTS Ptr<LookUpTable> createLookUpTable(InputArray lut);
502

M
Maksim Shabunin 已提交
503 504
/** @brief Forms a border around an image.

505
@param src Source image. CV_8UC1 , CV_8UC4 , CV_32SC1 , and CV_32FC1 types are supported.
M
Maksim Shabunin 已提交
506 507 508 509 510 511 512
@param dst Destination image with the same type as src. The size is
Size(src.cols+left+right, src.rows+top+bottom) .
@param top
@param bottom
@param left
@param right Number of pixels in each direction from the source image rectangle to extrapolate.
For example: top=1, bottom=1, left=1, right=1 mean that 1 pixel-wide border needs to be built.
513 514
@param borderType Border type. See borderInterpolate for details. BORDER_REFLECT101 ,
BORDER_REPLICATE , BORDER_CONSTANT , BORDER_REFLECT and BORDER_WRAP are supported for now.
M
Maksim Shabunin 已提交
515 516 517
@param value Border value.
@param stream Stream for the asynchronous version.
 */
518 519 520
CV_EXPORTS void copyMakeBorder(InputArray src, OutputArray dst, int top, int bottom, int left, int right, int borderType,
                               Scalar value = Scalar(), Stream& stream = Stream::Null());

M
Maksim Shabunin 已提交
521 522 523 524 525 526 527 528
//! @} cudaarithm_core

//! @addtogroup cudaarithm_reduce
//! @{

/** @brief Returns the norm of a matrix (or difference of two matrices).

@param src1 Source matrix. Any matrices except 64F are supported.
529 530
@param normType Norm type. NORM_L1 , NORM_L2 , and NORM_INF are supported for now.
@param mask optional operation mask; it must have the same size as src1 and CV_8UC1 type.
M
Maksim Shabunin 已提交
531 532 533

@sa norm
 */
534 535 536
CV_EXPORTS double norm(InputArray src1, int normType, InputArray mask = noArray());
/** @overload */
CV_EXPORTS void calcNorm(InputArray src, OutputArray dst, int normType, InputArray mask = noArray(), Stream& stream = Stream::Null());
537

M
Maksim Shabunin 已提交
538 539 540 541
/** @brief Returns the difference of two matrices.

@param src1 Source matrix. Any matrices except 64F are supported.
@param src2 Second source matrix (if any) with the same size and type as src1.
542
@param normType Norm type. NORM_L1 , NORM_L2 , and NORM_INF are supported for now.
M
Maksim Shabunin 已提交
543 544 545

@sa norm
 */
546 547 548
CV_EXPORTS double norm(InputArray src1, InputArray src2, int normType=NORM_L2);
/** @overload */
CV_EXPORTS void calcNormDiff(InputArray src1, InputArray src2, OutputArray dst, int normType=NORM_L2, Stream& stream = Stream::Null());
549

M
Maksim Shabunin 已提交
550 551
/** @brief Returns the sum of matrix elements.

552 553
@param src Source image of any depth except for CV_64F .
@param mask optional operation mask; it must have the same size as src1 and CV_8UC1 type.
M
Maksim Shabunin 已提交
554 555 556

@sa sum
 */
557 558 559
CV_EXPORTS Scalar sum(InputArray src, InputArray mask = noArray());
/** @overload */
CV_EXPORTS void calcSum(InputArray src, OutputArray dst, InputArray mask = noArray(), Stream& stream = Stream::Null());
560

M
Maksim Shabunin 已提交
561 562
/** @brief Returns the sum of absolute values for matrix elements.

563 564
@param src Source image of any depth except for CV_64F .
@param mask optional operation mask; it must have the same size as src1 and CV_8UC1 type.
M
Maksim Shabunin 已提交
565
 */
566 567 568
CV_EXPORTS Scalar absSum(InputArray src, InputArray mask = noArray());
/** @overload */
CV_EXPORTS void calcAbsSum(InputArray src, OutputArray dst, InputArray mask = noArray(), Stream& stream = Stream::Null());
569

M
Maksim Shabunin 已提交
570 571
/** @brief Returns the squared sum of matrix elements.

572 573
@param src Source image of any depth except for CV_64F .
@param mask optional operation mask; it must have the same size as src1 and CV_8UC1 type.
M
Maksim Shabunin 已提交
574
 */
575 576 577
CV_EXPORTS Scalar sqrSum(InputArray src, InputArray mask = noArray());
/** @overload */
CV_EXPORTS void calcSqrSum(InputArray src, OutputArray dst, InputArray mask = noArray(), Stream& stream = Stream::Null());
578

M
Maksim Shabunin 已提交
579 580 581 582 583 584 585
/** @brief Finds global minimum and maximum matrix elements and returns their values.

@param src Single-channel source image.
@param minVal Pointer to the returned minimum value. Use NULL if not required.
@param maxVal Pointer to the returned maximum value. Use NULL if not required.
@param mask Optional mask to select a sub-matrix.

586
The function does not work with CV_64F images on GPUs with the compute capability \< 1.3.
M
Maksim Shabunin 已提交
587 588 589

@sa minMaxLoc
 */
590 591 592
CV_EXPORTS void minMax(InputArray src, double* minVal, double* maxVal, InputArray mask = noArray());
/** @overload */
CV_EXPORTS void findMinMax(InputArray src, OutputArray dst, InputArray mask = noArray(), Stream& stream = Stream::Null());
593

M
Maksim Shabunin 已提交
594 595 596 597 598 599 600 601
/** @brief Finds global minimum and maximum matrix elements and returns their values with locations.

@param src Single-channel source image.
@param minVal Pointer to the returned minimum value. Use NULL if not required.
@param maxVal Pointer to the returned maximum value. Use NULL if not required.
@param minLoc Pointer to the returned minimum location. Use NULL if not required.
@param maxLoc Pointer to the returned maximum location. Use NULL if not required.
@param mask Optional mask to select a sub-matrix.
602

603
The function does not work with CV_64F images on GPU with the compute capability \< 1.3.
M
Maksim Shabunin 已提交
604 605 606

@sa minMaxLoc
 */
607
CV_EXPORTS void minMaxLoc(InputArray src, double* minVal, double* maxVal, Point* minLoc, Point* maxLoc,
608 609 610 611
                          InputArray mask = noArray());
/** @overload */
CV_EXPORTS void findMinMaxLoc(InputArray src, OutputArray minMaxVals, OutputArray loc,
                              InputArray mask = noArray(), Stream& stream = Stream::Null());
612

M
Maksim Shabunin 已提交
613 614 615 616
/** @brief Counts non-zero matrix elements.

@param src Single-channel source image.

617
The function does not work with CV_64F images on GPUs with the compute capability \< 1.3.
M
Maksim Shabunin 已提交
618 619 620

@sa countNonZero
 */
621 622 623
CV_EXPORTS int countNonZero(InputArray src);
/** @overload */
CV_EXPORTS void countNonZero(InputArray src, OutputArray dst, Stream& stream = Stream::Null());
624

M
Maksim Shabunin 已提交
625 626 627 628 629 630 631
/** @brief Reduces a matrix to a vector.

@param mtx Source 2D matrix.
@param vec Destination vector. Its size and type is defined by dim and dtype parameters.
@param dim Dimension index along which the matrix is reduced. 0 means that the matrix is reduced
to a single row. 1 means that the matrix is reduced to a single column.
@param reduceOp Reduction operation that could be one of the following:
632 633 634
-   **CV_REDUCE_SUM** The output is the sum of all rows/columns of the matrix.
-   **CV_REDUCE_AVG** The output is the mean vector of all rows/columns of the matrix.
-   **CV_REDUCE_MAX** The output is the maximum (column/row-wise) of all rows/columns of the
M
Maksim Shabunin 已提交
635
matrix.
636
-   **CV_REDUCE_MIN** The output is the minimum (column/row-wise) of all rows/columns of the
M
Maksim Shabunin 已提交
637 638
matrix.
@param dtype When it is negative, the destination vector will have the same type as the source
639
matrix. Otherwise, its type will be CV_MAKE_TYPE(CV_MAT_DEPTH(dtype), mtx.channels()) .
M
Maksim Shabunin 已提交
640 641 642 643 644
@param stream Stream for the asynchronous version.

The function reduce reduces the matrix to a vector by treating the matrix rows/columns as a set of
1D vectors and performing the specified operation on the vectors until a single row/column is
obtained. For example, the function can be used to compute horizontal and vertical projections of a
645
raster image. In case of CV_REDUCE_SUM and CV_REDUCE_AVG , the output may have a larger element
M
Maksim Shabunin 已提交
646 647 648 649 650
bit-depth to preserve accuracy. And multi-channel arrays are also supported in these two reduction
modes.

@sa reduce
 */
651
CV_EXPORTS void reduce(InputArray mtx, OutputArray vec, int dim, int reduceOp, int dtype = -1, Stream& stream = Stream::Null());
652

M
Maksim Shabunin 已提交
653 654
/** @brief Computes a mean value and a standard deviation of matrix elements.

655
@param mtx Source matrix. CV_8UC1 matrices are supported for now.
M
Maksim Shabunin 已提交
656 657 658 659 660
@param mean Mean value.
@param stddev Standard deviation value.

@sa meanStdDev
 */
661 662 663
CV_EXPORTS void meanStdDev(InputArray mtx, Scalar& mean, Scalar& stddev);
/** @overload */
CV_EXPORTS void meanStdDev(InputArray mtx, OutputArray dst, Stream& stream = Stream::Null());
664

M
Maksim Shabunin 已提交
665 666
/** @brief Computes a standard deviation of integral images.

667 668
@param src Source image. Only the CV_32SC1 type is supported.
@param sqr Squared source image. Only the CV_32FC1 type is supported.
M
Maksim Shabunin 已提交
669 670 671 672
@param dst Destination image with the same type and size as src .
@param rect Rectangular window.
@param stream Stream for the asynchronous version.
 */
673 674
CV_EXPORTS void rectStdDev(InputArray src, InputArray sqr, OutputArray dst, Rect rect, Stream& stream = Stream::Null());

M
Maksim Shabunin 已提交
675 676 677 678 679 680 681 682
/** @brief Normalizes the norm or value range of an array.

@param src Input array.
@param dst Output array of the same size as src .
@param alpha Norm value to normalize to or the lower range boundary in case of the range
normalization.
@param beta Upper range boundary in case of the range normalization; it is not used for the norm
normalization.
683
@param norm_type Normalization type ( NORM_MINMAX , NORM_L2 , NORM_L1 or NORM_INF ).
M
Maksim Shabunin 已提交
684
@param dtype When negative, the output array has the same type as src; otherwise, it has the same
685
number of channels as src and the depth =CV_MAT_DEPTH(dtype).
M
Maksim Shabunin 已提交
686
@param mask Optional operation mask.
687
@param stream Stream for the asynchronous version.
M
Maksim Shabunin 已提交
688 689 690

@sa normalize
 */
691
CV_EXPORTS void normalize(InputArray src, OutputArray dst, double alpha, double beta,
692 693
                          int norm_type, int dtype, InputArray mask = noArray(),
                          Stream& stream = Stream::Null());
694

M
Maksim Shabunin 已提交
695 696
/** @brief Computes an integral image.

697 698
@param src Source image. Only CV_8UC1 images are supported for now.
@param sum Integral image containing 32-bit unsigned integer values packed into CV_32SC1 .
M
Maksim Shabunin 已提交
699 700 701 702
@param stream Stream for the asynchronous version.

@sa integral
 */
703
CV_EXPORTS void integral(InputArray src, OutputArray sum, Stream& stream = Stream::Null());
704

M
Maksim Shabunin 已提交
705 706
/** @brief Computes a squared integral image.

707
@param src Source image. Only CV_8UC1 images are supported for now.
M
Maksim Shabunin 已提交
708
@param sqsum Squared integral image containing 64-bit unsigned integer values packed into
709
CV_64FC1 .
M
Maksim Shabunin 已提交
710 711
@param stream Stream for the asynchronous version.
 */
712
CV_EXPORTS void sqrIntegral(InputArray src, OutputArray sqsum, Stream& stream = Stream::Null());
713

M
Maksim Shabunin 已提交
714 715 716 717 718 719 720
//! @} cudaarithm_reduce

//! @addtogroup cudaarithm_arithm
//! @{

/** @brief Performs generalized matrix multiplication.

721 722
@param src1 First multiplied input matrix that should have CV_32FC1 , CV_64FC1 , CV_32FC2 , or
CV_64FC2 type.
M
Maksim Shabunin 已提交
723 724 725 726 727 728 729
@param src2 Second multiplied input matrix of the same type as src1 .
@param alpha Weight of the matrix product.
@param src3 Third optional delta matrix added to the matrix product. It should have the same type
as src1 and src2 .
@param beta Weight of src3 .
@param dst Destination matrix. It has the proper size and the same type as input matrices.
@param flags Operation flags:
730 731 732
-   **GEMM_1_T** transpose src1
-   **GEMM_2_T** transpose src2
-   **GEMM_3_T** transpose src3
M
Maksim Shabunin 已提交
733 734 735
@param stream Stream for the asynchronous version.

The function performs generalized matrix multiplication similar to the gemm functions in BLAS level
736
3. For example, gemm(src1, src2, alpha, src3, beta, dst, GEMM_1_T + GEMM_3_T) corresponds to
M
Maksim Shabunin 已提交
737 738 739

\f[\texttt{dst} =  \texttt{alpha} \cdot \texttt{src1} ^T  \cdot \texttt{src2} +  \texttt{beta} \cdot \texttt{src3} ^T\f]

740
@note Transposition operation doesn't support CV_64FC2 input type.
M
Maksim Shabunin 已提交
741 742 743

@sa gemm
 */
744 745
CV_EXPORTS void gemm(InputArray src1, InputArray src2, double alpha,
                     InputArray src3, double beta, OutputArray dst, int flags = 0, Stream& stream = Stream::Null());
746

M
Maksim Shabunin 已提交
747 748 749 750 751 752 753 754 755 756
/** @brief Performs a per-element multiplication of two Fourier spectrums.

@param src1 First spectrum.
@param src2 Second spectrum with the same size and type as a .
@param dst Destination spectrum.
@param flags Mock parameter used for CPU/CUDA interfaces similarity.
@param conjB Optional flag to specify if the second spectrum needs to be conjugated before the
multiplication.
@param stream Stream for the asynchronous version.

757
Only full (not packed) CV_32FC2 complex spectrums in the interleaved format are supported for now.
M
Maksim Shabunin 已提交
758 759 760

@sa mulSpectrums
 */
761
CV_EXPORTS void mulSpectrums(InputArray src1, InputArray src2, OutputArray dst, int flags, bool conjB=false, Stream& stream = Stream::Null());
762

M
Maksim Shabunin 已提交
763 764 765 766 767
/** @brief Performs a per-element multiplication of two Fourier spectrums and scales the result.

@param src1 First spectrum.
@param src2 Second spectrum with the same size and type as a .
@param dst Destination spectrum.
S
StevenPuttemans 已提交
768
@param flags Mock parameter used for CPU/CUDA interfaces similarity, simply add a `0` value.
M
Maksim Shabunin 已提交
769 770 771 772 773
@param scale Scale constant.
@param conjB Optional flag to specify if the second spectrum needs to be conjugated before the
multiplication.
@param stream Stream for the asynchronous version.

774
Only full (not packed) CV_32FC2 complex spectrums in the interleaved format are supported for now.
M
Maksim Shabunin 已提交
775 776 777

@sa mulSpectrums
 */
778
CV_EXPORTS void mulAndScaleSpectrums(InputArray src1, InputArray src2, OutputArray dst, int flags, float scale, bool conjB=false, Stream& stream = Stream::Null());
779

M
Maksim Shabunin 已提交
780 781 782 783
/** @brief Performs a forward or inverse discrete Fourier transform (1D or 2D) of the floating point matrix.

@param src Source matrix (real or complex).
@param dst Destination matrix (real or complex).
784
@param dft_size Size of a discrete Fourier transform.
M
Maksim Shabunin 已提交
785
@param flags Optional flags:
786 787 788 789
-   **DFT_ROWS** transforms each individual row of the source matrix.
-   **DFT_SCALE** scales the result: divide it by the number of elements in the transform
(obtained from dft_size ).
-   **DFT_INVERSE** inverts DFT. Use for complex-complex cases (real-complex and complex-real
M
Maksim Shabunin 已提交
790
cases are always forward and inverse, respectively).
791
-   **DFT_COMPLEX_INPUT** Specifies that input is complex input with 2 channels.
792
-   **DFT_REAL_OUTPUT** specifies the output as real. The source matrix is the result of
M
Maksim Shabunin 已提交
793 794 795 796 797 798 799 800 801 802
real-complex transform, so the destination matrix must be real.
@param stream Stream for the asynchronous version.

Use to handle real matrices ( CV32FC1 ) and complex matrices in the interleaved format ( CV32FC2 ).

The source matrix should be continuous, otherwise reallocation and data copying is performed. The
function chooses an operation mode depending on the flags, size, and channel count of the source
matrix:

-   If the source matrix is complex and the output is not specified as real, the destination
803
matrix is complex and has the dft_size size and CV_32FC2 type. The destination matrix
M
Maksim Shabunin 已提交
804 805 806
contains a full result of the DFT (forward or inverse).
-   If the source matrix is complex and the output is specified as real, the function assumes that
its input is the result of the forward transform (see the next item). The destination matrix
807 808 809 810
has the dft_size size and CV_32FC1 type. It contains the result of the inverse DFT.
-   If the source matrix is real (its type is CV_32FC1 ), forward DFT is performed. The result of
the DFT is packed into complex ( CV_32FC2 ) matrix. So, the width of the destination matrix
is dft_size.width / 2 + 1 . But if the source is a single column, the height is reduced
M
Maksim Shabunin 已提交
811 812 813 814
instead of the width.

@sa dft
 */
815
CV_EXPORTS void dft(InputArray src, OutputArray dst, Size dft_size, int flags=0, Stream& stream = Stream::Null());
816

817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845
/** @brief Base class for DFT operator as a cv::Algorithm. :
 */
class CV_EXPORTS DFT : public Algorithm
{
public:
    /** @brief Computes an FFT of a given image.

    @param image Source image. Only CV_32FC1 images are supported for now.
    @param result Result image.
    @param stream Stream for the asynchronous version.
     */
    virtual void compute(InputArray image, OutputArray result, Stream& stream = Stream::Null()) = 0;
};

/** @brief Creates implementation for cuda::DFT.

@param dft_size The image size.
@param flags Optional flags:
-   **DFT_ROWS** transforms each individual row of the source matrix.
-   **DFT_SCALE** scales the result: divide it by the number of elements in the transform
(obtained from dft_size ).
-   **DFT_INVERSE** inverts DFT. Use for complex-complex cases (real-complex and complex-real
cases are always forward and inverse, respectively).
-   **DFT_COMPLEX_INPUT** Specifies that inputs will be complex with 2 channels.
-   **DFT_REAL_OUTPUT** specifies the output as real. The source matrix is the result of
real-complex transform, so the destination matrix must be real.
 */
CV_EXPORTS Ptr<DFT> createDFT(Size dft_size, int flags);

M
Maksim Shabunin 已提交
846 847
/** @brief Base class for convolution (or cross-correlation) operator. :
 */
848 849 850
class CV_EXPORTS Convolution : public Algorithm
{
public:
M
Maksim Shabunin 已提交
851 852
    /** @brief Computes a convolution (or cross-correlation) of two images.

853
    @param image Source image. Only CV_32FC1 images are supported for now.
M
Maksim Shabunin 已提交
854 855 856 857 858 859 860
    @param templ Template image. The size is not greater than the image size. The type is the same as
    image .
    @param result Result image. If image is *W x H* and templ is *w x h*, then result must be *W-w+1 x
    H-h+1*.
    @param ccorr Flags to evaluate cross-correlation instead of convolution.
    @param stream Stream for the asynchronous version.
     */
861 862 863
    virtual void convolve(InputArray image, InputArray templ, OutputArray result, bool ccorr = false, Stream& stream = Stream::Null()) = 0;
};

M
Maksim Shabunin 已提交
864 865
/** @brief Creates implementation for cuda::Convolution .

866 867
@param user_block_size Block size. If you leave default value Size(0,0) then automatic
estimation of block size will be used (which is optimized for speed). By varying user_block_size
M
Maksim Shabunin 已提交
868 869
you can reduce memory requirements at the cost of speed.
 */
870
CV_EXPORTS Ptr<Convolution> createConvolution(Size user_block_size = Size());
871

M
Maksim Shabunin 已提交
872 873 874 875
//! @} cudaarithm_arithm

//! @} cudaarithm

876
}} // namespace cv { namespace cuda {
877

S
sourin 已提交
878
#endif /* OPENCV_CUDAARITHM_HPP */