1793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/*M///////////////////////////////////////////////////////////////////////////////////////
2793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler//
3793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler//
5793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler//  By downloading, copying, installing or using the software you agree to this license.
6793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler//  If you do not agree to this license, do not download, install,
7793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler//  copy or use the software.
8793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler//
9793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler//
10793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler//                           License Agreement
11793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler//                For Open Source Computer Vision Library
12793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler//
13793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// Copyright (C) 2000-2015, Intel Corporation, all rights reserved.
14793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved.
15793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// Copyright (C) 2015, OpenCV Foundation, all rights reserved.
16793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// Copyright (C) 2015, Itseez Inc., all rights reserved.
17793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// Third party copyrights are property of their respective owners.
18793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler//
19793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// Redistribution and use in source and binary forms, with or without modification,
20793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// are permitted provided that the following conditions are met:
21793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler//
22793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler//   * Redistribution's of source code must retain the above copyright notice,
23793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler//     this list of conditions and the following disclaimer.
24793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler//
25793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler//   * Redistribution's in binary form must reproduce the above copyright notice,
26793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler//     this list of conditions and the following disclaimer in the documentation
27793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler//     and/or other materials provided with the distribution.
28793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler//
29793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler//   * The name of the copyright holders may not be used to endorse or promote products
30793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler//     derived from this software without specific prior written permission.
31793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler//
32793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// This software is provided by the copyright holders and contributors "as is" and
33793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// any express or implied warranties, including, but not limited to, the implied
34793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// warranties of merchantability and fitness for a particular purpose are disclaimed.
35793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// In no event shall the Intel Corporation or contributors be liable for any direct,
36793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// indirect, incidental, special, exemplary, or consequential damages
37793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// (including, but not limited to, procurement of substitute goods or services;
38793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// loss of use, data, or profits; or business interruption) however caused
39793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// and on any theory of liability, whether in contract, strict liability,
40793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// or tort (including negligence or otherwise) arising in any way out of
41793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// the use of this software, even if advised of the possibility of such damage.
42793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler//
43793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler//M*/
44793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
45793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#ifndef __OPENCV_CORE_HPP__
46793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#define __OPENCV_CORE_HPP__
47793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
48793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#ifndef __cplusplus
49793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#  error core.hpp header must be compiled as C++
50793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#endif
51793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
52793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#include "opencv2/core/cvdef.h"
53793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#include "opencv2/core/version.hpp"
54793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#include "opencv2/core/base.hpp"
55793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#include "opencv2/core/cvstd.hpp"
56793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#include "opencv2/core/traits.hpp"
57793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#include "opencv2/core/matx.hpp"
58793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#include "opencv2/core/types.hpp"
59793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#include "opencv2/core/mat.hpp"
60793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#include "opencv2/core/persistence.hpp"
61793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
62793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/**
63793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@defgroup core Core functionality
64793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@{
65793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @defgroup core_basic Basic structures
66793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @defgroup core_c C structures and operations
67793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @{
68793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        @defgroup core_c_glue Connections with C++
69793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @}
70793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @defgroup core_array Operations on arrays
71793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @defgroup core_xml XML/YAML Persistence
72793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @defgroup core_cluster Clustering
73793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @defgroup core_utils Utility and system functions and macros
74793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @{
75793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        @defgroup core_utils_neon NEON utilities
76793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @}
77793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @defgroup core_opengl OpenGL interoperability
78793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @defgroup core_ipp Intel IPP Asynchronous C/C++ Converters
79793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @defgroup core_optim Optimization Algorithms
80793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @defgroup core_directx DirectX interoperability
81793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @defgroup core_eigen Eigen support
82793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @defgroup core_opencl OpenCL support
83793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@}
84793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler */
85793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
86793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslernamespace cv {
87793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
88793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler//! @addtogroup core_utils
89793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler//! @{
90793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
91793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/*! @brief Class passed to an error.
92793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
93793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThis class encapsulates all or almost all necessary
94793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerinformation about the error happened in the program. The exception is
95793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerusually constructed and thrown implicitly via CV_Error and CV_Error_ macros.
96793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@see error
97793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler */
98793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerclass CV_EXPORTS Exception : public std::exception
99793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{
100793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerpublic:
101793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /*!
102793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler     Default constructor
103793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler     */
104793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    Exception();
105793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /*!
106793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler     Full constructor. Normally the constuctor is not called explicitly.
107793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler     Instead, the macros CV_Error(), CV_Error_() and CV_Assert() are used.
108793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    */
109793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    Exception(int _code, const String& _err, const String& _func, const String& _file, int _line);
110793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    virtual ~Exception() throw();
111793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
112793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /*!
113793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler     \return the error description and the context as a text string.
114793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    */
115793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    virtual const char *what() const throw();
116793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    void formatMessage();
117793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
118793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    String msg; ///< the formatted error message
119793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
120793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    int code; ///< error code @see CVStatus
121793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    String err; ///< error description
122793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    String func; ///< function name. Available only when the compiler supports getting it
123793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    String file; ///< source file name where the error has occured
124793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    int line; ///< line number in the source file where the error has occured
125793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler};
126793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
127793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/*! @brief Signals an error and raises the exception.
128793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
129793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerBy default the function prints information about the error to stderr,
130793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerthen it either stops if cv::setBreakOnError() had been called before or raises the exception.
131793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerIt is possible to alternate error processing by using cv::redirectError().
132793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param exc the exception raisen.
133793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@deprecated drop this version
134793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler */
135793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS void error( const Exception& exc );
136793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
137793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerenum SortFlags { SORT_EVERY_ROW    = 0, //!< each matrix row is sorted independently
138793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                 SORT_EVERY_COLUMN = 1, //!< each matrix column is sorted
139793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                                        //!< independently; this flag and the previous one are
140793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                                        //!< mutually exclusive.
141793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                 SORT_ASCENDING    = 0, //!< each matrix row is sorted in the ascending
142793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                                        //!< order.
143793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                 SORT_DESCENDING   = 16 //!< each matrix row is sorted in the
144793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                                        //!< descending order; this flag and the previous one are also
145793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                                        //!< mutually exclusive.
146793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler               };
147793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
148793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler//! @} core_utils
149793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
150793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler//! @addtogroup core
151793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler//! @{
152793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
153793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler//! Covariation flags
154793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerenum CovarFlags {
155793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** The output covariance matrix is calculated as:
156793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler       \f[\texttt{scale}   \cdot  [  \texttt{vects}  [0]-  \texttt{mean}  , \texttt{vects}  [1]-  \texttt{mean}  ,...]^T  \cdot  [ \texttt{vects}  [0]- \texttt{mean}  , \texttt{vects}  [1]- \texttt{mean}  ,...],\f]
157793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler       The covariance matrix will be nsamples x nsamples. Such an unusual covariance matrix is used
158793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler       for fast PCA of a set of very large vectors (see, for example, the EigenFaces technique for
159793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler       face recognition). Eigenvalues of this "scrambled" matrix match the eigenvalues of the true
160793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler       covariance matrix. The "true" eigenvectors can be easily calculated from the eigenvectors of
161793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler       the "scrambled" covariance matrix. */
162793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    COVAR_SCRAMBLED = 0,
163793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /**The output covariance matrix is calculated as:
164793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        \f[\texttt{scale}   \cdot  [  \texttt{vects}  [0]-  \texttt{mean}  , \texttt{vects}  [1]-  \texttt{mean}  ,...]  \cdot  [ \texttt{vects}  [0]- \texttt{mean}  , \texttt{vects}  [1]- \texttt{mean}  ,...]^T,\f]
165793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        covar will be a square matrix of the same size as the total number of elements in each input
166793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        vector. One and only one of COVAR_SCRAMBLED and COVAR_NORMAL must be specified.*/
167793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    COVAR_NORMAL    = 1,
168793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** If the flag is specified, the function does not calculate mean from
169793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        the input vectors but, instead, uses the passed mean vector. This is useful if mean has been
170793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        pre-calculated or known in advance, or if the covariance matrix is calculated by parts. In
171793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        this case, mean is not a mean vector of the input sub-set of vectors but rather the mean
172793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        vector of the whole set.*/
173793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    COVAR_USE_AVG   = 2,
174793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** If the flag is specified, the covariance matrix is scaled. In the
175793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        "normal" mode, scale is 1./nsamples . In the "scrambled" mode, scale is the reciprocal of the
176793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        total number of elements in each input vector. By default (if the flag is not specified), the
177793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        covariance matrix is not scaled ( scale=1 ).*/
178793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    COVAR_SCALE     = 4,
179793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** If the flag is
180793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        specified, all the input vectors are stored as rows of the samples matrix. mean should be a
181793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        single-row vector in this case.*/
182793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    COVAR_ROWS      = 8,
183793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** If the flag is
184793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        specified, all the input vectors are stored as columns of the samples matrix. mean should be a
185793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        single-column vector in this case.*/
186793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    COVAR_COLS      = 16
187793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler};
188793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
189793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler//! k-Means flags
190793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerenum KmeansFlags {
191793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** Select random initial centers in each attempt.*/
192793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    KMEANS_RANDOM_CENTERS     = 0,
193793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** Use kmeans++ center initialization by Arthur and Vassilvitskii [Arthur2007].*/
194793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    KMEANS_PP_CENTERS         = 2,
195793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** During the first (and possibly the only) attempt, use the
196793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        user-supplied labels instead of computing them from the initial centers. For the second and
197793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        further attempts, use the random or semi-random centers. Use one of KMEANS_\*_CENTERS flag
198793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        to specify the exact method.*/
199793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    KMEANS_USE_INITIAL_LABELS = 1
200793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler};
201793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
202793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler//! type of line
203793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerenum LineTypes {
204793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    FILLED  = -1,
205793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    LINE_4  = 4, //!< 4-connected line
206793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    LINE_8  = 8, //!< 8-connected line
207793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    LINE_AA = 16 //!< antialiased line
208793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler};
209793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
210793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler//! Only a subset of Hershey fonts
211793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler//! <http://sources.isc.org/utils/misc/hershey-font.txt> are supported
212793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerenum HersheyFonts {
213793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    FONT_HERSHEY_SIMPLEX        = 0, //!< normal size sans-serif font
214793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    FONT_HERSHEY_PLAIN          = 1, //!< small size sans-serif font
215793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    FONT_HERSHEY_DUPLEX         = 2, //!< normal size sans-serif font (more complex than FONT_HERSHEY_SIMPLEX)
216793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    FONT_HERSHEY_COMPLEX        = 3, //!< normal size serif font
217793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    FONT_HERSHEY_TRIPLEX        = 4, //!< normal size serif font (more complex than FONT_HERSHEY_COMPLEX)
218793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    FONT_HERSHEY_COMPLEX_SMALL  = 5, //!< smaller version of FONT_HERSHEY_COMPLEX
219793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    FONT_HERSHEY_SCRIPT_SIMPLEX = 6, //!< hand-writing style font
220793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    FONT_HERSHEY_SCRIPT_COMPLEX = 7, //!< more complex variant of FONT_HERSHEY_SCRIPT_SIMPLEX
221793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    FONT_ITALIC                 = 16 //!< flag for italic font
222793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler};
223793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
224793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerenum ReduceTypes { REDUCE_SUM = 0, //!< the output is the sum of all rows/columns of the matrix.
225793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                   REDUCE_AVG = 1, //!< the output is the mean vector of all rows/columns of the matrix.
226793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                   REDUCE_MAX = 2, //!< the output is the maximum (column/row-wise) of all rows/columns of the matrix.
227793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                   REDUCE_MIN = 3  //!< the output is the minimum (column/row-wise) of all rows/columns of the matrix.
228793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                 };
229793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
230793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
231793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Swaps two matrices
232793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
233793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS void swap(Mat& a, Mat& b);
234793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @overload */
235793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS void swap( UMat& a, UMat& b );
236793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
237793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler//! @} core
238793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
239793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler//! @addtogroup core_array
240793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler//! @{
241793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
242793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Computes the source location of an extrapolated pixel.
243793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
244793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function computes and returns the coordinate of a donor pixel corresponding to the specified
245793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerextrapolated pixel when using the specified extrapolation border mode. For example, if you use
246793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslercv::BORDER_WRAP mode in the horizontal direction, cv::BORDER_REFLECT_101 in the vertical direction and
247793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerwant to compute value of the "virtual" pixel Point(-5, 100) in a floating-point image img , it
248793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerlooks like:
249793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@code{.cpp}
250793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    float val = img.at<float>(borderInterpolate(100, img.rows, cv::BORDER_REFLECT_101),
251793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                              borderInterpolate(-5, img.cols, cv::BORDER_WRAP));
252793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@endcode
253793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerNormally, the function is not called directly. It is used inside filtering functions and also in
254793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslercopyMakeBorder.
255793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param p 0-based coordinate of the extrapolated pixel along one of the axes, likely \<0 or \>= len
256793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param len Length of the array along the corresponding axis.
257793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param borderType Border type, one of the cv::BorderTypes, except for cv::BORDER_TRANSPARENT and
258793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslercv::BORDER_ISOLATED . When borderType==cv::BORDER_CONSTANT , the function always returns -1, regardless
259793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerof p and len.
260793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
261793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa copyMakeBorder
262793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
263793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W int borderInterpolate(int p, int len, int borderType);
264793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
265793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Forms a border around an image.
266793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
267793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function copies the source image into the middle of the destination image. The areas to the
268793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerleft, to the right, above and below the copied source image will be filled with extrapolated
269793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerpixels. This is not what filtering functions based on it do (they extrapolate pixels on-fly), but
270793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerwhat other more complex functions, including your own, may do to simplify image boundary handling.
271793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
272793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function supports the mode when src is already in the middle of dst . In this case, the
273793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerfunction does not copy src itself but simply constructs the border, for example:
274793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
275793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@code{.cpp}
276793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    // let border be the same in all directions
277793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    int border=2;
278793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    // constructs a larger image to fit both the image and the border
279793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    Mat gray_buf(rgb.rows + border*2, rgb.cols + border*2, rgb.depth());
280793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    // select the middle part of it w/o copying data
281793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    Mat gray(gray_canvas, Rect(border, border, rgb.cols, rgb.rows));
282793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    // convert image from RGB to grayscale
283793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    cvtColor(rgb, gray, COLOR_RGB2GRAY);
284793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    // form a border in-place
285793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    copyMakeBorder(gray, gray_buf, border, border,
286793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                   border, border, BORDER_REPLICATE);
287793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    // now do some custom filtering ...
288793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    ...
289793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@endcode
290793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@note When the source image is a part (ROI) of a bigger image, the function will try to use the
291793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerpixels outside of the ROI to form a border. To disable this feature and always do extrapolation, as
292793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerif src was not a ROI, use borderType | BORDER_ISOLATED.
293793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
294793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src Source image.
295793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dst Destination image of the same type as src and the size Size(src.cols+left+right,
296793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslersrc.rows+top+bottom) .
297793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param top
298793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param bottom
299793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param left
300793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param right Parameter specifying how many pixels in each direction from the source image rectangle
301793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerto extrapolate. For example, top=1, bottom=1, left=1, right=1 mean that 1 pixel-wide border needs
302793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerto be built.
303793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param borderType Border type. See borderInterpolate for details.
304793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param value Border value if borderType==BORDER_CONSTANT .
305793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
306793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa  borderInterpolate
307793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
308793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void copyMakeBorder(InputArray src, OutputArray dst,
309793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                                 int top, int bottom, int left, int right,
310793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                                 int borderType, const Scalar& value = Scalar() );
311793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
312793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Calculates the per-element sum of two arrays or an array and a scalar.
313793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
314793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function add calculates:
315793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler- Sum of two arrays when both input arrays have the same size and the same number of channels:
316793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\f[\texttt{dst}(I) =  \texttt{saturate} ( \texttt{src1}(I) +  \texttt{src2}(I)) \quad \texttt{if mask}(I) \ne0\f]
317793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler- Sum of an array and a scalar when src2 is constructed from Scalar or has the same number of
318793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerelements as `src1.channels()`:
319793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\f[\texttt{dst}(I) =  \texttt{saturate} ( \texttt{src1}(I) +  \texttt{src2} ) \quad \texttt{if mask}(I) \ne0\f]
320793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler- Sum of a scalar and an array when src1 is constructed from Scalar or has the same number of
321793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerelements as `src2.channels()`:
322793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\f[\texttt{dst}(I) =  \texttt{saturate} ( \texttt{src1} +  \texttt{src2}(I) ) \quad \texttt{if mask}(I) \ne0\f]
323793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerwhere `I` is a multi-dimensional index of array elements. In case of multi-channel arrays, each
324793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerchannel is processed independently.
325793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
326793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe first function in the list above can be replaced with matrix expressions:
327793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@code{.cpp}
328793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    dst = src1 + src2;
329793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    dst += src1; // equivalent to add(dst, src1, dst);
330793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@endcode
331793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe input arrays and the output array can all have the same or different depths. For example, you
332793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslercan add a 16-bit unsigned array to a 8-bit signed array and store the sum as a 32-bit
333793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerfloating-point array. Depth of the output array is determined by the dtype parameter. In the second
334793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerand third cases above, as well as in the first case, when src1.depth() == src2.depth(), dtype can
335793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerbe set to the default -1. In this case, the output array will have the same depth as the input
336793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerarray, be it src1, src2 or both.
337793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@note Saturation is not applied when the output array has the depth CV_32S. You may even get
338793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerresult of an incorrect sign in the case of overflow.
339793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src1 first input array or a scalar.
340793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src2 second input array or a scalar.
341793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dst output array that has the same size and number of channels as the input array(s); the
342793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerdepth is defined by dtype or src1/src2.
343793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param mask optional operation mask - 8-bit single channel array, that specifies elements of the
344793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presleroutput array to be changed.
345793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dtype optional depth of the output array (see the discussion below).
346793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa subtract, addWeighted, scaleAdd, Mat::convertTo
347793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
348793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void add(InputArray src1, InputArray src2, OutputArray dst,
349793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                      InputArray mask = noArray(), int dtype = -1);
350793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
351793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Calculates the per-element difference between two arrays or array and a scalar.
352793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
353793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function subtract calculates:
354793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler- Difference between two arrays, when both input arrays have the same size and the same number of
355793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerchannels:
356793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    \f[\texttt{dst}(I) =  \texttt{saturate} ( \texttt{src1}(I) -  \texttt{src2}(I)) \quad \texttt{if mask}(I) \ne0\f]
357793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler- Difference between an array and a scalar, when src2 is constructed from Scalar or has the same
358793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslernumber of elements as `src1.channels()`:
359793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    \f[\texttt{dst}(I) =  \texttt{saturate} ( \texttt{src1}(I) -  \texttt{src2} ) \quad \texttt{if mask}(I) \ne0\f]
360793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler- Difference between a scalar and an array, when src1 is constructed from Scalar or has the same
361793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslernumber of elements as `src2.channels()`:
362793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    \f[\texttt{dst}(I) =  \texttt{saturate} ( \texttt{src1} -  \texttt{src2}(I) ) \quad \texttt{if mask}(I) \ne0\f]
363793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler- The reverse difference between a scalar and an array in the case of `SubRS`:
364793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    \f[\texttt{dst}(I) =  \texttt{saturate} ( \texttt{src2} -  \texttt{src1}(I) ) \quad \texttt{if mask}(I) \ne0\f]
365793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerwhere I is a multi-dimensional index of array elements. In case of multi-channel arrays, each
366793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerchannel is processed independently.
367793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
368793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe first function in the list above can be replaced with matrix expressions:
369793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@code{.cpp}
370793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    dst = src1 - src2;
371793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    dst -= src1; // equivalent to subtract(dst, src1, dst);
372793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@endcode
373793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe input arrays and the output array can all have the same or different depths. For example, you
374793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslercan subtract to 8-bit unsigned arrays and store the difference in a 16-bit signed array. Depth of
375793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerthe output array is determined by dtype parameter. In the second and third cases above, as well as
376793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerin the first case, when src1.depth() == src2.depth(), dtype can be set to the default -1. In this
377793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslercase the output array will have the same depth as the input array, be it src1, src2 or both.
378793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@note Saturation is not applied when the output array has the depth CV_32S. You may even get
379793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerresult of an incorrect sign in the case of overflow.
380793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src1 first input array or a scalar.
381793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src2 second input array or a scalar.
382793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dst output array of the same size and the same number of channels as the input array.
383793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param mask optional operation mask; this is an 8-bit single channel array that specifies elements
384793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerof the output array to be changed.
385793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dtype optional depth of the output array
386793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa  add, addWeighted, scaleAdd, Mat::convertTo
387793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler  */
388793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void subtract(InputArray src1, InputArray src2, OutputArray dst,
389793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                           InputArray mask = noArray(), int dtype = -1);
390793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
391793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
392793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Calculates the per-element scaled product of two arrays.
393793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
394793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function multiply calculates the per-element product of two arrays:
395793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
396793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\f[\texttt{dst} (I)= \texttt{saturate} ( \texttt{scale} \cdot \texttt{src1} (I)  \cdot \texttt{src2} (I))\f]
397793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
398793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThere is also a @ref MatrixExpressions -friendly variant of the first function. See Mat::mul .
399793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
400793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerFor a not-per-element matrix product, see gemm .
401793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
402793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@note Saturation is not applied when the output array has the depth
403793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_32S. You may even get result of an incorrect sign in the case of
404793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presleroverflow.
405793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src1 first input array.
406793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src2 second input array of the same size and the same type as src1.
407793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dst output array of the same size and type as src1.
408793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param scale optional scale factor.
409793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dtype optional depth of the output array
410793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa add, subtract, divide, scaleAdd, addWeighted, accumulate, accumulateProduct, accumulateSquare,
411793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerMat::convertTo
412793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
413793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void multiply(InputArray src1, InputArray src2,
414793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                           OutputArray dst, double scale = 1, int dtype = -1);
415793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
416793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Performs per-element division of two arrays or a scalar by an array.
417793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
418793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe functions divide divide one array by another:
419793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\f[\texttt{dst(I) = saturate(src1(I)*scale/src2(I))}\f]
420793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presleror a scalar by an array when there is no src1 :
421793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\f[\texttt{dst(I) = saturate(scale/src2(I))}\f]
422793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
423793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerWhen src2(I) is zero, dst(I) will also be zero. Different channels of
424793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslermulti-channel arrays are processed independently.
425793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
426793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@note Saturation is not applied when the output array has the depth CV_32S. You may even get
427793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerresult of an incorrect sign in the case of overflow.
428793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src1 first input array.
429793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src2 second input array of the same size and type as src1.
430793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param scale scalar factor.
431793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dst output array of the same size and type as src2.
432793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dtype optional depth of the output array; if -1, dst will have depth src2.depth(), but in
433793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslercase of an array-by-array division, you can only pass -1 when src1.depth()==src2.depth().
434793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa  multiply, add, subtract
435793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
436793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void divide(InputArray src1, InputArray src2, OutputArray dst,
437793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                         double scale = 1, int dtype = -1);
438793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
439793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @overload */
440793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void divide(double scale, InputArray src2,
441793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                         OutputArray dst, int dtype = -1);
442793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
443793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Calculates the sum of a scaled array and another array.
444793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
445793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function scaleAdd is one of the classical primitive linear algebra operations, known as DAXPY
446793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presleror SAXPY in [BLAS](http://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms). It calculates
447793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerthe sum of a scaled array and another array:
448793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\f[\texttt{dst} (I)= \texttt{scale} \cdot \texttt{src1} (I) +  \texttt{src2} (I)\f]
449793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function can also be emulated with a matrix expression, for example:
450793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@code{.cpp}
451793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    Mat A(3, 3, CV_64F);
452793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    ...
453793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    A.row(0) = A.row(1)*2 + A.row(2);
454793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@endcode
455793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src1 first input array.
456793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param alpha scale factor for the first array.
457793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src2 second input array of the same size and type as src1.
458793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dst output array of the same size and type as src1.
459793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa add, addWeighted, subtract, Mat::dot, Mat::convertTo
460793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
461793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void scaleAdd(InputArray src1, double alpha, InputArray src2, OutputArray dst);
462793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
463793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Calculates the weighted sum of two arrays.
464793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
465793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function addWeighted calculates the weighted sum of two arrays as follows:
466793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\f[\texttt{dst} (I)= \texttt{saturate} ( \texttt{src1} (I)* \texttt{alpha} +  \texttt{src2} (I)* \texttt{beta} +  \texttt{gamma} )\f]
467793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerwhere I is a multi-dimensional index of array elements. In case of multi-channel arrays, each
468793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerchannel is processed independently.
469793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function can be replaced with a matrix expression:
470793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@code{.cpp}
471793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    dst = src1*alpha + src2*beta + gamma;
472793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@endcode
473793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@note Saturation is not applied when the output array has the depth CV_32S. You may even get
474793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerresult of an incorrect sign in the case of overflow.
475793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src1 first input array.
476793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param alpha weight of the first array elements.
477793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src2 second input array of the same size and channel number as src1.
478793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param beta weight of the second array elements.
479793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param gamma scalar added to each sum.
480793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dst output array that has the same size and number of channels as the input arrays.
481793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dtype optional depth of the output array; when both input arrays have the same depth, dtype
482793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslercan be set to -1, which will be equivalent to src1.depth().
483793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa  add, subtract, scaleAdd, Mat::convertTo
484793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
485793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void addWeighted(InputArray src1, double alpha, InputArray src2,
486793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                              double beta, double gamma, OutputArray dst, int dtype = -1);
487793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
488793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Scales, calculates absolute values, and converts the result to 8-bit.
489793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
490793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerOn each element of the input array, the function convertScaleAbs
491793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerperforms three operations sequentially: scaling, taking an absolute
492793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslervalue, conversion to an unsigned 8-bit type:
493793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\f[\texttt{dst} (I)= \texttt{saturate\_cast<uchar>} (| \texttt{src} (I)* \texttt{alpha} +  \texttt{beta} |)\f]
494793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerIn case of multi-channel arrays, the function processes each channel
495793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerindependently. When the output is not 8-bit, the operation can be
496793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presleremulated by calling the Mat::convertTo method (or by using matrix
497793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerexpressions) and then by calculating an absolute value of the result.
498793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerFor example:
499793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@code{.cpp}
500793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    Mat_<float> A(30,30);
501793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    randu(A, Scalar(-100), Scalar(100));
502793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    Mat_<float> B = A*5 + 3;
503793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    B = abs(B);
504793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    // Mat_<float> B = abs(A*5+3) will also do the job,
505793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    // but it will allocate a temporary matrix
506793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@endcode
507793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src input array.
508793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dst output array.
509793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param alpha optional scale factor.
510793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param beta optional delta added to the scaled values.
511793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa  Mat::convertTo, cv::abs(const Mat&)
512793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
513793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void convertScaleAbs(InputArray src, OutputArray dst,
514793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                                  double alpha = 1, double beta = 0);
515793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
516793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Performs a look-up table transform of an array.
517793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
518793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function LUT fills the output array with values from the look-up table. Indices of the entries
519793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerare taken from the input array. That is, the function processes each element of src as follows:
520793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\f[\texttt{dst} (I)  \leftarrow \texttt{lut(src(I) + d)}\f]
521793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerwhere
522793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\f[d =  \fork{0}{if \texttt{src} has depth \texttt{CV\_8U}}{128}{if \texttt{src} has depth \texttt{CV\_8S}}\f]
523793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src input array of 8-bit elements.
524793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param lut look-up table of 256 elements; in case of multi-channel input array, the table should
525793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslereither have a single channel (in this case the same table is used for all channels) or the same
526793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslernumber of channels as in the input array.
527793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dst output array of the same size and number of channels as src, and the same depth as lut.
528793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa  convertScaleAbs, Mat::convertTo
529793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
530793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void LUT(InputArray src, InputArray lut, OutputArray dst);
531793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
532793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Calculates the sum of array elements.
533793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
534793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe functions sum calculate and return the sum of array elements,
535793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerindependently for each channel.
536793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src input array that must have from 1 to 4 channels.
537793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa  countNonZero, mean, meanStdDev, norm, minMaxLoc, reduce
538793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
539793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_AS(sumElems) Scalar sum(InputArray src);
540793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
541793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Counts non-zero array elements.
542793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
543793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function returns the number of non-zero elements in src :
544793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\f[\sum _{I: \; \texttt{src} (I) \ne0 } 1\f]
545793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src single-channel array.
546793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa  mean, meanStdDev, norm, minMaxLoc, calcCovarMatrix
547793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
548793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W int countNonZero( InputArray src );
549793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
550793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Returns the list of locations of non-zero pixels
551793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
552793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerGiven a binary matrix (likely returned from an operation such
553793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presleras threshold(), compare(), >, ==, etc, return all of
554793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerthe non-zero indices as a cv::Mat or std::vector<cv::Point> (x,y)
555793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerFor example:
556793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@code{.cpp}
557793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    cv::Mat binaryImage; // input, binary image
558793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    cv::Mat locations;   // output, locations of non-zero pixels
559793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    cv::findNonZero(binaryImage, locations);
560793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
561793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    // access pixel coordinates
562793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    Point pnt = locations.at<Point>(i);
563793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@endcode
564793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presleror
565793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@code{.cpp}
566793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    cv::Mat binaryImage; // input, binary image
567793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    vector<Point> locations;   // output, locations of non-zero pixels
568793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    cv::findNonZero(binaryImage, locations);
569793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
570793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    // access pixel coordinates
571793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    Point pnt = locations[i];
572793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@endcode
573793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src single-channel array (type CV_8UC1)
574793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param idx the output array, type of cv::Mat or std::vector<Point>, corresponding to non-zero indices in the input
575793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
576793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void findNonZero( InputArray src, OutputArray idx );
577793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
578793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Calculates an average (mean) of array elements.
579793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
580793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function mean calculates the mean value M of array elements,
581793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerindependently for each channel, and return it:
582793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\f[\begin{array}{l} N =  \sum _{I: \; \texttt{mask} (I) \ne 0} 1 \\ M_c =  \left ( \sum _{I: \; \texttt{mask} (I) \ne 0}{ \texttt{mtx} (I)_c} \right )/N \end{array}\f]
583793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerWhen all the mask elements are 0's, the functions return Scalar::all(0)
584793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src input array that should have from 1 to 4 channels so that the result can be stored in
585793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerScalar_ .
586793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param mask optional operation mask.
587793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa  countNonZero, meanStdDev, norm, minMaxLoc
588793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
589793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W Scalar mean(InputArray src, InputArray mask = noArray());
590793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
591793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** Calculates a mean and standard deviation of array elements.
592793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
593793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function meanStdDev calculates the mean and the standard deviation M
594793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerof array elements independently for each channel and returns it via the
595793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presleroutput parameters:
596793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\f[\begin{array}{l} N =  \sum _{I, \texttt{mask} (I)  \ne 0} 1 \\ \texttt{mean} _c =  \frac{\sum_{ I: \; \texttt{mask}(I) \ne 0} \texttt{src} (I)_c}{N} \\ \texttt{stddev} _c =  \sqrt{\frac{\sum_{ I: \; \texttt{mask}(I) \ne 0} \left ( \texttt{src} (I)_c -  \texttt{mean} _c \right )^2}{N}} \end{array}\f]
597793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerWhen all the mask elements are 0's, the functions return
598793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslermean=stddev=Scalar::all(0).
599793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@note The calculated standard deviation is only the diagonal of the
600793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslercomplete normalized covariance matrix. If the full matrix is needed, you
601793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslercan reshape the multi-channel array M x N to the single-channel array
602793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerM\*N x mtx.channels() (only possible when the matrix is continuous) and
603793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerthen pass the matrix to calcCovarMatrix .
604793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src input array that should have from 1 to 4 channels so that the results can be stored in
605793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerScalar_ 's.
606793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param mean output parameter: calculated mean value.
607793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param stddev output parameter: calculateded standard deviation.
608793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param mask optional operation mask.
609793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa  countNonZero, mean, norm, minMaxLoc, calcCovarMatrix
610793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
611793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void meanStdDev(InputArray src, OutputArray mean, OutputArray stddev,
612793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                             InputArray mask=noArray());
613793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
614793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Calculates an absolute array norm, an absolute difference norm, or a
615793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerrelative difference norm.
616793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
617793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe functions norm calculate an absolute norm of src1 (when there is no
618793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslersrc2 ):
619793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
620793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\f[norm =  \forkthree{\|\texttt{src1}\|_{L_{\infty}} =  \max _I | \texttt{src1} (I)|}{if  \(\texttt{normType} = \texttt{NORM\_INF}\) }
621793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ \| \texttt{src1} \| _{L_1} =  \sum _I | \texttt{src1} (I)|}{if  \(\texttt{normType} = \texttt{NORM\_L1}\) }
622793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ \| \texttt{src1} \| _{L_2} =  \sqrt{\sum_I \texttt{src1}(I)^2} }{if  \(\texttt{normType} = \texttt{NORM\_L2}\) }\f]
623793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
624793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presleror an absolute or relative difference norm if src2 is there:
625793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
626793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\f[norm =  \forkthree{\|\texttt{src1}-\texttt{src2}\|_{L_{\infty}} =  \max _I | \texttt{src1} (I) -  \texttt{src2} (I)|}{if  \(\texttt{normType} = \texttt{NORM\_INF}\) }
627793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ \| \texttt{src1} - \texttt{src2} \| _{L_1} =  \sum _I | \texttt{src1} (I) -  \texttt{src2} (I)|}{if  \(\texttt{normType} = \texttt{NORM\_L1}\) }
628793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ \| \texttt{src1} - \texttt{src2} \| _{L_2} =  \sqrt{\sum_I (\texttt{src1}(I) - \texttt{src2}(I))^2} }{if  \(\texttt{normType} = \texttt{NORM\_L2}\) }\f]
629793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
630793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presleror
631793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
632793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\f[norm =  \forkthree{\frac{\|\texttt{src1}-\texttt{src2}\|_{L_{\infty}}    }{\|\texttt{src2}\|_{L_{\infty}} }}{if  \(\texttt{normType} = \texttt{NORM\_RELATIVE\_INF}\) }
633793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ \frac{\|\texttt{src1}-\texttt{src2}\|_{L_1} }{\|\texttt{src2}\|_{L_1}} }{if  \(\texttt{normType} = \texttt{NORM\_RELATIVE\_L1}\) }
634793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ \frac{\|\texttt{src1}-\texttt{src2}\|_{L_2} }{\|\texttt{src2}\|_{L_2}} }{if  \(\texttt{normType} = \texttt{NORM\_RELATIVE\_L2}\) }\f]
635793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
636793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe functions norm return the calculated norm.
637793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
638793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerWhen the mask parameter is specified and it is not empty, the norm is
639793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslercalculated only over the region specified by the mask.
640793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
641793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerA multi-channel input arrays are treated as a single-channel, that is,
642793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerthe results for all channels are combined.
643793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
644793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src1 first input array.
645793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param normType type of the norm (see cv::NormTypes).
646793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param mask optional operation mask; it must have the same size as src1 and CV_8UC1 type.
647793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
648793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W double norm(InputArray src1, int normType = NORM_L2, InputArray mask = noArray());
649793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
650793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @overload
651793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src1 first input array.
652793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src2 second input array of the same size and the same type as src1.
653793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param normType type of the norm (cv::NormTypes).
654793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param mask optional operation mask; it must have the same size as src1 and CV_8UC1 type.
655793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
656793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W double norm(InputArray src1, InputArray src2,
657793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                         int normType = NORM_L2, InputArray mask = noArray());
658793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @overload
659793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src first input array.
660793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param normType type of the norm (see cv::NormTypes).
661793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
662793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS double norm( const SparseMat& src, int normType );
663793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
664793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief computes PSNR image/video quality metric
665793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
666793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslersee http://en.wikipedia.org/wiki/Peak_signal-to-noise_ratio for details
667793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@todo document
668793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler  */
669793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W double PSNR(InputArray src1, InputArray src2);
670793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
671793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief naive nearest neighbor finder
672793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
673793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslersee http://en.wikipedia.org/wiki/Nearest_neighbor_search
674793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@todo document
675793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler  */
676793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void batchDistance(InputArray src1, InputArray src2,
677793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                                OutputArray dist, int dtype, OutputArray nidx,
678793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                                int normType = NORM_L2, int K = 0,
679793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                                InputArray mask = noArray(), int update = 0,
680793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                                bool crosscheck = false);
681793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
682793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Normalizes the norm or value range of an array.
683793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
684793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe functions normalize scale and shift the input array elements so that
685793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\f[\| \texttt{dst} \| _{L_p}= \texttt{alpha}\f]
686793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler(where p=Inf, 1 or 2) when normType=NORM_INF, NORM_L1, or NORM_L2, respectively; or so that
687793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\f[\min _I  \texttt{dst} (I)= \texttt{alpha} , \, \, \max _I  \texttt{dst} (I)= \texttt{beta}\f]
688793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
689793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerwhen normType=NORM_MINMAX (for dense arrays only). The optional mask specifies a sub-array to be
690793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslernormalized. This means that the norm or min-n-max are calculated over the sub-array, and then this
691793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslersub-array is modified to be normalized. If you want to only use the mask to calculate the norm or
692793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslermin-max but modify the whole array, you can use norm and Mat::convertTo.
693793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
694793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerIn case of sparse matrices, only the non-zero values are analyzed and transformed. Because of this,
695793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerthe range transformation for sparse matrices is not allowed since it can shift the zero level.
696793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
697793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src input array.
698793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dst output array of the same size as src .
699793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param alpha norm value to normalize to or the lower range boundary in case of the range
700793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslernormalization.
701793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param beta upper range boundary in case of the range normalization; it is not used for the norm
702793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslernormalization.
703793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param norm_type normalization type (see cv::NormTypes).
704793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dtype when negative, the output array has the same type as src; otherwise, it has the same
705793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslernumber of channels as src and the depth =CV_MAT_DEPTH(dtype).
706793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param mask optional operation mask.
707793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa norm, Mat::convertTo, SparseMat::convertTo
708793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
709793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void normalize( InputArray src, InputOutputArray dst, double alpha = 1, double beta = 0,
710793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                             int norm_type = NORM_L2, int dtype = -1, InputArray mask = noArray());
711793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
712793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @overload
713793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src input array.
714793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dst output array of the same size as src .
715793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param alpha norm value to normalize to or the lower range boundary in case of the range
716793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslernormalization.
717793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param normType normalization type (see cv::NormTypes).
718793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
719793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS void normalize( const SparseMat& src, SparseMat& dst, double alpha, int normType );
720793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
721793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Finds the global minimum and maximum in an array.
722793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
723793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe functions minMaxLoc find the minimum and maximum element values and their positions. The
724793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerextremums are searched across the whole array or, if mask is not an empty array, in the specified
725793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerarray region.
726793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
727793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe functions do not work with multi-channel arrays. If you need to find minimum or maximum
728793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerelements across all the channels, use Mat::reshape first to reinterpret the array as
729793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslersingle-channel. Or you may extract the particular channel using either extractImageCOI , or
730793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslermixChannels , or split .
731793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src input single-channel array.
732793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param minVal pointer to the returned minimum value; NULL is used if not required.
733793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param maxVal pointer to the returned maximum value; NULL is used if not required.
734793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param minLoc pointer to the returned minimum location (in 2D case); NULL is used if not required.
735793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param maxLoc pointer to the returned maximum location (in 2D case); NULL is used if not required.
736793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param mask optional mask used to select a sub-array.
737793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa max, min, compare, inRange, extractImageCOI, mixChannels, split, Mat::reshape
738793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
739793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void minMaxLoc(InputArray src, CV_OUT double* minVal,
740793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                            CV_OUT double* maxVal = 0, CV_OUT Point* minLoc = 0,
741793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                            CV_OUT Point* maxLoc = 0, InputArray mask = noArray());
742793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
743793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
744793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Finds the global minimum and maximum in an array
745793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
746793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function minMaxIdx finds the minimum and maximum element values and their positions. The
747793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerextremums are searched across the whole array or, if mask is not an empty array, in the specified
748793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerarray region. The function does not work with multi-channel arrays. If you need to find minimum or
749793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslermaximum elements across all the channels, use Mat::reshape first to reinterpret the array as
750793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslersingle-channel. Or you may extract the particular channel using either extractImageCOI , or
751793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslermixChannels , or split . In case of a sparse matrix, the minimum is found among non-zero elements
752793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presleronly.
753793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@note When minIdx is not NULL, it must have at least 2 elements (as well as maxIdx), even if src is
754793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslera single-row or single-column matrix. In OpenCV (following MATLAB) each array has at least 2
755793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerdimensions, i.e. single-column matrix is Mx1 matrix (and therefore minIdx/maxIdx will be
756793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler(i1,0)/(i2,0)) and single-row matrix is 1xN matrix (and therefore minIdx/maxIdx will be
757793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler(0,j1)/(0,j2)).
758793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src input single-channel array.
759793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param minVal pointer to the returned minimum value; NULL is used if not required.
760793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param maxVal pointer to the returned maximum value; NULL is used if not required.
761793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param minIdx pointer to the returned minimum location (in nD case); NULL is used if not required;
762793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerOtherwise, it must point to an array of src.dims elements, the coordinates of the minimum element
763793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerin each dimension are stored there sequentially.
764793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param maxIdx pointer to the returned maximum location (in nD case). NULL is used if not required.
765793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param mask specified array region
766793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
767793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS void minMaxIdx(InputArray src, double* minVal, double* maxVal = 0,
768793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                          int* minIdx = 0, int* maxIdx = 0, InputArray mask = noArray());
769793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
770793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @overload
771793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param a input single-channel array.
772793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param minVal pointer to the returned minimum value; NULL is used if not required.
773793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param maxVal pointer to the returned maximum value; NULL is used if not required.
774793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param minIdx pointer to the returned minimum location (in nD case); NULL is used if not required;
775793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerOtherwise, it must point to an array of src.dims elements, the coordinates of the minimum element
776793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerin each dimension are stored there sequentially.
777793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param maxIdx pointer to the returned maximum location (in nD case). NULL is used if not required.
778793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
779793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS void minMaxLoc(const SparseMat& a, double* minVal,
780793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                          double* maxVal, int* minIdx = 0, int* maxIdx = 0);
781793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
782793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Reduces a matrix to a vector.
783793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
784793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function reduce reduces the matrix to a vector by treating the matrix rows/columns as a set of
785793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler1D vectors and performing the specified operation on the vectors until a single row/column is
786793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerobtained. For example, the function can be used to compute horizontal and vertical projections of a
787793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerraster image. In case of REDUCE_SUM and REDUCE_AVG , the output may have a larger element
788793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerbit-depth to preserve accuracy. And multi-channel arrays are also supported in these two reduction
789793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslermodes.
790793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src input 2D matrix.
791793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dst output vector. Its size and type is defined by dim and dtype parameters.
792793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dim dimension index along which the matrix is reduced. 0 means that the matrix is reduced to
793793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslera single row. 1 means that the matrix is reduced to a single column.
794793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param rtype reduction operation that could be one of cv::ReduceTypes
795793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dtype when negative, the output vector will have the same type as the input matrix,
796793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerotherwise, its type will be CV_MAKE_TYPE(CV_MAT_DEPTH(dtype), src.channels()).
797793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa repeat
798793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
799793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void reduce(InputArray src, OutputArray dst, int dim, int rtype, int dtype = -1);
800793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
801793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Creates one multichannel array out of several single-channel ones.
802793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
803793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe functions merge merge several arrays to make a single multi-channel array. That is, each
804793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerelement of the output array will be a concatenation of the elements of the input arrays, where
805793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerelements of i-th input array are treated as mv[i].channels()-element vectors.
806793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
807793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function split does the reverse operation. If you need to shuffle channels in some other
808793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presleradvanced way, use mixChannels .
809793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param mv input array of matrices to be merged; all the matrices in mv must have the same
810793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslersize and the same depth.
811793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param count number of input matrices when mv is a plain C array; it must be greater than zero.
812793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dst output array of the same size and the same depth as mv[0]; The number of channels will
813793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerbe the total number of channels in the matrix array.
814793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa  mixChannels, split, Mat::reshape
815793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
816793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS void merge(const Mat* mv, size_t count, OutputArray dst);
817793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
818793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @overload
819793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param mv input vector of matrices to be merged; all the matrices in mv must have the same
820793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslersize and the same depth.
821793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dst output array of the same size and the same depth as mv[0]; The number of channels will
822793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerbe the total number of channels in the matrix array.
823793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler  */
824793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void merge(InputArrayOfArrays mv, OutputArray dst);
825793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
826793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Divides a multi-channel array into several single-channel arrays.
827793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
828793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe functions split split a multi-channel array into separate single-channel arrays:
829793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\f[\texttt{mv} [c](I) =  \texttt{src} (I)_c\f]
830793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerIf you need to extract a single channel or do some other sophisticated channel permutation, use
831793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslermixChannels .
832793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src input multi-channel array.
833793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param mvbegin output array; the number of arrays must match src.channels(); the arrays themselves are
834793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerreallocated, if needed.
835793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa merge, mixChannels, cvtColor
836793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
837793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS void split(const Mat& src, Mat* mvbegin);
838793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
839793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @overload
840793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param m input multi-channel array.
841793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param mv output vector of arrays; the arrays themselves are reallocated, if needed.
842793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
843793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void split(InputArray m, OutputArrayOfArrays mv);
844793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
845793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Copies specified channels from input arrays to the specified channels of
846793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presleroutput arrays.
847793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
848793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe functions mixChannels provide an advanced mechanism for shuffling image channels.
849793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
850793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslersplit and merge and some forms of cvtColor are partial cases of mixChannels .
851793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
852793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerIn the example below, the code splits a 4-channel RGBA image into a 3-channel BGR (with R and B
853793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerchannels swapped) and a separate alpha-channel image:
854793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@code{.cpp}
855793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    Mat rgba( 100, 100, CV_8UC4, Scalar(1,2,3,4) );
856793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    Mat bgr( rgba.rows, rgba.cols, CV_8UC3 );
857793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    Mat alpha( rgba.rows, rgba.cols, CV_8UC1 );
858793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
859793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    // forming an array of matrices is a quite efficient operation,
860793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    // because the matrix data is not copied, only the headers
861793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    Mat out[] = { bgr, alpha };
862793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    // rgba[0] -> bgr[2], rgba[1] -> bgr[1],
863793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    // rgba[2] -> bgr[0], rgba[3] -> alpha[0]
864793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    int from_to[] = { 0,2, 1,1, 2,0, 3,3 };
865793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    mixChannels( &rgba, 1, out, 2, from_to, 4 );
866793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@endcode
867793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@note Unlike many other new-style C++ functions in OpenCV (see the introduction section and
868793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerMat::create ), mixChannels requires the output arrays to be pre-allocated before calling the
869793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerfunction.
870793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src input array or vector of matricesl; all of the matrices must have the same size and the
871793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslersame depth.
872793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param nsrcs number of matrices in src.
873793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dst output array or vector of matrices; all the matrices *must be allocated*; their size and
874793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerdepth must be the same as in src[0].
875793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param ndsts number of matrices in dst.
876793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param fromTo array of index pairs specifying which channels are copied and where; fromTo[k\*2] is
877793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslera 0-based index of the input channel in src, fromTo[k\*2+1] is an index of the output channel in
878793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerdst; the continuous channel numbering is used: the first input image channels are indexed from 0 to
879793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslersrc[0].channels()-1, the second input image channels are indexed from src[0].channels() to
880793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslersrc[0].channels() + src[1].channels()-1, and so on, the same scheme is used for the output image
881793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerchannels; as a special case, when fromTo[k\*2] is negative, the corresponding output channel is
882793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerfilled with zero .
883793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param npairs number of index pairs in fromTo.
884793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa split, merge, cvtColor
885793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
886793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS void mixChannels(const Mat* src, size_t nsrcs, Mat* dst, size_t ndsts,
887793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                            const int* fromTo, size_t npairs);
888793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
889793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @overload
890793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src input array or vector of matricesl; all of the matrices must have the same size and the
891793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslersame depth.
892793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dst output array or vector of matrices; all the matrices *must be allocated*; their size and
893793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerdepth must be the same as in src[0].
894793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param fromTo array of index pairs specifying which channels are copied and where; fromTo[k\*2] is
895793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslera 0-based index of the input channel in src, fromTo[k\*2+1] is an index of the output channel in
896793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerdst; the continuous channel numbering is used: the first input image channels are indexed from 0 to
897793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslersrc[0].channels()-1, the second input image channels are indexed from src[0].channels() to
898793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslersrc[0].channels() + src[1].channels()-1, and so on, the same scheme is used for the output image
899793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerchannels; as a special case, when fromTo[k\*2] is negative, the corresponding output channel is
900793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerfilled with zero .
901793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param npairs number of index pairs in fromTo.
902793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
903793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS void mixChannels(InputArrayOfArrays src, InputOutputArrayOfArrays dst,
904793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                            const int* fromTo, size_t npairs);
905793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
906793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @overload
907793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src input array or vector of matricesl; all of the matrices must have the same size and the
908793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslersame depth.
909793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dst output array or vector of matrices; all the matrices *must be allocated*; their size and
910793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerdepth must be the same as in src[0].
911793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param fromTo array of index pairs specifying which channels are copied and where; fromTo[k\*2] is
912793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslera 0-based index of the input channel in src, fromTo[k\*2+1] is an index of the output channel in
913793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerdst; the continuous channel numbering is used: the first input image channels are indexed from 0 to
914793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslersrc[0].channels()-1, the second input image channels are indexed from src[0].channels() to
915793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslersrc[0].channels() + src[1].channels()-1, and so on, the same scheme is used for the output image
916793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerchannels; as a special case, when fromTo[k\*2] is negative, the corresponding output channel is
917793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerfilled with zero .
918793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
919793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void mixChannels(InputArrayOfArrays src, InputOutputArrayOfArrays dst,
920793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                              const std::vector<int>& fromTo);
921793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
922793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief extracts a single channel from src (coi is 0-based index)
923793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@todo document
924793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
925793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void extractChannel(InputArray src, OutputArray dst, int coi);
926793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
927793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief inserts a single channel to dst (coi is 0-based index)
928793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@todo document
929793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
930793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void insertChannel(InputArray src, InputOutputArray dst, int coi);
931793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
932793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Flips a 2D array around vertical, horizontal, or both axes.
933793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
934793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function flip flips the array in one of three different ways (row
935793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerand column indices are 0-based):
936793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\f[\texttt{dst} _{ij} =
937793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\left\{
938793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\begin{array}{l l}
939793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\texttt{src} _{\texttt{src.rows}-i-1,j} & if\;  \texttt{flipCode} = 0 \\
940793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\texttt{src} _{i, \texttt{src.cols} -j-1} & if\;  \texttt{flipCode} > 0 \\
941793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\texttt{src} _{ \texttt{src.rows} -i-1, \texttt{src.cols} -j-1} & if\; \texttt{flipCode} < 0 \\
942793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\end{array}
943793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\right.\f]
944793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe example scenarios of using the function are the following:
945793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*   Vertical flipping of the image (flipCode == 0) to switch between
946793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    top-left and bottom-left image origin. This is a typical operation
947793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    in video processing on Microsoft Windows\* OS.
948793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*   Horizontal flipping of the image with the subsequent horizontal
949793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    shift and absolute difference calculation to check for a
950793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    vertical-axis symmetry (flipCode \> 0).
951793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*   Simultaneous horizontal and vertical flipping of the image with
952793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    the subsequent shift and absolute difference calculation to check
953793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    for a central symmetry (flipCode \< 0).
954793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*   Reversing the order of point arrays (flipCode \> 0 or
955793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    flipCode == 0).
956793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src input array.
957793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dst output array of the same size and type as src.
958793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param flipCode a flag to specify how to flip the array; 0 means
959793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerflipping around the x-axis and positive value (for example, 1) means
960793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerflipping around y-axis. Negative value (for example, -1) means flipping
961793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presleraround both axes.
962793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa transpose , repeat , completeSymm
963793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
964793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void flip(InputArray src, OutputArray dst, int flipCode);
965793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
966793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Fills the output array with repeated copies of the input array.
967793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
968793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe functions repeat duplicate the input array one or more times along each of the two axes:
969793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\f[\texttt{dst} _{ij}= \texttt{src} _{i\mod src.rows, \; j\mod src.cols }\f]
970793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe second variant of the function is more convenient to use with @ref MatrixExpressions.
971793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src input array to replicate.
972793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dst output array of the same type as src.
973793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param ny Flag to specify how many times the src is repeated along the
974793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslervertical axis.
975793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param nx Flag to specify how many times the src is repeated along the
976793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerhorizontal axis.
977793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa reduce
978793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
979793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void repeat(InputArray src, int ny, int nx, OutputArray dst);
980793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
981793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @overload
982793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src input array to replicate.
983793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param ny Flag to specify how many times the src is repeated along the
984793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslervertical axis.
985793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param nx Flag to specify how many times the src is repeated along the
986793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerhorizontal axis.
987793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler  */
988793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS Mat repeat(const Mat& src, int ny, int nx);
989793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
990793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Applies horizontal concatenation to given matrices.
991793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
992793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function horizontally concatenates two or more cv::Mat matrices (with the same number of rows).
993793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@code{.cpp}
994793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    cv::Mat matArray[] = { cv::Mat(4, 1, CV_8UC1, cv::Scalar(1)),
995793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                           cv::Mat(4, 1, CV_8UC1, cv::Scalar(2)),
996793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                           cv::Mat(4, 1, CV_8UC1, cv::Scalar(3)),};
997793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
998793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    cv::Mat out;
999793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    cv::hconcat( matArray, 3, out );
1000793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    //out:
1001793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    //[1, 2, 3;
1002793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    // 1, 2, 3;
1003793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    // 1, 2, 3;
1004793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    // 1, 2, 3]
1005793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@endcode
1006793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src input array or vector of matrices. all of the matrices must have the same number of rows and the same depth.
1007793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param nsrc number of matrices in src.
1008793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dst output array. It has the same number of rows and depth as the src, and the sum of cols of the src.
1009793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa cv::vconcat(const Mat*, size_t, OutputArray), @sa cv::vconcat(InputArrayOfArrays, OutputArray) and @sa cv::vconcat(InputArray, InputArray, OutputArray)
1010793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
1011793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS void hconcat(const Mat* src, size_t nsrc, OutputArray dst);
1012793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @overload
1013793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler @code{.cpp}
1014793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    cv::Mat_<float> A = (cv::Mat_<float>(3, 2) << 1, 4,
1015793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                                                  2, 5,
1016793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                                                  3, 6);
1017793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    cv::Mat_<float> B = (cv::Mat_<float>(3, 2) << 7, 10,
1018793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                                                  8, 11,
1019793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                                                  9, 12);
1020793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1021793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    cv::Mat C;
1022793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    cv::hconcat(A, B, C);
1023793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    //C:
1024793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    //[1, 4, 7, 10;
1025793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    // 2, 5, 8, 11;
1026793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    // 3, 6, 9, 12]
1027793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler @endcode
1028793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler @param src1 first input array to be considered for horizontal concatenation.
1029793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler @param src2 second input array to be considered for horizontal concatenation.
1030793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler @param dst output array. It has the same number of rows and depth as the src1 and src2, and the sum of cols of the src1 and src2.
1031793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler */
1032793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS void hconcat(InputArray src1, InputArray src2, OutputArray dst);
1033793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @overload
1034793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler @code{.cpp}
1035793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    std::vector<cv::Mat> matrices = { cv::Mat(4, 1, CV_8UC1, cv::Scalar(1)),
1036793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                                      cv::Mat(4, 1, CV_8UC1, cv::Scalar(2)),
1037793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                                      cv::Mat(4, 1, CV_8UC1, cv::Scalar(3)),};
1038793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1039793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    cv::Mat out;
1040793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    cv::hconcat( matrices, out );
1041793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    //out:
1042793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    //[1, 2, 3;
1043793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    // 1, 2, 3;
1044793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    // 1, 2, 3;
1045793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    // 1, 2, 3]
1046793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler @endcode
1047793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler @param src input array or vector of matrices. all of the matrices must have the same number of rows and the same depth.
1048793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler @param dst output array. It has the same number of rows and depth as the src, and the sum of cols of the src.
1049793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslersame depth.
1050793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler */
1051793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void hconcat(InputArrayOfArrays src, OutputArray dst);
1052793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1053793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Applies vertical concatenation to given matrices.
1054793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1055793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function vertically concatenates two or more cv::Mat matrices (with the same number of cols).
1056793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@code{.cpp}
1057793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    cv::Mat matArray[] = { cv::Mat(1, 4, CV_8UC1, cv::Scalar(1)),
1058793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                           cv::Mat(1, 4, CV_8UC1, cv::Scalar(2)),
1059793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                           cv::Mat(1, 4, CV_8UC1, cv::Scalar(3)),};
1060793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1061793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    cv::Mat out;
1062793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    cv::vconcat( matArray, 3, out );
1063793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    //out:
1064793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    //[1,   1,   1,   1;
1065793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    // 2,   2,   2,   2;
1066793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    // 3,   3,   3,   3]
1067793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@endcode
1068793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src input array or vector of matrices. all of the matrices must have the same number of cols and the same depth.
1069793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param nsrc number of matrices in src.
1070793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dst output array. It has the same number of cols and depth as the src, and the sum of rows of the src.
1071793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa cv::hconcat(const Mat*, size_t, OutputArray), @sa cv::hconcat(InputArrayOfArrays, OutputArray) and @sa cv::hconcat(InputArray, InputArray, OutputArray)
1072793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
1073793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS void vconcat(const Mat* src, size_t nsrc, OutputArray dst);
1074793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @overload
1075793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler @code{.cpp}
1076793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    cv::Mat_<float> A = (cv::Mat_<float>(3, 2) << 1, 7,
1077793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                                                  2, 8,
1078793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                                                  3, 9);
1079793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    cv::Mat_<float> B = (cv::Mat_<float>(3, 2) << 4, 10,
1080793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                                                  5, 11,
1081793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                                                  6, 12);
1082793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1083793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    cv::Mat C;
1084793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    cv::vconcat(A, B, C);
1085793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    //C:
1086793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    //[1, 7;
1087793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    // 2, 8;
1088793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    // 3, 9;
1089793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    // 4, 10;
1090793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    // 5, 11;
1091793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    // 6, 12]
1092793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler @endcode
1093793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler @param src1 first input array to be considered for vertical concatenation.
1094793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler @param src2 second input array to be considered for vertical concatenation.
1095793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler @param dst output array. It has the same number of cols and depth as the src1 and src2, and the sum of rows of the src1 and src2.
1096793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler */
1097793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS void vconcat(InputArray src1, InputArray src2, OutputArray dst);
1098793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @overload
1099793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler @code{.cpp}
1100793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    std::vector<cv::Mat> matrices = { cv::Mat(1, 4, CV_8UC1, cv::Scalar(1)),
1101793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                                      cv::Mat(1, 4, CV_8UC1, cv::Scalar(2)),
1102793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                                      cv::Mat(1, 4, CV_8UC1, cv::Scalar(3)),};
1103793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1104793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    cv::Mat out;
1105793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    cv::vconcat( matrices, out );
1106793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    //out:
1107793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    //[1,   1,   1,   1;
1108793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    // 2,   2,   2,   2;
1109793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    // 3,   3,   3,   3]
1110793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler @endcode
1111793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler @param src input array or vector of matrices. all of the matrices must have the same number of cols and the same depth
1112793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler @param dst output array. It has the same number of cols and depth as the src, and the sum of rows of the src.
1113793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslersame depth.
1114793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler */
1115793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void vconcat(InputArrayOfArrays src, OutputArray dst);
1116793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1117793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief computes bitwise conjunction of the two arrays (dst = src1 & src2)
1118793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCalculates the per-element bit-wise conjunction of two arrays or an
1119793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerarray and a scalar.
1120793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1121793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function calculates the per-element bit-wise logical conjunction for:
1122793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*   Two arrays when src1 and src2 have the same size:
1123793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    \f[\texttt{dst} (I) =  \texttt{src1} (I)  \wedge \texttt{src2} (I) \quad \texttt{if mask} (I) \ne0\f]
1124793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*   An array and a scalar when src2 is constructed from Scalar or has
1125793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    the same number of elements as `src1.channels()`:
1126793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    \f[\texttt{dst} (I) =  \texttt{src1} (I)  \wedge \texttt{src2} \quad \texttt{if mask} (I) \ne0\f]
1127793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*   A scalar and an array when src1 is constructed from Scalar or has
1128793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    the same number of elements as `src2.channels()`:
1129793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    \f[\texttt{dst} (I) =  \texttt{src1}  \wedge \texttt{src2} (I) \quad \texttt{if mask} (I) \ne0\f]
1130793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerIn case of floating-point arrays, their machine-specific bit
1131793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerrepresentations (usually IEEE754-compliant) are used for the operation.
1132793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerIn case of multi-channel arrays, each channel is processed
1133793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerindependently. In the second and third cases above, the scalar is first
1134793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerconverted to the array type.
1135793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src1 first input array or a scalar.
1136793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src2 second input array or a scalar.
1137793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dst output array that has the same size and type as the input
1138793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerarrays.
1139793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param mask optional operation mask, 8-bit single channel array, that
1140793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerspecifies elements of the output array to be changed.
1141793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
1142793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void bitwise_and(InputArray src1, InputArray src2,
1143793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                              OutputArray dst, InputArray mask = noArray());
1144793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1145793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Calculates the per-element bit-wise disjunction of two arrays or an
1146793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerarray and a scalar.
1147793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1148793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function calculates the per-element bit-wise logical disjunction for:
1149793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*   Two arrays when src1 and src2 have the same size:
1150793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    \f[\texttt{dst} (I) =  \texttt{src1} (I)  \vee \texttt{src2} (I) \quad \texttt{if mask} (I) \ne0\f]
1151793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*   An array and a scalar when src2 is constructed from Scalar or has
1152793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    the same number of elements as `src1.channels()`:
1153793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    \f[\texttt{dst} (I) =  \texttt{src1} (I)  \vee \texttt{src2} \quad \texttt{if mask} (I) \ne0\f]
1154793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*   A scalar and an array when src1 is constructed from Scalar or has
1155793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    the same number of elements as `src2.channels()`:
1156793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    \f[\texttt{dst} (I) =  \texttt{src1}  \vee \texttt{src2} (I) \quad \texttt{if mask} (I) \ne0\f]
1157793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerIn case of floating-point arrays, their machine-specific bit
1158793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerrepresentations (usually IEEE754-compliant) are used for the operation.
1159793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerIn case of multi-channel arrays, each channel is processed
1160793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerindependently. In the second and third cases above, the scalar is first
1161793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerconverted to the array type.
1162793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src1 first input array or a scalar.
1163793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src2 second input array or a scalar.
1164793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dst output array that has the same size and type as the input
1165793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerarrays.
1166793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param mask optional operation mask, 8-bit single channel array, that
1167793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerspecifies elements of the output array to be changed.
1168793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
1169793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void bitwise_or(InputArray src1, InputArray src2,
1170793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                             OutputArray dst, InputArray mask = noArray());
1171793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1172793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Calculates the per-element bit-wise "exclusive or" operation on two
1173793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerarrays or an array and a scalar.
1174793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1175793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function calculates the per-element bit-wise logical "exclusive-or"
1176793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presleroperation for:
1177793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*   Two arrays when src1 and src2 have the same size:
1178793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    \f[\texttt{dst} (I) =  \texttt{src1} (I)  \oplus \texttt{src2} (I) \quad \texttt{if mask} (I) \ne0\f]
1179793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*   An array and a scalar when src2 is constructed from Scalar or has
1180793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    the same number of elements as `src1.channels()`:
1181793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    \f[\texttt{dst} (I) =  \texttt{src1} (I)  \oplus \texttt{src2} \quad \texttt{if mask} (I) \ne0\f]
1182793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*   A scalar and an array when src1 is constructed from Scalar or has
1183793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    the same number of elements as `src2.channels()`:
1184793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    \f[\texttt{dst} (I) =  \texttt{src1}  \oplus \texttt{src2} (I) \quad \texttt{if mask} (I) \ne0\f]
1185793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerIn case of floating-point arrays, their machine-specific bit
1186793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerrepresentations (usually IEEE754-compliant) are used for the operation.
1187793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerIn case of multi-channel arrays, each channel is processed
1188793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerindependently. In the 2nd and 3rd cases above, the scalar is first
1189793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerconverted to the array type.
1190793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src1 first input array or a scalar.
1191793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src2 second input array or a scalar.
1192793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dst output array that has the same size and type as the input
1193793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerarrays.
1194793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param mask optional operation mask, 8-bit single channel array, that
1195793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerspecifies elements of the output array to be changed.
1196793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
1197793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void bitwise_xor(InputArray src1, InputArray src2,
1198793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                              OutputArray dst, InputArray mask = noArray());
1199793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1200793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief  Inverts every bit of an array.
1201793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1202793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function calculates per-element bit-wise inversion of the input
1203793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerarray:
1204793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\f[\texttt{dst} (I) =  \neg \texttt{src} (I)\f]
1205793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerIn case of a floating-point input array, its machine-specific bit
1206793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerrepresentation (usually IEEE754-compliant) is used for the operation. In
1207793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslercase of multi-channel arrays, each channel is processed independently.
1208793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src input array.
1209793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dst output array that has the same size and type as the input
1210793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerarray.
1211793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param mask optional operation mask, 8-bit single channel array, that
1212793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerspecifies elements of the output array to be changed.
1213793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
1214793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void bitwise_not(InputArray src, OutputArray dst,
1215793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                              InputArray mask = noArray());
1216793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1217793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Calculates the per-element absolute difference between two arrays or between an array and a scalar.
1218793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1219793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function absdiff calculates:
1220793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*   Absolute difference between two arrays when they have the same
1221793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    size and type:
1222793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    \f[\texttt{dst}(I) =  \texttt{saturate} (| \texttt{src1}(I) -  \texttt{src2}(I)|)\f]
1223793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*   Absolute difference between an array and a scalar when the second
1224793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    array is constructed from Scalar or has as many elements as the
1225793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    number of channels in `src1`:
1226793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    \f[\texttt{dst}(I) =  \texttt{saturate} (| \texttt{src1}(I) -  \texttt{src2} |)\f]
1227793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*   Absolute difference between a scalar and an array when the first
1228793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    array is constructed from Scalar or has as many elements as the
1229793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    number of channels in `src2`:
1230793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    \f[\texttt{dst}(I) =  \texttt{saturate} (| \texttt{src1} -  \texttt{src2}(I) |)\f]
1231793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    where I is a multi-dimensional index of array elements. In case of
1232793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    multi-channel arrays, each channel is processed independently.
1233793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@note Saturation is not applied when the arrays have the depth CV_32S.
1234793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerYou may even get a negative value in the case of overflow.
1235793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src1 first input array or a scalar.
1236793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src2 second input array or a scalar.
1237793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dst output array that has the same size and type as input arrays.
1238793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa cv::abs(const Mat&)
1239793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
1240793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void absdiff(InputArray src1, InputArray src2, OutputArray dst);
1241793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1242793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief  Checks if array elements lie between the elements of two other arrays.
1243793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1244793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function checks the range as follows:
1245793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler-   For every element of a single-channel input array:
1246793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    \f[\texttt{dst} (I)= \texttt{lowerb} (I)_0  \leq \texttt{src} (I)_0 \leq  \texttt{upperb} (I)_0\f]
1247793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler-   For two-channel arrays:
1248793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    \f[\texttt{dst} (I)= \texttt{lowerb} (I)_0  \leq \texttt{src} (I)_0 \leq  \texttt{upperb} (I)_0  \land \texttt{lowerb} (I)_1  \leq \texttt{src} (I)_1 \leq  \texttt{upperb} (I)_1\f]
1249793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler-   and so forth.
1250793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1251793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThat is, dst (I) is set to 255 (all 1 -bits) if src (I) is within the
1252793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerspecified 1D, 2D, 3D, ... box and 0 otherwise.
1253793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1254793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerWhen the lower and/or upper boundary parameters are scalars, the indexes
1255793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler(I) at lowerb and upperb in the above formulas should be omitted.
1256793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src first input array.
1257793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param lowerb inclusive lower boundary array or a scalar.
1258793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param upperb inclusive upper boundary array or a scalar.
1259793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dst output array of the same size as src and CV_8U type.
1260793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
1261793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void inRange(InputArray src, InputArray lowerb,
1262793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                          InputArray upperb, OutputArray dst);
1263793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1264793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Performs the per-element comparison of two arrays or an array and scalar value.
1265793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1266793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function compares:
1267793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*   Elements of two arrays when src1 and src2 have the same size:
1268793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    \f[\texttt{dst} (I) =  \texttt{src1} (I)  \,\texttt{cmpop}\, \texttt{src2} (I)\f]
1269793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*   Elements of src1 with a scalar src2 when src2 is constructed from
1270793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    Scalar or has a single element:
1271793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    \f[\texttt{dst} (I) =  \texttt{src1}(I) \,\texttt{cmpop}\,  \texttt{src2}\f]
1272793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*   src1 with elements of src2 when src1 is constructed from Scalar or
1273793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    has a single element:
1274793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    \f[\texttt{dst} (I) =  \texttt{src1}  \,\texttt{cmpop}\, \texttt{src2} (I)\f]
1275793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerWhen the comparison result is true, the corresponding element of output
1276793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerarray is set to 255. The comparison operations can be replaced with the
1277793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerequivalent matrix expressions:
1278793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@code{.cpp}
1279793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    Mat dst1 = src1 >= src2;
1280793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    Mat dst2 = src1 < 8;
1281793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    ...
1282793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@endcode
1283793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src1 first input array or a scalar; when it is an array, it must have a single channel.
1284793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src2 second input array or a scalar; when it is an array, it must have a single channel.
1285793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dst output array of type ref CV_8U that has the same size and the same number of channels as
1286793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    the input arrays.
1287793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param cmpop a flag, that specifies correspondence between the arrays (cv::CmpTypes)
1288793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa checkRange, min, max, threshold
1289793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
1290793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void compare(InputArray src1, InputArray src2, OutputArray dst, int cmpop);
1291793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1292793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Calculates per-element minimum of two arrays or an array and a scalar.
1293793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1294793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe functions min calculate the per-element minimum of two arrays:
1295793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\f[\texttt{dst} (I)= \min ( \texttt{src1} (I), \texttt{src2} (I))\f]
1296793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presleror array and a scalar:
1297793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\f[\texttt{dst} (I)= \min ( \texttt{src1} (I), \texttt{value} )\f]
1298793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src1 first input array.
1299793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src2 second input array of the same size and type as src1.
1300793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dst output array of the same size and type as src1.
1301793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa max, compare, inRange, minMaxLoc
1302793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
1303793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void min(InputArray src1, InputArray src2, OutputArray dst);
1304793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @overload
1305793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerneeded to avoid conflicts with const _Tp& std::min(const _Tp&, const _Tp&, _Compare)
1306793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
1307793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS void min(const Mat& src1, const Mat& src2, Mat& dst);
1308793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @overload
1309793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerneeded to avoid conflicts with const _Tp& std::min(const _Tp&, const _Tp&, _Compare)
1310793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
1311793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS void min(const UMat& src1, const UMat& src2, UMat& dst);
1312793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1313793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Calculates per-element maximum of two arrays or an array and a scalar.
1314793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1315793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe functions max calculate the per-element maximum of two arrays:
1316793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\f[\texttt{dst} (I)= \max ( \texttt{src1} (I), \texttt{src2} (I))\f]
1317793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presleror array and a scalar:
1318793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\f[\texttt{dst} (I)= \max ( \texttt{src1} (I), \texttt{value} )\f]
1319793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src1 first input array.
1320793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src2 second input array of the same size and type as src1 .
1321793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dst output array of the same size and type as src1.
1322793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa  min, compare, inRange, minMaxLoc, @ref MatrixExpressions
1323793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
1324793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void max(InputArray src1, InputArray src2, OutputArray dst);
1325793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @overload
1326793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerneeded to avoid conflicts with const _Tp& std::min(const _Tp&, const _Tp&, _Compare)
1327793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
1328793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS void max(const Mat& src1, const Mat& src2, Mat& dst);
1329793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @overload
1330793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerneeded to avoid conflicts with const _Tp& std::min(const _Tp&, const _Tp&, _Compare)
1331793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
1332793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS void max(const UMat& src1, const UMat& src2, UMat& dst);
1333793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1334793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Calculates a square root of array elements.
1335793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1336793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe functions sqrt calculate a square root of each input array element.
1337793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerIn case of multi-channel arrays, each channel is processed
1338793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerindependently. The accuracy is approximately the same as of the built-in
1339793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerstd::sqrt .
1340793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src input floating-point array.
1341793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dst output array of the same size and type as src.
1342793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
1343793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void sqrt(InputArray src, OutputArray dst);
1344793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1345793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Raises every array element to a power.
1346793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1347793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function pow raises every element of the input array to power :
1348793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\f[\texttt{dst} (I) =  \fork{\texttt{src}(I)^power}{if \texttt{power} is integer}{|\texttt{src}(I)|^power}{otherwise}\f]
1349793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1350793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerSo, for a non-integer power exponent, the absolute values of input array
1351793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerelements are used. However, it is possible to get true values for
1352793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslernegative values using some extra operations. In the example below,
1353793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslercomputing the 5th root of array src shows:
1354793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@code{.cpp}
1355793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    Mat mask = src < 0;
1356793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    pow(src, 1./5, dst);
1357793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    subtract(Scalar::all(0), dst, dst, mask);
1358793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@endcode
1359793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerFor some values of power, such as integer values, 0.5 and -0.5,
1360793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerspecialized faster algorithms are used.
1361793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1362793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerSpecial values (NaN, Inf) are not handled.
1363793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src input array.
1364793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param power exponent of power.
1365793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dst output array of the same size and type as src.
1366793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa sqrt, exp, log, cartToPolar, polarToCart
1367793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
1368793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void pow(InputArray src, double power, OutputArray dst);
1369793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1370793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Calculates the exponent of every array element.
1371793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1372793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function exp calculates the exponent of every element of the input
1373793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerarray:
1374793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\f[\texttt{dst} [I] = e^{ src(I) }\f]
1375793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1376793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe maximum relative error is about 7e-6 for single-precision input and
1377793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerless than 1e-10 for double-precision input. Currently, the function
1378793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerconverts denormalized values to zeros on output. Special values (NaN,
1379793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerInf) are not handled.
1380793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src input array.
1381793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dst output array of the same size and type as src.
1382793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa log , cartToPolar , polarToCart , phase , pow , sqrt , magnitude
1383793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
1384793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void exp(InputArray src, OutputArray dst);
1385793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1386793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Calculates the natural logarithm of every array element.
1387793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1388793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function log calculates the natural logarithm of the absolute value
1389793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerof every element of the input array:
1390793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\f[\texttt{dst} (I) =  \fork{\log |\texttt{src}(I)|}{if \(\texttt{src}(I) \ne 0\) }{\texttt{C}}{otherwise}\f]
1391793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1392793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerwhere C is a large negative number (about -700 in the current
1393793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerimplementation). The maximum relative error is about 7e-6 for
1394793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslersingle-precision input and less than 1e-10 for double-precision input.
1395793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerSpecial values (NaN, Inf) are not handled.
1396793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src input array.
1397793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dst output array of the same size and type as src .
1398793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa exp, cartToPolar, polarToCart, phase, pow, sqrt, magnitude
1399793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
1400793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void log(InputArray src, OutputArray dst);
1401793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1402793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Calculates x and y coordinates of 2D vectors from their magnitude and angle.
1403793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1404793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function polarToCart calculates the Cartesian coordinates of each 2D
1405793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslervector represented by the corresponding elements of magnitude and angle:
1406793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\f[\begin{array}{l} \texttt{x} (I) =  \texttt{magnitude} (I) \cos ( \texttt{angle} (I)) \\ \texttt{y} (I) =  \texttt{magnitude} (I) \sin ( \texttt{angle} (I)) \\ \end{array}\f]
1407793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1408793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe relative accuracy of the estimated coordinates is about 1e-6.
1409793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param magnitude input floating-point array of magnitudes of 2D vectors;
1410793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerit can be an empty matrix (=Mat()), in this case, the function assumes
1411793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerthat all the magnitudes are =1; if it is not empty, it must have the
1412793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslersame size and type as angle.
1413793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param angle input floating-point array of angles of 2D vectors.
1414793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param x output array of x-coordinates of 2D vectors; it has the same
1415793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslersize and type as angle.
1416793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param y output array of y-coordinates of 2D vectors; it has the same
1417793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslersize and type as angle.
1418793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param angleInDegrees when true, the input angles are measured in
1419793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerdegrees, otherwise, they are measured in radians.
1420793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa cartToPolar, magnitude, phase, exp, log, pow, sqrt
1421793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
1422793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void polarToCart(InputArray magnitude, InputArray angle,
1423793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                              OutputArray x, OutputArray y, bool angleInDegrees = false);
1424793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1425793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Calculates the magnitude and angle of 2D vectors.
1426793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1427793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function cartToPolar calculates either the magnitude, angle, or both
1428793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerfor every 2D vector (x(I),y(I)):
1429793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\f[\begin{array}{l} \texttt{magnitude} (I)= \sqrt{\texttt{x}(I)^2+\texttt{y}(I)^2} , \\ \texttt{angle} (I)= \texttt{atan2} ( \texttt{y} (I), \texttt{x} (I))[ \cdot180 / \pi ] \end{array}\f]
1430793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1431793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe angles are calculated with accuracy about 0.3 degrees. For the point
1432793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler(0,0), the angle is set to 0.
1433793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param x array of x-coordinates; this must be a single-precision or
1434793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerdouble-precision floating-point array.
1435793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param y array of y-coordinates, that must have the same size and same type as x.
1436793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param magnitude output array of magnitudes of the same size and type as x.
1437793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param angle output array of angles that has the same size and type as
1438793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerx; the angles are measured in radians (from 0 to 2\*Pi) or in degrees (0 to 360 degrees).
1439793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param angleInDegrees a flag, indicating whether the angles are measured
1440793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerin radians (which is by default), or in degrees.
1441793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa Sobel, Scharr
1442793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
1443793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void cartToPolar(InputArray x, InputArray y,
1444793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                              OutputArray magnitude, OutputArray angle,
1445793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                              bool angleInDegrees = false);
1446793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1447793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Calculates the rotation angle of 2D vectors.
1448793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1449793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function phase calculates the rotation angle of each 2D vector that
1450793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presleris formed from the corresponding elements of x and y :
1451793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\f[\texttt{angle} (I) =  \texttt{atan2} ( \texttt{y} (I), \texttt{x} (I))\f]
1452793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1453793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe angle estimation accuracy is about 0.3 degrees. When x(I)=y(I)=0 ,
1454793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerthe corresponding angle(I) is set to 0.
1455793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param x input floating-point array of x-coordinates of 2D vectors.
1456793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param y input array of y-coordinates of 2D vectors; it must have the
1457793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslersame size and the same type as x.
1458793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param angle output array of vector angles; it has the same size and
1459793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslersame type as x .
1460793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param angleInDegrees when true, the function calculates the angle in
1461793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerdegrees, otherwise, they are measured in radians.
1462793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
1463793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void phase(InputArray x, InputArray y, OutputArray angle,
1464793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                        bool angleInDegrees = false);
1465793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1466793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Calculates the magnitude of 2D vectors.
1467793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1468793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function magnitude calculates the magnitude of 2D vectors formed
1469793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerfrom the corresponding elements of x and y arrays:
1470793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\f[\texttt{dst} (I) =  \sqrt{\texttt{x}(I)^2 + \texttt{y}(I)^2}\f]
1471793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param x floating-point array of x-coordinates of the vectors.
1472793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param y floating-point array of y-coordinates of the vectors; it must
1473793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerhave the same size as x.
1474793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param magnitude output array of the same size and type as x.
1475793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa cartToPolar, polarToCart, phase, sqrt
1476793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
1477793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void magnitude(InputArray x, InputArray y, OutputArray magnitude);
1478793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1479793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Checks every element of an input array for invalid values.
1480793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1481793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe functions checkRange check that every array element is neither NaN nor infinite. When minVal \<
1482793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler-DBL_MAX and maxVal \< DBL_MAX, the functions also check that each value is between minVal and
1483793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslermaxVal. In case of multi-channel arrays, each channel is processed independently. If some values
1484793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerare out of range, position of the first outlier is stored in pos (when pos != NULL). Then, the
1485793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerfunctions either return false (when quiet=true) or throw an exception.
1486793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param a input array.
1487793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param quiet a flag, indicating whether the functions quietly return false when the array elements
1488793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerare out of range or they throw an exception.
1489793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param pos optional output parameter, when not NULL, must be a pointer to array of src.dims
1490793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerelements.
1491793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param minVal inclusive lower boundary of valid values range.
1492793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param maxVal exclusive upper boundary of valid values range.
1493793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
1494793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W bool checkRange(InputArray a, bool quiet = true, CV_OUT Point* pos = 0,
1495793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                            double minVal = -DBL_MAX, double maxVal = DBL_MAX);
1496793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1497793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief converts NaN's to the given number
1498793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
1499793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void patchNaNs(InputOutputArray a, double val = 0);
1500793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1501793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Performs generalized matrix multiplication.
1502793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1503793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function performs generalized matrix multiplication similar to the
1504793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslergemm functions in BLAS level 3. For example,
1505793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler`gemm(src1, src2, alpha, src3, beta, dst, GEMM_1_T + GEMM_3_T)`
1506793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslercorresponds to
1507793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\f[\texttt{dst} =  \texttt{alpha} \cdot \texttt{src1} ^T  \cdot \texttt{src2} +  \texttt{beta} \cdot \texttt{src3} ^T\f]
1508793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1509793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerIn case of complex (two-channel) data, performed a complex matrix
1510793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslermultiplication.
1511793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1512793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function can be replaced with a matrix expression. For example, the
1513793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerabove call can be replaced with:
1514793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@code{.cpp}
1515793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    dst = alpha*src1.t()*src2 + beta*src3.t();
1516793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@endcode
1517793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src1 first multiplied input matrix that could be real(CV_32FC1,
1518793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_64FC1) or complex(CV_32FC2, CV_64FC2).
1519793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src2 second multiplied input matrix of the same type as src1.
1520793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param alpha weight of the matrix product.
1521793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src3 third optional delta matrix added to the matrix product; it
1522793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslershould have the same type as src1 and src2.
1523793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param beta weight of src3.
1524793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dst output matrix; it has the proper size and the same type as
1525793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerinput matrices.
1526793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param flags operation flags (cv::GemmFlags)
1527793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa mulTransposed , transform
1528793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
1529793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void gemm(InputArray src1, InputArray src2, double alpha,
1530793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                       InputArray src3, double beta, OutputArray dst, int flags = 0);
1531793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1532793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Calculates the product of a matrix and its transposition.
1533793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1534793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function mulTransposed calculates the product of src and its
1535793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslertransposition:
1536793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\f[\texttt{dst} = \texttt{scale} ( \texttt{src} - \texttt{delta} )^T ( \texttt{src} - \texttt{delta} )\f]
1537793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerif aTa=true , and
1538793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\f[\texttt{dst} = \texttt{scale} ( \texttt{src} - \texttt{delta} ) ( \texttt{src} - \texttt{delta} )^T\f]
1539793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerotherwise. The function is used to calculate the covariance matrix. With
1540793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerzero delta, it can be used as a faster substitute for general matrix
1541793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerproduct A\*B when B=A'
1542793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src input single-channel matrix. Note that unlike gemm, the
1543793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerfunction can multiply not only floating-point matrices.
1544793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dst output square matrix.
1545793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param aTa Flag specifying the multiplication ordering. See the
1546793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerdescription below.
1547793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param delta Optional delta matrix subtracted from src before the
1548793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslermultiplication. When the matrix is empty ( delta=noArray() ), it is
1549793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerassumed to be zero, that is, nothing is subtracted. If it has the same
1550793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslersize as src , it is simply subtracted. Otherwise, it is "repeated" (see
1551793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerrepeat ) to cover the full src and then subtracted. Type of the delta
1552793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslermatrix, when it is not empty, must be the same as the type of created
1553793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presleroutput matrix. See the dtype parameter description below.
1554793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param scale Optional scale factor for the matrix product.
1555793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dtype Optional type of the output matrix. When it is negative,
1556793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerthe output matrix will have the same type as src . Otherwise, it will be
1557793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslertype=CV_MAT_DEPTH(dtype) that should be either CV_32F or CV_64F .
1558793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa calcCovarMatrix, gemm, repeat, reduce
1559793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
1560793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void mulTransposed( InputArray src, OutputArray dst, bool aTa,
1561793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                                 InputArray delta = noArray(),
1562793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                                 double scale = 1, int dtype = -1 );
1563793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1564793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Transposes a matrix.
1565793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1566793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function transpose transposes the matrix src :
1567793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\f[\texttt{dst} (i,j) =  \texttt{src} (j,i)\f]
1568793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@note No complex conjugation is done in case of a complex matrix. It it
1569793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslershould be done separately if needed.
1570793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src input array.
1571793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dst output array of the same type as src.
1572793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
1573793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void transpose(InputArray src, OutputArray dst);
1574793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1575793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Performs the matrix transformation of every array element.
1576793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1577793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function transform performs the matrix transformation of every
1578793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerelement of the array src and stores the results in dst :
1579793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\f[\texttt{dst} (I) =  \texttt{m} \cdot \texttt{src} (I)\f]
1580793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler(when m.cols=src.channels() ), or
1581793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\f[\texttt{dst} (I) =  \texttt{m} \cdot [ \texttt{src} (I); 1]\f]
1582793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler(when m.cols=src.channels()+1 )
1583793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1584793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerEvery element of the N -channel array src is interpreted as N -element
1585793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslervector that is transformed using the M x N or M x (N+1) matrix m to
1586793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerM-element vector - the corresponding element of the output array dst .
1587793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1588793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function may be used for geometrical transformation of
1589793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerN -dimensional points, arbitrary linear color space transformation (such
1590793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presleras various kinds of RGB to YUV transforms), shuffling the image
1591793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerchannels, and so forth.
1592793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src input array that must have as many channels (1 to 4) as
1593793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerm.cols or m.cols-1.
1594793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dst output array of the same size and depth as src; it has as
1595793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslermany channels as m.rows.
1596793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param m transformation 2x2 or 2x3 floating-point matrix.
1597793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa perspectiveTransform, getAffineTransform, estimateRigidTransform, warpAffine, warpPerspective
1598793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
1599793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void transform(InputArray src, OutputArray dst, InputArray m );
1600793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1601793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Performs the perspective matrix transformation of vectors.
1602793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1603793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function perspectiveTransform transforms every element of src by
1604793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslertreating it as a 2D or 3D vector, in the following way:
1605793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\f[(x, y, z)  \rightarrow (x'/w, y'/w, z'/w)\f]
1606793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerwhere
1607793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\f[(x', y', z', w') =  \texttt{mat} \cdot \begin{bmatrix} x & y & z & 1  \end{bmatrix}\f]
1608793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerand
1609793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\f[w =  \fork{w'}{if \(w' \ne 0\)}{\infty}{otherwise}\f]
1610793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1611793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerHere a 3D vector transformation is shown. In case of a 2D vector
1612793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslertransformation, the z component is omitted.
1613793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1614793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@note The function transforms a sparse set of 2D or 3D vectors. If you
1615793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerwant to transform an image using perspective transformation, use
1616793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerwarpPerspective . If you have an inverse problem, that is, you want to
1617793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslercompute the most probable perspective transformation out of several
1618793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerpairs of corresponding points, you can use getPerspectiveTransform or
1619793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerfindHomography .
1620793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src input two-channel or three-channel floating-point array; each
1621793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerelement is a 2D/3D vector to be transformed.
1622793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dst output array of the same size and type as src.
1623793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param m 3x3 or 4x4 floating-point transformation matrix.
1624793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa  transform, warpPerspective, getPerspectiveTransform, findHomography
1625793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
1626793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void perspectiveTransform(InputArray src, OutputArray dst, InputArray m );
1627793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1628793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Copies the lower or the upper half of a square matrix to another half.
1629793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1630793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function completeSymm copies the lower half of a square matrix to
1631793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerits another half. The matrix diagonal remains unchanged:
1632793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*   \f$\texttt{mtx}_{ij}=\texttt{mtx}_{ji}\f$ for \f$i > j\f$ if
1633793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    lowerToUpper=false
1634793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*   \f$\texttt{mtx}_{ij}=\texttt{mtx}_{ji}\f$ for \f$i < j\f$ if
1635793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    lowerToUpper=true
1636793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param mtx input-output floating-point square matrix.
1637793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param lowerToUpper operation flag; if true, the lower half is copied to
1638793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerthe upper half. Otherwise, the upper half is copied to the lower half.
1639793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa flip, transpose
1640793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
1641793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void completeSymm(InputOutputArray mtx, bool lowerToUpper = false);
1642793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1643793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Initializes a scaled identity matrix.
1644793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1645793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function setIdentity initializes a scaled identity matrix:
1646793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\f[\texttt{mtx} (i,j)= \fork{\texttt{value}}{ if \(i=j\)}{0}{otherwise}\f]
1647793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1648793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function can also be emulated using the matrix initializers and the
1649793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslermatrix expressions:
1650793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@code
1651793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    Mat A = Mat::eye(4, 3, CV_32F)*5;
1652793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    // A will be set to [[5, 0, 0], [0, 5, 0], [0, 0, 5], [0, 0, 0]]
1653793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@endcode
1654793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param mtx matrix to initialize (not necessarily square).
1655793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param s value to assign to diagonal elements.
1656793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa Mat::zeros, Mat::ones, Mat::setTo, Mat::operator=
1657793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
1658793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void setIdentity(InputOutputArray mtx, const Scalar& s = Scalar(1));
1659793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1660793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Returns the determinant of a square floating-point matrix.
1661793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1662793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function determinant calculates and returns the determinant of the
1663793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerspecified matrix. For small matrices ( mtx.cols=mtx.rows\<=3 ), the
1664793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerdirect method is used. For larger matrices, the function uses LU
1665793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerfactorization with partial pivoting.
1666793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1667793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerFor symmetric positively-determined matrices, it is also possible to use
1668793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslereigen decomposition to calculate the determinant.
1669793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param mtx input matrix that must have CV_32FC1 or CV_64FC1 type and
1670793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslersquare size.
1671793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa trace, invert, solve, eigen, @ref MatrixExpressions
1672793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
1673793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W double determinant(InputArray mtx);
1674793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1675793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Returns the trace of a matrix.
1676793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1677793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function trace returns the sum of the diagonal elements of the
1678793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslermatrix mtx .
1679793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\f[\mathrm{tr} ( \texttt{mtx} ) =  \sum _i  \texttt{mtx} (i,i)\f]
1680793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param mtx input matrix.
1681793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
1682793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W Scalar trace(InputArray mtx);
1683793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1684793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Finds the inverse or pseudo-inverse of a matrix.
1685793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1686793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function invert inverts the matrix src and stores the result in dst
1687793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler. When the matrix src is singular or non-square, the function calculates
1688793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerthe pseudo-inverse matrix (the dst matrix) so that norm(src\*dst - I) is
1689793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerminimal, where I is an identity matrix.
1690793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1691793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerIn case of the DECOMP_LU method, the function returns non-zero value if
1692793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerthe inverse has been successfully calculated and 0 if src is singular.
1693793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1694793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerIn case of the DECOMP_SVD method, the function returns the inverse
1695793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslercondition number of src (the ratio of the smallest singular value to the
1696793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerlargest singular value) and 0 if src is singular. The SVD method
1697793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslercalculates a pseudo-inverse matrix if src is singular.
1698793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1699793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerSimilarly to DECOMP_LU, the method DECOMP_CHOLESKY works only with
1700793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslernon-singular square matrices that should also be symmetrical and
1701793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerpositively defined. In this case, the function stores the inverted
1702793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslermatrix in dst and returns non-zero. Otherwise, it returns 0.
1703793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1704793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src input floating-point M x N matrix.
1705793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dst output matrix of N x M size and the same type as src.
1706793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param flags inversion method (cv::DecompTypes)
1707793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa solve, SVD
1708793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
1709793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W double invert(InputArray src, OutputArray dst, int flags = DECOMP_LU);
1710793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1711793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Solves one or more linear systems or least-squares problems.
1712793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1713793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function solve solves a linear system or least-squares problem (the
1714793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerlatter is possible with SVD or QR methods, or by specifying the flag
1715793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerDECOMP_NORMAL ):
1716793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\f[\texttt{dst} =  \arg \min _X \| \texttt{src1} \cdot \texttt{X} -  \texttt{src2} \|\f]
1717793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1718793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerIf DECOMP_LU or DECOMP_CHOLESKY method is used, the function returns 1
1719793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerif src1 (or \f$\texttt{src1}^T\texttt{src1}\f$ ) is non-singular. Otherwise,
1720793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerit returns 0. In the latter case, dst is not valid. Other methods find a
1721793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerpseudo-solution in case of a singular left-hand side part.
1722793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1723793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@note If you want to find a unity-norm solution of an under-defined
1724793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslersingular system \f$\texttt{src1}\cdot\texttt{dst}=0\f$ , the function solve
1725793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerwill not do the work. Use SVD::solveZ instead.
1726793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1727793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src1 input matrix on the left-hand side of the system.
1728793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src2 input matrix on the right-hand side of the system.
1729793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dst output solution.
1730793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param flags solution (matrix inversion) method (cv::DecompTypes)
1731793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa invert, SVD, eigen
1732793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
1733793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W bool solve(InputArray src1, InputArray src2,
1734793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                        OutputArray dst, int flags = DECOMP_LU);
1735793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1736793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Sorts each row or each column of a matrix.
1737793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1738793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function sort sorts each matrix row or each matrix column in
1739793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerascending or descending order. So you should pass two operation flags to
1740793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerget desired behaviour. If you want to sort matrix rows or columns
1741793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerlexicographically, you can use STL std::sort generic function with the
1742793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerproper comparison predicate.
1743793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1744793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src input single-channel array.
1745793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dst output array of the same size and type as src.
1746793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param flags operation flags, a combination of cv::SortFlags
1747793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa sortIdx, randShuffle
1748793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
1749793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void sort(InputArray src, OutputArray dst, int flags);
1750793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1751793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Sorts each row or each column of a matrix.
1752793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1753793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function sortIdx sorts each matrix row or each matrix column in the
1754793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerascending or descending order. So you should pass two operation flags to
1755793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerget desired behaviour. Instead of reordering the elements themselves, it
1756793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerstores the indices of sorted elements in the output array. For example:
1757793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@code
1758793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    Mat A = Mat::eye(3,3,CV_32F), B;
1759793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    sortIdx(A, B, SORT_EVERY_ROW + SORT_ASCENDING);
1760793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    // B will probably contain
1761793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    // (because of equal elements in A some permutations are possible):
1762793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    // [[1, 2, 0], [0, 2, 1], [0, 1, 2]]
1763793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@endcode
1764793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src input single-channel array.
1765793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dst output integer array of the same size as src.
1766793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param flags operation flags that could be a combination of cv::SortFlags
1767793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa sort, randShuffle
1768793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
1769793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void sortIdx(InputArray src, OutputArray dst, int flags);
1770793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1771793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Finds the real roots of a cubic equation.
1772793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1773793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function solveCubic finds the real roots of a cubic equation:
1774793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler-   if coeffs is a 4-element vector:
1775793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\f[\texttt{coeffs} [0] x^3 +  \texttt{coeffs} [1] x^2 +  \texttt{coeffs} [2] x +  \texttt{coeffs} [3] = 0\f]
1776793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler-   if coeffs is a 3-element vector:
1777793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\f[x^3 +  \texttt{coeffs} [0] x^2 +  \texttt{coeffs} [1] x +  \texttt{coeffs} [2] = 0\f]
1778793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1779793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe roots are stored in the roots array.
1780793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param coeffs equation coefficients, an array of 3 or 4 elements.
1781793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param roots output array of real roots that has 1 or 3 elements.
1782793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
1783793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W int solveCubic(InputArray coeffs, OutputArray roots);
1784793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1785793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Finds the real or complex roots of a polynomial equation.
1786793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1787793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function solvePoly finds real and complex roots of a polynomial equation:
1788793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\f[\texttt{coeffs} [n] x^{n} +  \texttt{coeffs} [n-1] x^{n-1} + ... +  \texttt{coeffs} [1] x +  \texttt{coeffs} [0] = 0\f]
1789793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param coeffs array of polynomial coefficients.
1790793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param roots output (complex) array of roots.
1791793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param maxIters maximum number of iterations the algorithm does.
1792793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
1793793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W double solvePoly(InputArray coeffs, OutputArray roots, int maxIters = 300);
1794793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1795793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Calculates eigenvalues and eigenvectors of a symmetric matrix.
1796793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1797793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe functions eigen calculate just eigenvalues, or eigenvalues and eigenvectors of the symmetric
1798793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslermatrix src:
1799793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@code
1800793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    src*eigenvectors.row(i).t() = eigenvalues.at<srcType>(i)*eigenvectors.row(i).t()
1801793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@endcode
1802793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@note in the new and the old interfaces different ordering of eigenvalues and eigenvectors
1803793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerparameters is used.
1804793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src input matrix that must have CV_32FC1 or CV_64FC1 type, square size and be symmetrical
1805793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler(src ^T^ == src).
1806793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param eigenvalues output vector of eigenvalues of the same type as src; the eigenvalues are stored
1807793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerin the descending order.
1808793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param eigenvectors output matrix of eigenvectors; it has the same size and type as src; the
1809793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslereigenvectors are stored as subsequent matrix rows, in the same order as the corresponding
1810793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslereigenvalues.
1811793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa completeSymm , PCA
1812793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
1813793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W bool eigen(InputArray src, OutputArray eigenvalues,
1814793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                        OutputArray eigenvectors = noArray());
1815793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1816793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Calculates the covariance matrix of a set of vectors.
1817793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1818793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe functions calcCovarMatrix calculate the covariance matrix and, optionally, the mean vector of
1819793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerthe set of input vectors.
1820793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param samples samples stored as separate matrices
1821793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param nsamples number of samples
1822793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param covar output covariance matrix of the type ctype and square size.
1823793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param mean input or output (depending on the flags) array as the average value of the input vectors.
1824793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param flags operation flags as a combination of cv::CovarFlags
1825793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param ctype type of the matrixl; it equals 'CV_64F' by default.
1826793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa PCA, mulTransposed, Mahalanobis
1827793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@todo InputArrayOfArrays
1828793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
1829793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS void calcCovarMatrix( const Mat* samples, int nsamples, Mat& covar, Mat& mean,
1830793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                                 int flags, int ctype = CV_64F);
1831793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1832793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @overload
1833793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@note use cv::COVAR_ROWS or cv::COVAR_COLS flag
1834793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param samples samples stored as rows/columns of a single matrix.
1835793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param covar output covariance matrix of the type ctype and square size.
1836793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param mean input or output (depending on the flags) array as the average value of the input vectors.
1837793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param flags operation flags as a combination of cv::CovarFlags
1838793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param ctype type of the matrixl; it equals 'CV_64F' by default.
1839793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
1840793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void calcCovarMatrix( InputArray samples, OutputArray covar,
1841793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                                   InputOutputArray mean, int flags, int ctype = CV_64F);
1842793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1843793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** wrap PCA::operator() */
1844793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void PCACompute(InputArray data, InputOutputArray mean,
1845793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                             OutputArray eigenvectors, int maxComponents = 0);
1846793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1847793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** wrap PCA::operator() */
1848793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void PCACompute(InputArray data, InputOutputArray mean,
1849793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                             OutputArray eigenvectors, double retainedVariance);
1850793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1851793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** wrap PCA::project */
1852793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void PCAProject(InputArray data, InputArray mean,
1853793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                             InputArray eigenvectors, OutputArray result);
1854793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1855793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** wrap PCA::backProject */
1856793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void PCABackProject(InputArray data, InputArray mean,
1857793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                                 InputArray eigenvectors, OutputArray result);
1858793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1859793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** wrap SVD::compute */
1860793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void SVDecomp( InputArray src, OutputArray w, OutputArray u, OutputArray vt, int flags = 0 );
1861793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1862793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** wrap SVD::backSubst */
1863793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void SVBackSubst( InputArray w, InputArray u, InputArray vt,
1864793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                               InputArray rhs, OutputArray dst );
1865793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1866793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Calculates the Mahalanobis distance between two vectors.
1867793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1868793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function Mahalanobis calculates and returns the weighted distance between two vectors:
1869793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\f[d( \texttt{vec1} , \texttt{vec2} )= \sqrt{\sum_{i,j}{\texttt{icovar(i,j)}\cdot(\texttt{vec1}(I)-\texttt{vec2}(I))\cdot(\texttt{vec1(j)}-\texttt{vec2(j)})} }\f]
1870793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe covariance matrix may be calculated using the cv::calcCovarMatrix function and then inverted using
1871793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerthe invert function (preferably using the cv::DECOMP_SVD method, as the most accurate).
1872793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param v1 first 1D input vector.
1873793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param v2 second 1D input vector.
1874793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param icovar inverse covariance matrix.
1875793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
1876793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W double Mahalanobis(InputArray v1, InputArray v2, InputArray icovar);
1877793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1878793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Performs a forward or inverse Discrete Fourier transform of a 1D or 2D floating-point array.
1879793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1880793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function performs one of the following:
1881793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler-   Forward the Fourier transform of a 1D vector of N elements:
1882793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    \f[Y = F^{(N)}  \cdot X,\f]
1883793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    where \f$F^{(N)}_{jk}=\exp(-2\pi i j k/N)\f$ and \f$i=\sqrt{-1}\f$
1884793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler-   Inverse the Fourier transform of a 1D vector of N elements:
1885793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    \f[\begin{array}{l} X'=  \left (F^{(N)} \right )^{-1}  \cdot Y =  \left (F^{(N)} \right )^*  \cdot y  \\ X = (1/N)  \cdot X, \end{array}\f]
1886793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    where \f$F^*=\left(\textrm{Re}(F^{(N)})-\textrm{Im}(F^{(N)})\right)^T\f$
1887793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler-   Forward the 2D Fourier transform of a M x N matrix:
1888793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    \f[Y = F^{(M)}  \cdot X  \cdot F^{(N)}\f]
1889793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler-   Inverse the 2D Fourier transform of a M x N matrix:
1890793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    \f[\begin{array}{l} X'=  \left (F^{(M)} \right )^*  \cdot Y  \cdot \left (F^{(N)} \right )^* \\ X =  \frac{1}{M \cdot N} \cdot X' \end{array}\f]
1891793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1892793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerIn case of real (single-channel) data, the output spectrum of the forward Fourier transform or input
1893793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerspectrum of the inverse Fourier transform can be represented in a packed format called *CCS*
1894793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler(complex-conjugate-symmetrical). It was borrowed from IPL (Intel\* Image Processing Library). Here
1895793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presleris how 2D *CCS* spectrum looks:
1896793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\f[\begin{bmatrix} Re Y_{0,0} & Re Y_{0,1} & Im Y_{0,1} & Re Y_{0,2} & Im Y_{0,2} &  \cdots & Re Y_{0,N/2-1} & Im Y_{0,N/2-1} & Re Y_{0,N/2}  \\ Re Y_{1,0} & Re Y_{1,1} & Im Y_{1,1} & Re Y_{1,2} & Im Y_{1,2} &  \cdots & Re Y_{1,N/2-1} & Im Y_{1,N/2-1} & Re Y_{1,N/2}  \\ Im Y_{1,0} & Re Y_{2,1} & Im Y_{2,1} & Re Y_{2,2} & Im Y_{2,2} &  \cdots & Re Y_{2,N/2-1} & Im Y_{2,N/2-1} & Im Y_{1,N/2}  \\ \hdotsfor{9} \\ Re Y_{M/2-1,0} &  Re Y_{M-3,1}  & Im Y_{M-3,1} &  \hdotsfor{3} & Re Y_{M-3,N/2-1} & Im Y_{M-3,N/2-1}& Re Y_{M/2-1,N/2}  \\ Im Y_{M/2-1,0} &  Re Y_{M-2,1}  & Im Y_{M-2,1} &  \hdotsfor{3} & Re Y_{M-2,N/2-1} & Im Y_{M-2,N/2-1}& Im Y_{M/2-1,N/2}  \\ Re Y_{M/2,0}  &  Re Y_{M-1,1} &  Im Y_{M-1,1} &  \hdotsfor{3} & Re Y_{M-1,N/2-1} & Im Y_{M-1,N/2-1}& Re Y_{M/2,N/2} \end{bmatrix}\f]
1897793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1898793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerIn case of 1D transform of a real vector, the output looks like the first row of the matrix above.
1899793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1900793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerSo, the function chooses an operation mode depending on the flags and size of the input array:
1901793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler-   If DFT_ROWS is set or the input array has a single row or single column, the function
1902793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    performs a 1D forward or inverse transform of each row of a matrix when DFT_ROWS is set.
1903793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    Otherwise, it performs a 2D transform.
1904793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler-   If the input array is real and DFT_INVERSE is not set, the function performs a forward 1D or
1905793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    2D transform:
1906793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    -   When DFT_COMPLEX_OUTPUT is set, the output is a complex matrix of the same size as
1907793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        input.
1908793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    -   When DFT_COMPLEX_OUTPUT is not set, the output is a real matrix of the same size as
1909793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        input. In case of 2D transform, it uses the packed format as shown above. In case of a
1910793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        single 1D transform, it looks like the first row of the matrix above. In case of
1911793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        multiple 1D transforms (when using the DFT_ROWS flag), each row of the output matrix
1912793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        looks like the first row of the matrix above.
1913793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler-   If the input array is complex and either DFT_INVERSE or DFT_REAL_OUTPUT are not set, the
1914793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    output is a complex array of the same size as input. The function performs a forward or
1915793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    inverse 1D or 2D transform of the whole input array or each row of the input array
1916793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    independently, depending on the flags DFT_INVERSE and DFT_ROWS.
1917793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler-   When DFT_INVERSE is set and the input array is real, or it is complex but DFT_REAL_OUTPUT
1918793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    is set, the output is a real array of the same size as input. The function performs a 1D or 2D
1919793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    inverse transformation of the whole input array or each individual row, depending on the flags
1920793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    DFT_INVERSE and DFT_ROWS.
1921793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1922793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerIf DFT_SCALE is set, the scaling is done after the transformation.
1923793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1924793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerUnlike dct , the function supports arrays of arbitrary size. But only those arrays are processed
1925793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerefficiently, whose sizes can be factorized in a product of small prime numbers (2, 3, and 5 in the
1926793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslercurrent implementation). Such an efficient DFT size can be calculated using the getOptimalDFTSize
1927793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslermethod.
1928793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1929793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe sample below illustrates how to calculate a DFT-based convolution of two 2D real arrays:
1930793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@code
1931793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    void convolveDFT(InputArray A, InputArray B, OutputArray C)
1932793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    {
1933793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        // reallocate the output array if needed
1934793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        C.create(abs(A.rows - B.rows)+1, abs(A.cols - B.cols)+1, A.type());
1935793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        Size dftSize;
1936793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        // calculate the size of DFT transform
1937793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        dftSize.width = getOptimalDFTSize(A.cols + B.cols - 1);
1938793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        dftSize.height = getOptimalDFTSize(A.rows + B.rows - 1);
1939793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1940793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        // allocate temporary buffers and initialize them with 0's
1941793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        Mat tempA(dftSize, A.type(), Scalar::all(0));
1942793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        Mat tempB(dftSize, B.type(), Scalar::all(0));
1943793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1944793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        // copy A and B to the top-left corners of tempA and tempB, respectively
1945793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        Mat roiA(tempA, Rect(0,0,A.cols,A.rows));
1946793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        A.copyTo(roiA);
1947793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        Mat roiB(tempB, Rect(0,0,B.cols,B.rows));
1948793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        B.copyTo(roiB);
1949793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1950793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        // now transform the padded A & B in-place;
1951793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        // use "nonzeroRows" hint for faster processing
1952793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        dft(tempA, tempA, 0, A.rows);
1953793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        dft(tempB, tempB, 0, B.rows);
1954793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1955793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        // multiply the spectrums;
1956793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        // the function handles packed spectrum representations well
1957793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        mulSpectrums(tempA, tempB, tempA);
1958793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1959793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        // transform the product back from the frequency domain.
1960793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        // Even though all the result rows will be non-zero,
1961793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        // you need only the first C.rows of them, and thus you
1962793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        // pass nonzeroRows == C.rows
1963793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        dft(tempA, tempA, DFT_INVERSE + DFT_SCALE, C.rows);
1964793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1965793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        // now copy the result back to C.
1966793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        tempA(Rect(0, 0, C.cols, C.rows)).copyTo(C);
1967793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1968793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        // all the temporary buffers will be deallocated automatically
1969793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    }
1970793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@endcode
1971793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerTo optimize this sample, consider the following approaches:
1972793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler-   Since nonzeroRows != 0 is passed to the forward transform calls and since A and B are copied to
1973793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    the top-left corners of tempA and tempB, respectively, it is not necessary to clear the whole
1974793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    tempA and tempB. It is only necessary to clear the tempA.cols - A.cols ( tempB.cols - B.cols)
1975793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    rightmost columns of the matrices.
1976793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler-   This DFT-based convolution does not have to be applied to the whole big arrays, especially if B
1977793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    is significantly smaller than A or vice versa. Instead, you can calculate convolution by parts.
1978793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    To do this, you need to split the output array C into multiple tiles. For each tile, estimate
1979793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    which parts of A and B are required to calculate convolution in this tile. If the tiles in C are
1980793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    too small, the speed will decrease a lot because of repeated work. In the ultimate case, when
1981793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    each tile in C is a single pixel, the algorithm becomes equivalent to the naive convolution
1982793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    algorithm. If the tiles are too big, the temporary arrays tempA and tempB become too big and
1983793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    there is also a slowdown because of bad cache locality. So, there is an optimal tile size
1984793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    somewhere in the middle.
1985793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler-   If different tiles in C can be calculated in parallel and, thus, the convolution is done by
1986793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    parts, the loop can be threaded.
1987793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
1988793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerAll of the above improvements have been implemented in matchTemplate and filter2D . Therefore, by
1989793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerusing them, you can get the performance even better than with the above theoretically optimal
1990793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerimplementation. Though, those two functions actually calculate cross-correlation, not convolution,
1991793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerso you need to "flip" the second convolution operand B vertically and horizontally using flip .
1992793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@note
1993793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler-   An example using the discrete fourier transform can be found at
1994793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    opencv_source_code/samples/cpp/dft.cpp
1995793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler-   (Python) An example using the dft functionality to perform Wiener deconvolution can be found
1996793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    at opencv_source/samples/python2/deconvolution.py
1997793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler-   (Python) An example rearranging the quadrants of a Fourier image can be found at
1998793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    opencv_source/samples/python2/dft.py
1999793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src input array that could be real or complex.
2000793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dst output array whose size and type depends on the flags .
2001793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param flags transformation flags, representing a combination of the cv::DftFlags
2002793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param nonzeroRows when the parameter is not zero, the function assumes that only the first
2003793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslernonzeroRows rows of the input array (DFT_INVERSE is not set) or only the first nonzeroRows of the
2004793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presleroutput array (DFT_INVERSE is set) contain non-zeros, thus, the function can handle the rest of the
2005793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerrows more efficiently and save some time; this technique is very useful for calculating array
2006793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslercross-correlation or convolution using DFT.
2007793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa dct , getOptimalDFTSize , mulSpectrums, filter2D , matchTemplate , flip , cartToPolar ,
2008793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslermagnitude , phase
2009793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
2010793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void dft(InputArray src, OutputArray dst, int flags = 0, int nonzeroRows = 0);
2011793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2012793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Calculates the inverse Discrete Fourier Transform of a 1D or 2D array.
2013793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2014793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presleridft(src, dst, flags) is equivalent to dft(src, dst, flags | DFT_INVERSE) .
2015793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@note None of dft and idft scales the result by default. So, you should pass DFT_SCALE to one of
2016793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerdft or idft explicitly to make these transforms mutually inverse.
2017793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa dft, dct, idct, mulSpectrums, getOptimalDFTSize
2018793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src input floating-point real or complex array.
2019793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dst output array whose size and type depend on the flags.
2020793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param flags operation flags (see dft and cv::DftFlags).
2021793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param nonzeroRows number of dst rows to process; the rest of the rows have undefined content (see
2022793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerthe convolution sample in dft description.
2023793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
2024793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void idft(InputArray src, OutputArray dst, int flags = 0, int nonzeroRows = 0);
2025793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2026793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Performs a forward or inverse discrete Cosine transform of 1D or 2D array.
2027793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2028793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function dct performs a forward or inverse discrete Cosine transform (DCT) of a 1D or 2D
2029793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerfloating-point array:
2030793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler-   Forward Cosine transform of a 1D vector of N elements:
2031793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    \f[Y = C^{(N)}  \cdot X\f]
2032793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    where
2033793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    \f[C^{(N)}_{jk}= \sqrt{\alpha_j/N} \cos \left ( \frac{\pi(2k+1)j}{2N} \right )\f]
2034793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    and
2035793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    \f$\alpha_0=1\f$, \f$\alpha_j=2\f$ for *j \> 0*.
2036793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler-   Inverse Cosine transform of a 1D vector of N elements:
2037793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    \f[X =  \left (C^{(N)} \right )^{-1}  \cdot Y =  \left (C^{(N)} \right )^T  \cdot Y\f]
2038793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    (since \f$C^{(N)}\f$ is an orthogonal matrix, \f$C^{(N)} \cdot \left(C^{(N)}\right)^T = I\f$ )
2039793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler-   Forward 2D Cosine transform of M x N matrix:
2040793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    \f[Y = C^{(N)}  \cdot X  \cdot \left (C^{(N)} \right )^T\f]
2041793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler-   Inverse 2D Cosine transform of M x N matrix:
2042793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    \f[X =  \left (C^{(N)} \right )^T  \cdot X  \cdot C^{(N)}\f]
2043793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2044793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function chooses the mode of operation by looking at the flags and size of the input array:
2045793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler-   If (flags & DCT_INVERSE) == 0 , the function does a forward 1D or 2D transform. Otherwise, it
2046793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    is an inverse 1D or 2D transform.
2047793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler-   If (flags & DCT_ROWS) != 0 , the function performs a 1D transform of each row.
2048793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler-   If the array is a single column or a single row, the function performs a 1D transform.
2049793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler-   If none of the above is true, the function performs a 2D transform.
2050793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2051793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@note Currently dct supports even-size arrays (2, 4, 6 ...). For data analysis and approximation, you
2052793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslercan pad the array when necessary.
2053793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerAlso, the function performance depends very much, and not monotonically, on the array size (see
2054793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslergetOptimalDFTSize ). In the current implementation DCT of a vector of size N is calculated via DFT
2055793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerof a vector of size N/2 . Thus, the optimal DCT size N1 \>= N can be calculated as:
2056793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@code
2057793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    size_t getOptimalDCTSize(size_t N) { return 2*getOptimalDFTSize((N+1)/2); }
2058793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    N1 = getOptimalDCTSize(N);
2059793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@endcode
2060793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src input floating-point array.
2061793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dst output array of the same size and type as src .
2062793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param flags transformation flags as a combination of cv::DftFlags (DCT_*)
2063793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa dft , getOptimalDFTSize , idct
2064793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
2065793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void dct(InputArray src, OutputArray dst, int flags = 0);
2066793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2067793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Calculates the inverse Discrete Cosine Transform of a 1D or 2D array.
2068793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2069793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presleridct(src, dst, flags) is equivalent to dct(src, dst, flags | DCT_INVERSE).
2070793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param src input floating-point single-channel array.
2071793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dst output array of the same size and type as src.
2072793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param flags operation flags.
2073793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa  dct, dft, idft, getOptimalDFTSize
2074793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
2075793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void idct(InputArray src, OutputArray dst, int flags = 0);
2076793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2077793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Performs the per-element multiplication of two Fourier spectrums.
2078793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2079793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function mulSpectrums performs the per-element multiplication of the two CCS-packed or complex
2080793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslermatrices that are results of a real or complex Fourier transform.
2081793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2082793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function, together with dft and idft , may be used to calculate convolution (pass conjB=false )
2083793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presleror correlation (pass conjB=true ) of two arrays rapidly. When the arrays are complex, they are
2084793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslersimply multiplied (per element) with an optional conjugation of the second-array elements. When the
2085793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerarrays are real, they are assumed to be CCS-packed (see dft for details).
2086793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param a first input array.
2087793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param b second input array of the same size and type as src1 .
2088793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param c output array of the same size and type as src1 .
2089793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param flags operation flags; currently, the only supported flag is cv::DFT_ROWS, which indicates that
2090793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslereach row of src1 and src2 is an independent 1D Fourier spectrum. If you do not want to use this flag, then simply add a `0` as value.
2091793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param conjB optional flag that conjugates the second input array before the multiplication (true)
2092793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presleror not (false).
2093793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
2094793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void mulSpectrums(InputArray a, InputArray b, OutputArray c,
2095793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                               int flags, bool conjB = false);
2096793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2097793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Returns the optimal DFT size for a given vector size.
2098793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2099793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerDFT performance is not a monotonic function of a vector size. Therefore, when you calculate
2100793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerconvolution of two arrays or perform the spectral analysis of an array, it usually makes sense to
2101793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerpad the input data with zeros to get a bit larger array that can be transformed much faster than the
2102793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presleroriginal one. Arrays whose size is a power-of-two (2, 4, 8, 16, 32, ...) are the fastest to process.
2103793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThough, the arrays whose size is a product of 2's, 3's, and 5's (for example, 300 = 5\*5\*3\*2\*2)
2104793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerare also processed quite efficiently.
2105793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2106793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function getOptimalDFTSize returns the minimum number N that is greater than or equal to vecsize
2107793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerso that the DFT of a vector of size N can be processed efficiently. In the current implementation N
2108793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler= 2 ^p^ \* 3 ^q^ \* 5 ^r^ for some integer p, q, r.
2109793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2110793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function returns a negative number if vecsize is too large (very close to INT_MAX ).
2111793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2112793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerWhile the function cannot be used directly to estimate the optimal vector size for DCT transform
2113793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler(since the current DCT implementation supports only even-size vectors), it can be easily processed
2114793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presleras getOptimalDFTSize((vecsize+1)/2)\*2.
2115793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param vecsize vector size.
2116793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa dft , dct , idft , idct , mulSpectrums
2117793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
2118793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W int getOptimalDFTSize(int vecsize);
2119793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2120793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Returns the default random number generator.
2121793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2122793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function theRNG returns the default random number generator. For each thread, there is a
2123793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerseparate random number generator, so you can use the function safely in multi-thread environments.
2124793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerIf you just need to get a single random number using this generator or initialize an array, you can
2125793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presleruse randu or randn instead. But if you are going to generate many random numbers inside a loop, it
2126793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presleris much faster to use this function to retrieve the generator and then use RNG::operator _Tp() .
2127793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa RNG, randu, randn
2128793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
2129793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS RNG& theRNG();
2130793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2131793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Generates a single uniformly-distributed random number or an array of random numbers.
2132793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2133793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerNon-template variant of the function fills the matrix dst with uniformly-distributed
2134793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerrandom numbers from the specified range:
2135793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\f[\texttt{low} _c  \leq \texttt{dst} (I)_c <  \texttt{high} _c\f]
2136793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dst output array of random numbers; the array must be pre-allocated.
2137793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param low inclusive lower boundary of the generated random numbers.
2138793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param high exclusive upper boundary of the generated random numbers.
2139793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa RNG, randn, theRNG
2140793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
2141793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void randu(InputOutputArray dst, InputArray low, InputArray high);
2142793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2143793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Fills the array with normally distributed random numbers.
2144793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2145793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function randn fills the matrix dst with normally distributed random numbers with the specified
2146793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslermean vector and the standard deviation matrix. The generated random numbers are clipped to fit the
2147793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslervalue range of the output array data type.
2148793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dst output array of random numbers; the array must be pre-allocated and have 1 to 4 channels.
2149793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param mean mean value (expectation) of the generated random numbers.
2150793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param stddev standard deviation of the generated random numbers; it can be either a vector (in
2151793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerwhich case a diagonal standard deviation matrix is assumed) or a square matrix.
2152793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa RNG, randu
2153793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
2154793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void randn(InputOutputArray dst, InputArray mean, InputArray stddev);
2155793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2156793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Shuffles the array elements randomly.
2157793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2158793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function randShuffle shuffles the specified 1D array by randomly choosing pairs of elements and
2159793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerswapping them. The number of such swap operations will be dst.rows\*dst.cols\*iterFactor .
2160793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param dst input/output numerical 1D array.
2161793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param iterFactor scale factor that determines the number of random swap operations (see the details
2162793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerbelow).
2163793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param rng optional random number generator used for shuffling; if it is zero, theRNG () is used
2164793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerinstead.
2165793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa RNG, sort
2166793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
2167793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W void randShuffle(InputOutputArray dst, double iterFactor = 1., RNG* rng = 0);
2168793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2169793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Principal Component Analysis
2170793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2171793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe class is used to calculate a special basis for a set of vectors. The
2172793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerbasis will consist of eigenvectors of the covariance matrix calculated
2173793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerfrom the input set of vectors. The class %PCA can also transform
2174793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslervectors to/from the new coordinate space defined by the basis. Usually,
2175793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerin this new coordinate system, each vector from the original set (and
2176793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerany linear combination of such vectors) can be quite accurately
2177793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerapproximated by taking its first few components, corresponding to the
2178793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslereigenvectors of the largest eigenvalues of the covariance matrix.
2179793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerGeometrically it means that you calculate a projection of the vector to
2180793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslera subspace formed by a few eigenvectors corresponding to the dominant
2181793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslereigenvalues of the covariance matrix. And usually such a projection is
2182793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslervery close to the original vector. So, you can represent the original
2183793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslervector from a high-dimensional space with a much shorter vector
2184793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerconsisting of the projected vector's coordinates in the subspace. Such a
2185793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslertransformation is also known as Karhunen-Loeve Transform, or KLT.
2186793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerSee http://en.wikipedia.org/wiki/Principal_component_analysis
2187793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2188793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe sample below is the function that takes two matrices. The first
2189793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerfunction stores a set of vectors (a row per vector) that is used to
2190793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslercalculate PCA. The second function stores another "test" set of vectors
2191793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler(a row per vector). First, these vectors are compressed with PCA, then
2192793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerreconstructed back, and then the reconstruction error norm is computed
2193793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerand printed for each vector. :
2194793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2195793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@code{.cpp}
2196793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerusing namespace cv;
2197793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2198793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerPCA compressPCA(const Mat& pcaset, int maxComponents,
2199793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                const Mat& testset, Mat& compressed)
2200793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{
2201793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    PCA pca(pcaset, // pass the data
2202793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler            Mat(), // we do not have a pre-computed mean vector,
2203793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                   // so let the PCA engine to compute it
2204793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler            PCA::DATA_AS_ROW, // indicate that the vectors
2205793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                                // are stored as matrix rows
2206793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                                // (use PCA::DATA_AS_COL if the vectors are
2207793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                                // the matrix columns)
2208793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler            maxComponents // specify, how many principal components to retain
2209793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler            );
2210793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    // if there is no test data, just return the computed basis, ready-to-use
2211793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    if( !testset.data )
2212793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        return pca;
2213793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    CV_Assert( testset.cols == pcaset.cols );
2214793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2215793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    compressed.create(testset.rows, maxComponents, testset.type());
2216793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2217793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    Mat reconstructed;
2218793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    for( int i = 0; i < testset.rows; i++ )
2219793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    {
2220793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        Mat vec = testset.row(i), coeffs = compressed.row(i), reconstructed;
2221793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        // compress the vector, the result will be stored
2222793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        // in the i-th row of the output matrix
2223793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        pca.project(vec, coeffs);
2224793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        // and then reconstruct it
2225793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        pca.backProject(coeffs, reconstructed);
2226793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        // and measure the error
2227793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        printf("%d. diff = %g\n", i, norm(vec, reconstructed, NORM_L2));
2228793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    }
2229793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    return pca;
2230793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler}
2231793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@endcode
2232793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa calcCovarMatrix, mulTransposed, SVD, dft, dct
2233793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
2234793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerclass CV_EXPORTS PCA
2235793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{
2236793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerpublic:
2237793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    enum Flags { DATA_AS_ROW = 0, //!< indicates that the input samples are stored as matrix rows
2238793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                 DATA_AS_COL = 1, //!< indicates that the input samples are stored as matrix columns
2239793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                 USE_AVG     = 2  //!
2240793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler               };
2241793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2242793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** @brief default constructor
2243793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2244793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    The default constructor initializes an empty %PCA structure. The other
2245793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    constructors initialize the structure and call PCA::operator()().
2246793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    */
2247793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    PCA();
2248793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2249793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** @overload
2250793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @param data input samples stored as matrix rows or matrix columns.
2251793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @param mean optional mean value; if the matrix is empty (@c noArray()),
2252793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    the mean is computed from the data.
2253793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @param flags operation flags; currently the parameter is only used to
2254793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    specify the data layout (PCA::Flags)
2255793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @param maxComponents maximum number of components that %PCA should
2256793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    retain; by default, all the components are retained.
2257793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    */
2258793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    PCA(InputArray data, InputArray mean, int flags, int maxComponents = 0);
2259793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2260793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** @overload
2261793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @param data input samples stored as matrix rows or matrix columns.
2262793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @param mean optional mean value; if the matrix is empty (noArray()),
2263793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    the mean is computed from the data.
2264793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @param flags operation flags; currently the parameter is only used to
2265793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    specify the data layout (PCA::Flags)
2266793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @param retainedVariance Percentage of variance that PCA should retain.
2267793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    Using this parameter will let the PCA decided how many components to
2268793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    retain but it will always keep at least 2.
2269793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    */
2270793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    PCA(InputArray data, InputArray mean, int flags, double retainedVariance);
2271793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2272793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** @brief performs %PCA
2273793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2274793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    The operator performs %PCA of the supplied dataset. It is safe to reuse
2275793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    the same PCA structure for multiple datasets. That is, if the structure
2276793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    has been previously used with another dataset, the existing internal
2277793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    data is reclaimed and the new eigenvalues, @ref eigenvectors , and @ref
2278793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    mean are allocated and computed.
2279793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2280793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    The computed eigenvalues are sorted from the largest to the smallest and
2281793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    the corresponding eigenvectors are stored as eigenvectors rows.
2282793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2283793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @param data input samples stored as the matrix rows or as the matrix
2284793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    columns.
2285793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @param mean optional mean value; if the matrix is empty (noArray()),
2286793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    the mean is computed from the data.
2287793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @param flags operation flags; currently the parameter is only used to
2288793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    specify the data layout. (Flags)
2289793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @param maxComponents maximum number of components that PCA should
2290793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    retain; by default, all the components are retained.
2291793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    */
2292793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    PCA& operator()(InputArray data, InputArray mean, int flags, int maxComponents = 0);
2293793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2294793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** @overload
2295793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @param data input samples stored as the matrix rows or as the matrix
2296793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    columns.
2297793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @param mean optional mean value; if the matrix is empty (noArray()),
2298793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    the mean is computed from the data.
2299793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @param flags operation flags; currently the parameter is only used to
2300793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    specify the data layout. (PCA::Flags)
2301793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @param retainedVariance Percentage of variance that %PCA should retain.
2302793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    Using this parameter will let the %PCA decided how many components to
2303793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    retain but it will always keep at least 2.
2304793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler     */
2305793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    PCA& operator()(InputArray data, InputArray mean, int flags, double retainedVariance);
2306793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2307793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** @brief Projects vector(s) to the principal component subspace.
2308793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2309793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    The methods project one or more vectors to the principal component
2310793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    subspace, where each vector projection is represented by coefficients in
2311793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    the principal component basis. The first form of the method returns the
2312793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    matrix that the second form writes to the result. So the first form can
2313793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    be used as a part of expression while the second form can be more
2314793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    efficient in a processing loop.
2315793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @param vec input vector(s); must have the same dimensionality and the
2316793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    same layout as the input data used at %PCA phase, that is, if
2317793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    DATA_AS_ROW are specified, then `vec.cols==data.cols`
2318793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    (vector dimensionality) and `vec.rows` is the number of vectors to
2319793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    project, and the same is true for the PCA::DATA_AS_COL case.
2320793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    */
2321793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    Mat project(InputArray vec) const;
2322793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2323793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** @overload
2324793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @param vec input vector(s); must have the same dimensionality and the
2325793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    same layout as the input data used at PCA phase, that is, if
2326793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    DATA_AS_ROW are specified, then `vec.cols==data.cols`
2327793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    (vector dimensionality) and `vec.rows` is the number of vectors to
2328793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    project, and the same is true for the PCA::DATA_AS_COL case.
2329793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @param result output vectors; in case of PCA::DATA_AS_COL, the
2330793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    output matrix has as many columns as the number of input vectors, this
2331793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    means that `result.cols==vec.cols` and the number of rows match the
2332793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    number of principal components (for example, `maxComponents` parameter
2333793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    passed to the constructor).
2334793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler     */
2335793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    void project(InputArray vec, OutputArray result) const;
2336793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2337793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** @brief Reconstructs vectors from their PC projections.
2338793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2339793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    The methods are inverse operations to PCA::project. They take PC
2340793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    coordinates of projected vectors and reconstruct the original vectors.
2341793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    Unless all the principal components have been retained, the
2342793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    reconstructed vectors are different from the originals. But typically,
2343793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    the difference is small if the number of components is large enough (but
2344793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    still much smaller than the original vector dimensionality). As a
2345793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    result, PCA is used.
2346793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @param vec coordinates of the vectors in the principal component
2347793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    subspace, the layout and size are the same as of PCA::project output
2348793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    vectors.
2349793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler     */
2350793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    Mat backProject(InputArray vec) const;
2351793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2352793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** @overload
2353793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @param vec coordinates of the vectors in the principal component
2354793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    subspace, the layout and size are the same as of PCA::project output
2355793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    vectors.
2356793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @param result reconstructed vectors; the layout and size are the same as
2357793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    of PCA::project input vectors.
2358793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler     */
2359793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    void backProject(InputArray vec, OutputArray result) const;
2360793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2361793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** @brief write and load PCA matrix
2362793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2363793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
2364793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    void write(FileStorage& fs ) const;
2365793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    void read(const FileNode& fs);
2366793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2367793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    Mat eigenvectors; //!< eigenvectors of the covariation matrix
2368793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    Mat eigenvalues; //!< eigenvalues of the covariation matrix
2369793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    Mat mean; //!< mean value subtracted before the projection and added after the back projection
2370793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler};
2371793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2372793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @example pca.cpp
2373793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler  An example using %PCA for dimensionality reduction while maintaining an amount of variance
2374793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler */
2375793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2376793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/**
2377793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler   @brief Linear Discriminant Analysis
2378793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler   @todo document this class
2379793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler */
2380793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerclass CV_EXPORTS LDA
2381793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{
2382793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerpublic:
2383793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** @brief constructor
2384793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    Initializes a LDA with num_components (default 0) and specifies how
2385793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    samples are aligned (default dataAsRow=true).
2386793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    */
2387793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    explicit LDA(int num_components = 0);
2388793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2389793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** Initializes and performs a Discriminant Analysis with Fisher's
2390793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler     Optimization Criterion on given data in src and corresponding labels
2391793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler     in labels. If 0 (or less) number of components are given, they are
2392793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler     automatically determined for given data in computation.
2393793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    */
2394793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    LDA(InputArrayOfArrays src, InputArray labels, int num_components = 0);
2395793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2396793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** Serializes this object to a given filename.
2397793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler      */
2398793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    void save(const String& filename) const;
2399793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2400793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** Deserializes this object from a given filename.
2401793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler      */
2402793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    void load(const String& filename);
2403793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2404793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** Serializes this object to a given cv::FileStorage.
2405793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler      */
2406793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    void save(FileStorage& fs) const;
2407793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2408793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** Deserializes this object from a given cv::FileStorage.
2409793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler      */
2410793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    void load(const FileStorage& node);
2411793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2412793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** destructor
2413793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler      */
2414793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    ~LDA();
2415793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2416793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** Compute the discriminants for data in src and labels.
2417793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler      */
2418793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    void compute(InputArrayOfArrays src, InputArray labels);
2419793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2420793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** Projects samples into the LDA subspace.
2421793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler      */
2422793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    Mat project(InputArray src);
2423793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2424793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** Reconstructs projections from the LDA subspace.
2425793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler      */
2426793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    Mat reconstruct(InputArray src);
2427793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2428793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** Returns the eigenvectors of this LDA.
2429793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler      */
2430793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    Mat eigenvectors() const { return _eigenvectors; }
2431793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2432793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** Returns the eigenvalues of this LDA.
2433793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler      */
2434793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    Mat eigenvalues() const { return _eigenvalues; }
2435793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2436793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    static Mat subspaceProject(InputArray W, InputArray mean, InputArray src);
2437793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    static Mat subspaceReconstruct(InputArray W, InputArray mean, InputArray src);
2438793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2439793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerprotected:
2440793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    bool _dataAsRow;
2441793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    int _num_components;
2442793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    Mat _eigenvectors;
2443793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    Mat _eigenvalues;
2444793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2445793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    void lda(InputArrayOfArrays src, InputArray labels);
2446793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler};
2447793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2448793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Singular Value Decomposition
2449793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2450793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerClass for computing Singular Value Decomposition of a floating-point
2451793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslermatrix. The Singular Value Decomposition is used to solve least-square
2452793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerproblems, under-determined linear systems, invert matrices, compute
2453793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslercondition numbers, and so on.
2454793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2455793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerIf you want to compute a condition number of a matrix or an absolute value of
2456793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerits determinant, you do not need `u` and `vt`. You can pass
2457793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerflags=SVD::NO_UV|... . Another flag SVD::FULL_UV indicates that full-size u
2458793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerand vt must be computed, which is not necessary most of the time.
2459793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2460793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@sa invert, solve, eigen, determinant
2461793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
2462793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerclass CV_EXPORTS SVD
2463793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{
2464793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerpublic:
2465793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    enum Flags {
2466793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        /** allow the algorithm to modify the decomposed matrix; it can save space and speed up
2467793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler            processing. currently ignored. */
2468793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        MODIFY_A = 1,
2469793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        /** indicates that only a vector of singular values `w` is to be processed, while u and vt
2470793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler            will be set to empty matrices */
2471793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        NO_UV    = 2,
2472793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        /** when the matrix is not square, by default the algorithm produces u and vt matrices of
2473793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler            sufficiently large size for the further A reconstruction; if, however, FULL_UV flag is
2474793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler            specified, u and vt will be full-size square orthogonal matrices.*/
2475793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        FULL_UV  = 4
2476793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    };
2477793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2478793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** @brief the default constructor
2479793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2480793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    initializes an empty SVD structure
2481793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler      */
2482793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    SVD();
2483793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2484793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** @overload
2485793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    initializes an empty SVD structure and then calls SVD::operator()
2486793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @param src decomposed matrix.
2487793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @param flags operation flags (SVD::Flags)
2488793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler      */
2489793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    SVD( InputArray src, int flags = 0 );
2490793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2491793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** @brief the operator that performs SVD. The previously allocated u, w and vt are released.
2492793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2493793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    The operator performs the singular value decomposition of the supplied
2494793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    matrix. The u,`vt` , and the vector of singular values w are stored in
2495793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    the structure. The same SVD structure can be reused many times with
2496793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    different matrices. Each time, if needed, the previous u,`vt` , and w
2497793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    are reclaimed and the new matrices are created, which is all handled by
2498793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    Mat::create.
2499793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @param src decomposed matrix.
2500793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @param flags operation flags (SVD::Flags)
2501793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler      */
2502793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    SVD& operator ()( InputArray src, int flags = 0 );
2503793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2504793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** @brief decomposes matrix and stores the results to user-provided matrices
2505793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2506793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    The methods/functions perform SVD of matrix. Unlike SVD::SVD constructor
2507793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    and SVD::operator(), they store the results to the user-provided
2508793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    matrices:
2509793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2510793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @code{.cpp}
2511793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    Mat A, w, u, vt;
2512793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    SVD::compute(A, w, u, vt);
2513793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @endcode
2514793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2515793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @param src decomposed matrix
2516793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @param w calculated singular values
2517793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @param u calculated left singular vectors
2518793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @param vt transposed matrix of right singular values
2519793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @param flags operation flags - see SVD::SVD.
2520793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler      */
2521793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    static void compute( InputArray src, OutputArray w,
2522793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                         OutputArray u, OutputArray vt, int flags = 0 );
2523793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2524793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** @overload
2525793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    computes singular values of a matrix
2526793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @param src decomposed matrix
2527793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @param w calculated singular values
2528793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @param flags operation flags - see SVD::Flags.
2529793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler      */
2530793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    static void compute( InputArray src, OutputArray w, int flags = 0 );
2531793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2532793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** @brief performs back substitution
2533793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler      */
2534793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    static void backSubst( InputArray w, InputArray u,
2535793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                           InputArray vt, InputArray rhs,
2536793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                           OutputArray dst );
2537793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2538793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** @brief solves an under-determined singular linear system
2539793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2540793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    The method finds a unit-length solution x of a singular linear system
2541793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    A\*x = 0. Depending on the rank of A, there can be no solutions, a
2542793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    single solution or an infinite number of solutions. In general, the
2543793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    algorithm solves the following problem:
2544793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    \f[dst =  \arg \min _{x:  \| x \| =1}  \| src  \cdot x  \|\f]
2545793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @param src left-hand-side matrix.
2546793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @param dst found solution.
2547793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler      */
2548793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    static void solveZ( InputArray src, OutputArray dst );
2549793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2550793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** @brief performs a singular value back substitution.
2551793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2552793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    The method calculates a back substitution for the specified right-hand
2553793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    side:
2554793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2555793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    \f[\texttt{x} =  \texttt{vt} ^T  \cdot diag( \texttt{w} )^{-1}  \cdot \texttt{u} ^T  \cdot \texttt{rhs} \sim \texttt{A} ^{-1}  \cdot \texttt{rhs}\f]
2556793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2557793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    Using this technique you can either get a very accurate solution of the
2558793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    convenient linear system, or the best (in the least-squares terms)
2559793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    pseudo-solution of an overdetermined linear system.
2560793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2561793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @param rhs right-hand side of a linear system (u\*w\*v')\*dst = rhs to
2562793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    be solved, where A has been previously decomposed.
2563793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2564793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @param dst found solution of the system.
2565793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2566793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @note Explicit SVD with the further back substitution only makes sense
2567793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    if you need to solve many linear systems with the same left-hand side
2568793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    (for example, src ). If all you need is to solve a single system
2569793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    (possibly with multiple rhs immediately available), simply call solve
2570793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    add pass DECOMP_SVD there. It does absolutely the same thing.
2571793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler      */
2572793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    void backSubst( InputArray rhs, OutputArray dst ) const;
2573793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2574793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** @todo document */
2575793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    template<typename _Tp, int m, int n, int nm> static
2576793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    void compute( const Matx<_Tp, m, n>& a, Matx<_Tp, nm, 1>& w, Matx<_Tp, m, nm>& u, Matx<_Tp, n, nm>& vt );
2577793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2578793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** @todo document */
2579793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    template<typename _Tp, int m, int n, int nm> static
2580793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    void compute( const Matx<_Tp, m, n>& a, Matx<_Tp, nm, 1>& w );
2581793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2582793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** @todo document */
2583793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    template<typename _Tp, int m, int n, int nm, int nb> static
2584793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    void backSubst( const Matx<_Tp, nm, 1>& w, const Matx<_Tp, m, nm>& u, const Matx<_Tp, n, nm>& vt, const Matx<_Tp, m, nb>& rhs, Matx<_Tp, n, nb>& dst );
2585793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2586793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    Mat u, w, vt;
2587793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler};
2588793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2589793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Random Number Generator
2590793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2591793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerRandom number generator. It encapsulates the state (currently, a 64-bit
2592793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerinteger) and has methods to return scalar random values and to fill
2593793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerarrays with random values. Currently it supports uniform and Gaussian
2594793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler(normal) distributions. The generator uses Multiply-With-Carry
2595793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presleralgorithm, introduced by G. Marsaglia (
2596793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler<http://en.wikipedia.org/wiki/Multiply-with-carry> ).
2597793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerGaussian-distribution random numbers are generated using the Ziggurat
2598793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presleralgorithm ( <http://en.wikipedia.org/wiki/Ziggurat_algorithm> ),
2599793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerintroduced by G. Marsaglia and W. W. Tsang.
2600793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
2601793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerclass CV_EXPORTS RNG
2602793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{
2603793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerpublic:
2604793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    enum { UNIFORM = 0,
2605793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler           NORMAL  = 1
2606793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler         };
2607793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2608793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** @brief constructor
2609793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2610793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    These are the RNG constructors. The first form sets the state to some
2611793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    pre-defined value, equal to 2\*\*32-1 in the current implementation. The
2612793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    second form sets the state to the specified value. If you passed state=0
2613793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    , the constructor uses the above default value instead to avoid the
2614793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    singular random number sequence, consisting of all zeros.
2615793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    */
2616793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    RNG();
2617793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** @overload
2618793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @param state 64-bit value used to initialize the RNG.
2619793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    */
2620793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    RNG(uint64 state);
2621793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /**The method updates the state using the MWC algorithm and returns the
2622793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    next 32-bit random number.*/
2623793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    unsigned next();
2624793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2625793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /**Each of the methods updates the state using the MWC algorithm and
2626793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    returns the next random number of the specified type. In case of integer
2627793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    types, the returned number is from the available value range for the
2628793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    specified type. In case of floating-point types, the returned value is
2629793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    from [0,1) range.
2630793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    */
2631793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    operator uchar();
2632793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** @overload */
2633793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    operator schar();
2634793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** @overload */
2635793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    operator ushort();
2636793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** @overload */
2637793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    operator short();
2638793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** @overload */
2639793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    operator unsigned();
2640793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** @overload */
2641793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    operator int();
2642793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** @overload */
2643793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    operator float();
2644793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** @overload */
2645793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    operator double();
2646793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2647793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** @brief returns a random integer sampled uniformly from [0, N).
2648793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2649793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    The methods transform the state using the MWC algorithm and return the
2650793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    next random number. The first form is equivalent to RNG::next . The
2651793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    second form returns the random number modulo N , which means that the
2652793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    result is in the range [0, N) .
2653793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    */
2654793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    unsigned operator ()();
2655793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** @overload
2656793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @param N upper non-inclusive boundary of the returned random number.
2657793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    */
2658793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    unsigned operator ()(unsigned N);
2659793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2660793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** @brief returns uniformly distributed integer random number from [a,b) range
2661793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2662793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    The methods transform the state using the MWC algorithm and return the
2663793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    next uniformly-distributed random number of the specified type, deduced
2664793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    from the input parameter type, from the range [a, b) . There is a nuance
2665793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    illustrated by the following sample:
2666793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2667793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @code{.cpp}
2668793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    RNG rng;
2669793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2670793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    // always produces 0
2671793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    double a = rng.uniform(0, 1);
2672793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2673793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    // produces double from [0, 1)
2674793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    double a1 = rng.uniform((double)0, (double)1);
2675793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2676793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    // produces float from [0, 1)
2677793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    double b = rng.uniform(0.f, 1.f);
2678793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2679793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    // produces double from [0, 1)
2680793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    double c = rng.uniform(0., 1.);
2681793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2682793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    // may cause compiler error because of ambiguity:
2683793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    //  RNG::uniform(0, (int)0.999999)? or RNG::uniform((double)0, 0.99999)?
2684793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    double d = rng.uniform(0, 0.999999);
2685793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @endcode
2686793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2687793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    The compiler does not take into account the type of the variable to
2688793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    which you assign the result of RNG::uniform . The only thing that
2689793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    matters to the compiler is the type of a and b parameters. So, if you
2690793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    want a floating-point random number, but the range boundaries are
2691793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    integer numbers, either put dots in the end, if they are constants, or
2692793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    use explicit type cast operators, as in the a1 initialization above.
2693793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @param a lower inclusive boundary of the returned random numbers.
2694793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @param b upper non-inclusive boundary of the returned random numbers.
2695793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler      */
2696793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    int uniform(int a, int b);
2697793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** @overload */
2698793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    float uniform(float a, float b);
2699793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** @overload */
2700793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    double uniform(double a, double b);
2701793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2702793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** @brief Fills arrays with random numbers.
2703793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2704793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @param mat 2D or N-dimensional matrix; currently matrices with more than
2705793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    4 channels are not supported by the methods, use Mat::reshape as a
2706793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    possible workaround.
2707793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @param distType distribution type, RNG::UNIFORM or RNG::NORMAL.
2708793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @param a first distribution parameter; in case of the uniform
2709793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    distribution, this is an inclusive lower boundary, in case of the normal
2710793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    distribution, this is a mean value.
2711793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @param b second distribution parameter; in case of the uniform
2712793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    distribution, this is a non-inclusive upper boundary, in case of the
2713793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    normal distribution, this is a standard deviation (diagonal of the
2714793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    standard deviation matrix or the full standard deviation matrix).
2715793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @param saturateRange pre-saturation flag; for uniform distribution only;
2716793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    if true, the method will first convert a and b to the acceptable value
2717793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    range (according to the mat datatype) and then will generate uniformly
2718793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    distributed random numbers within the range [saturate(a), saturate(b)),
2719793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    if saturateRange=false, the method will generate uniformly distributed
2720793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    random numbers in the original range [a, b) and then will saturate them,
2721793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    it means, for example, that
2722793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    <tt>theRNG().fill(mat_8u, RNG::UNIFORM, -DBL_MAX, DBL_MAX)</tt> will likely
2723793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    produce array mostly filled with 0's and 255's, since the range (0, 255)
2724793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    is significantly smaller than [-DBL_MAX, DBL_MAX).
2725793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2726793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    Each of the methods fills the matrix with the random values from the
2727793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    specified distribution. As the new numbers are generated, the RNG state
2728793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    is updated accordingly. In case of multiple-channel images, every
2729793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    channel is filled independently, which means that RNG cannot generate
2730793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    samples from the multi-dimensional Gaussian distribution with
2731793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    non-diagonal covariance matrix directly. To do that, the method
2732793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    generates samples from multi-dimensional standard Gaussian distribution
2733793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    with zero mean and identity covariation matrix, and then transforms them
2734793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    using transform to get samples from the specified Gaussian distribution.
2735793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    */
2736793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    void fill( InputOutputArray mat, int distType, InputArray a, InputArray b, bool saturateRange = false );
2737793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2738793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** @brief Returns the next random number sampled from the Gaussian distribution
2739793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    @param sigma standard deviation of the distribution.
2740793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2741793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    The method transforms the state using the MWC algorithm and returns the
2742793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    next random number from the Gaussian distribution N(0,sigma) . That is,
2743793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    the mean value of the returned random numbers is zero and the standard
2744793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    deviation is the specified sigma .
2745793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    */
2746793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    double gaussian(double sigma);
2747793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2748793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    uint64 state;
2749793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler};
2750793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2751793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Mersenne Twister random number generator
2752793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2753793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerInspired by http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/CODES/mt19937ar.c
2754793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@todo document
2755793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler */
2756793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerclass CV_EXPORTS RNG_MT19937
2757793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{
2758793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerpublic:
2759793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    RNG_MT19937();
2760793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    RNG_MT19937(unsigned s);
2761793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    void seed(unsigned s);
2762793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2763793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    unsigned next();
2764793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2765793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    operator int();
2766793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    operator unsigned();
2767793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    operator float();
2768793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    operator double();
2769793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2770793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    unsigned operator ()(unsigned N);
2771793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    unsigned operator ()();
2772793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2773793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** @brief returns uniformly distributed integer random number from [a,b) range
2774793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2775793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
2776793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    int uniform(int a, int b);
2777793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** @brief returns uniformly distributed floating-point random number from [a,b) range
2778793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2779793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
2780793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    float uniform(float a, float b);
2781793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** @brief returns uniformly distributed double-precision floating-point random number from [a,b) range
2782793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2783793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
2784793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    double uniform(double a, double b);
2785793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2786793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerprivate:
2787793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    enum PeriodParameters {N = 624, M = 397};
2788793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    unsigned state[N];
2789793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    int mti;
2790793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler};
2791793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2792793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler//! @} core_array
2793793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2794793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler//! @addtogroup core_cluster
2795793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler//!  @{
2796793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2797793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @example kmeans.cpp
2798793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler  An example on K-means clustering
2799793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
2800793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2801793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief Finds centers of clusters and groups input samples around the clusters.
2802793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2803793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerThe function kmeans implements a k-means algorithm that finds the centers of cluster_count clusters
2804793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerand groups the input samples around the clusters. As an output, \f$\texttt{labels}_i\f$ contains a
2805793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler0-based cluster index for the sample stored in the \f$i^{th}\f$ row of the samples matrix.
2806793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2807793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@note
2808793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler-   (Python) An example on K-means clustering can be found at
2809793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    opencv_source_code/samples/python2/kmeans.py
2810793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param data Data for clustering. An array of N-Dimensional points with float coordinates is needed.
2811793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerExamples of this array can be:
2812793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler-   Mat points(count, 2, CV_32F);
2813793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler-   Mat points(count, 1, CV_32FC2);
2814793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler-   Mat points(1, count, CV_32FC2);
2815793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler-   std::vector\<cv::Point2f\> points(sampleCount);
2816793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param K Number of clusters to split the set by.
2817793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param bestLabels Input/output integer array that stores the cluster indices for every sample.
2818793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param criteria The algorithm termination criteria, that is, the maximum number of iterations and/or
2819793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerthe desired accuracy. The accuracy is specified as criteria.epsilon. As soon as each of the cluster
2820793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslercenters moves by less than criteria.epsilon on some iteration, the algorithm stops.
2821793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param attempts Flag to specify the number of times the algorithm is executed using different
2822793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerinitial labellings. The algorithm returns the labels that yield the best compactness (see the last
2823793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerfunction parameter).
2824793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param flags Flag that can take values of cv::KmeansFlags
2825793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@param centers Output matrix of the cluster centers, one row per each cluster center.
2826793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@return The function returns the compactness measure that is computed as
2827793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\f[\sum _i  \| \texttt{samples} _i -  \texttt{centers} _{ \texttt{labels} _i} \| ^2\f]
2828793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerafter every attempt. The best (minimum) value is chosen and the corresponding labels and the
2829793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslercompactness value are returned by the function. Basically, you can use only the core of the
2830793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerfunction, set the number of attempts to 1, initialize labels each time using a custom algorithm,
2831793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerpass them with the ( flags = KMEANS_USE_INITIAL_LABELS ) flag, and then choose the best
2832793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler(most-compact) clustering.
2833793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler*/
2834793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS_W double kmeans( InputArray data, int K, InputOutputArray bestLabels,
2835793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                            TermCriteria criteria, int attempts,
2836793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                            int flags, OutputArray centers = noArray() );
2837793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2838793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler//! @} core_cluster
2839793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2840793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler//! @addtogroup core_basic
2841793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler//! @{
2842793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2843793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/////////////////////////////// Formatted output of cv::Mat ///////////////////////////
2844793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2845793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @todo document */
2846793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerclass CV_EXPORTS Formatted
2847793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{
2848793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerpublic:
2849793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    virtual const char* next() = 0;
2850793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    virtual void reset() = 0;
2851793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    virtual ~Formatted();
2852793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler};
2853793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2854793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @todo document */
2855793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerclass CV_EXPORTS Formatter
2856793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{
2857793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerpublic:
2858793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    enum { FMT_DEFAULT = 0,
2859793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler           FMT_MATLAB  = 1,
2860793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler           FMT_CSV     = 2,
2861793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler           FMT_PYTHON  = 3,
2862793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler           FMT_NUMPY   = 4,
2863793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler           FMT_C       = 5
2864793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler         };
2865793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2866793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    virtual ~Formatter();
2867793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2868793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    virtual Ptr<Formatted> format(const Mat& mtx) const = 0;
2869793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2870793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    virtual void set32fPrecision(int p = 8) = 0;
2871793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    virtual void set64fPrecision(int p = 16) = 0;
2872793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    virtual void setMultiline(bool ml = true) = 0;
2873793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2874793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    static Ptr<Formatter> get(int fmt = FMT_DEFAULT);
2875793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2876793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler};
2877793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2878793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler//////////////////////////////////////// Algorithm ////////////////////////////////////
2879793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2880793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerclass CV_EXPORTS Algorithm;
2881793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2882793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslertemplate<typename _Tp> struct ParamType {};
2883793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2884793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2885793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/** @brief This is a base class for all more or less complex algorithms in OpenCV
2886793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2887793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerespecially for classes of algorithms, for which there can be multiple implementations. The examples
2888793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerare stereo correspondence (for which there are algorithms like block matching, semi-global block
2889793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslermatching, graph-cut etc.), background subtraction (which can be done using mixture-of-gaussians
2890793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslermodels, codebook-based algorithm etc.), optical flow (block matching, Lucas-Kanade, Horn-Schunck
2891793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presleretc.).
2892793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2893793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerHere is example of SIFT use in your application via Algorithm interface:
2894793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@code
2895793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    #include "opencv2/opencv.hpp"
2896793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    #include "opencv2/xfeatures2d.hpp"
2897793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    using namespace cv::xfeatures2d;
2898793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2899793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    Ptr<Feature2D> sift = SIFT::create();
2900793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    FileStorage fs("sift_params.xml", FileStorage::READ);
2901793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    if( fs.isOpened() ) // if we have file with parameters, read them
2902793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    {
2903793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        sift->read(fs["sift_params"]);
2904793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        fs.release();
2905793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    }
2906793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    else // else modify the parameters and store them; user can later edit the file to use different parameters
2907793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    {
2908793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        sift->setContrastThreshold(0.01f); // lower the contrast threshold, compared to the default value
2909793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        {
2910793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler            WriteStructContext ws(fs, "sift_params", CV_NODE_MAP);
2911793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler            sift->write(fs);
2912793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        }
2913793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    }
2914793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    Mat image = imread("myimage.png", 0), descriptors;
2915793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    vector<KeyPoint> keypoints;
2916793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    sift->detectAndCompute(image, noArray(), keypoints, descriptors);
2917793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler@endcode
2918793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler */
2919793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerclass CV_EXPORTS_W Algorithm
2920793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{
2921793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerpublic:
2922793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    Algorithm();
2923793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    virtual ~Algorithm();
2924793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2925793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** @brief Clears the algorithm state
2926793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    */
2927793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    CV_WRAP virtual void clear() {}
2928793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2929793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** @brief Stores algorithm parameters in a file storage
2930793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    */
2931793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    virtual void write(FileStorage& fs) const { (void)fs; }
2932793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2933793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** @brief Reads algorithm parameters from a file storage
2934793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    */
2935793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    virtual void read(const FileNode& fn) { (void)fn; }
2936793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2937793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** @brief Returns true if the Algorithm is empty (e.g. in the very beginning or after unsuccessful read
2938793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler     */
2939793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    virtual bool empty() const { return false; }
2940793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2941793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** @brief Reads algorithm from the file node
2942793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2943793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler     This is static template method of Algorithm. It's usage is following (in the case of SVM):
2944793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler     @code
2945793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler     Ptr<SVM> svm = Algorithm::read<SVM>(fn);
2946793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler     @endcode
2947793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler     In order to make this method work, the derived class must overwrite Algorithm::read(const
2948793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler     FileNode& fn) and also have static create() method without parameters
2949793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler     (or with all the optional parameters)
2950793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler     */
2951793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    template<typename _Tp> static Ptr<_Tp> read(const FileNode& fn)
2952793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    {
2953793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        Ptr<_Tp> obj = _Tp::create();
2954793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        obj->read(fn);
2955793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        return !obj->empty() ? obj : Ptr<_Tp>();
2956793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    }
2957793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2958793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** @brief Loads algorithm from the file
2959793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2960793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler     @param filename Name of the file to read.
2961793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler     @param objname The optional name of the node to read (if empty, the first top-level node will be used)
2962793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2963793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler     This is static template method of Algorithm. It's usage is following (in the case of SVM):
2964793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler     @code
2965793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler     Ptr<SVM> svm = Algorithm::load<SVM>("my_svm_model.xml");
2966793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler     @endcode
2967793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler     In order to make this method work, the derived class must overwrite Algorithm::read(const
2968793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler     FileNode& fn).
2969793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler     */
2970793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    template<typename _Tp> static Ptr<_Tp> load(const String& filename, const String& objname=String())
2971793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    {
2972793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        FileStorage fs(filename, FileStorage::READ);
2973793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        FileNode fn = objname.empty() ? fs.getFirstTopLevelNode() : fs[objname];
2974793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        Ptr<_Tp> obj = _Tp::create();
2975793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        obj->read(fn);
2976793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        return !obj->empty() ? obj : Ptr<_Tp>();
2977793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    }
2978793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2979793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** @brief Loads algorithm from a String
2980793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2981793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler     @param strModel The string variable containing the model you want to load.
2982793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler     @param objname The optional name of the node to read (if empty, the first top-level node will be used)
2983793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2984793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler     This is static template method of Algorithm. It's usage is following (in the case of SVM):
2985793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler     @code
2986793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler     Ptr<SVM> svm = Algorithm::loadFromString<SVM>(myStringModel);
2987793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler     @endcode
2988793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler     */
2989793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    template<typename _Tp> static Ptr<_Tp> loadFromString(const String& strModel, const String& objname=String())
2990793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    {
2991793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        FileStorage fs(strModel, FileStorage::READ + FileStorage::MEMORY);
2992793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        FileNode fn = objname.empty() ? fs.getFirstTopLevelNode() : fs[objname];
2993793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        Ptr<_Tp> obj = _Tp::create();
2994793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        obj->read(fn);
2995793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        return !obj->empty() ? obj : Ptr<_Tp>();
2996793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    }
2997793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
2998793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** Saves the algorithm to a file.
2999793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler     In order to make this method work, the derived class must implement Algorithm::write(FileStorage& fs). */
3000793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    CV_WRAP virtual void save(const String& filename) const;
3001793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
3002793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    /** Returns the algorithm string identifier.
3003793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler     This string is used as top level xml/yml node tag when the object is saved to a file or string. */
3004793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    CV_WRAP virtual String getDefaultName() const;
3005793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler};
3006793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
3007793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerstruct Param {
3008793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    enum { INT=0, BOOLEAN=1, REAL=2, STRING=3, MAT=4, MAT_VECTOR=5, ALGORITHM=6, FLOAT=7,
3009793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler           UNSIGNED_INT=8, UINT64=9, UCHAR=11 };
3010793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler};
3011793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
3012793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
3013793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
3014793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslertemplate<> struct ParamType<bool>
3015793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{
3016793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    typedef bool const_param_type;
3017793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    typedef bool member_type;
3018793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
3019793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    enum { type = Param::BOOLEAN };
3020793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler};
3021793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
3022793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslertemplate<> struct ParamType<int>
3023793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{
3024793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    typedef int const_param_type;
3025793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    typedef int member_type;
3026793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
3027793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    enum { type = Param::INT };
3028793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler};
3029793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
3030793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslertemplate<> struct ParamType<double>
3031793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{
3032793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    typedef double const_param_type;
3033793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    typedef double member_type;
3034793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
3035793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    enum { type = Param::REAL };
3036793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler};
3037793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
3038793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslertemplate<> struct ParamType<String>
3039793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{
3040793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    typedef const String& const_param_type;
3041793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    typedef String member_type;
3042793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
3043793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    enum { type = Param::STRING };
3044793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler};
3045793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
3046793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslertemplate<> struct ParamType<Mat>
3047793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{
3048793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    typedef const Mat& const_param_type;
3049793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    typedef Mat member_type;
3050793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
3051793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    enum { type = Param::MAT };
3052793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler};
3053793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
3054793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslertemplate<> struct ParamType<std::vector<Mat> >
3055793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{
3056793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    typedef const std::vector<Mat>& const_param_type;
3057793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    typedef std::vector<Mat> member_type;
3058793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
3059793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    enum { type = Param::MAT_VECTOR };
3060793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler};
3061793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
3062793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslertemplate<> struct ParamType<Algorithm>
3063793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{
3064793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    typedef const Ptr<Algorithm>& const_param_type;
3065793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    typedef Ptr<Algorithm> member_type;
3066793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
3067793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    enum { type = Param::ALGORITHM };
3068793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler};
3069793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
3070793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslertemplate<> struct ParamType<float>
3071793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{
3072793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    typedef float const_param_type;
3073793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    typedef float member_type;
3074793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
3075793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    enum { type = Param::FLOAT };
3076793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler};
3077793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
3078793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslertemplate<> struct ParamType<unsigned>
3079793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{
3080793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    typedef unsigned const_param_type;
3081793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    typedef unsigned member_type;
3082793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
3083793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    enum { type = Param::UNSIGNED_INT };
3084793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler};
3085793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
3086793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslertemplate<> struct ParamType<uint64>
3087793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{
3088793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    typedef uint64 const_param_type;
3089793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    typedef uint64 member_type;
3090793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
3091793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    enum { type = Param::UINT64 };
3092793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler};
3093793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
3094793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslertemplate<> struct ParamType<uchar>
3095793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{
3096793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    typedef uchar const_param_type;
3097793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    typedef uchar member_type;
3098793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
3099793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    enum { type = Param::UCHAR };
3100793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler};
3101793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
3102793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler//! @} core_basic
3103793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
3104793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler} //namespace cv
3105793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
3106793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#include "opencv2/core/operations.hpp"
3107793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#include "opencv2/core/cvstd.inl.hpp"
3108793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#include "opencv2/core/utility.hpp"
3109793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#include "opencv2/core/optim.hpp"
3110793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
3111793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#endif /*__OPENCV_CORE_HPP__*/
3112