opencv on mbed

Dependencies:   mbed

Committer:
joeverbout
Date:
Thu Mar 31 21:16:38 2016 +0000
Revision:
0:ea44dc9ed014
OpenCV on mbed attempt

Who changed what in which revision?

UserRevisionLine numberNew contents of line
joeverbout 0:ea44dc9ed014 1 /*M///////////////////////////////////////////////////////////////////////////////////////
joeverbout 0:ea44dc9ed014 2 //
joeverbout 0:ea44dc9ed014 3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
joeverbout 0:ea44dc9ed014 4 //
joeverbout 0:ea44dc9ed014 5 // By downloading, copying, installing or using the software you agree to this license.
joeverbout 0:ea44dc9ed014 6 // If you do not agree to this license, do not download, install,
joeverbout 0:ea44dc9ed014 7 // copy or use the software.
joeverbout 0:ea44dc9ed014 8 //
joeverbout 0:ea44dc9ed014 9 //
joeverbout 0:ea44dc9ed014 10 // License Agreement
joeverbout 0:ea44dc9ed014 11 // For Open Source Computer Vision Library
joeverbout 0:ea44dc9ed014 12 //
joeverbout 0:ea44dc9ed014 13 // Copyright (C) 2000-2015, Intel Corporation, all rights reserved.
joeverbout 0:ea44dc9ed014 14 // Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved.
joeverbout 0:ea44dc9ed014 15 // Copyright (C) 2015, OpenCV Foundation, all rights reserved.
joeverbout 0:ea44dc9ed014 16 // Copyright (C) 2015, Itseez Inc., all rights reserved.
joeverbout 0:ea44dc9ed014 17 // Third party copyrights are property of their respective owners.
joeverbout 0:ea44dc9ed014 18 //
joeverbout 0:ea44dc9ed014 19 // Redistribution and use in source and binary forms, with or without modification,
joeverbout 0:ea44dc9ed014 20 // are permitted provided that the following conditions are met:
joeverbout 0:ea44dc9ed014 21 //
joeverbout 0:ea44dc9ed014 22 // * Redistribution's of source code must retain the above copyright notice,
joeverbout 0:ea44dc9ed014 23 // this list of conditions and the following disclaimer.
joeverbout 0:ea44dc9ed014 24 //
joeverbout 0:ea44dc9ed014 25 // * Redistribution's in binary form must reproduce the above copyright notice,
joeverbout 0:ea44dc9ed014 26 // this list of conditions and the following disclaimer in the documentation
joeverbout 0:ea44dc9ed014 27 // and/or other materials provided with the distribution.
joeverbout 0:ea44dc9ed014 28 //
joeverbout 0:ea44dc9ed014 29 // * The name of the copyright holders may not be used to endorse or promote products
joeverbout 0:ea44dc9ed014 30 // derived from this software without specific prior written permission.
joeverbout 0:ea44dc9ed014 31 //
joeverbout 0:ea44dc9ed014 32 // This software is provided by the copyright holders and contributors "as is" and
joeverbout 0:ea44dc9ed014 33 // any express or implied warranties, including, but not limited to, the implied
joeverbout 0:ea44dc9ed014 34 // warranties of merchantability and fitness for a particular purpose are disclaimed.
joeverbout 0:ea44dc9ed014 35 // In no event shall the Intel Corporation or contributors be liable for any direct,
joeverbout 0:ea44dc9ed014 36 // indirect, incidental, special, exemplary, or consequential damages
joeverbout 0:ea44dc9ed014 37 // (including, but not limited to, procurement of substitute goods or services;
joeverbout 0:ea44dc9ed014 38 // loss of use, data, or profits; or business interruption) however caused
joeverbout 0:ea44dc9ed014 39 // and on any theory of liability, whether in contract, strict liability,
joeverbout 0:ea44dc9ed014 40 // or tort (including negligence or otherwise) arising in any way out of
joeverbout 0:ea44dc9ed014 41 // the use of this software, even if advised of the possibility of such damage.
joeverbout 0:ea44dc9ed014 42 //
joeverbout 0:ea44dc9ed014 43 //M*/
joeverbout 0:ea44dc9ed014 44
joeverbout 0:ea44dc9ed014 45 #ifndef __OPENCV_CORE_HPP__
joeverbout 0:ea44dc9ed014 46 #define __OPENCV_CORE_HPP__
joeverbout 0:ea44dc9ed014 47
joeverbout 0:ea44dc9ed014 48 #ifndef __cplusplus
joeverbout 0:ea44dc9ed014 49 # error core.hpp header must be compiled as C++
joeverbout 0:ea44dc9ed014 50 #endif
joeverbout 0:ea44dc9ed014 51
joeverbout 0:ea44dc9ed014 52 #include "opencv2/core/cvdef.h"
joeverbout 0:ea44dc9ed014 53 #include "opencv2/core/version.hpp"
joeverbout 0:ea44dc9ed014 54 #include "opencv2/core/base.hpp"
joeverbout 0:ea44dc9ed014 55 #include "opencv2/core/cvstd.hpp"
joeverbout 0:ea44dc9ed014 56 #include "opencv2/core/traits.hpp"
joeverbout 0:ea44dc9ed014 57 #include "opencv2/core/matx.hpp"
joeverbout 0:ea44dc9ed014 58 #include "opencv2/core/types.hpp"
joeverbout 0:ea44dc9ed014 59 #include "opencv2/core/mat.hpp"
joeverbout 0:ea44dc9ed014 60 #include "opencv2/core/persistence.hpp"
joeverbout 0:ea44dc9ed014 61
joeverbout 0:ea44dc9ed014 62 /**
joeverbout 0:ea44dc9ed014 63 @defgroup core Core functionality
joeverbout 0:ea44dc9ed014 64 @{
joeverbout 0:ea44dc9ed014 65 @defgroup core_basic Basic structures
joeverbout 0:ea44dc9ed014 66 @defgroup core_c C structures and operations
joeverbout 0:ea44dc9ed014 67 @{
joeverbout 0:ea44dc9ed014 68 @defgroup core_c_glue Connections with C++
joeverbout 0:ea44dc9ed014 69 @}
joeverbout 0:ea44dc9ed014 70 @defgroup core_array Operations on arrays
joeverbout 0:ea44dc9ed014 71 @defgroup core_xml XML/YAML Persistence
joeverbout 0:ea44dc9ed014 72 @defgroup core_cluster Clustering
joeverbout 0:ea44dc9ed014 73 @defgroup core_utils Utility and system functions and macros
joeverbout 0:ea44dc9ed014 74 @{
joeverbout 0:ea44dc9ed014 75 @defgroup core_utils_sse SSE utilities
joeverbout 0:ea44dc9ed014 76 @defgroup core_utils_neon NEON utilities
joeverbout 0:ea44dc9ed014 77 @}
joeverbout 0:ea44dc9ed014 78 @defgroup core_opengl OpenGL interoperability
joeverbout 0:ea44dc9ed014 79 @defgroup core_ipp Intel IPP Asynchronous C/C++ Converters
joeverbout 0:ea44dc9ed014 80 @defgroup core_optim Optimization Algorithms
joeverbout 0:ea44dc9ed014 81 @defgroup core_directx DirectX interoperability
joeverbout 0:ea44dc9ed014 82 @defgroup core_eigen Eigen support
joeverbout 0:ea44dc9ed014 83 @defgroup core_opencl OpenCL support
joeverbout 0:ea44dc9ed014 84 @defgroup core_va_intel Intel VA-API/OpenCL (CL-VA) interoperability
joeverbout 0:ea44dc9ed014 85 @defgroup core_hal Hardware Acceleration Layer
joeverbout 0:ea44dc9ed014 86 @{
joeverbout 0:ea44dc9ed014 87 @defgroup core_hal_functions Functions
joeverbout 0:ea44dc9ed014 88 @defgroup core_hal_interface Interface
joeverbout 0:ea44dc9ed014 89 @defgroup core_hal_intrin Universal intrinsics
joeverbout 0:ea44dc9ed014 90 @{
joeverbout 0:ea44dc9ed014 91 @defgroup core_hal_intrin_impl Private implementation helpers
joeverbout 0:ea44dc9ed014 92 @}
joeverbout 0:ea44dc9ed014 93 @}
joeverbout 0:ea44dc9ed014 94 @}
joeverbout 0:ea44dc9ed014 95 */
joeverbout 0:ea44dc9ed014 96
joeverbout 0:ea44dc9ed014 97 namespace cv {
joeverbout 0:ea44dc9ed014 98
joeverbout 0:ea44dc9ed014 99 //! @addtogroup core_utils
joeverbout 0:ea44dc9ed014 100 //! @{
joeverbout 0:ea44dc9ed014 101
joeverbout 0:ea44dc9ed014 102 /*! @brief Class passed to an error.
joeverbout 0:ea44dc9ed014 103
joeverbout 0:ea44dc9ed014 104 This class encapsulates all or almost all necessary
joeverbout 0:ea44dc9ed014 105 information about the error happened in the program. The exception is
joeverbout 0:ea44dc9ed014 106 usually constructed and thrown implicitly via CV_Error and CV_Error_ macros.
joeverbout 0:ea44dc9ed014 107 @see error
joeverbout 0:ea44dc9ed014 108 */
joeverbout 0:ea44dc9ed014 109 class CV_EXPORTS Exception : public std::exception
joeverbout 0:ea44dc9ed014 110 {
joeverbout 0:ea44dc9ed014 111 public:
joeverbout 0:ea44dc9ed014 112 /*!
joeverbout 0:ea44dc9ed014 113 Default constructor
joeverbout 0:ea44dc9ed014 114 */
joeverbout 0:ea44dc9ed014 115 Exception();
joeverbout 0:ea44dc9ed014 116 /*!
joeverbout 0:ea44dc9ed014 117 Full constructor. Normally the constuctor is not called explicitly.
joeverbout 0:ea44dc9ed014 118 Instead, the macros CV_Error(), CV_Error_() and CV_Assert() are used.
joeverbout 0:ea44dc9ed014 119 */
joeverbout 0:ea44dc9ed014 120 Exception(int _code, const String& _err, const String& _func, const String& _file, int _line);
joeverbout 0:ea44dc9ed014 121 virtual ~Exception() throw();
joeverbout 0:ea44dc9ed014 122
joeverbout 0:ea44dc9ed014 123 /*!
joeverbout 0:ea44dc9ed014 124 \return the error description and the context as a text string.
joeverbout 0:ea44dc9ed014 125 */
joeverbout 0:ea44dc9ed014 126 virtual const char *what() const throw();
joeverbout 0:ea44dc9ed014 127 void formatMessage();
joeverbout 0:ea44dc9ed014 128
joeverbout 0:ea44dc9ed014 129 String msg; ///< the formatted error message
joeverbout 0:ea44dc9ed014 130
joeverbout 0:ea44dc9ed014 131 int code; ///< error code @see CVStatus
joeverbout 0:ea44dc9ed014 132 String err; ///< error description
joeverbout 0:ea44dc9ed014 133 String func; ///< function name. Available only when the compiler supports getting it
joeverbout 0:ea44dc9ed014 134 String file; ///< source file name where the error has occured
joeverbout 0:ea44dc9ed014 135 int line; ///< line number in the source file where the error has occured
joeverbout 0:ea44dc9ed014 136 };
joeverbout 0:ea44dc9ed014 137
joeverbout 0:ea44dc9ed014 138 /*! @brief Signals an error and raises the exception.
joeverbout 0:ea44dc9ed014 139
joeverbout 0:ea44dc9ed014 140 By default the function prints information about the error to stderr,
joeverbout 0:ea44dc9ed014 141 then it either stops if cv::setBreakOnError() had been called before or raises the exception.
joeverbout 0:ea44dc9ed014 142 It is possible to alternate error processing by using cv::redirectError().
joeverbout 0:ea44dc9ed014 143 @param exc the exception raisen.
joeverbout 0:ea44dc9ed014 144 @deprecated drop this version
joeverbout 0:ea44dc9ed014 145 */
joeverbout 0:ea44dc9ed014 146 CV_EXPORTS void error( const Exception& exc );
joeverbout 0:ea44dc9ed014 147
joeverbout 0:ea44dc9ed014 148 enum SortFlags { SORT_EVERY_ROW = 0, //!< each matrix row is sorted independently
joeverbout 0:ea44dc9ed014 149 SORT_EVERY_COLUMN = 1, //!< each matrix column is sorted
joeverbout 0:ea44dc9ed014 150 //!< independently; this flag and the previous one are
joeverbout 0:ea44dc9ed014 151 //!< mutually exclusive.
joeverbout 0:ea44dc9ed014 152 SORT_ASCENDING = 0, //!< each matrix row is sorted in the ascending
joeverbout 0:ea44dc9ed014 153 //!< order.
joeverbout 0:ea44dc9ed014 154 SORT_DESCENDING = 16 //!< each matrix row is sorted in the
joeverbout 0:ea44dc9ed014 155 //!< descending order; this flag and the previous one are also
joeverbout 0:ea44dc9ed014 156 //!< mutually exclusive.
joeverbout 0:ea44dc9ed014 157 };
joeverbout 0:ea44dc9ed014 158
joeverbout 0:ea44dc9ed014 159 //! @} core_utils
joeverbout 0:ea44dc9ed014 160
joeverbout 0:ea44dc9ed014 161 //! @addtogroup core
joeverbout 0:ea44dc9ed014 162 //! @{
joeverbout 0:ea44dc9ed014 163
joeverbout 0:ea44dc9ed014 164 //! Covariation flags
joeverbout 0:ea44dc9ed014 165 enum CovarFlags {
joeverbout 0:ea44dc9ed014 166 /** The output covariance matrix is calculated as:
joeverbout 0:ea44dc9ed014 167 \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]
joeverbout 0:ea44dc9ed014 168 The covariance matrix will be nsamples x nsamples. Such an unusual covariance matrix is used
joeverbout 0:ea44dc9ed014 169 for fast PCA of a set of very large vectors (see, for example, the EigenFaces technique for
joeverbout 0:ea44dc9ed014 170 face recognition). Eigenvalues of this "scrambled" matrix match the eigenvalues of the true
joeverbout 0:ea44dc9ed014 171 covariance matrix. The "true" eigenvectors can be easily calculated from the eigenvectors of
joeverbout 0:ea44dc9ed014 172 the "scrambled" covariance matrix. */
joeverbout 0:ea44dc9ed014 173 COVAR_SCRAMBLED = 0,
joeverbout 0:ea44dc9ed014 174 /**The output covariance matrix is calculated as:
joeverbout 0:ea44dc9ed014 175 \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]
joeverbout 0:ea44dc9ed014 176 covar will be a square matrix of the same size as the total number of elements in each input
joeverbout 0:ea44dc9ed014 177 vector. One and only one of COVAR_SCRAMBLED and COVAR_NORMAL must be specified.*/
joeverbout 0:ea44dc9ed014 178 COVAR_NORMAL = 1,
joeverbout 0:ea44dc9ed014 179 /** If the flag is specified, the function does not calculate mean from
joeverbout 0:ea44dc9ed014 180 the input vectors but, instead, uses the passed mean vector. This is useful if mean has been
joeverbout 0:ea44dc9ed014 181 pre-calculated or known in advance, or if the covariance matrix is calculated by parts. In
joeverbout 0:ea44dc9ed014 182 this case, mean is not a mean vector of the input sub-set of vectors but rather the mean
joeverbout 0:ea44dc9ed014 183 vector of the whole set.*/
joeverbout 0:ea44dc9ed014 184 COVAR_USE_AVG = 2,
joeverbout 0:ea44dc9ed014 185 /** If the flag is specified, the covariance matrix is scaled. In the
joeverbout 0:ea44dc9ed014 186 "normal" mode, scale is 1./nsamples . In the "scrambled" mode, scale is the reciprocal of the
joeverbout 0:ea44dc9ed014 187 total number of elements in each input vector. By default (if the flag is not specified), the
joeverbout 0:ea44dc9ed014 188 covariance matrix is not scaled ( scale=1 ).*/
joeverbout 0:ea44dc9ed014 189 COVAR_SCALE = 4,
joeverbout 0:ea44dc9ed014 190 /** If the flag is
joeverbout 0:ea44dc9ed014 191 specified, all the input vectors are stored as rows of the samples matrix. mean should be a
joeverbout 0:ea44dc9ed014 192 single-row vector in this case.*/
joeverbout 0:ea44dc9ed014 193 COVAR_ROWS = 8,
joeverbout 0:ea44dc9ed014 194 /** If the flag is
joeverbout 0:ea44dc9ed014 195 specified, all the input vectors are stored as columns of the samples matrix. mean should be a
joeverbout 0:ea44dc9ed014 196 single-column vector in this case.*/
joeverbout 0:ea44dc9ed014 197 COVAR_COLS = 16
joeverbout 0:ea44dc9ed014 198 };
joeverbout 0:ea44dc9ed014 199
joeverbout 0:ea44dc9ed014 200 //! k-Means flags
joeverbout 0:ea44dc9ed014 201 enum KmeansFlags {
joeverbout 0:ea44dc9ed014 202 /** Select random initial centers in each attempt.*/
joeverbout 0:ea44dc9ed014 203 KMEANS_RANDOM_CENTERS = 0,
joeverbout 0:ea44dc9ed014 204 /** Use kmeans++ center initialization by Arthur and Vassilvitskii [Arthur2007].*/
joeverbout 0:ea44dc9ed014 205 KMEANS_PP_CENTERS = 2,
joeverbout 0:ea44dc9ed014 206 /** During the first (and possibly the only) attempt, use the
joeverbout 0:ea44dc9ed014 207 user-supplied labels instead of computing them from the initial centers. For the second and
joeverbout 0:ea44dc9ed014 208 further attempts, use the random or semi-random centers. Use one of KMEANS_\*_CENTERS flag
joeverbout 0:ea44dc9ed014 209 to specify the exact method.*/
joeverbout 0:ea44dc9ed014 210 KMEANS_USE_INITIAL_LABELS = 1
joeverbout 0:ea44dc9ed014 211 };
joeverbout 0:ea44dc9ed014 212
joeverbout 0:ea44dc9ed014 213 //! type of line
joeverbout 0:ea44dc9ed014 214 enum LineTypes {
joeverbout 0:ea44dc9ed014 215 FILLED = -1,
joeverbout 0:ea44dc9ed014 216 LINE_4 = 4, //!< 4-connected line
joeverbout 0:ea44dc9ed014 217 LINE_8 = 8, //!< 8-connected line
joeverbout 0:ea44dc9ed014 218 LINE_AA = 16 //!< antialiased line
joeverbout 0:ea44dc9ed014 219 };
joeverbout 0:ea44dc9ed014 220
joeverbout 0:ea44dc9ed014 221 //! Only a subset of Hershey fonts
joeverbout 0:ea44dc9ed014 222 //! <http://sources.isc.org/utils/misc/hershey-font.txt> are supported
joeverbout 0:ea44dc9ed014 223 enum HersheyFonts {
joeverbout 0:ea44dc9ed014 224 FONT_HERSHEY_SIMPLEX = 0, //!< normal size sans-serif font
joeverbout 0:ea44dc9ed014 225 FONT_HERSHEY_PLAIN = 1, //!< small size sans-serif font
joeverbout 0:ea44dc9ed014 226 FONT_HERSHEY_DUPLEX = 2, //!< normal size sans-serif font (more complex than FONT_HERSHEY_SIMPLEX)
joeverbout 0:ea44dc9ed014 227 FONT_HERSHEY_COMPLEX = 3, //!< normal size serif font
joeverbout 0:ea44dc9ed014 228 FONT_HERSHEY_TRIPLEX = 4, //!< normal size serif font (more complex than FONT_HERSHEY_COMPLEX)
joeverbout 0:ea44dc9ed014 229 FONT_HERSHEY_COMPLEX_SMALL = 5, //!< smaller version of FONT_HERSHEY_COMPLEX
joeverbout 0:ea44dc9ed014 230 FONT_HERSHEY_SCRIPT_SIMPLEX = 6, //!< hand-writing style font
joeverbout 0:ea44dc9ed014 231 FONT_HERSHEY_SCRIPT_COMPLEX = 7, //!< more complex variant of FONT_HERSHEY_SCRIPT_SIMPLEX
joeverbout 0:ea44dc9ed014 232 FONT_ITALIC = 16 //!< flag for italic font
joeverbout 0:ea44dc9ed014 233 };
joeverbout 0:ea44dc9ed014 234
joeverbout 0:ea44dc9ed014 235 enum ReduceTypes { REDUCE_SUM = 0, //!< the output is the sum of all rows/columns of the matrix.
joeverbout 0:ea44dc9ed014 236 REDUCE_AVG = 1, //!< the output is the mean vector of all rows/columns of the matrix.
joeverbout 0:ea44dc9ed014 237 REDUCE_MAX = 2, //!< the output is the maximum (column/row-wise) of all rows/columns of the matrix.
joeverbout 0:ea44dc9ed014 238 REDUCE_MIN = 3 //!< the output is the minimum (column/row-wise) of all rows/columns of the matrix.
joeverbout 0:ea44dc9ed014 239 };
joeverbout 0:ea44dc9ed014 240
joeverbout 0:ea44dc9ed014 241
joeverbout 0:ea44dc9ed014 242 /** @brief Swaps two matrices
joeverbout 0:ea44dc9ed014 243 */
joeverbout 0:ea44dc9ed014 244 CV_EXPORTS void swap(Mat& a, Mat& b);
joeverbout 0:ea44dc9ed014 245 /** @overload */
joeverbout 0:ea44dc9ed014 246 CV_EXPORTS void swap( UMat& a, UMat& b );
joeverbout 0:ea44dc9ed014 247
joeverbout 0:ea44dc9ed014 248 //! @} core
joeverbout 0:ea44dc9ed014 249
joeverbout 0:ea44dc9ed014 250 //! @addtogroup core_array
joeverbout 0:ea44dc9ed014 251 //! @{
joeverbout 0:ea44dc9ed014 252
joeverbout 0:ea44dc9ed014 253 /** @brief Computes the source location of an extrapolated pixel.
joeverbout 0:ea44dc9ed014 254
joeverbout 0:ea44dc9ed014 255 The function computes and returns the coordinate of a donor pixel corresponding to the specified
joeverbout 0:ea44dc9ed014 256 extrapolated pixel when using the specified extrapolation border mode. For example, if you use
joeverbout 0:ea44dc9ed014 257 cv::BORDER_WRAP mode in the horizontal direction, cv::BORDER_REFLECT_101 in the vertical direction and
joeverbout 0:ea44dc9ed014 258 want to compute value of the "virtual" pixel Point(-5, 100) in a floating-point image img , it
joeverbout 0:ea44dc9ed014 259 looks like:
joeverbout 0:ea44dc9ed014 260 @code{.cpp}
joeverbout 0:ea44dc9ed014 261 float val = img.at<float>(borderInterpolate(100, img.rows, cv::BORDER_REFLECT_101),
joeverbout 0:ea44dc9ed014 262 borderInterpolate(-5, img.cols, cv::BORDER_WRAP));
joeverbout 0:ea44dc9ed014 263 @endcode
joeverbout 0:ea44dc9ed014 264 Normally, the function is not called directly. It is used inside filtering functions and also in
joeverbout 0:ea44dc9ed014 265 copyMakeBorder.
joeverbout 0:ea44dc9ed014 266 @param p 0-based coordinate of the extrapolated pixel along one of the axes, likely \<0 or \>= len
joeverbout 0:ea44dc9ed014 267 @param len Length of the array along the corresponding axis.
joeverbout 0:ea44dc9ed014 268 @param borderType Border type, one of the cv::BorderTypes, except for cv::BORDER_TRANSPARENT and
joeverbout 0:ea44dc9ed014 269 cv::BORDER_ISOLATED . When borderType==cv::BORDER_CONSTANT , the function always returns -1, regardless
joeverbout 0:ea44dc9ed014 270 of p and len.
joeverbout 0:ea44dc9ed014 271
joeverbout 0:ea44dc9ed014 272 @sa copyMakeBorder
joeverbout 0:ea44dc9ed014 273 */
joeverbout 0:ea44dc9ed014 274 CV_EXPORTS_W int borderInterpolate(int p, int len, int borderType);
joeverbout 0:ea44dc9ed014 275
joeverbout 0:ea44dc9ed014 276 /** @brief Forms a border around an image.
joeverbout 0:ea44dc9ed014 277
joeverbout 0:ea44dc9ed014 278 The function copies the source image into the middle of the destination image. The areas to the
joeverbout 0:ea44dc9ed014 279 left, to the right, above and below the copied source image will be filled with extrapolated
joeverbout 0:ea44dc9ed014 280 pixels. This is not what filtering functions based on it do (they extrapolate pixels on-fly), but
joeverbout 0:ea44dc9ed014 281 what other more complex functions, including your own, may do to simplify image boundary handling.
joeverbout 0:ea44dc9ed014 282
joeverbout 0:ea44dc9ed014 283 The function supports the mode when src is already in the middle of dst . In this case, the
joeverbout 0:ea44dc9ed014 284 function does not copy src itself but simply constructs the border, for example:
joeverbout 0:ea44dc9ed014 285
joeverbout 0:ea44dc9ed014 286 @code{.cpp}
joeverbout 0:ea44dc9ed014 287 // let border be the same in all directions
joeverbout 0:ea44dc9ed014 288 int border=2;
joeverbout 0:ea44dc9ed014 289 // constructs a larger image to fit both the image and the border
joeverbout 0:ea44dc9ed014 290 Mat gray_buf(rgb.rows + border*2, rgb.cols + border*2, rgb.depth());
joeverbout 0:ea44dc9ed014 291 // select the middle part of it w/o copying data
joeverbout 0:ea44dc9ed014 292 Mat gray(gray_canvas, Rect(border, border, rgb.cols, rgb.rows));
joeverbout 0:ea44dc9ed014 293 // convert image from RGB to grayscale
joeverbout 0:ea44dc9ed014 294 cvtColor(rgb, gray, COLOR_RGB2GRAY);
joeverbout 0:ea44dc9ed014 295 // form a border in-place
joeverbout 0:ea44dc9ed014 296 copyMakeBorder(gray, gray_buf, border, border,
joeverbout 0:ea44dc9ed014 297 border, border, BORDER_REPLICATE);
joeverbout 0:ea44dc9ed014 298 // now do some custom filtering ...
joeverbout 0:ea44dc9ed014 299 ...
joeverbout 0:ea44dc9ed014 300 @endcode
joeverbout 0:ea44dc9ed014 301 @note When the source image is a part (ROI) of a bigger image, the function will try to use the
joeverbout 0:ea44dc9ed014 302 pixels outside of the ROI to form a border. To disable this feature and always do extrapolation, as
joeverbout 0:ea44dc9ed014 303 if src was not a ROI, use borderType | BORDER_ISOLATED.
joeverbout 0:ea44dc9ed014 304
joeverbout 0:ea44dc9ed014 305 @param src Source image.
joeverbout 0:ea44dc9ed014 306 @param dst Destination image of the same type as src and the size Size(src.cols+left+right,
joeverbout 0:ea44dc9ed014 307 src.rows+top+bottom) .
joeverbout 0:ea44dc9ed014 308 @param top
joeverbout 0:ea44dc9ed014 309 @param bottom
joeverbout 0:ea44dc9ed014 310 @param left
joeverbout 0:ea44dc9ed014 311 @param right Parameter specifying how many pixels in each direction from the source image rectangle
joeverbout 0:ea44dc9ed014 312 to extrapolate. For example, top=1, bottom=1, left=1, right=1 mean that 1 pixel-wide border needs
joeverbout 0:ea44dc9ed014 313 to be built.
joeverbout 0:ea44dc9ed014 314 @param borderType Border type. See borderInterpolate for details.
joeverbout 0:ea44dc9ed014 315 @param value Border value if borderType==BORDER_CONSTANT .
joeverbout 0:ea44dc9ed014 316
joeverbout 0:ea44dc9ed014 317 @sa borderInterpolate
joeverbout 0:ea44dc9ed014 318 */
joeverbout 0:ea44dc9ed014 319 CV_EXPORTS_W void copyMakeBorder(InputArray src, OutputArray dst,
joeverbout 0:ea44dc9ed014 320 int top, int bottom, int left, int right,
joeverbout 0:ea44dc9ed014 321 int borderType, const Scalar& value = Scalar() );
joeverbout 0:ea44dc9ed014 322
joeverbout 0:ea44dc9ed014 323 /** @brief Calculates the per-element sum of two arrays or an array and a scalar.
joeverbout 0:ea44dc9ed014 324
joeverbout 0:ea44dc9ed014 325 The function add calculates:
joeverbout 0:ea44dc9ed014 326 - Sum of two arrays when both input arrays have the same size and the same number of channels:
joeverbout 0:ea44dc9ed014 327 \f[\texttt{dst}(I) = \texttt{saturate} ( \texttt{src1}(I) + \texttt{src2}(I)) \quad \texttt{if mask}(I) \ne0\f]
joeverbout 0:ea44dc9ed014 328 - Sum of an array and a scalar when src2 is constructed from Scalar or has the same number of
joeverbout 0:ea44dc9ed014 329 elements as `src1.channels()`:
joeverbout 0:ea44dc9ed014 330 \f[\texttt{dst}(I) = \texttt{saturate} ( \texttt{src1}(I) + \texttt{src2} ) \quad \texttt{if mask}(I) \ne0\f]
joeverbout 0:ea44dc9ed014 331 - Sum of a scalar and an array when src1 is constructed from Scalar or has the same number of
joeverbout 0:ea44dc9ed014 332 elements as `src2.channels()`:
joeverbout 0:ea44dc9ed014 333 \f[\texttt{dst}(I) = \texttt{saturate} ( \texttt{src1} + \texttt{src2}(I) ) \quad \texttt{if mask}(I) \ne0\f]
joeverbout 0:ea44dc9ed014 334 where `I` is a multi-dimensional index of array elements. In case of multi-channel arrays, each
joeverbout 0:ea44dc9ed014 335 channel is processed independently.
joeverbout 0:ea44dc9ed014 336
joeverbout 0:ea44dc9ed014 337 The first function in the list above can be replaced with matrix expressions:
joeverbout 0:ea44dc9ed014 338 @code{.cpp}
joeverbout 0:ea44dc9ed014 339 dst = src1 + src2;
joeverbout 0:ea44dc9ed014 340 dst += src1; // equivalent to add(dst, src1, dst);
joeverbout 0:ea44dc9ed014 341 @endcode
joeverbout 0:ea44dc9ed014 342 The input arrays and the output array can all have the same or different depths. For example, you
joeverbout 0:ea44dc9ed014 343 can add a 16-bit unsigned array to a 8-bit signed array and store the sum as a 32-bit
joeverbout 0:ea44dc9ed014 344 floating-point array. Depth of the output array is determined by the dtype parameter. In the second
joeverbout 0:ea44dc9ed014 345 and third cases above, as well as in the first case, when src1.depth() == src2.depth(), dtype can
joeverbout 0:ea44dc9ed014 346 be set to the default -1. In this case, the output array will have the same depth as the input
joeverbout 0:ea44dc9ed014 347 array, be it src1, src2 or both.
joeverbout 0:ea44dc9ed014 348 @note Saturation is not applied when the output array has the depth CV_32S. You may even get
joeverbout 0:ea44dc9ed014 349 result of an incorrect sign in the case of overflow.
joeverbout 0:ea44dc9ed014 350 @param src1 first input array or a scalar.
joeverbout 0:ea44dc9ed014 351 @param src2 second input array or a scalar.
joeverbout 0:ea44dc9ed014 352 @param dst output array that has the same size and number of channels as the input array(s); the
joeverbout 0:ea44dc9ed014 353 depth is defined by dtype or src1/src2.
joeverbout 0:ea44dc9ed014 354 @param mask optional operation mask - 8-bit single channel array, that specifies elements of the
joeverbout 0:ea44dc9ed014 355 output array to be changed.
joeverbout 0:ea44dc9ed014 356 @param dtype optional depth of the output array (see the discussion below).
joeverbout 0:ea44dc9ed014 357 @sa subtract, addWeighted, scaleAdd, Mat::convertTo
joeverbout 0:ea44dc9ed014 358 */
joeverbout 0:ea44dc9ed014 359 CV_EXPORTS_W void add(InputArray src1, InputArray src2, OutputArray dst,
joeverbout 0:ea44dc9ed014 360 InputArray mask = noArray(), int dtype = -1);
joeverbout 0:ea44dc9ed014 361
joeverbout 0:ea44dc9ed014 362 /** @brief Calculates the per-element difference between two arrays or array and a scalar.
joeverbout 0:ea44dc9ed014 363
joeverbout 0:ea44dc9ed014 364 The function subtract calculates:
joeverbout 0:ea44dc9ed014 365 - Difference between two arrays, when both input arrays have the same size and the same number of
joeverbout 0:ea44dc9ed014 366 channels:
joeverbout 0:ea44dc9ed014 367 \f[\texttt{dst}(I) = \texttt{saturate} ( \texttt{src1}(I) - \texttt{src2}(I)) \quad \texttt{if mask}(I) \ne0\f]
joeverbout 0:ea44dc9ed014 368 - Difference between an array and a scalar, when src2 is constructed from Scalar or has the same
joeverbout 0:ea44dc9ed014 369 number of elements as `src1.channels()`:
joeverbout 0:ea44dc9ed014 370 \f[\texttt{dst}(I) = \texttt{saturate} ( \texttt{src1}(I) - \texttt{src2} ) \quad \texttt{if mask}(I) \ne0\f]
joeverbout 0:ea44dc9ed014 371 - Difference between a scalar and an array, when src1 is constructed from Scalar or has the same
joeverbout 0:ea44dc9ed014 372 number of elements as `src2.channels()`:
joeverbout 0:ea44dc9ed014 373 \f[\texttt{dst}(I) = \texttt{saturate} ( \texttt{src1} - \texttt{src2}(I) ) \quad \texttt{if mask}(I) \ne0\f]
joeverbout 0:ea44dc9ed014 374 - The reverse difference between a scalar and an array in the case of `SubRS`:
joeverbout 0:ea44dc9ed014 375 \f[\texttt{dst}(I) = \texttt{saturate} ( \texttt{src2} - \texttt{src1}(I) ) \quad \texttt{if mask}(I) \ne0\f]
joeverbout 0:ea44dc9ed014 376 where I is a multi-dimensional index of array elements. In case of multi-channel arrays, each
joeverbout 0:ea44dc9ed014 377 channel is processed independently.
joeverbout 0:ea44dc9ed014 378
joeverbout 0:ea44dc9ed014 379 The first function in the list above can be replaced with matrix expressions:
joeverbout 0:ea44dc9ed014 380 @code{.cpp}
joeverbout 0:ea44dc9ed014 381 dst = src1 - src2;
joeverbout 0:ea44dc9ed014 382 dst -= src1; // equivalent to subtract(dst, src1, dst);
joeverbout 0:ea44dc9ed014 383 @endcode
joeverbout 0:ea44dc9ed014 384 The input arrays and the output array can all have the same or different depths. For example, you
joeverbout 0:ea44dc9ed014 385 can subtract to 8-bit unsigned arrays and store the difference in a 16-bit signed array. Depth of
joeverbout 0:ea44dc9ed014 386 the output array is determined by dtype parameter. In the second and third cases above, as well as
joeverbout 0:ea44dc9ed014 387 in the first case, when src1.depth() == src2.depth(), dtype can be set to the default -1. In this
joeverbout 0:ea44dc9ed014 388 case the output array will have the same depth as the input array, be it src1, src2 or both.
joeverbout 0:ea44dc9ed014 389 @note Saturation is not applied when the output array has the depth CV_32S. You may even get
joeverbout 0:ea44dc9ed014 390 result of an incorrect sign in the case of overflow.
joeverbout 0:ea44dc9ed014 391 @param src1 first input array or a scalar.
joeverbout 0:ea44dc9ed014 392 @param src2 second input array or a scalar.
joeverbout 0:ea44dc9ed014 393 @param dst output array of the same size and the same number of channels as the input array.
joeverbout 0:ea44dc9ed014 394 @param mask optional operation mask; this is an 8-bit single channel array that specifies elements
joeverbout 0:ea44dc9ed014 395 of the output array to be changed.
joeverbout 0:ea44dc9ed014 396 @param dtype optional depth of the output array
joeverbout 0:ea44dc9ed014 397 @sa add, addWeighted, scaleAdd, Mat::convertTo
joeverbout 0:ea44dc9ed014 398 */
joeverbout 0:ea44dc9ed014 399 CV_EXPORTS_W void subtract(InputArray src1, InputArray src2, OutputArray dst,
joeverbout 0:ea44dc9ed014 400 InputArray mask = noArray(), int dtype = -1);
joeverbout 0:ea44dc9ed014 401
joeverbout 0:ea44dc9ed014 402
joeverbout 0:ea44dc9ed014 403 /** @brief Calculates the per-element scaled product of two arrays.
joeverbout 0:ea44dc9ed014 404
joeverbout 0:ea44dc9ed014 405 The function multiply calculates the per-element product of two arrays:
joeverbout 0:ea44dc9ed014 406
joeverbout 0:ea44dc9ed014 407 \f[\texttt{dst} (I)= \texttt{saturate} ( \texttt{scale} \cdot \texttt{src1} (I) \cdot \texttt{src2} (I))\f]
joeverbout 0:ea44dc9ed014 408
joeverbout 0:ea44dc9ed014 409 There is also a @ref MatrixExpressions -friendly variant of the first function. See Mat::mul .
joeverbout 0:ea44dc9ed014 410
joeverbout 0:ea44dc9ed014 411 For a not-per-element matrix product, see gemm .
joeverbout 0:ea44dc9ed014 412
joeverbout 0:ea44dc9ed014 413 @note Saturation is not applied when the output array has the depth
joeverbout 0:ea44dc9ed014 414 CV_32S. You may even get result of an incorrect sign in the case of
joeverbout 0:ea44dc9ed014 415 overflow.
joeverbout 0:ea44dc9ed014 416 @param src1 first input array.
joeverbout 0:ea44dc9ed014 417 @param src2 second input array of the same size and the same type as src1.
joeverbout 0:ea44dc9ed014 418 @param dst output array of the same size and type as src1.
joeverbout 0:ea44dc9ed014 419 @param scale optional scale factor.
joeverbout 0:ea44dc9ed014 420 @param dtype optional depth of the output array
joeverbout 0:ea44dc9ed014 421 @sa add, subtract, divide, scaleAdd, addWeighted, accumulate, accumulateProduct, accumulateSquare,
joeverbout 0:ea44dc9ed014 422 Mat::convertTo
joeverbout 0:ea44dc9ed014 423 */
joeverbout 0:ea44dc9ed014 424 CV_EXPORTS_W void multiply(InputArray src1, InputArray src2,
joeverbout 0:ea44dc9ed014 425 OutputArray dst, double scale = 1, int dtype = -1);
joeverbout 0:ea44dc9ed014 426
joeverbout 0:ea44dc9ed014 427 /** @brief Performs per-element division of two arrays or a scalar by an array.
joeverbout 0:ea44dc9ed014 428
joeverbout 0:ea44dc9ed014 429 The functions divide divide one array by another:
joeverbout 0:ea44dc9ed014 430 \f[\texttt{dst(I) = saturate(src1(I)*scale/src2(I))}\f]
joeverbout 0:ea44dc9ed014 431 or a scalar by an array when there is no src1 :
joeverbout 0:ea44dc9ed014 432 \f[\texttt{dst(I) = saturate(scale/src2(I))}\f]
joeverbout 0:ea44dc9ed014 433
joeverbout 0:ea44dc9ed014 434 When src2(I) is zero, dst(I) will also be zero. Different channels of
joeverbout 0:ea44dc9ed014 435 multi-channel arrays are processed independently.
joeverbout 0:ea44dc9ed014 436
joeverbout 0:ea44dc9ed014 437 @note Saturation is not applied when the output array has the depth CV_32S. You may even get
joeverbout 0:ea44dc9ed014 438 result of an incorrect sign in the case of overflow.
joeverbout 0:ea44dc9ed014 439 @param src1 first input array.
joeverbout 0:ea44dc9ed014 440 @param src2 second input array of the same size and type as src1.
joeverbout 0:ea44dc9ed014 441 @param scale scalar factor.
joeverbout 0:ea44dc9ed014 442 @param dst output array of the same size and type as src2.
joeverbout 0:ea44dc9ed014 443 @param dtype optional depth of the output array; if -1, dst will have depth src2.depth(), but in
joeverbout 0:ea44dc9ed014 444 case of an array-by-array division, you can only pass -1 when src1.depth()==src2.depth().
joeverbout 0:ea44dc9ed014 445 @sa multiply, add, subtract
joeverbout 0:ea44dc9ed014 446 */
joeverbout 0:ea44dc9ed014 447 CV_EXPORTS_W void divide(InputArray src1, InputArray src2, OutputArray dst,
joeverbout 0:ea44dc9ed014 448 double scale = 1, int dtype = -1);
joeverbout 0:ea44dc9ed014 449
joeverbout 0:ea44dc9ed014 450 /** @overload */
joeverbout 0:ea44dc9ed014 451 CV_EXPORTS_W void divide(double scale, InputArray src2,
joeverbout 0:ea44dc9ed014 452 OutputArray dst, int dtype = -1);
joeverbout 0:ea44dc9ed014 453
joeverbout 0:ea44dc9ed014 454 /** @brief Calculates the sum of a scaled array and another array.
joeverbout 0:ea44dc9ed014 455
joeverbout 0:ea44dc9ed014 456 The function scaleAdd is one of the classical primitive linear algebra operations, known as DAXPY
joeverbout 0:ea44dc9ed014 457 or SAXPY in [BLAS](http://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms). It calculates
joeverbout 0:ea44dc9ed014 458 the sum of a scaled array and another array:
joeverbout 0:ea44dc9ed014 459 \f[\texttt{dst} (I)= \texttt{scale} \cdot \texttt{src1} (I) + \texttt{src2} (I)\f]
joeverbout 0:ea44dc9ed014 460 The function can also be emulated with a matrix expression, for example:
joeverbout 0:ea44dc9ed014 461 @code{.cpp}
joeverbout 0:ea44dc9ed014 462 Mat A(3, 3, CV_64F);
joeverbout 0:ea44dc9ed014 463 ...
joeverbout 0:ea44dc9ed014 464 A.row(0) = A.row(1)*2 + A.row(2);
joeverbout 0:ea44dc9ed014 465 @endcode
joeverbout 0:ea44dc9ed014 466 @param src1 first input array.
joeverbout 0:ea44dc9ed014 467 @param alpha scale factor for the first array.
joeverbout 0:ea44dc9ed014 468 @param src2 second input array of the same size and type as src1.
joeverbout 0:ea44dc9ed014 469 @param dst output array of the same size and type as src1.
joeverbout 0:ea44dc9ed014 470 @sa add, addWeighted, subtract, Mat::dot, Mat::convertTo
joeverbout 0:ea44dc9ed014 471 */
joeverbout 0:ea44dc9ed014 472 CV_EXPORTS_W void scaleAdd(InputArray src1, double alpha, InputArray src2, OutputArray dst);
joeverbout 0:ea44dc9ed014 473
joeverbout 0:ea44dc9ed014 474 /** @brief Calculates the weighted sum of two arrays.
joeverbout 0:ea44dc9ed014 475
joeverbout 0:ea44dc9ed014 476 The function addWeighted calculates the weighted sum of two arrays as follows:
joeverbout 0:ea44dc9ed014 477 \f[\texttt{dst} (I)= \texttt{saturate} ( \texttt{src1} (I)* \texttt{alpha} + \texttt{src2} (I)* \texttt{beta} + \texttt{gamma} )\f]
joeverbout 0:ea44dc9ed014 478 where I is a multi-dimensional index of array elements. In case of multi-channel arrays, each
joeverbout 0:ea44dc9ed014 479 channel is processed independently.
joeverbout 0:ea44dc9ed014 480 The function can be replaced with a matrix expression:
joeverbout 0:ea44dc9ed014 481 @code{.cpp}
joeverbout 0:ea44dc9ed014 482 dst = src1*alpha + src2*beta + gamma;
joeverbout 0:ea44dc9ed014 483 @endcode
joeverbout 0:ea44dc9ed014 484 @note Saturation is not applied when the output array has the depth CV_32S. You may even get
joeverbout 0:ea44dc9ed014 485 result of an incorrect sign in the case of overflow.
joeverbout 0:ea44dc9ed014 486 @param src1 first input array.
joeverbout 0:ea44dc9ed014 487 @param alpha weight of the first array elements.
joeverbout 0:ea44dc9ed014 488 @param src2 second input array of the same size and channel number as src1.
joeverbout 0:ea44dc9ed014 489 @param beta weight of the second array elements.
joeverbout 0:ea44dc9ed014 490 @param gamma scalar added to each sum.
joeverbout 0:ea44dc9ed014 491 @param dst output array that has the same size and number of channels as the input arrays.
joeverbout 0:ea44dc9ed014 492 @param dtype optional depth of the output array; when both input arrays have the same depth, dtype
joeverbout 0:ea44dc9ed014 493 can be set to -1, which will be equivalent to src1.depth().
joeverbout 0:ea44dc9ed014 494 @sa add, subtract, scaleAdd, Mat::convertTo
joeverbout 0:ea44dc9ed014 495 */
joeverbout 0:ea44dc9ed014 496 CV_EXPORTS_W void addWeighted(InputArray src1, double alpha, InputArray src2,
joeverbout 0:ea44dc9ed014 497 double beta, double gamma, OutputArray dst, int dtype = -1);
joeverbout 0:ea44dc9ed014 498
joeverbout 0:ea44dc9ed014 499 /** @brief Scales, calculates absolute values, and converts the result to 8-bit.
joeverbout 0:ea44dc9ed014 500
joeverbout 0:ea44dc9ed014 501 On each element of the input array, the function convertScaleAbs
joeverbout 0:ea44dc9ed014 502 performs three operations sequentially: scaling, taking an absolute
joeverbout 0:ea44dc9ed014 503 value, conversion to an unsigned 8-bit type:
joeverbout 0:ea44dc9ed014 504 \f[\texttt{dst} (I)= \texttt{saturate\_cast<uchar>} (| \texttt{src} (I)* \texttt{alpha} + \texttt{beta} |)\f]
joeverbout 0:ea44dc9ed014 505 In case of multi-channel arrays, the function processes each channel
joeverbout 0:ea44dc9ed014 506 independently. When the output is not 8-bit, the operation can be
joeverbout 0:ea44dc9ed014 507 emulated by calling the Mat::convertTo method (or by using matrix
joeverbout 0:ea44dc9ed014 508 expressions) and then by calculating an absolute value of the result.
joeverbout 0:ea44dc9ed014 509 For example:
joeverbout 0:ea44dc9ed014 510 @code{.cpp}
joeverbout 0:ea44dc9ed014 511 Mat_<float> A(30,30);
joeverbout 0:ea44dc9ed014 512 randu(A, Scalar(-100), Scalar(100));
joeverbout 0:ea44dc9ed014 513 Mat_<float> B = A*5 + 3;
joeverbout 0:ea44dc9ed014 514 B = abs(B);
joeverbout 0:ea44dc9ed014 515 // Mat_<float> B = abs(A*5+3) will also do the job,
joeverbout 0:ea44dc9ed014 516 // but it will allocate a temporary matrix
joeverbout 0:ea44dc9ed014 517 @endcode
joeverbout 0:ea44dc9ed014 518 @param src input array.
joeverbout 0:ea44dc9ed014 519 @param dst output array.
joeverbout 0:ea44dc9ed014 520 @param alpha optional scale factor.
joeverbout 0:ea44dc9ed014 521 @param beta optional delta added to the scaled values.
joeverbout 0:ea44dc9ed014 522 @sa Mat::convertTo, cv::abs(const Mat&)
joeverbout 0:ea44dc9ed014 523 */
joeverbout 0:ea44dc9ed014 524 CV_EXPORTS_W void convertScaleAbs(InputArray src, OutputArray dst,
joeverbout 0:ea44dc9ed014 525 double alpha = 1, double beta = 0);
joeverbout 0:ea44dc9ed014 526
joeverbout 0:ea44dc9ed014 527 /** @brief Performs a look-up table transform of an array.
joeverbout 0:ea44dc9ed014 528
joeverbout 0:ea44dc9ed014 529 The function LUT fills the output array with values from the look-up table. Indices of the entries
joeverbout 0:ea44dc9ed014 530 are taken from the input array. That is, the function processes each element of src as follows:
joeverbout 0:ea44dc9ed014 531 \f[\texttt{dst} (I) \leftarrow \texttt{lut(src(I) + d)}\f]
joeverbout 0:ea44dc9ed014 532 where
joeverbout 0:ea44dc9ed014 533 \f[d = \fork{0}{if \(\texttt{src}\) has depth \(\texttt{CV_8U}\)}{128}{if \(\texttt{src}\) has depth \(\texttt{CV_8S}\)}\f]
joeverbout 0:ea44dc9ed014 534 @param src input array of 8-bit elements.
joeverbout 0:ea44dc9ed014 535 @param lut look-up table of 256 elements; in case of multi-channel input array, the table should
joeverbout 0:ea44dc9ed014 536 either have a single channel (in this case the same table is used for all channels) or the same
joeverbout 0:ea44dc9ed014 537 number of channels as in the input array.
joeverbout 0:ea44dc9ed014 538 @param dst output array of the same size and number of channels as src, and the same depth as lut.
joeverbout 0:ea44dc9ed014 539 @sa convertScaleAbs, Mat::convertTo
joeverbout 0:ea44dc9ed014 540 */
joeverbout 0:ea44dc9ed014 541 CV_EXPORTS_W void LUT(InputArray src, InputArray lut, OutputArray dst);
joeverbout 0:ea44dc9ed014 542
joeverbout 0:ea44dc9ed014 543 /** @brief Calculates the sum of array elements.
joeverbout 0:ea44dc9ed014 544
joeverbout 0:ea44dc9ed014 545 The functions sum calculate and return the sum of array elements,
joeverbout 0:ea44dc9ed014 546 independently for each channel.
joeverbout 0:ea44dc9ed014 547 @param src input array that must have from 1 to 4 channels.
joeverbout 0:ea44dc9ed014 548 @sa countNonZero, mean, meanStdDev, norm, minMaxLoc, reduce
joeverbout 0:ea44dc9ed014 549 */
joeverbout 0:ea44dc9ed014 550 CV_EXPORTS_AS(sumElems) Scalar sum(InputArray src);
joeverbout 0:ea44dc9ed014 551
joeverbout 0:ea44dc9ed014 552 /** @brief Counts non-zero array elements.
joeverbout 0:ea44dc9ed014 553
joeverbout 0:ea44dc9ed014 554 The function returns the number of non-zero elements in src :
joeverbout 0:ea44dc9ed014 555 \f[\sum _{I: \; \texttt{src} (I) \ne0 } 1\f]
joeverbout 0:ea44dc9ed014 556 @param src single-channel array.
joeverbout 0:ea44dc9ed014 557 @sa mean, meanStdDev, norm, minMaxLoc, calcCovarMatrix
joeverbout 0:ea44dc9ed014 558 */
joeverbout 0:ea44dc9ed014 559 CV_EXPORTS_W int countNonZero( InputArray src );
joeverbout 0:ea44dc9ed014 560
joeverbout 0:ea44dc9ed014 561 /** @brief Returns the list of locations of non-zero pixels
joeverbout 0:ea44dc9ed014 562
joeverbout 0:ea44dc9ed014 563 Given a binary matrix (likely returned from an operation such
joeverbout 0:ea44dc9ed014 564 as threshold(), compare(), >, ==, etc, return all of
joeverbout 0:ea44dc9ed014 565 the non-zero indices as a cv::Mat or std::vector<cv::Point> (x,y)
joeverbout 0:ea44dc9ed014 566 For example:
joeverbout 0:ea44dc9ed014 567 @code{.cpp}
joeverbout 0:ea44dc9ed014 568 cv::Mat binaryImage; // input, binary image
joeverbout 0:ea44dc9ed014 569 cv::Mat locations; // output, locations of non-zero pixels
joeverbout 0:ea44dc9ed014 570 cv::findNonZero(binaryImage, locations);
joeverbout 0:ea44dc9ed014 571
joeverbout 0:ea44dc9ed014 572 // access pixel coordinates
joeverbout 0:ea44dc9ed014 573 Point pnt = locations.at<Point>(i);
joeverbout 0:ea44dc9ed014 574 @endcode
joeverbout 0:ea44dc9ed014 575 or
joeverbout 0:ea44dc9ed014 576 @code{.cpp}
joeverbout 0:ea44dc9ed014 577 cv::Mat binaryImage; // input, binary image
joeverbout 0:ea44dc9ed014 578 vector<Point> locations; // output, locations of non-zero pixels
joeverbout 0:ea44dc9ed014 579 cv::findNonZero(binaryImage, locations);
joeverbout 0:ea44dc9ed014 580
joeverbout 0:ea44dc9ed014 581 // access pixel coordinates
joeverbout 0:ea44dc9ed014 582 Point pnt = locations[i];
joeverbout 0:ea44dc9ed014 583 @endcode
joeverbout 0:ea44dc9ed014 584 @param src single-channel array (type CV_8UC1)
joeverbout 0:ea44dc9ed014 585 @param idx the output array, type of cv::Mat or std::vector<Point>, corresponding to non-zero indices in the input
joeverbout 0:ea44dc9ed014 586 */
joeverbout 0:ea44dc9ed014 587 CV_EXPORTS_W void findNonZero( InputArray src, OutputArray idx );
joeverbout 0:ea44dc9ed014 588
joeverbout 0:ea44dc9ed014 589 /** @brief Calculates an average (mean) of array elements.
joeverbout 0:ea44dc9ed014 590
joeverbout 0:ea44dc9ed014 591 The function mean calculates the mean value M of array elements,
joeverbout 0:ea44dc9ed014 592 independently for each channel, and return it:
joeverbout 0:ea44dc9ed014 593 \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]
joeverbout 0:ea44dc9ed014 594 When all the mask elements are 0's, the functions return Scalar::all(0)
joeverbout 0:ea44dc9ed014 595 @param src input array that should have from 1 to 4 channels so that the result can be stored in
joeverbout 0:ea44dc9ed014 596 Scalar_ .
joeverbout 0:ea44dc9ed014 597 @param mask optional operation mask.
joeverbout 0:ea44dc9ed014 598 @sa countNonZero, meanStdDev, norm, minMaxLoc
joeverbout 0:ea44dc9ed014 599 */
joeverbout 0:ea44dc9ed014 600 CV_EXPORTS_W Scalar mean(InputArray src, InputArray mask = noArray());
joeverbout 0:ea44dc9ed014 601
joeverbout 0:ea44dc9ed014 602 /** Calculates a mean and standard deviation of array elements.
joeverbout 0:ea44dc9ed014 603
joeverbout 0:ea44dc9ed014 604 The function meanStdDev calculates the mean and the standard deviation M
joeverbout 0:ea44dc9ed014 605 of array elements independently for each channel and returns it via the
joeverbout 0:ea44dc9ed014 606 output parameters:
joeverbout 0:ea44dc9ed014 607 \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]
joeverbout 0:ea44dc9ed014 608 When all the mask elements are 0's, the functions return
joeverbout 0:ea44dc9ed014 609 mean=stddev=Scalar::all(0).
joeverbout 0:ea44dc9ed014 610 @note The calculated standard deviation is only the diagonal of the
joeverbout 0:ea44dc9ed014 611 complete normalized covariance matrix. If the full matrix is needed, you
joeverbout 0:ea44dc9ed014 612 can reshape the multi-channel array M x N to the single-channel array
joeverbout 0:ea44dc9ed014 613 M\*N x mtx.channels() (only possible when the matrix is continuous) and
joeverbout 0:ea44dc9ed014 614 then pass the matrix to calcCovarMatrix .
joeverbout 0:ea44dc9ed014 615 @param src input array that should have from 1 to 4 channels so that the results can be stored in
joeverbout 0:ea44dc9ed014 616 Scalar_ 's.
joeverbout 0:ea44dc9ed014 617 @param mean output parameter: calculated mean value.
joeverbout 0:ea44dc9ed014 618 @param stddev output parameter: calculateded standard deviation.
joeverbout 0:ea44dc9ed014 619 @param mask optional operation mask.
joeverbout 0:ea44dc9ed014 620 @sa countNonZero, mean, norm, minMaxLoc, calcCovarMatrix
joeverbout 0:ea44dc9ed014 621 */
joeverbout 0:ea44dc9ed014 622 CV_EXPORTS_W void meanStdDev(InputArray src, OutputArray mean, OutputArray stddev,
joeverbout 0:ea44dc9ed014 623 InputArray mask=noArray());
joeverbout 0:ea44dc9ed014 624
joeverbout 0:ea44dc9ed014 625 /** @brief Calculates an absolute array norm, an absolute difference norm, or a
joeverbout 0:ea44dc9ed014 626 relative difference norm.
joeverbout 0:ea44dc9ed014 627
joeverbout 0:ea44dc9ed014 628 The functions norm calculate an absolute norm of src1 (when there is no
joeverbout 0:ea44dc9ed014 629 src2 ):
joeverbout 0:ea44dc9ed014 630
joeverbout 0:ea44dc9ed014 631 \f[norm = \forkthree{\|\texttt{src1}\|_{L_{\infty}} = \max _I | \texttt{src1} (I)|}{if \(\texttt{normType} = \texttt{NORM_INF}\) }
joeverbout 0:ea44dc9ed014 632 { \| \texttt{src1} \| _{L_1} = \sum _I | \texttt{src1} (I)|}{if \(\texttt{normType} = \texttt{NORM_L1}\) }
joeverbout 0:ea44dc9ed014 633 { \| \texttt{src1} \| _{L_2} = \sqrt{\sum_I \texttt{src1}(I)^2} }{if \(\texttt{normType} = \texttt{NORM_L2}\) }\f]
joeverbout 0:ea44dc9ed014 634
joeverbout 0:ea44dc9ed014 635 or an absolute or relative difference norm if src2 is there:
joeverbout 0:ea44dc9ed014 636
joeverbout 0:ea44dc9ed014 637 \f[norm = \forkthree{\|\texttt{src1}-\texttt{src2}\|_{L_{\infty}} = \max _I | \texttt{src1} (I) - \texttt{src2} (I)|}{if \(\texttt{normType} = \texttt{NORM_INF}\) }
joeverbout 0:ea44dc9ed014 638 { \| \texttt{src1} - \texttt{src2} \| _{L_1} = \sum _I | \texttt{src1} (I) - \texttt{src2} (I)|}{if \(\texttt{normType} = \texttt{NORM_L1}\) }
joeverbout 0:ea44dc9ed014 639 { \| \texttt{src1} - \texttt{src2} \| _{L_2} = \sqrt{\sum_I (\texttt{src1}(I) - \texttt{src2}(I))^2} }{if \(\texttt{normType} = \texttt{NORM_L2}\) }\f]
joeverbout 0:ea44dc9ed014 640
joeverbout 0:ea44dc9ed014 641 or
joeverbout 0:ea44dc9ed014 642
joeverbout 0:ea44dc9ed014 643 \f[norm = \forkthree{\frac{\|\texttt{src1}-\texttt{src2}\|_{L_{\infty}} }{\|\texttt{src2}\|_{L_{\infty}} }}{if \(\texttt{normType} = \texttt{NORM_RELATIVE_INF}\) }
joeverbout 0:ea44dc9ed014 644 { \frac{\|\texttt{src1}-\texttt{src2}\|_{L_1} }{\|\texttt{src2}\|_{L_1}} }{if \(\texttt{normType} = \texttt{NORM_RELATIVE_L1}\) }
joeverbout 0:ea44dc9ed014 645 { \frac{\|\texttt{src1}-\texttt{src2}\|_{L_2} }{\|\texttt{src2}\|_{L_2}} }{if \(\texttt{normType} = \texttt{NORM_RELATIVE_L2}\) }\f]
joeverbout 0:ea44dc9ed014 646
joeverbout 0:ea44dc9ed014 647 The functions norm return the calculated norm.
joeverbout 0:ea44dc9ed014 648
joeverbout 0:ea44dc9ed014 649 When the mask parameter is specified and it is not empty, the norm is
joeverbout 0:ea44dc9ed014 650 calculated only over the region specified by the mask.
joeverbout 0:ea44dc9ed014 651
joeverbout 0:ea44dc9ed014 652 A multi-channel input arrays are treated as a single-channel, that is,
joeverbout 0:ea44dc9ed014 653 the results for all channels are combined.
joeverbout 0:ea44dc9ed014 654
joeverbout 0:ea44dc9ed014 655 @param src1 first input array.
joeverbout 0:ea44dc9ed014 656 @param normType type of the norm (see cv::NormTypes).
joeverbout 0:ea44dc9ed014 657 @param mask optional operation mask; it must have the same size as src1 and CV_8UC1 type.
joeverbout 0:ea44dc9ed014 658 */
joeverbout 0:ea44dc9ed014 659 CV_EXPORTS_W double norm(InputArray src1, int normType = NORM_L2, InputArray mask = noArray());
joeverbout 0:ea44dc9ed014 660
joeverbout 0:ea44dc9ed014 661 /** @overload
joeverbout 0:ea44dc9ed014 662 @param src1 first input array.
joeverbout 0:ea44dc9ed014 663 @param src2 second input array of the same size and the same type as src1.
joeverbout 0:ea44dc9ed014 664 @param normType type of the norm (cv::NormTypes).
joeverbout 0:ea44dc9ed014 665 @param mask optional operation mask; it must have the same size as src1 and CV_8UC1 type.
joeverbout 0:ea44dc9ed014 666 */
joeverbout 0:ea44dc9ed014 667 CV_EXPORTS_W double norm(InputArray src1, InputArray src2,
joeverbout 0:ea44dc9ed014 668 int normType = NORM_L2, InputArray mask = noArray());
joeverbout 0:ea44dc9ed014 669 /** @overload
joeverbout 0:ea44dc9ed014 670 @param src first input array.
joeverbout 0:ea44dc9ed014 671 @param normType type of the norm (see cv::NormTypes).
joeverbout 0:ea44dc9ed014 672 */
joeverbout 0:ea44dc9ed014 673 CV_EXPORTS double norm( const SparseMat& src, int normType );
joeverbout 0:ea44dc9ed014 674
joeverbout 0:ea44dc9ed014 675 /** @brief computes PSNR image/video quality metric
joeverbout 0:ea44dc9ed014 676
joeverbout 0:ea44dc9ed014 677 see http://en.wikipedia.org/wiki/Peak_signal-to-noise_ratio for details
joeverbout 0:ea44dc9ed014 678 @todo document
joeverbout 0:ea44dc9ed014 679 */
joeverbout 0:ea44dc9ed014 680 CV_EXPORTS_W double PSNR(InputArray src1, InputArray src2);
joeverbout 0:ea44dc9ed014 681
joeverbout 0:ea44dc9ed014 682 /** @brief naive nearest neighbor finder
joeverbout 0:ea44dc9ed014 683
joeverbout 0:ea44dc9ed014 684 see http://en.wikipedia.org/wiki/Nearest_neighbor_search
joeverbout 0:ea44dc9ed014 685 @todo document
joeverbout 0:ea44dc9ed014 686 */
joeverbout 0:ea44dc9ed014 687 CV_EXPORTS_W void batchDistance(InputArray src1, InputArray src2,
joeverbout 0:ea44dc9ed014 688 OutputArray dist, int dtype, OutputArray nidx,
joeverbout 0:ea44dc9ed014 689 int normType = NORM_L2, int K = 0,
joeverbout 0:ea44dc9ed014 690 InputArray mask = noArray(), int update = 0,
joeverbout 0:ea44dc9ed014 691 bool crosscheck = false);
joeverbout 0:ea44dc9ed014 692
joeverbout 0:ea44dc9ed014 693 /** @brief Normalizes the norm or value range of an array.
joeverbout 0:ea44dc9ed014 694
joeverbout 0:ea44dc9ed014 695 The functions normalize scale and shift the input array elements so that
joeverbout 0:ea44dc9ed014 696 \f[\| \texttt{dst} \| _{L_p}= \texttt{alpha}\f]
joeverbout 0:ea44dc9ed014 697 (where p=Inf, 1 or 2) when normType=NORM_INF, NORM_L1, or NORM_L2, respectively; or so that
joeverbout 0:ea44dc9ed014 698 \f[\min _I \texttt{dst} (I)= \texttt{alpha} , \, \, \max _I \texttt{dst} (I)= \texttt{beta}\f]
joeverbout 0:ea44dc9ed014 699
joeverbout 0:ea44dc9ed014 700 when normType=NORM_MINMAX (for dense arrays only). The optional mask specifies a sub-array to be
joeverbout 0:ea44dc9ed014 701 normalized. This means that the norm or min-n-max are calculated over the sub-array, and then this
joeverbout 0:ea44dc9ed014 702 sub-array is modified to be normalized. If you want to only use the mask to calculate the norm or
joeverbout 0:ea44dc9ed014 703 min-max but modify the whole array, you can use norm and Mat::convertTo.
joeverbout 0:ea44dc9ed014 704
joeverbout 0:ea44dc9ed014 705 In case of sparse matrices, only the non-zero values are analyzed and transformed. Because of this,
joeverbout 0:ea44dc9ed014 706 the range transformation for sparse matrices is not allowed since it can shift the zero level.
joeverbout 0:ea44dc9ed014 707
joeverbout 0:ea44dc9ed014 708 Possible usage with some positive example data:
joeverbout 0:ea44dc9ed014 709 @code{.cpp}
joeverbout 0:ea44dc9ed014 710 vector<double> positiveData = { 2.0, 8.0, 10.0 };
joeverbout 0:ea44dc9ed014 711 vector<double> normalizedData_l1, normalizedData_l2, normalizedData_inf, normalizedData_minmax;
joeverbout 0:ea44dc9ed014 712
joeverbout 0:ea44dc9ed014 713 // Norm to probability (total count)
joeverbout 0:ea44dc9ed014 714 // sum(numbers) = 20.0
joeverbout 0:ea44dc9ed014 715 // 2.0 0.1 (2.0/20.0)
joeverbout 0:ea44dc9ed014 716 // 8.0 0.4 (8.0/20.0)
joeverbout 0:ea44dc9ed014 717 // 10.0 0.5 (10.0/20.0)
joeverbout 0:ea44dc9ed014 718 normalize(positiveData, normalizedData_l1, 1.0, 0.0, NORM_L1);
joeverbout 0:ea44dc9ed014 719
joeverbout 0:ea44dc9ed014 720 // Norm to unit vector: ||positiveData|| = 1.0
joeverbout 0:ea44dc9ed014 721 // 2.0 0.15
joeverbout 0:ea44dc9ed014 722 // 8.0 0.62
joeverbout 0:ea44dc9ed014 723 // 10.0 0.77
joeverbout 0:ea44dc9ed014 724 normalize(positiveData, normalizedData_l2, 1.0, 0.0, NORM_L2);
joeverbout 0:ea44dc9ed014 725
joeverbout 0:ea44dc9ed014 726 // Norm to max element
joeverbout 0:ea44dc9ed014 727 // 2.0 0.2 (2.0/10.0)
joeverbout 0:ea44dc9ed014 728 // 8.0 0.8 (8.0/10.0)
joeverbout 0:ea44dc9ed014 729 // 10.0 1.0 (10.0/10.0)
joeverbout 0:ea44dc9ed014 730 normalize(positiveData, normalizedData_inf, 1.0, 0.0, NORM_INF);
joeverbout 0:ea44dc9ed014 731
joeverbout 0:ea44dc9ed014 732 // Norm to range [0.0;1.0]
joeverbout 0:ea44dc9ed014 733 // 2.0 0.0 (shift to left border)
joeverbout 0:ea44dc9ed014 734 // 8.0 0.75 (6.0/8.0)
joeverbout 0:ea44dc9ed014 735 // 10.0 1.0 (shift to right border)
joeverbout 0:ea44dc9ed014 736 normalize(positiveData, normalizedData_minmax, 1.0, 0.0, NORM_MINMAX);
joeverbout 0:ea44dc9ed014 737 @endcode
joeverbout 0:ea44dc9ed014 738
joeverbout 0:ea44dc9ed014 739 @param src input array.
joeverbout 0:ea44dc9ed014 740 @param dst output array of the same size as src .
joeverbout 0:ea44dc9ed014 741 @param alpha norm value to normalize to or the lower range boundary in case of the range
joeverbout 0:ea44dc9ed014 742 normalization.
joeverbout 0:ea44dc9ed014 743 @param beta upper range boundary in case of the range normalization; it is not used for the norm
joeverbout 0:ea44dc9ed014 744 normalization.
joeverbout 0:ea44dc9ed014 745 @param norm_type normalization type (see cv::NormTypes).
joeverbout 0:ea44dc9ed014 746 @param dtype when negative, the output array has the same type as src; otherwise, it has the same
joeverbout 0:ea44dc9ed014 747 number of channels as src and the depth =CV_MAT_DEPTH(dtype).
joeverbout 0:ea44dc9ed014 748 @param mask optional operation mask.
joeverbout 0:ea44dc9ed014 749 @sa norm, Mat::convertTo, SparseMat::convertTo
joeverbout 0:ea44dc9ed014 750 */
joeverbout 0:ea44dc9ed014 751 CV_EXPORTS_W void normalize( InputArray src, InputOutputArray dst, double alpha = 1, double beta = 0,
joeverbout 0:ea44dc9ed014 752 int norm_type = NORM_L2, int dtype = -1, InputArray mask = noArray());
joeverbout 0:ea44dc9ed014 753
joeverbout 0:ea44dc9ed014 754 /** @overload
joeverbout 0:ea44dc9ed014 755 @param src input array.
joeverbout 0:ea44dc9ed014 756 @param dst output array of the same size as src .
joeverbout 0:ea44dc9ed014 757 @param alpha norm value to normalize to or the lower range boundary in case of the range
joeverbout 0:ea44dc9ed014 758 normalization.
joeverbout 0:ea44dc9ed014 759 @param normType normalization type (see cv::NormTypes).
joeverbout 0:ea44dc9ed014 760 */
joeverbout 0:ea44dc9ed014 761 CV_EXPORTS void normalize( const SparseMat& src, SparseMat& dst, double alpha, int normType );
joeverbout 0:ea44dc9ed014 762
joeverbout 0:ea44dc9ed014 763 /** @brief Finds the global minimum and maximum in an array.
joeverbout 0:ea44dc9ed014 764
joeverbout 0:ea44dc9ed014 765 The functions minMaxLoc find the minimum and maximum element values and their positions. The
joeverbout 0:ea44dc9ed014 766 extremums are searched across the whole array or, if mask is not an empty array, in the specified
joeverbout 0:ea44dc9ed014 767 array region.
joeverbout 0:ea44dc9ed014 768
joeverbout 0:ea44dc9ed014 769 The functions do not work with multi-channel arrays. If you need to find minimum or maximum
joeverbout 0:ea44dc9ed014 770 elements across all the channels, use Mat::reshape first to reinterpret the array as
joeverbout 0:ea44dc9ed014 771 single-channel. Or you may extract the particular channel using either extractImageCOI , or
joeverbout 0:ea44dc9ed014 772 mixChannels , or split .
joeverbout 0:ea44dc9ed014 773 @param src input single-channel array.
joeverbout 0:ea44dc9ed014 774 @param minVal pointer to the returned minimum value; NULL is used if not required.
joeverbout 0:ea44dc9ed014 775 @param maxVal pointer to the returned maximum value; NULL is used if not required.
joeverbout 0:ea44dc9ed014 776 @param minLoc pointer to the returned minimum location (in 2D case); NULL is used if not required.
joeverbout 0:ea44dc9ed014 777 @param maxLoc pointer to the returned maximum location (in 2D case); NULL is used if not required.
joeverbout 0:ea44dc9ed014 778 @param mask optional mask used to select a sub-array.
joeverbout 0:ea44dc9ed014 779 @sa max, min, compare, inRange, extractImageCOI, mixChannels, split, Mat::reshape
joeverbout 0:ea44dc9ed014 780 */
joeverbout 0:ea44dc9ed014 781 CV_EXPORTS_W void minMaxLoc(InputArray src, CV_OUT double* minVal,
joeverbout 0:ea44dc9ed014 782 CV_OUT double* maxVal = 0, CV_OUT Point* minLoc = 0,
joeverbout 0:ea44dc9ed014 783 CV_OUT Point* maxLoc = 0, InputArray mask = noArray());
joeverbout 0:ea44dc9ed014 784
joeverbout 0:ea44dc9ed014 785
joeverbout 0:ea44dc9ed014 786 /** @brief Finds the global minimum and maximum in an array
joeverbout 0:ea44dc9ed014 787
joeverbout 0:ea44dc9ed014 788 The function minMaxIdx finds the minimum and maximum element values and their positions. The
joeverbout 0:ea44dc9ed014 789 extremums are searched across the whole array or, if mask is not an empty array, in the specified
joeverbout 0:ea44dc9ed014 790 array region. The function does not work with multi-channel arrays. If you need to find minimum or
joeverbout 0:ea44dc9ed014 791 maximum elements across all the channels, use Mat::reshape first to reinterpret the array as
joeverbout 0:ea44dc9ed014 792 single-channel. Or you may extract the particular channel using either extractImageCOI , or
joeverbout 0:ea44dc9ed014 793 mixChannels , or split . In case of a sparse matrix, the minimum is found among non-zero elements
joeverbout 0:ea44dc9ed014 794 only.
joeverbout 0:ea44dc9ed014 795 @note When minIdx is not NULL, it must have at least 2 elements (as well as maxIdx), even if src is
joeverbout 0:ea44dc9ed014 796 a single-row or single-column matrix. In OpenCV (following MATLAB) each array has at least 2
joeverbout 0:ea44dc9ed014 797 dimensions, i.e. single-column matrix is Mx1 matrix (and therefore minIdx/maxIdx will be
joeverbout 0:ea44dc9ed014 798 (i1,0)/(i2,0)) and single-row matrix is 1xN matrix (and therefore minIdx/maxIdx will be
joeverbout 0:ea44dc9ed014 799 (0,j1)/(0,j2)).
joeverbout 0:ea44dc9ed014 800 @param src input single-channel array.
joeverbout 0:ea44dc9ed014 801 @param minVal pointer to the returned minimum value; NULL is used if not required.
joeverbout 0:ea44dc9ed014 802 @param maxVal pointer to the returned maximum value; NULL is used if not required.
joeverbout 0:ea44dc9ed014 803 @param minIdx pointer to the returned minimum location (in nD case); NULL is used if not required;
joeverbout 0:ea44dc9ed014 804 Otherwise, it must point to an array of src.dims elements, the coordinates of the minimum element
joeverbout 0:ea44dc9ed014 805 in each dimension are stored there sequentially.
joeverbout 0:ea44dc9ed014 806 @param maxIdx pointer to the returned maximum location (in nD case). NULL is used if not required.
joeverbout 0:ea44dc9ed014 807 @param mask specified array region
joeverbout 0:ea44dc9ed014 808 */
joeverbout 0:ea44dc9ed014 809 CV_EXPORTS void minMaxIdx(InputArray src, double* minVal, double* maxVal = 0,
joeverbout 0:ea44dc9ed014 810 int* minIdx = 0, int* maxIdx = 0, InputArray mask = noArray());
joeverbout 0:ea44dc9ed014 811
joeverbout 0:ea44dc9ed014 812 /** @overload
joeverbout 0:ea44dc9ed014 813 @param a input single-channel array.
joeverbout 0:ea44dc9ed014 814 @param minVal pointer to the returned minimum value; NULL is used if not required.
joeverbout 0:ea44dc9ed014 815 @param maxVal pointer to the returned maximum value; NULL is used if not required.
joeverbout 0:ea44dc9ed014 816 @param minIdx pointer to the returned minimum location (in nD case); NULL is used if not required;
joeverbout 0:ea44dc9ed014 817 Otherwise, it must point to an array of src.dims elements, the coordinates of the minimum element
joeverbout 0:ea44dc9ed014 818 in each dimension are stored there sequentially.
joeverbout 0:ea44dc9ed014 819 @param maxIdx pointer to the returned maximum location (in nD case). NULL is used if not required.
joeverbout 0:ea44dc9ed014 820 */
joeverbout 0:ea44dc9ed014 821 CV_EXPORTS void minMaxLoc(const SparseMat& a, double* minVal,
joeverbout 0:ea44dc9ed014 822 double* maxVal, int* minIdx = 0, int* maxIdx = 0);
joeverbout 0:ea44dc9ed014 823
joeverbout 0:ea44dc9ed014 824 /** @brief Reduces a matrix to a vector.
joeverbout 0:ea44dc9ed014 825
joeverbout 0:ea44dc9ed014 826 The function reduce reduces the matrix to a vector by treating the matrix rows/columns as a set of
joeverbout 0:ea44dc9ed014 827 1D vectors and performing the specified operation on the vectors until a single row/column is
joeverbout 0:ea44dc9ed014 828 obtained. For example, the function can be used to compute horizontal and vertical projections of a
joeverbout 0:ea44dc9ed014 829 raster image. In case of REDUCE_SUM and REDUCE_AVG , the output may have a larger element
joeverbout 0:ea44dc9ed014 830 bit-depth to preserve accuracy. And multi-channel arrays are also supported in these two reduction
joeverbout 0:ea44dc9ed014 831 modes.
joeverbout 0:ea44dc9ed014 832 @param src input 2D matrix.
joeverbout 0:ea44dc9ed014 833 @param dst output vector. Its size and type is defined by dim and dtype parameters.
joeverbout 0:ea44dc9ed014 834 @param dim dimension index along which the matrix is reduced. 0 means that the matrix is reduced to
joeverbout 0:ea44dc9ed014 835 a single row. 1 means that the matrix is reduced to a single column.
joeverbout 0:ea44dc9ed014 836 @param rtype reduction operation that could be one of cv::ReduceTypes
joeverbout 0:ea44dc9ed014 837 @param dtype when negative, the output vector will have the same type as the input matrix,
joeverbout 0:ea44dc9ed014 838 otherwise, its type will be CV_MAKE_TYPE(CV_MAT_DEPTH(dtype), src.channels()).
joeverbout 0:ea44dc9ed014 839 @sa repeat
joeverbout 0:ea44dc9ed014 840 */
joeverbout 0:ea44dc9ed014 841 CV_EXPORTS_W void reduce(InputArray src, OutputArray dst, int dim, int rtype, int dtype = -1);
joeverbout 0:ea44dc9ed014 842
joeverbout 0:ea44dc9ed014 843 /** @brief Creates one multi-channel array out of several single-channel ones.
joeverbout 0:ea44dc9ed014 844
joeverbout 0:ea44dc9ed014 845 The function merge merges several arrays to make a single multi-channel array. That is, each
joeverbout 0:ea44dc9ed014 846 element of the output array will be a concatenation of the elements of the input arrays, where
joeverbout 0:ea44dc9ed014 847 elements of i-th input array are treated as mv[i].channels()-element vectors.
joeverbout 0:ea44dc9ed014 848
joeverbout 0:ea44dc9ed014 849 The function cv::split does the reverse operation. If you need to shuffle channels in some other
joeverbout 0:ea44dc9ed014 850 advanced way, use cv::mixChannels.
joeverbout 0:ea44dc9ed014 851 @param mv input array of matrices to be merged; all the matrices in mv must have the same
joeverbout 0:ea44dc9ed014 852 size and the same depth.
joeverbout 0:ea44dc9ed014 853 @param count number of input matrices when mv is a plain C array; it must be greater than zero.
joeverbout 0:ea44dc9ed014 854 @param dst output array of the same size and the same depth as mv[0]; The number of channels will
joeverbout 0:ea44dc9ed014 855 be equal to the parameter count.
joeverbout 0:ea44dc9ed014 856 @sa mixChannels, split, Mat::reshape
joeverbout 0:ea44dc9ed014 857 */
joeverbout 0:ea44dc9ed014 858 CV_EXPORTS void merge(const Mat* mv, size_t count, OutputArray dst);
joeverbout 0:ea44dc9ed014 859
joeverbout 0:ea44dc9ed014 860 /** @overload
joeverbout 0:ea44dc9ed014 861 @param mv input vector of matrices to be merged; all the matrices in mv must have the same
joeverbout 0:ea44dc9ed014 862 size and the same depth.
joeverbout 0:ea44dc9ed014 863 @param dst output array of the same size and the same depth as mv[0]; The number of channels will
joeverbout 0:ea44dc9ed014 864 be the total number of channels in the matrix array.
joeverbout 0:ea44dc9ed014 865 */
joeverbout 0:ea44dc9ed014 866 CV_EXPORTS_W void merge(InputArrayOfArrays mv, OutputArray dst);
joeverbout 0:ea44dc9ed014 867
joeverbout 0:ea44dc9ed014 868 /** @brief Divides a multi-channel array into several single-channel arrays.
joeverbout 0:ea44dc9ed014 869
joeverbout 0:ea44dc9ed014 870 The functions split split a multi-channel array into separate single-channel arrays:
joeverbout 0:ea44dc9ed014 871 \f[\texttt{mv} [c](I) = \texttt{src} (I)_c\f]
joeverbout 0:ea44dc9ed014 872 If you need to extract a single channel or do some other sophisticated channel permutation, use
joeverbout 0:ea44dc9ed014 873 mixChannels .
joeverbout 0:ea44dc9ed014 874 @param src input multi-channel array.
joeverbout 0:ea44dc9ed014 875 @param mvbegin output array; the number of arrays must match src.channels(); the arrays themselves are
joeverbout 0:ea44dc9ed014 876 reallocated, if needed.
joeverbout 0:ea44dc9ed014 877 @sa merge, mixChannels, cvtColor
joeverbout 0:ea44dc9ed014 878 */
joeverbout 0:ea44dc9ed014 879 CV_EXPORTS void split(const Mat& src, Mat* mvbegin);
joeverbout 0:ea44dc9ed014 880
joeverbout 0:ea44dc9ed014 881 /** @overload
joeverbout 0:ea44dc9ed014 882 @param m input multi-channel array.
joeverbout 0:ea44dc9ed014 883 @param mv output vector of arrays; the arrays themselves are reallocated, if needed.
joeverbout 0:ea44dc9ed014 884 */
joeverbout 0:ea44dc9ed014 885 CV_EXPORTS_W void split(InputArray m, OutputArrayOfArrays mv);
joeverbout 0:ea44dc9ed014 886
joeverbout 0:ea44dc9ed014 887 /** @brief Copies specified channels from input arrays to the specified channels of
joeverbout 0:ea44dc9ed014 888 output arrays.
joeverbout 0:ea44dc9ed014 889
joeverbout 0:ea44dc9ed014 890 The function cv::mixChannels provides an advanced mechanism for shuffling image channels.
joeverbout 0:ea44dc9ed014 891
joeverbout 0:ea44dc9ed014 892 cv::split and cv::merge and some forms of cv::cvtColor are partial cases of cv::mixChannels .
joeverbout 0:ea44dc9ed014 893
joeverbout 0:ea44dc9ed014 894 In the example below, the code splits a 4-channel BGRA image into a 3-channel BGR (with B and R
joeverbout 0:ea44dc9ed014 895 channels swapped) and a separate alpha-channel image:
joeverbout 0:ea44dc9ed014 896 @code{.cpp}
joeverbout 0:ea44dc9ed014 897 Mat bgra( 100, 100, CV_8UC4, Scalar(255,0,0,255) );
joeverbout 0:ea44dc9ed014 898 Mat bgr( bgra.rows, bgra.cols, CV_8UC3 );
joeverbout 0:ea44dc9ed014 899 Mat alpha( bgra.rows, bgra.cols, CV_8UC1 );
joeverbout 0:ea44dc9ed014 900
joeverbout 0:ea44dc9ed014 901 // forming an array of matrices is a quite efficient operation,
joeverbout 0:ea44dc9ed014 902 // because the matrix data is not copied, only the headers
joeverbout 0:ea44dc9ed014 903 Mat out[] = { bgr, alpha };
joeverbout 0:ea44dc9ed014 904 // bgra[0] -> bgr[2], bgra[1] -> bgr[1],
joeverbout 0:ea44dc9ed014 905 // bgra[2] -> bgr[0], bgra[3] -> alpha[0]
joeverbout 0:ea44dc9ed014 906 int from_to[] = { 0,2, 1,1, 2,0, 3,3 };
joeverbout 0:ea44dc9ed014 907 mixChannels( &bgra, 1, out, 2, from_to, 4 );
joeverbout 0:ea44dc9ed014 908 @endcode
joeverbout 0:ea44dc9ed014 909 @note Unlike many other new-style C++ functions in OpenCV (see the introduction section and
joeverbout 0:ea44dc9ed014 910 Mat::create ), cv::mixChannels requires the output arrays to be pre-allocated before calling the
joeverbout 0:ea44dc9ed014 911 function.
joeverbout 0:ea44dc9ed014 912 @param src input array or vector of matrices; all of the matrices must have the same size and the
joeverbout 0:ea44dc9ed014 913 same depth.
joeverbout 0:ea44dc9ed014 914 @param nsrcs number of matrices in `src`.
joeverbout 0:ea44dc9ed014 915 @param dst output array or vector of matrices; all the matrices **must be allocated**; their size and
joeverbout 0:ea44dc9ed014 916 depth must be the same as in `src[0]`.
joeverbout 0:ea44dc9ed014 917 @param ndsts number of matrices in `dst`.
joeverbout 0:ea44dc9ed014 918 @param fromTo array of index pairs specifying which channels are copied and where; fromTo[k\*2] is
joeverbout 0:ea44dc9ed014 919 a 0-based index of the input channel in src, fromTo[k\*2+1] is an index of the output channel in
joeverbout 0:ea44dc9ed014 920 dst; the continuous channel numbering is used: the first input image channels are indexed from 0 to
joeverbout 0:ea44dc9ed014 921 src[0].channels()-1, the second input image channels are indexed from src[0].channels() to
joeverbout 0:ea44dc9ed014 922 src[0].channels() + src[1].channels()-1, and so on, the same scheme is used for the output image
joeverbout 0:ea44dc9ed014 923 channels; as a special case, when fromTo[k\*2] is negative, the corresponding output channel is
joeverbout 0:ea44dc9ed014 924 filled with zero .
joeverbout 0:ea44dc9ed014 925 @param npairs number of index pairs in `fromTo`.
joeverbout 0:ea44dc9ed014 926 @sa cv::split, cv::merge, cv::cvtColor
joeverbout 0:ea44dc9ed014 927 */
joeverbout 0:ea44dc9ed014 928 CV_EXPORTS void mixChannels(const Mat* src, size_t nsrcs, Mat* dst, size_t ndsts,
joeverbout 0:ea44dc9ed014 929 const int* fromTo, size_t npairs);
joeverbout 0:ea44dc9ed014 930
joeverbout 0:ea44dc9ed014 931 /** @overload
joeverbout 0:ea44dc9ed014 932 @param src input array or vector of matrices; all of the matrices must have the same size and the
joeverbout 0:ea44dc9ed014 933 same depth.
joeverbout 0:ea44dc9ed014 934 @param dst output array or vector of matrices; all the matrices **must be allocated**; their size and
joeverbout 0:ea44dc9ed014 935 depth must be the same as in src[0].
joeverbout 0:ea44dc9ed014 936 @param fromTo array of index pairs specifying which channels are copied and where; fromTo[k\*2] is
joeverbout 0:ea44dc9ed014 937 a 0-based index of the input channel in src, fromTo[k\*2+1] is an index of the output channel in
joeverbout 0:ea44dc9ed014 938 dst; the continuous channel numbering is used: the first input image channels are indexed from 0 to
joeverbout 0:ea44dc9ed014 939 src[0].channels()-1, the second input image channels are indexed from src[0].channels() to
joeverbout 0:ea44dc9ed014 940 src[0].channels() + src[1].channels()-1, and so on, the same scheme is used for the output image
joeverbout 0:ea44dc9ed014 941 channels; as a special case, when fromTo[k\*2] is negative, the corresponding output channel is
joeverbout 0:ea44dc9ed014 942 filled with zero .
joeverbout 0:ea44dc9ed014 943 @param npairs number of index pairs in fromTo.
joeverbout 0:ea44dc9ed014 944 */
joeverbout 0:ea44dc9ed014 945 CV_EXPORTS void mixChannels(InputArrayOfArrays src, InputOutputArrayOfArrays dst,
joeverbout 0:ea44dc9ed014 946 const int* fromTo, size_t npairs);
joeverbout 0:ea44dc9ed014 947
joeverbout 0:ea44dc9ed014 948 /** @overload
joeverbout 0:ea44dc9ed014 949 @param src input array or vector of matrices; all of the matrices must have the same size and the
joeverbout 0:ea44dc9ed014 950 same depth.
joeverbout 0:ea44dc9ed014 951 @param dst output array or vector of matrices; all the matrices **must be allocated**; their size and
joeverbout 0:ea44dc9ed014 952 depth must be the same as in src[0].
joeverbout 0:ea44dc9ed014 953 @param fromTo array of index pairs specifying which channels are copied and where; fromTo[k\*2] is
joeverbout 0:ea44dc9ed014 954 a 0-based index of the input channel in src, fromTo[k\*2+1] is an index of the output channel in
joeverbout 0:ea44dc9ed014 955 dst; the continuous channel numbering is used: the first input image channels are indexed from 0 to
joeverbout 0:ea44dc9ed014 956 src[0].channels()-1, the second input image channels are indexed from src[0].channels() to
joeverbout 0:ea44dc9ed014 957 src[0].channels() + src[1].channels()-1, and so on, the same scheme is used for the output image
joeverbout 0:ea44dc9ed014 958 channels; as a special case, when fromTo[k\*2] is negative, the corresponding output channel is
joeverbout 0:ea44dc9ed014 959 filled with zero .
joeverbout 0:ea44dc9ed014 960 */
joeverbout 0:ea44dc9ed014 961 CV_EXPORTS_W void mixChannels(InputArrayOfArrays src, InputOutputArrayOfArrays dst,
joeverbout 0:ea44dc9ed014 962 const std::vector<int>& fromTo);
joeverbout 0:ea44dc9ed014 963
joeverbout 0:ea44dc9ed014 964 /** @brief extracts a single channel from src (coi is 0-based index)
joeverbout 0:ea44dc9ed014 965 @todo document
joeverbout 0:ea44dc9ed014 966 */
joeverbout 0:ea44dc9ed014 967 CV_EXPORTS_W void extractChannel(InputArray src, OutputArray dst, int coi);
joeverbout 0:ea44dc9ed014 968
joeverbout 0:ea44dc9ed014 969 /** @brief inserts a single channel to dst (coi is 0-based index)
joeverbout 0:ea44dc9ed014 970 @todo document
joeverbout 0:ea44dc9ed014 971 */
joeverbout 0:ea44dc9ed014 972 CV_EXPORTS_W void insertChannel(InputArray src, InputOutputArray dst, int coi);
joeverbout 0:ea44dc9ed014 973
joeverbout 0:ea44dc9ed014 974 /** @brief Flips a 2D array around vertical, horizontal, or both axes.
joeverbout 0:ea44dc9ed014 975
joeverbout 0:ea44dc9ed014 976 The function flip flips the array in one of three different ways (row
joeverbout 0:ea44dc9ed014 977 and column indices are 0-based):
joeverbout 0:ea44dc9ed014 978 \f[\texttt{dst} _{ij} =
joeverbout 0:ea44dc9ed014 979 \left\{
joeverbout 0:ea44dc9ed014 980 \begin{array}{l l}
joeverbout 0:ea44dc9ed014 981 \texttt{src} _{\texttt{src.rows}-i-1,j} & if\; \texttt{flipCode} = 0 \\
joeverbout 0:ea44dc9ed014 982 \texttt{src} _{i, \texttt{src.cols} -j-1} & if\; \texttt{flipCode} > 0 \\
joeverbout 0:ea44dc9ed014 983 \texttt{src} _{ \texttt{src.rows} -i-1, \texttt{src.cols} -j-1} & if\; \texttt{flipCode} < 0 \\
joeverbout 0:ea44dc9ed014 984 \end{array}
joeverbout 0:ea44dc9ed014 985 \right.\f]
joeverbout 0:ea44dc9ed014 986 The example scenarios of using the function are the following:
joeverbout 0:ea44dc9ed014 987 * Vertical flipping of the image (flipCode == 0) to switch between
joeverbout 0:ea44dc9ed014 988 top-left and bottom-left image origin. This is a typical operation
joeverbout 0:ea44dc9ed014 989 in video processing on Microsoft Windows\* OS.
joeverbout 0:ea44dc9ed014 990 * Horizontal flipping of the image with the subsequent horizontal
joeverbout 0:ea44dc9ed014 991 shift and absolute difference calculation to check for a
joeverbout 0:ea44dc9ed014 992 vertical-axis symmetry (flipCode \> 0).
joeverbout 0:ea44dc9ed014 993 * Simultaneous horizontal and vertical flipping of the image with
joeverbout 0:ea44dc9ed014 994 the subsequent shift and absolute difference calculation to check
joeverbout 0:ea44dc9ed014 995 for a central symmetry (flipCode \< 0).
joeverbout 0:ea44dc9ed014 996 * Reversing the order of point arrays (flipCode \> 0 or
joeverbout 0:ea44dc9ed014 997 flipCode == 0).
joeverbout 0:ea44dc9ed014 998 @param src input array.
joeverbout 0:ea44dc9ed014 999 @param dst output array of the same size and type as src.
joeverbout 0:ea44dc9ed014 1000 @param flipCode a flag to specify how to flip the array; 0 means
joeverbout 0:ea44dc9ed014 1001 flipping around the x-axis and positive value (for example, 1) means
joeverbout 0:ea44dc9ed014 1002 flipping around y-axis. Negative value (for example, -1) means flipping
joeverbout 0:ea44dc9ed014 1003 around both axes.
joeverbout 0:ea44dc9ed014 1004 @sa transpose , repeat , completeSymm
joeverbout 0:ea44dc9ed014 1005 */
joeverbout 0:ea44dc9ed014 1006 CV_EXPORTS_W void flip(InputArray src, OutputArray dst, int flipCode);
joeverbout 0:ea44dc9ed014 1007
joeverbout 0:ea44dc9ed014 1008 /** @brief Fills the output array with repeated copies of the input array.
joeverbout 0:ea44dc9ed014 1009
joeverbout 0:ea44dc9ed014 1010 The functions repeat duplicate the input array one or more times along each of the two axes:
joeverbout 0:ea44dc9ed014 1011 \f[\texttt{dst} _{ij}= \texttt{src} _{i\mod src.rows, \; j\mod src.cols }\f]
joeverbout 0:ea44dc9ed014 1012 The second variant of the function is more convenient to use with @ref MatrixExpressions.
joeverbout 0:ea44dc9ed014 1013 @param src input array to replicate.
joeverbout 0:ea44dc9ed014 1014 @param dst output array of the same type as src.
joeverbout 0:ea44dc9ed014 1015 @param ny Flag to specify how many times the src is repeated along the
joeverbout 0:ea44dc9ed014 1016 vertical axis.
joeverbout 0:ea44dc9ed014 1017 @param nx Flag to specify how many times the src is repeated along the
joeverbout 0:ea44dc9ed014 1018 horizontal axis.
joeverbout 0:ea44dc9ed014 1019 @sa reduce
joeverbout 0:ea44dc9ed014 1020 */
joeverbout 0:ea44dc9ed014 1021 CV_EXPORTS_W void repeat(InputArray src, int ny, int nx, OutputArray dst);
joeverbout 0:ea44dc9ed014 1022
joeverbout 0:ea44dc9ed014 1023 /** @overload
joeverbout 0:ea44dc9ed014 1024 @param src input array to replicate.
joeverbout 0:ea44dc9ed014 1025 @param ny Flag to specify how many times the src is repeated along the
joeverbout 0:ea44dc9ed014 1026 vertical axis.
joeverbout 0:ea44dc9ed014 1027 @param nx Flag to specify how many times the src is repeated along the
joeverbout 0:ea44dc9ed014 1028 horizontal axis.
joeverbout 0:ea44dc9ed014 1029 */
joeverbout 0:ea44dc9ed014 1030 CV_EXPORTS Mat repeat(const Mat& src, int ny, int nx);
joeverbout 0:ea44dc9ed014 1031
joeverbout 0:ea44dc9ed014 1032 /** @brief Applies horizontal concatenation to given matrices.
joeverbout 0:ea44dc9ed014 1033
joeverbout 0:ea44dc9ed014 1034 The function horizontally concatenates two or more cv::Mat matrices (with the same number of rows).
joeverbout 0:ea44dc9ed014 1035 @code{.cpp}
joeverbout 0:ea44dc9ed014 1036 cv::Mat matArray[] = { cv::Mat(4, 1, CV_8UC1, cv::Scalar(1)),
joeverbout 0:ea44dc9ed014 1037 cv::Mat(4, 1, CV_8UC1, cv::Scalar(2)),
joeverbout 0:ea44dc9ed014 1038 cv::Mat(4, 1, CV_8UC1, cv::Scalar(3)),};
joeverbout 0:ea44dc9ed014 1039
joeverbout 0:ea44dc9ed014 1040 cv::Mat out;
joeverbout 0:ea44dc9ed014 1041 cv::hconcat( matArray, 3, out );
joeverbout 0:ea44dc9ed014 1042 //out:
joeverbout 0:ea44dc9ed014 1043 //[1, 2, 3;
joeverbout 0:ea44dc9ed014 1044 // 1, 2, 3;
joeverbout 0:ea44dc9ed014 1045 // 1, 2, 3;
joeverbout 0:ea44dc9ed014 1046 // 1, 2, 3]
joeverbout 0:ea44dc9ed014 1047 @endcode
joeverbout 0:ea44dc9ed014 1048 @param src input array or vector of matrices. all of the matrices must have the same number of rows and the same depth.
joeverbout 0:ea44dc9ed014 1049 @param nsrc number of matrices in src.
joeverbout 0:ea44dc9ed014 1050 @param dst output array. It has the same number of rows and depth as the src, and the sum of cols of the src.
joeverbout 0:ea44dc9ed014 1051 @sa cv::vconcat(const Mat*, size_t, OutputArray), @sa cv::vconcat(InputArrayOfArrays, OutputArray) and @sa cv::vconcat(InputArray, InputArray, OutputArray)
joeverbout 0:ea44dc9ed014 1052 */
joeverbout 0:ea44dc9ed014 1053 CV_EXPORTS void hconcat(const Mat* src, size_t nsrc, OutputArray dst);
joeverbout 0:ea44dc9ed014 1054 /** @overload
joeverbout 0:ea44dc9ed014 1055 @code{.cpp}
joeverbout 0:ea44dc9ed014 1056 cv::Mat_<float> A = (cv::Mat_<float>(3, 2) << 1, 4,
joeverbout 0:ea44dc9ed014 1057 2, 5,
joeverbout 0:ea44dc9ed014 1058 3, 6);
joeverbout 0:ea44dc9ed014 1059 cv::Mat_<float> B = (cv::Mat_<float>(3, 2) << 7, 10,
joeverbout 0:ea44dc9ed014 1060 8, 11,
joeverbout 0:ea44dc9ed014 1061 9, 12);
joeverbout 0:ea44dc9ed014 1062
joeverbout 0:ea44dc9ed014 1063 cv::Mat C;
joeverbout 0:ea44dc9ed014 1064 cv::hconcat(A, B, C);
joeverbout 0:ea44dc9ed014 1065 //C:
joeverbout 0:ea44dc9ed014 1066 //[1, 4, 7, 10;
joeverbout 0:ea44dc9ed014 1067 // 2, 5, 8, 11;
joeverbout 0:ea44dc9ed014 1068 // 3, 6, 9, 12]
joeverbout 0:ea44dc9ed014 1069 @endcode
joeverbout 0:ea44dc9ed014 1070 @param src1 first input array to be considered for horizontal concatenation.
joeverbout 0:ea44dc9ed014 1071 @param src2 second input array to be considered for horizontal concatenation.
joeverbout 0:ea44dc9ed014 1072 @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.
joeverbout 0:ea44dc9ed014 1073 */
joeverbout 0:ea44dc9ed014 1074 CV_EXPORTS void hconcat(InputArray src1, InputArray src2, OutputArray dst);
joeverbout 0:ea44dc9ed014 1075 /** @overload
joeverbout 0:ea44dc9ed014 1076 @code{.cpp}
joeverbout 0:ea44dc9ed014 1077 std::vector<cv::Mat> matrices = { cv::Mat(4, 1, CV_8UC1, cv::Scalar(1)),
joeverbout 0:ea44dc9ed014 1078 cv::Mat(4, 1, CV_8UC1, cv::Scalar(2)),
joeverbout 0:ea44dc9ed014 1079 cv::Mat(4, 1, CV_8UC1, cv::Scalar(3)),};
joeverbout 0:ea44dc9ed014 1080
joeverbout 0:ea44dc9ed014 1081 cv::Mat out;
joeverbout 0:ea44dc9ed014 1082 cv::hconcat( matrices, out );
joeverbout 0:ea44dc9ed014 1083 //out:
joeverbout 0:ea44dc9ed014 1084 //[1, 2, 3;
joeverbout 0:ea44dc9ed014 1085 // 1, 2, 3;
joeverbout 0:ea44dc9ed014 1086 // 1, 2, 3;
joeverbout 0:ea44dc9ed014 1087 // 1, 2, 3]
joeverbout 0:ea44dc9ed014 1088 @endcode
joeverbout 0:ea44dc9ed014 1089 @param src input array or vector of matrices. all of the matrices must have the same number of rows and the same depth.
joeverbout 0:ea44dc9ed014 1090 @param dst output array. It has the same number of rows and depth as the src, and the sum of cols of the src.
joeverbout 0:ea44dc9ed014 1091 same depth.
joeverbout 0:ea44dc9ed014 1092 */
joeverbout 0:ea44dc9ed014 1093 CV_EXPORTS_W void hconcat(InputArrayOfArrays src, OutputArray dst);
joeverbout 0:ea44dc9ed014 1094
joeverbout 0:ea44dc9ed014 1095 /** @brief Applies vertical concatenation to given matrices.
joeverbout 0:ea44dc9ed014 1096
joeverbout 0:ea44dc9ed014 1097 The function vertically concatenates two or more cv::Mat matrices (with the same number of cols).
joeverbout 0:ea44dc9ed014 1098 @code{.cpp}
joeverbout 0:ea44dc9ed014 1099 cv::Mat matArray[] = { cv::Mat(1, 4, CV_8UC1, cv::Scalar(1)),
joeverbout 0:ea44dc9ed014 1100 cv::Mat(1, 4, CV_8UC1, cv::Scalar(2)),
joeverbout 0:ea44dc9ed014 1101 cv::Mat(1, 4, CV_8UC1, cv::Scalar(3)),};
joeverbout 0:ea44dc9ed014 1102
joeverbout 0:ea44dc9ed014 1103 cv::Mat out;
joeverbout 0:ea44dc9ed014 1104 cv::vconcat( matArray, 3, out );
joeverbout 0:ea44dc9ed014 1105 //out:
joeverbout 0:ea44dc9ed014 1106 //[1, 1, 1, 1;
joeverbout 0:ea44dc9ed014 1107 // 2, 2, 2, 2;
joeverbout 0:ea44dc9ed014 1108 // 3, 3, 3, 3]
joeverbout 0:ea44dc9ed014 1109 @endcode
joeverbout 0:ea44dc9ed014 1110 @param src input array or vector of matrices. all of the matrices must have the same number of cols and the same depth.
joeverbout 0:ea44dc9ed014 1111 @param nsrc number of matrices in src.
joeverbout 0:ea44dc9ed014 1112 @param dst output array. It has the same number of cols and depth as the src, and the sum of rows of the src.
joeverbout 0:ea44dc9ed014 1113 @sa cv::hconcat(const Mat*, size_t, OutputArray), @sa cv::hconcat(InputArrayOfArrays, OutputArray) and @sa cv::hconcat(InputArray, InputArray, OutputArray)
joeverbout 0:ea44dc9ed014 1114 */
joeverbout 0:ea44dc9ed014 1115 CV_EXPORTS void vconcat(const Mat* src, size_t nsrc, OutputArray dst);
joeverbout 0:ea44dc9ed014 1116 /** @overload
joeverbout 0:ea44dc9ed014 1117 @code{.cpp}
joeverbout 0:ea44dc9ed014 1118 cv::Mat_<float> A = (cv::Mat_<float>(3, 2) << 1, 7,
joeverbout 0:ea44dc9ed014 1119 2, 8,
joeverbout 0:ea44dc9ed014 1120 3, 9);
joeverbout 0:ea44dc9ed014 1121 cv::Mat_<float> B = (cv::Mat_<float>(3, 2) << 4, 10,
joeverbout 0:ea44dc9ed014 1122 5, 11,
joeverbout 0:ea44dc9ed014 1123 6, 12);
joeverbout 0:ea44dc9ed014 1124
joeverbout 0:ea44dc9ed014 1125 cv::Mat C;
joeverbout 0:ea44dc9ed014 1126 cv::vconcat(A, B, C);
joeverbout 0:ea44dc9ed014 1127 //C:
joeverbout 0:ea44dc9ed014 1128 //[1, 7;
joeverbout 0:ea44dc9ed014 1129 // 2, 8;
joeverbout 0:ea44dc9ed014 1130 // 3, 9;
joeverbout 0:ea44dc9ed014 1131 // 4, 10;
joeverbout 0:ea44dc9ed014 1132 // 5, 11;
joeverbout 0:ea44dc9ed014 1133 // 6, 12]
joeverbout 0:ea44dc9ed014 1134 @endcode
joeverbout 0:ea44dc9ed014 1135 @param src1 first input array to be considered for vertical concatenation.
joeverbout 0:ea44dc9ed014 1136 @param src2 second input array to be considered for vertical concatenation.
joeverbout 0:ea44dc9ed014 1137 @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.
joeverbout 0:ea44dc9ed014 1138 */
joeverbout 0:ea44dc9ed014 1139 CV_EXPORTS void vconcat(InputArray src1, InputArray src2, OutputArray dst);
joeverbout 0:ea44dc9ed014 1140 /** @overload
joeverbout 0:ea44dc9ed014 1141 @code{.cpp}
joeverbout 0:ea44dc9ed014 1142 std::vector<cv::Mat> matrices = { cv::Mat(1, 4, CV_8UC1, cv::Scalar(1)),
joeverbout 0:ea44dc9ed014 1143 cv::Mat(1, 4, CV_8UC1, cv::Scalar(2)),
joeverbout 0:ea44dc9ed014 1144 cv::Mat(1, 4, CV_8UC1, cv::Scalar(3)),};
joeverbout 0:ea44dc9ed014 1145
joeverbout 0:ea44dc9ed014 1146 cv::Mat out;
joeverbout 0:ea44dc9ed014 1147 cv::vconcat( matrices, out );
joeverbout 0:ea44dc9ed014 1148 //out:
joeverbout 0:ea44dc9ed014 1149 //[1, 1, 1, 1;
joeverbout 0:ea44dc9ed014 1150 // 2, 2, 2, 2;
joeverbout 0:ea44dc9ed014 1151 // 3, 3, 3, 3]
joeverbout 0:ea44dc9ed014 1152 @endcode
joeverbout 0:ea44dc9ed014 1153 @param src input array or vector of matrices. all of the matrices must have the same number of cols and the same depth
joeverbout 0:ea44dc9ed014 1154 @param dst output array. It has the same number of cols and depth as the src, and the sum of rows of the src.
joeverbout 0:ea44dc9ed014 1155 same depth.
joeverbout 0:ea44dc9ed014 1156 */
joeverbout 0:ea44dc9ed014 1157 CV_EXPORTS_W void vconcat(InputArrayOfArrays src, OutputArray dst);
joeverbout 0:ea44dc9ed014 1158
joeverbout 0:ea44dc9ed014 1159 /** @brief computes bitwise conjunction of the two arrays (dst = src1 & src2)
joeverbout 0:ea44dc9ed014 1160 Calculates the per-element bit-wise conjunction of two arrays or an
joeverbout 0:ea44dc9ed014 1161 array and a scalar.
joeverbout 0:ea44dc9ed014 1162
joeverbout 0:ea44dc9ed014 1163 The function calculates the per-element bit-wise logical conjunction for:
joeverbout 0:ea44dc9ed014 1164 * Two arrays when src1 and src2 have the same size:
joeverbout 0:ea44dc9ed014 1165 \f[\texttt{dst} (I) = \texttt{src1} (I) \wedge \texttt{src2} (I) \quad \texttt{if mask} (I) \ne0\f]
joeverbout 0:ea44dc9ed014 1166 * An array and a scalar when src2 is constructed from Scalar or has
joeverbout 0:ea44dc9ed014 1167 the same number of elements as `src1.channels()`:
joeverbout 0:ea44dc9ed014 1168 \f[\texttt{dst} (I) = \texttt{src1} (I) \wedge \texttt{src2} \quad \texttt{if mask} (I) \ne0\f]
joeverbout 0:ea44dc9ed014 1169 * A scalar and an array when src1 is constructed from Scalar or has
joeverbout 0:ea44dc9ed014 1170 the same number of elements as `src2.channels()`:
joeverbout 0:ea44dc9ed014 1171 \f[\texttt{dst} (I) = \texttt{src1} \wedge \texttt{src2} (I) \quad \texttt{if mask} (I) \ne0\f]
joeverbout 0:ea44dc9ed014 1172 In case of floating-point arrays, their machine-specific bit
joeverbout 0:ea44dc9ed014 1173 representations (usually IEEE754-compliant) are used for the operation.
joeverbout 0:ea44dc9ed014 1174 In case of multi-channel arrays, each channel is processed
joeverbout 0:ea44dc9ed014 1175 independently. In the second and third cases above, the scalar is first
joeverbout 0:ea44dc9ed014 1176 converted to the array type.
joeverbout 0:ea44dc9ed014 1177 @param src1 first input array or a scalar.
joeverbout 0:ea44dc9ed014 1178 @param src2 second input array or a scalar.
joeverbout 0:ea44dc9ed014 1179 @param dst output array that has the same size and type as the input
joeverbout 0:ea44dc9ed014 1180 arrays.
joeverbout 0:ea44dc9ed014 1181 @param mask optional operation mask, 8-bit single channel array, that
joeverbout 0:ea44dc9ed014 1182 specifies elements of the output array to be changed.
joeverbout 0:ea44dc9ed014 1183 */
joeverbout 0:ea44dc9ed014 1184 CV_EXPORTS_W void bitwise_and(InputArray src1, InputArray src2,
joeverbout 0:ea44dc9ed014 1185 OutputArray dst, InputArray mask = noArray());
joeverbout 0:ea44dc9ed014 1186
joeverbout 0:ea44dc9ed014 1187 /** @brief Calculates the per-element bit-wise disjunction of two arrays or an
joeverbout 0:ea44dc9ed014 1188 array and a scalar.
joeverbout 0:ea44dc9ed014 1189
joeverbout 0:ea44dc9ed014 1190 The function calculates the per-element bit-wise logical disjunction for:
joeverbout 0:ea44dc9ed014 1191 * Two arrays when src1 and src2 have the same size:
joeverbout 0:ea44dc9ed014 1192 \f[\texttt{dst} (I) = \texttt{src1} (I) \vee \texttt{src2} (I) \quad \texttt{if mask} (I) \ne0\f]
joeverbout 0:ea44dc9ed014 1193 * An array and a scalar when src2 is constructed from Scalar or has
joeverbout 0:ea44dc9ed014 1194 the same number of elements as `src1.channels()`:
joeverbout 0:ea44dc9ed014 1195 \f[\texttt{dst} (I) = \texttt{src1} (I) \vee \texttt{src2} \quad \texttt{if mask} (I) \ne0\f]
joeverbout 0:ea44dc9ed014 1196 * A scalar and an array when src1 is constructed from Scalar or has
joeverbout 0:ea44dc9ed014 1197 the same number of elements as `src2.channels()`:
joeverbout 0:ea44dc9ed014 1198 \f[\texttt{dst} (I) = \texttt{src1} \vee \texttt{src2} (I) \quad \texttt{if mask} (I) \ne0\f]
joeverbout 0:ea44dc9ed014 1199 In case of floating-point arrays, their machine-specific bit
joeverbout 0:ea44dc9ed014 1200 representations (usually IEEE754-compliant) are used for the operation.
joeverbout 0:ea44dc9ed014 1201 In case of multi-channel arrays, each channel is processed
joeverbout 0:ea44dc9ed014 1202 independently. In the second and third cases above, the scalar is first
joeverbout 0:ea44dc9ed014 1203 converted to the array type.
joeverbout 0:ea44dc9ed014 1204 @param src1 first input array or a scalar.
joeverbout 0:ea44dc9ed014 1205 @param src2 second input array or a scalar.
joeverbout 0:ea44dc9ed014 1206 @param dst output array that has the same size and type as the input
joeverbout 0:ea44dc9ed014 1207 arrays.
joeverbout 0:ea44dc9ed014 1208 @param mask optional operation mask, 8-bit single channel array, that
joeverbout 0:ea44dc9ed014 1209 specifies elements of the output array to be changed.
joeverbout 0:ea44dc9ed014 1210 */
joeverbout 0:ea44dc9ed014 1211 CV_EXPORTS_W void bitwise_or(InputArray src1, InputArray src2,
joeverbout 0:ea44dc9ed014 1212 OutputArray dst, InputArray mask = noArray());
joeverbout 0:ea44dc9ed014 1213
joeverbout 0:ea44dc9ed014 1214 /** @brief Calculates the per-element bit-wise "exclusive or" operation on two
joeverbout 0:ea44dc9ed014 1215 arrays or an array and a scalar.
joeverbout 0:ea44dc9ed014 1216
joeverbout 0:ea44dc9ed014 1217 The function calculates the per-element bit-wise logical "exclusive-or"
joeverbout 0:ea44dc9ed014 1218 operation for:
joeverbout 0:ea44dc9ed014 1219 * Two arrays when src1 and src2 have the same size:
joeverbout 0:ea44dc9ed014 1220 \f[\texttt{dst} (I) = \texttt{src1} (I) \oplus \texttt{src2} (I) \quad \texttt{if mask} (I) \ne0\f]
joeverbout 0:ea44dc9ed014 1221 * An array and a scalar when src2 is constructed from Scalar or has
joeverbout 0:ea44dc9ed014 1222 the same number of elements as `src1.channels()`:
joeverbout 0:ea44dc9ed014 1223 \f[\texttt{dst} (I) = \texttt{src1} (I) \oplus \texttt{src2} \quad \texttt{if mask} (I) \ne0\f]
joeverbout 0:ea44dc9ed014 1224 * A scalar and an array when src1 is constructed from Scalar or has
joeverbout 0:ea44dc9ed014 1225 the same number of elements as `src2.channels()`:
joeverbout 0:ea44dc9ed014 1226 \f[\texttt{dst} (I) = \texttt{src1} \oplus \texttt{src2} (I) \quad \texttt{if mask} (I) \ne0\f]
joeverbout 0:ea44dc9ed014 1227 In case of floating-point arrays, their machine-specific bit
joeverbout 0:ea44dc9ed014 1228 representations (usually IEEE754-compliant) are used for the operation.
joeverbout 0:ea44dc9ed014 1229 In case of multi-channel arrays, each channel is processed
joeverbout 0:ea44dc9ed014 1230 independently. In the 2nd and 3rd cases above, the scalar is first
joeverbout 0:ea44dc9ed014 1231 converted to the array type.
joeverbout 0:ea44dc9ed014 1232 @param src1 first input array or a scalar.
joeverbout 0:ea44dc9ed014 1233 @param src2 second input array or a scalar.
joeverbout 0:ea44dc9ed014 1234 @param dst output array that has the same size and type as the input
joeverbout 0:ea44dc9ed014 1235 arrays.
joeverbout 0:ea44dc9ed014 1236 @param mask optional operation mask, 8-bit single channel array, that
joeverbout 0:ea44dc9ed014 1237 specifies elements of the output array to be changed.
joeverbout 0:ea44dc9ed014 1238 */
joeverbout 0:ea44dc9ed014 1239 CV_EXPORTS_W void bitwise_xor(InputArray src1, InputArray src2,
joeverbout 0:ea44dc9ed014 1240 OutputArray dst, InputArray mask = noArray());
joeverbout 0:ea44dc9ed014 1241
joeverbout 0:ea44dc9ed014 1242 /** @brief Inverts every bit of an array.
joeverbout 0:ea44dc9ed014 1243
joeverbout 0:ea44dc9ed014 1244 The function calculates per-element bit-wise inversion of the input
joeverbout 0:ea44dc9ed014 1245 array:
joeverbout 0:ea44dc9ed014 1246 \f[\texttt{dst} (I) = \neg \texttt{src} (I)\f]
joeverbout 0:ea44dc9ed014 1247 In case of a floating-point input array, its machine-specific bit
joeverbout 0:ea44dc9ed014 1248 representation (usually IEEE754-compliant) is used for the operation. In
joeverbout 0:ea44dc9ed014 1249 case of multi-channel arrays, each channel is processed independently.
joeverbout 0:ea44dc9ed014 1250 @param src input array.
joeverbout 0:ea44dc9ed014 1251 @param dst output array that has the same size and type as the input
joeverbout 0:ea44dc9ed014 1252 array.
joeverbout 0:ea44dc9ed014 1253 @param mask optional operation mask, 8-bit single channel array, that
joeverbout 0:ea44dc9ed014 1254 specifies elements of the output array to be changed.
joeverbout 0:ea44dc9ed014 1255 */
joeverbout 0:ea44dc9ed014 1256 CV_EXPORTS_W void bitwise_not(InputArray src, OutputArray dst,
joeverbout 0:ea44dc9ed014 1257 InputArray mask = noArray());
joeverbout 0:ea44dc9ed014 1258
joeverbout 0:ea44dc9ed014 1259 /** @brief Calculates the per-element absolute difference between two arrays or between an array and a scalar.
joeverbout 0:ea44dc9ed014 1260
joeverbout 0:ea44dc9ed014 1261 The function absdiff calculates:
joeverbout 0:ea44dc9ed014 1262 * Absolute difference between two arrays when they have the same
joeverbout 0:ea44dc9ed014 1263 size and type:
joeverbout 0:ea44dc9ed014 1264 \f[\texttt{dst}(I) = \texttt{saturate} (| \texttt{src1}(I) - \texttt{src2}(I)|)\f]
joeverbout 0:ea44dc9ed014 1265 * Absolute difference between an array and a scalar when the second
joeverbout 0:ea44dc9ed014 1266 array is constructed from Scalar or has as many elements as the
joeverbout 0:ea44dc9ed014 1267 number of channels in `src1`:
joeverbout 0:ea44dc9ed014 1268 \f[\texttt{dst}(I) = \texttt{saturate} (| \texttt{src1}(I) - \texttt{src2} |)\f]
joeverbout 0:ea44dc9ed014 1269 * Absolute difference between a scalar and an array when the first
joeverbout 0:ea44dc9ed014 1270 array is constructed from Scalar or has as many elements as the
joeverbout 0:ea44dc9ed014 1271 number of channels in `src2`:
joeverbout 0:ea44dc9ed014 1272 \f[\texttt{dst}(I) = \texttt{saturate} (| \texttt{src1} - \texttt{src2}(I) |)\f]
joeverbout 0:ea44dc9ed014 1273 where I is a multi-dimensional index of array elements. In case of
joeverbout 0:ea44dc9ed014 1274 multi-channel arrays, each channel is processed independently.
joeverbout 0:ea44dc9ed014 1275 @note Saturation is not applied when the arrays have the depth CV_32S.
joeverbout 0:ea44dc9ed014 1276 You may even get a negative value in the case of overflow.
joeverbout 0:ea44dc9ed014 1277 @param src1 first input array or a scalar.
joeverbout 0:ea44dc9ed014 1278 @param src2 second input array or a scalar.
joeverbout 0:ea44dc9ed014 1279 @param dst output array that has the same size and type as input arrays.
joeverbout 0:ea44dc9ed014 1280 @sa cv::abs(const Mat&)
joeverbout 0:ea44dc9ed014 1281 */
joeverbout 0:ea44dc9ed014 1282 CV_EXPORTS_W void absdiff(InputArray src1, InputArray src2, OutputArray dst);
joeverbout 0:ea44dc9ed014 1283
joeverbout 0:ea44dc9ed014 1284 /** @brief Checks if array elements lie between the elements of two other arrays.
joeverbout 0:ea44dc9ed014 1285
joeverbout 0:ea44dc9ed014 1286 The function checks the range as follows:
joeverbout 0:ea44dc9ed014 1287 - For every element of a single-channel input array:
joeverbout 0:ea44dc9ed014 1288 \f[\texttt{dst} (I)= \texttt{lowerb} (I)_0 \leq \texttt{src} (I)_0 \leq \texttt{upperb} (I)_0\f]
joeverbout 0:ea44dc9ed014 1289 - For two-channel arrays:
joeverbout 0:ea44dc9ed014 1290 \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]
joeverbout 0:ea44dc9ed014 1291 - and so forth.
joeverbout 0:ea44dc9ed014 1292
joeverbout 0:ea44dc9ed014 1293 That is, dst (I) is set to 255 (all 1 -bits) if src (I) is within the
joeverbout 0:ea44dc9ed014 1294 specified 1D, 2D, 3D, ... box and 0 otherwise.
joeverbout 0:ea44dc9ed014 1295
joeverbout 0:ea44dc9ed014 1296 When the lower and/or upper boundary parameters are scalars, the indexes
joeverbout 0:ea44dc9ed014 1297 (I) at lowerb and upperb in the above formulas should be omitted.
joeverbout 0:ea44dc9ed014 1298 @param src first input array.
joeverbout 0:ea44dc9ed014 1299 @param lowerb inclusive lower boundary array or a scalar.
joeverbout 0:ea44dc9ed014 1300 @param upperb inclusive upper boundary array or a scalar.
joeverbout 0:ea44dc9ed014 1301 @param dst output array of the same size as src and CV_8U type.
joeverbout 0:ea44dc9ed014 1302 */
joeverbout 0:ea44dc9ed014 1303 CV_EXPORTS_W void inRange(InputArray src, InputArray lowerb,
joeverbout 0:ea44dc9ed014 1304 InputArray upperb, OutputArray dst);
joeverbout 0:ea44dc9ed014 1305
joeverbout 0:ea44dc9ed014 1306 /** @brief Performs the per-element comparison of two arrays or an array and scalar value.
joeverbout 0:ea44dc9ed014 1307
joeverbout 0:ea44dc9ed014 1308 The function compares:
joeverbout 0:ea44dc9ed014 1309 * Elements of two arrays when src1 and src2 have the same size:
joeverbout 0:ea44dc9ed014 1310 \f[\texttt{dst} (I) = \texttt{src1} (I) \,\texttt{cmpop}\, \texttt{src2} (I)\f]
joeverbout 0:ea44dc9ed014 1311 * Elements of src1 with a scalar src2 when src2 is constructed from
joeverbout 0:ea44dc9ed014 1312 Scalar or has a single element:
joeverbout 0:ea44dc9ed014 1313 \f[\texttt{dst} (I) = \texttt{src1}(I) \,\texttt{cmpop}\, \texttt{src2}\f]
joeverbout 0:ea44dc9ed014 1314 * src1 with elements of src2 when src1 is constructed from Scalar or
joeverbout 0:ea44dc9ed014 1315 has a single element:
joeverbout 0:ea44dc9ed014 1316 \f[\texttt{dst} (I) = \texttt{src1} \,\texttt{cmpop}\, \texttt{src2} (I)\f]
joeverbout 0:ea44dc9ed014 1317 When the comparison result is true, the corresponding element of output
joeverbout 0:ea44dc9ed014 1318 array is set to 255. The comparison operations can be replaced with the
joeverbout 0:ea44dc9ed014 1319 equivalent matrix expressions:
joeverbout 0:ea44dc9ed014 1320 @code{.cpp}
joeverbout 0:ea44dc9ed014 1321 Mat dst1 = src1 >= src2;
joeverbout 0:ea44dc9ed014 1322 Mat dst2 = src1 < 8;
joeverbout 0:ea44dc9ed014 1323 ...
joeverbout 0:ea44dc9ed014 1324 @endcode
joeverbout 0:ea44dc9ed014 1325 @param src1 first input array or a scalar; when it is an array, it must have a single channel.
joeverbout 0:ea44dc9ed014 1326 @param src2 second input array or a scalar; when it is an array, it must have a single channel.
joeverbout 0:ea44dc9ed014 1327 @param dst output array of type ref CV_8U that has the same size and the same number of channels as
joeverbout 0:ea44dc9ed014 1328 the input arrays.
joeverbout 0:ea44dc9ed014 1329 @param cmpop a flag, that specifies correspondence between the arrays (cv::CmpTypes)
joeverbout 0:ea44dc9ed014 1330 @sa checkRange, min, max, threshold
joeverbout 0:ea44dc9ed014 1331 */
joeverbout 0:ea44dc9ed014 1332 CV_EXPORTS_W void compare(InputArray src1, InputArray src2, OutputArray dst, int cmpop);
joeverbout 0:ea44dc9ed014 1333
joeverbout 0:ea44dc9ed014 1334 /** @brief Calculates per-element minimum of two arrays or an array and a scalar.
joeverbout 0:ea44dc9ed014 1335
joeverbout 0:ea44dc9ed014 1336 The functions min calculate the per-element minimum of two arrays:
joeverbout 0:ea44dc9ed014 1337 \f[\texttt{dst} (I)= \min ( \texttt{src1} (I), \texttt{src2} (I))\f]
joeverbout 0:ea44dc9ed014 1338 or array and a scalar:
joeverbout 0:ea44dc9ed014 1339 \f[\texttt{dst} (I)= \min ( \texttt{src1} (I), \texttt{value} )\f]
joeverbout 0:ea44dc9ed014 1340 @param src1 first input array.
joeverbout 0:ea44dc9ed014 1341 @param src2 second input array of the same size and type as src1.
joeverbout 0:ea44dc9ed014 1342 @param dst output array of the same size and type as src1.
joeverbout 0:ea44dc9ed014 1343 @sa max, compare, inRange, minMaxLoc
joeverbout 0:ea44dc9ed014 1344 */
joeverbout 0:ea44dc9ed014 1345 CV_EXPORTS_W void min(InputArray src1, InputArray src2, OutputArray dst);
joeverbout 0:ea44dc9ed014 1346 /** @overload
joeverbout 0:ea44dc9ed014 1347 needed to avoid conflicts with const _Tp& std::min(const _Tp&, const _Tp&, _Compare)
joeverbout 0:ea44dc9ed014 1348 */
joeverbout 0:ea44dc9ed014 1349 CV_EXPORTS void min(const Mat& src1, const Mat& src2, Mat& dst);
joeverbout 0:ea44dc9ed014 1350 /** @overload
joeverbout 0:ea44dc9ed014 1351 needed to avoid conflicts with const _Tp& std::min(const _Tp&, const _Tp&, _Compare)
joeverbout 0:ea44dc9ed014 1352 */
joeverbout 0:ea44dc9ed014 1353 CV_EXPORTS void min(const UMat& src1, const UMat& src2, UMat& dst);
joeverbout 0:ea44dc9ed014 1354
joeverbout 0:ea44dc9ed014 1355 /** @brief Calculates per-element maximum of two arrays or an array and a scalar.
joeverbout 0:ea44dc9ed014 1356
joeverbout 0:ea44dc9ed014 1357 The functions max calculate the per-element maximum of two arrays:
joeverbout 0:ea44dc9ed014 1358 \f[\texttt{dst} (I)= \max ( \texttt{src1} (I), \texttt{src2} (I))\f]
joeverbout 0:ea44dc9ed014 1359 or array and a scalar:
joeverbout 0:ea44dc9ed014 1360 \f[\texttt{dst} (I)= \max ( \texttt{src1} (I), \texttt{value} )\f]
joeverbout 0:ea44dc9ed014 1361 @param src1 first input array.
joeverbout 0:ea44dc9ed014 1362 @param src2 second input array of the same size and type as src1 .
joeverbout 0:ea44dc9ed014 1363 @param dst output array of the same size and type as src1.
joeverbout 0:ea44dc9ed014 1364 @sa min, compare, inRange, minMaxLoc, @ref MatrixExpressions
joeverbout 0:ea44dc9ed014 1365 */
joeverbout 0:ea44dc9ed014 1366 CV_EXPORTS_W void max(InputArray src1, InputArray src2, OutputArray dst);
joeverbout 0:ea44dc9ed014 1367 /** @overload
joeverbout 0:ea44dc9ed014 1368 needed to avoid conflicts with const _Tp& std::min(const _Tp&, const _Tp&, _Compare)
joeverbout 0:ea44dc9ed014 1369 */
joeverbout 0:ea44dc9ed014 1370 CV_EXPORTS void max(const Mat& src1, const Mat& src2, Mat& dst);
joeverbout 0:ea44dc9ed014 1371 /** @overload
joeverbout 0:ea44dc9ed014 1372 needed to avoid conflicts with const _Tp& std::min(const _Tp&, const _Tp&, _Compare)
joeverbout 0:ea44dc9ed014 1373 */
joeverbout 0:ea44dc9ed014 1374 CV_EXPORTS void max(const UMat& src1, const UMat& src2, UMat& dst);
joeverbout 0:ea44dc9ed014 1375
joeverbout 0:ea44dc9ed014 1376 /** @brief Calculates a square root of array elements.
joeverbout 0:ea44dc9ed014 1377
joeverbout 0:ea44dc9ed014 1378 The functions sqrt calculate a square root of each input array element.
joeverbout 0:ea44dc9ed014 1379 In case of multi-channel arrays, each channel is processed
joeverbout 0:ea44dc9ed014 1380 independently. The accuracy is approximately the same as of the built-in
joeverbout 0:ea44dc9ed014 1381 std::sqrt .
joeverbout 0:ea44dc9ed014 1382 @param src input floating-point array.
joeverbout 0:ea44dc9ed014 1383 @param dst output array of the same size and type as src.
joeverbout 0:ea44dc9ed014 1384 */
joeverbout 0:ea44dc9ed014 1385 CV_EXPORTS_W void sqrt(InputArray src, OutputArray dst);
joeverbout 0:ea44dc9ed014 1386
joeverbout 0:ea44dc9ed014 1387 /** @brief Raises every array element to a power.
joeverbout 0:ea44dc9ed014 1388
joeverbout 0:ea44dc9ed014 1389 The function pow raises every element of the input array to power :
joeverbout 0:ea44dc9ed014 1390 \f[\texttt{dst} (I) = \fork{\texttt{src}(I)^{power}}{if \(\texttt{power}\) is integer}{|\texttt{src}(I)|^{power}}{otherwise}\f]
joeverbout 0:ea44dc9ed014 1391
joeverbout 0:ea44dc9ed014 1392 So, for a non-integer power exponent, the absolute values of input array
joeverbout 0:ea44dc9ed014 1393 elements are used. However, it is possible to get true values for
joeverbout 0:ea44dc9ed014 1394 negative values using some extra operations. In the example below,
joeverbout 0:ea44dc9ed014 1395 computing the 5th root of array src shows:
joeverbout 0:ea44dc9ed014 1396 @code{.cpp}
joeverbout 0:ea44dc9ed014 1397 Mat mask = src < 0;
joeverbout 0:ea44dc9ed014 1398 pow(src, 1./5, dst);
joeverbout 0:ea44dc9ed014 1399 subtract(Scalar::all(0), dst, dst, mask);
joeverbout 0:ea44dc9ed014 1400 @endcode
joeverbout 0:ea44dc9ed014 1401 For some values of power, such as integer values, 0.5 and -0.5,
joeverbout 0:ea44dc9ed014 1402 specialized faster algorithms are used.
joeverbout 0:ea44dc9ed014 1403
joeverbout 0:ea44dc9ed014 1404 Special values (NaN, Inf) are not handled.
joeverbout 0:ea44dc9ed014 1405 @param src input array.
joeverbout 0:ea44dc9ed014 1406 @param power exponent of power.
joeverbout 0:ea44dc9ed014 1407 @param dst output array of the same size and type as src.
joeverbout 0:ea44dc9ed014 1408 @sa sqrt, exp, log, cartToPolar, polarToCart
joeverbout 0:ea44dc9ed014 1409 */
joeverbout 0:ea44dc9ed014 1410 CV_EXPORTS_W void pow(InputArray src, double power, OutputArray dst);
joeverbout 0:ea44dc9ed014 1411
joeverbout 0:ea44dc9ed014 1412 /** @brief Calculates the exponent of every array element.
joeverbout 0:ea44dc9ed014 1413
joeverbout 0:ea44dc9ed014 1414 The function exp calculates the exponent of every element of the input
joeverbout 0:ea44dc9ed014 1415 array:
joeverbout 0:ea44dc9ed014 1416 \f[\texttt{dst} [I] = e^{ src(I) }\f]
joeverbout 0:ea44dc9ed014 1417
joeverbout 0:ea44dc9ed014 1418 The maximum relative error is about 7e-6 for single-precision input and
joeverbout 0:ea44dc9ed014 1419 less than 1e-10 for double-precision input. Currently, the function
joeverbout 0:ea44dc9ed014 1420 converts denormalized values to zeros on output. Special values (NaN,
joeverbout 0:ea44dc9ed014 1421 Inf) are not handled.
joeverbout 0:ea44dc9ed014 1422 @param src input array.
joeverbout 0:ea44dc9ed014 1423 @param dst output array of the same size and type as src.
joeverbout 0:ea44dc9ed014 1424 @sa log , cartToPolar , polarToCart , phase , pow , sqrt , magnitude
joeverbout 0:ea44dc9ed014 1425 */
joeverbout 0:ea44dc9ed014 1426 CV_EXPORTS_W void exp(InputArray src, OutputArray dst);
joeverbout 0:ea44dc9ed014 1427
joeverbout 0:ea44dc9ed014 1428 /** @brief Calculates the natural logarithm of every array element.
joeverbout 0:ea44dc9ed014 1429
joeverbout 0:ea44dc9ed014 1430 The function log calculates the natural logarithm of the absolute value
joeverbout 0:ea44dc9ed014 1431 of every element of the input array:
joeverbout 0:ea44dc9ed014 1432 \f[\texttt{dst} (I) = \fork{\log |\texttt{src}(I)|}{if \(\texttt{src}(I) \ne 0\) }{\texttt{C}}{otherwise}\f]
joeverbout 0:ea44dc9ed014 1433
joeverbout 0:ea44dc9ed014 1434 where C is a large negative number (about -700 in the current
joeverbout 0:ea44dc9ed014 1435 implementation). The maximum relative error is about 7e-6 for
joeverbout 0:ea44dc9ed014 1436 single-precision input and less than 1e-10 for double-precision input.
joeverbout 0:ea44dc9ed014 1437 Special values (NaN, Inf) are not handled.
joeverbout 0:ea44dc9ed014 1438 @param src input array.
joeverbout 0:ea44dc9ed014 1439 @param dst output array of the same size and type as src .
joeverbout 0:ea44dc9ed014 1440 @sa exp, cartToPolar, polarToCart, phase, pow, sqrt, magnitude
joeverbout 0:ea44dc9ed014 1441 */
joeverbout 0:ea44dc9ed014 1442 CV_EXPORTS_W void log(InputArray src, OutputArray dst);
joeverbout 0:ea44dc9ed014 1443
joeverbout 0:ea44dc9ed014 1444 /** @brief Calculates x and y coordinates of 2D vectors from their magnitude and angle.
joeverbout 0:ea44dc9ed014 1445
joeverbout 0:ea44dc9ed014 1446 The function polarToCart calculates the Cartesian coordinates of each 2D
joeverbout 0:ea44dc9ed014 1447 vector represented by the corresponding elements of magnitude and angle:
joeverbout 0:ea44dc9ed014 1448 \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]
joeverbout 0:ea44dc9ed014 1449
joeverbout 0:ea44dc9ed014 1450 The relative accuracy of the estimated coordinates is about 1e-6.
joeverbout 0:ea44dc9ed014 1451 @param magnitude input floating-point array of magnitudes of 2D vectors;
joeverbout 0:ea44dc9ed014 1452 it can be an empty matrix (=Mat()), in this case, the function assumes
joeverbout 0:ea44dc9ed014 1453 that all the magnitudes are =1; if it is not empty, it must have the
joeverbout 0:ea44dc9ed014 1454 same size and type as angle.
joeverbout 0:ea44dc9ed014 1455 @param angle input floating-point array of angles of 2D vectors.
joeverbout 0:ea44dc9ed014 1456 @param x output array of x-coordinates of 2D vectors; it has the same
joeverbout 0:ea44dc9ed014 1457 size and type as angle.
joeverbout 0:ea44dc9ed014 1458 @param y output array of y-coordinates of 2D vectors; it has the same
joeverbout 0:ea44dc9ed014 1459 size and type as angle.
joeverbout 0:ea44dc9ed014 1460 @param angleInDegrees when true, the input angles are measured in
joeverbout 0:ea44dc9ed014 1461 degrees, otherwise, they are measured in radians.
joeverbout 0:ea44dc9ed014 1462 @sa cartToPolar, magnitude, phase, exp, log, pow, sqrt
joeverbout 0:ea44dc9ed014 1463 */
joeverbout 0:ea44dc9ed014 1464 CV_EXPORTS_W void polarToCart(InputArray magnitude, InputArray angle,
joeverbout 0:ea44dc9ed014 1465 OutputArray x, OutputArray y, bool angleInDegrees = false);
joeverbout 0:ea44dc9ed014 1466
joeverbout 0:ea44dc9ed014 1467 /** @brief Calculates the magnitude and angle of 2D vectors.
joeverbout 0:ea44dc9ed014 1468
joeverbout 0:ea44dc9ed014 1469 The function cartToPolar calculates either the magnitude, angle, or both
joeverbout 0:ea44dc9ed014 1470 for every 2D vector (x(I),y(I)):
joeverbout 0:ea44dc9ed014 1471 \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]
joeverbout 0:ea44dc9ed014 1472
joeverbout 0:ea44dc9ed014 1473 The angles are calculated with accuracy about 0.3 degrees. For the point
joeverbout 0:ea44dc9ed014 1474 (0,0), the angle is set to 0.
joeverbout 0:ea44dc9ed014 1475 @param x array of x-coordinates; this must be a single-precision or
joeverbout 0:ea44dc9ed014 1476 double-precision floating-point array.
joeverbout 0:ea44dc9ed014 1477 @param y array of y-coordinates, that must have the same size and same type as x.
joeverbout 0:ea44dc9ed014 1478 @param magnitude output array of magnitudes of the same size and type as x.
joeverbout 0:ea44dc9ed014 1479 @param angle output array of angles that has the same size and type as
joeverbout 0:ea44dc9ed014 1480 x; the angles are measured in radians (from 0 to 2\*Pi) or in degrees (0 to 360 degrees).
joeverbout 0:ea44dc9ed014 1481 @param angleInDegrees a flag, indicating whether the angles are measured
joeverbout 0:ea44dc9ed014 1482 in radians (which is by default), or in degrees.
joeverbout 0:ea44dc9ed014 1483 @sa Sobel, Scharr
joeverbout 0:ea44dc9ed014 1484 */
joeverbout 0:ea44dc9ed014 1485 CV_EXPORTS_W void cartToPolar(InputArray x, InputArray y,
joeverbout 0:ea44dc9ed014 1486 OutputArray magnitude, OutputArray angle,
joeverbout 0:ea44dc9ed014 1487 bool angleInDegrees = false);
joeverbout 0:ea44dc9ed014 1488
joeverbout 0:ea44dc9ed014 1489 /** @brief Calculates the rotation angle of 2D vectors.
joeverbout 0:ea44dc9ed014 1490
joeverbout 0:ea44dc9ed014 1491 The function phase calculates the rotation angle of each 2D vector that
joeverbout 0:ea44dc9ed014 1492 is formed from the corresponding elements of x and y :
joeverbout 0:ea44dc9ed014 1493 \f[\texttt{angle} (I) = \texttt{atan2} ( \texttt{y} (I), \texttt{x} (I))\f]
joeverbout 0:ea44dc9ed014 1494
joeverbout 0:ea44dc9ed014 1495 The angle estimation accuracy is about 0.3 degrees. When x(I)=y(I)=0 ,
joeverbout 0:ea44dc9ed014 1496 the corresponding angle(I) is set to 0.
joeverbout 0:ea44dc9ed014 1497 @param x input floating-point array of x-coordinates of 2D vectors.
joeverbout 0:ea44dc9ed014 1498 @param y input array of y-coordinates of 2D vectors; it must have the
joeverbout 0:ea44dc9ed014 1499 same size and the same type as x.
joeverbout 0:ea44dc9ed014 1500 @param angle output array of vector angles; it has the same size and
joeverbout 0:ea44dc9ed014 1501 same type as x .
joeverbout 0:ea44dc9ed014 1502 @param angleInDegrees when true, the function calculates the angle in
joeverbout 0:ea44dc9ed014 1503 degrees, otherwise, they are measured in radians.
joeverbout 0:ea44dc9ed014 1504 */
joeverbout 0:ea44dc9ed014 1505 CV_EXPORTS_W void phase(InputArray x, InputArray y, OutputArray angle,
joeverbout 0:ea44dc9ed014 1506 bool angleInDegrees = false);
joeverbout 0:ea44dc9ed014 1507
joeverbout 0:ea44dc9ed014 1508 /** @brief Calculates the magnitude of 2D vectors.
joeverbout 0:ea44dc9ed014 1509
joeverbout 0:ea44dc9ed014 1510 The function magnitude calculates the magnitude of 2D vectors formed
joeverbout 0:ea44dc9ed014 1511 from the corresponding elements of x and y arrays:
joeverbout 0:ea44dc9ed014 1512 \f[\texttt{dst} (I) = \sqrt{\texttt{x}(I)^2 + \texttt{y}(I)^2}\f]
joeverbout 0:ea44dc9ed014 1513 @param x floating-point array of x-coordinates of the vectors.
joeverbout 0:ea44dc9ed014 1514 @param y floating-point array of y-coordinates of the vectors; it must
joeverbout 0:ea44dc9ed014 1515 have the same size as x.
joeverbout 0:ea44dc9ed014 1516 @param magnitude output array of the same size and type as x.
joeverbout 0:ea44dc9ed014 1517 @sa cartToPolar, polarToCart, phase, sqrt
joeverbout 0:ea44dc9ed014 1518 */
joeverbout 0:ea44dc9ed014 1519 CV_EXPORTS_W void magnitude(InputArray x, InputArray y, OutputArray magnitude);
joeverbout 0:ea44dc9ed014 1520
joeverbout 0:ea44dc9ed014 1521 /** @brief Checks every element of an input array for invalid values.
joeverbout 0:ea44dc9ed014 1522
joeverbout 0:ea44dc9ed014 1523 The functions checkRange check that every array element is neither NaN nor infinite. When minVal \>
joeverbout 0:ea44dc9ed014 1524 -DBL_MAX and maxVal \< DBL_MAX, the functions also check that each value is between minVal and
joeverbout 0:ea44dc9ed014 1525 maxVal. In case of multi-channel arrays, each channel is processed independently. If some values
joeverbout 0:ea44dc9ed014 1526 are out of range, position of the first outlier is stored in pos (when pos != NULL). Then, the
joeverbout 0:ea44dc9ed014 1527 functions either return false (when quiet=true) or throw an exception.
joeverbout 0:ea44dc9ed014 1528 @param a input array.
joeverbout 0:ea44dc9ed014 1529 @param quiet a flag, indicating whether the functions quietly return false when the array elements
joeverbout 0:ea44dc9ed014 1530 are out of range or they throw an exception.
joeverbout 0:ea44dc9ed014 1531 @param pos optional output parameter, when not NULL, must be a pointer to array of src.dims
joeverbout 0:ea44dc9ed014 1532 elements.
joeverbout 0:ea44dc9ed014 1533 @param minVal inclusive lower boundary of valid values range.
joeverbout 0:ea44dc9ed014 1534 @param maxVal exclusive upper boundary of valid values range.
joeverbout 0:ea44dc9ed014 1535 */
joeverbout 0:ea44dc9ed014 1536 CV_EXPORTS_W bool checkRange(InputArray a, bool quiet = true, CV_OUT Point* pos = 0,
joeverbout 0:ea44dc9ed014 1537 double minVal = -DBL_MAX, double maxVal = DBL_MAX);
joeverbout 0:ea44dc9ed014 1538
joeverbout 0:ea44dc9ed014 1539 /** @brief converts NaN's to the given number
joeverbout 0:ea44dc9ed014 1540 */
joeverbout 0:ea44dc9ed014 1541 CV_EXPORTS_W void patchNaNs(InputOutputArray a, double val = 0);
joeverbout 0:ea44dc9ed014 1542
joeverbout 0:ea44dc9ed014 1543 /** @brief Performs generalized matrix multiplication.
joeverbout 0:ea44dc9ed014 1544
joeverbout 0:ea44dc9ed014 1545 The function performs generalized matrix multiplication similar to the
joeverbout 0:ea44dc9ed014 1546 gemm functions in BLAS level 3. For example,
joeverbout 0:ea44dc9ed014 1547 `gemm(src1, src2, alpha, src3, beta, dst, GEMM_1_T + GEMM_3_T)`
joeverbout 0:ea44dc9ed014 1548 corresponds to
joeverbout 0:ea44dc9ed014 1549 \f[\texttt{dst} = \texttt{alpha} \cdot \texttt{src1} ^T \cdot \texttt{src2} + \texttt{beta} \cdot \texttt{src3} ^T\f]
joeverbout 0:ea44dc9ed014 1550
joeverbout 0:ea44dc9ed014 1551 In case of complex (two-channel) data, performed a complex matrix
joeverbout 0:ea44dc9ed014 1552 multiplication.
joeverbout 0:ea44dc9ed014 1553
joeverbout 0:ea44dc9ed014 1554 The function can be replaced with a matrix expression. For example, the
joeverbout 0:ea44dc9ed014 1555 above call can be replaced with:
joeverbout 0:ea44dc9ed014 1556 @code{.cpp}
joeverbout 0:ea44dc9ed014 1557 dst = alpha*src1.t()*src2 + beta*src3.t();
joeverbout 0:ea44dc9ed014 1558 @endcode
joeverbout 0:ea44dc9ed014 1559 @param src1 first multiplied input matrix that could be real(CV_32FC1,
joeverbout 0:ea44dc9ed014 1560 CV_64FC1) or complex(CV_32FC2, CV_64FC2).
joeverbout 0:ea44dc9ed014 1561 @param src2 second multiplied input matrix of the same type as src1.
joeverbout 0:ea44dc9ed014 1562 @param alpha weight of the matrix product.
joeverbout 0:ea44dc9ed014 1563 @param src3 third optional delta matrix added to the matrix product; it
joeverbout 0:ea44dc9ed014 1564 should have the same type as src1 and src2.
joeverbout 0:ea44dc9ed014 1565 @param beta weight of src3.
joeverbout 0:ea44dc9ed014 1566 @param dst output matrix; it has the proper size and the same type as
joeverbout 0:ea44dc9ed014 1567 input matrices.
joeverbout 0:ea44dc9ed014 1568 @param flags operation flags (cv::GemmFlags)
joeverbout 0:ea44dc9ed014 1569 @sa mulTransposed , transform
joeverbout 0:ea44dc9ed014 1570 */
joeverbout 0:ea44dc9ed014 1571 CV_EXPORTS_W void gemm(InputArray src1, InputArray src2, double alpha,
joeverbout 0:ea44dc9ed014 1572 InputArray src3, double beta, OutputArray dst, int flags = 0);
joeverbout 0:ea44dc9ed014 1573
joeverbout 0:ea44dc9ed014 1574 /** @brief Calculates the product of a matrix and its transposition.
joeverbout 0:ea44dc9ed014 1575
joeverbout 0:ea44dc9ed014 1576 The function mulTransposed calculates the product of src and its
joeverbout 0:ea44dc9ed014 1577 transposition:
joeverbout 0:ea44dc9ed014 1578 \f[\texttt{dst} = \texttt{scale} ( \texttt{src} - \texttt{delta} )^T ( \texttt{src} - \texttt{delta} )\f]
joeverbout 0:ea44dc9ed014 1579 if aTa=true , and
joeverbout 0:ea44dc9ed014 1580 \f[\texttt{dst} = \texttt{scale} ( \texttt{src} - \texttt{delta} ) ( \texttt{src} - \texttt{delta} )^T\f]
joeverbout 0:ea44dc9ed014 1581 otherwise. The function is used to calculate the covariance matrix. With
joeverbout 0:ea44dc9ed014 1582 zero delta, it can be used as a faster substitute for general matrix
joeverbout 0:ea44dc9ed014 1583 product A\*B when B=A'
joeverbout 0:ea44dc9ed014 1584 @param src input single-channel matrix. Note that unlike gemm, the
joeverbout 0:ea44dc9ed014 1585 function can multiply not only floating-point matrices.
joeverbout 0:ea44dc9ed014 1586 @param dst output square matrix.
joeverbout 0:ea44dc9ed014 1587 @param aTa Flag specifying the multiplication ordering. See the
joeverbout 0:ea44dc9ed014 1588 description below.
joeverbout 0:ea44dc9ed014 1589 @param delta Optional delta matrix subtracted from src before the
joeverbout 0:ea44dc9ed014 1590 multiplication. When the matrix is empty ( delta=noArray() ), it is
joeverbout 0:ea44dc9ed014 1591 assumed to be zero, that is, nothing is subtracted. If it has the same
joeverbout 0:ea44dc9ed014 1592 size as src , it is simply subtracted. Otherwise, it is "repeated" (see
joeverbout 0:ea44dc9ed014 1593 repeat ) to cover the full src and then subtracted. Type of the delta
joeverbout 0:ea44dc9ed014 1594 matrix, when it is not empty, must be the same as the type of created
joeverbout 0:ea44dc9ed014 1595 output matrix. See the dtype parameter description below.
joeverbout 0:ea44dc9ed014 1596 @param scale Optional scale factor for the matrix product.
joeverbout 0:ea44dc9ed014 1597 @param dtype Optional type of the output matrix. When it is negative,
joeverbout 0:ea44dc9ed014 1598 the output matrix will have the same type as src . Otherwise, it will be
joeverbout 0:ea44dc9ed014 1599 type=CV_MAT_DEPTH(dtype) that should be either CV_32F or CV_64F .
joeverbout 0:ea44dc9ed014 1600 @sa calcCovarMatrix, gemm, repeat, reduce
joeverbout 0:ea44dc9ed014 1601 */
joeverbout 0:ea44dc9ed014 1602 CV_EXPORTS_W void mulTransposed( InputArray src, OutputArray dst, bool aTa,
joeverbout 0:ea44dc9ed014 1603 InputArray delta = noArray(),
joeverbout 0:ea44dc9ed014 1604 double scale = 1, int dtype = -1 );
joeverbout 0:ea44dc9ed014 1605
joeverbout 0:ea44dc9ed014 1606 /** @brief Transposes a matrix.
joeverbout 0:ea44dc9ed014 1607
joeverbout 0:ea44dc9ed014 1608 The function transpose transposes the matrix src :
joeverbout 0:ea44dc9ed014 1609 \f[\texttt{dst} (i,j) = \texttt{src} (j,i)\f]
joeverbout 0:ea44dc9ed014 1610 @note No complex conjugation is done in case of a complex matrix. It it
joeverbout 0:ea44dc9ed014 1611 should be done separately if needed.
joeverbout 0:ea44dc9ed014 1612 @param src input array.
joeverbout 0:ea44dc9ed014 1613 @param dst output array of the same type as src.
joeverbout 0:ea44dc9ed014 1614 */
joeverbout 0:ea44dc9ed014 1615 CV_EXPORTS_W void transpose(InputArray src, OutputArray dst);
joeverbout 0:ea44dc9ed014 1616
joeverbout 0:ea44dc9ed014 1617 /** @brief Performs the matrix transformation of every array element.
joeverbout 0:ea44dc9ed014 1618
joeverbout 0:ea44dc9ed014 1619 The function transform performs the matrix transformation of every
joeverbout 0:ea44dc9ed014 1620 element of the array src and stores the results in dst :
joeverbout 0:ea44dc9ed014 1621 \f[\texttt{dst} (I) = \texttt{m} \cdot \texttt{src} (I)\f]
joeverbout 0:ea44dc9ed014 1622 (when m.cols=src.channels() ), or
joeverbout 0:ea44dc9ed014 1623 \f[\texttt{dst} (I) = \texttt{m} \cdot [ \texttt{src} (I); 1]\f]
joeverbout 0:ea44dc9ed014 1624 (when m.cols=src.channels()+1 )
joeverbout 0:ea44dc9ed014 1625
joeverbout 0:ea44dc9ed014 1626 Every element of the N -channel array src is interpreted as N -element
joeverbout 0:ea44dc9ed014 1627 vector that is transformed using the M x N or M x (N+1) matrix m to
joeverbout 0:ea44dc9ed014 1628 M-element vector - the corresponding element of the output array dst .
joeverbout 0:ea44dc9ed014 1629
joeverbout 0:ea44dc9ed014 1630 The function may be used for geometrical transformation of
joeverbout 0:ea44dc9ed014 1631 N -dimensional points, arbitrary linear color space transformation (such
joeverbout 0:ea44dc9ed014 1632 as various kinds of RGB to YUV transforms), shuffling the image
joeverbout 0:ea44dc9ed014 1633 channels, and so forth.
joeverbout 0:ea44dc9ed014 1634 @param src input array that must have as many channels (1 to 4) as
joeverbout 0:ea44dc9ed014 1635 m.cols or m.cols-1.
joeverbout 0:ea44dc9ed014 1636 @param dst output array of the same size and depth as src; it has as
joeverbout 0:ea44dc9ed014 1637 many channels as m.rows.
joeverbout 0:ea44dc9ed014 1638 @param m transformation 2x2 or 2x3 floating-point matrix.
joeverbout 0:ea44dc9ed014 1639 @sa perspectiveTransform, getAffineTransform, estimateRigidTransform, warpAffine, warpPerspective
joeverbout 0:ea44dc9ed014 1640 */
joeverbout 0:ea44dc9ed014 1641 CV_EXPORTS_W void transform(InputArray src, OutputArray dst, InputArray m );
joeverbout 0:ea44dc9ed014 1642
joeverbout 0:ea44dc9ed014 1643 /** @brief Performs the perspective matrix transformation of vectors.
joeverbout 0:ea44dc9ed014 1644
joeverbout 0:ea44dc9ed014 1645 The function perspectiveTransform transforms every element of src by
joeverbout 0:ea44dc9ed014 1646 treating it as a 2D or 3D vector, in the following way:
joeverbout 0:ea44dc9ed014 1647 \f[(x, y, z) \rightarrow (x'/w, y'/w, z'/w)\f]
joeverbout 0:ea44dc9ed014 1648 where
joeverbout 0:ea44dc9ed014 1649 \f[(x', y', z', w') = \texttt{mat} \cdot \begin{bmatrix} x & y & z & 1 \end{bmatrix}\f]
joeverbout 0:ea44dc9ed014 1650 and
joeverbout 0:ea44dc9ed014 1651 \f[w = \fork{w'}{if \(w' \ne 0\)}{\infty}{otherwise}\f]
joeverbout 0:ea44dc9ed014 1652
joeverbout 0:ea44dc9ed014 1653 Here a 3D vector transformation is shown. In case of a 2D vector
joeverbout 0:ea44dc9ed014 1654 transformation, the z component is omitted.
joeverbout 0:ea44dc9ed014 1655
joeverbout 0:ea44dc9ed014 1656 @note The function transforms a sparse set of 2D or 3D vectors. If you
joeverbout 0:ea44dc9ed014 1657 want to transform an image using perspective transformation, use
joeverbout 0:ea44dc9ed014 1658 warpPerspective . If you have an inverse problem, that is, you want to
joeverbout 0:ea44dc9ed014 1659 compute the most probable perspective transformation out of several
joeverbout 0:ea44dc9ed014 1660 pairs of corresponding points, you can use getPerspectiveTransform or
joeverbout 0:ea44dc9ed014 1661 findHomography .
joeverbout 0:ea44dc9ed014 1662 @param src input two-channel or three-channel floating-point array; each
joeverbout 0:ea44dc9ed014 1663 element is a 2D/3D vector to be transformed.
joeverbout 0:ea44dc9ed014 1664 @param dst output array of the same size and type as src.
joeverbout 0:ea44dc9ed014 1665 @param m 3x3 or 4x4 floating-point transformation matrix.
joeverbout 0:ea44dc9ed014 1666 @sa transform, warpPerspective, getPerspectiveTransform, findHomography
joeverbout 0:ea44dc9ed014 1667 */
joeverbout 0:ea44dc9ed014 1668 CV_EXPORTS_W void perspectiveTransform(InputArray src, OutputArray dst, InputArray m );
joeverbout 0:ea44dc9ed014 1669
joeverbout 0:ea44dc9ed014 1670 /** @brief Copies the lower or the upper half of a square matrix to another half.
joeverbout 0:ea44dc9ed014 1671
joeverbout 0:ea44dc9ed014 1672 The function completeSymm copies the lower half of a square matrix to
joeverbout 0:ea44dc9ed014 1673 its another half. The matrix diagonal remains unchanged:
joeverbout 0:ea44dc9ed014 1674 * \f$\texttt{mtx}_{ij}=\texttt{mtx}_{ji}\f$ for \f$i > j\f$ if
joeverbout 0:ea44dc9ed014 1675 lowerToUpper=false
joeverbout 0:ea44dc9ed014 1676 * \f$\texttt{mtx}_{ij}=\texttt{mtx}_{ji}\f$ for \f$i < j\f$ if
joeverbout 0:ea44dc9ed014 1677 lowerToUpper=true
joeverbout 0:ea44dc9ed014 1678 @param mtx input-output floating-point square matrix.
joeverbout 0:ea44dc9ed014 1679 @param lowerToUpper operation flag; if true, the lower half is copied to
joeverbout 0:ea44dc9ed014 1680 the upper half. Otherwise, the upper half is copied to the lower half.
joeverbout 0:ea44dc9ed014 1681 @sa flip, transpose
joeverbout 0:ea44dc9ed014 1682 */
joeverbout 0:ea44dc9ed014 1683 CV_EXPORTS_W void completeSymm(InputOutputArray mtx, bool lowerToUpper = false);
joeverbout 0:ea44dc9ed014 1684
joeverbout 0:ea44dc9ed014 1685 /** @brief Initializes a scaled identity matrix.
joeverbout 0:ea44dc9ed014 1686
joeverbout 0:ea44dc9ed014 1687 The function setIdentity initializes a scaled identity matrix:
joeverbout 0:ea44dc9ed014 1688 \f[\texttt{mtx} (i,j)= \fork{\texttt{value}}{ if \(i=j\)}{0}{otherwise}\f]
joeverbout 0:ea44dc9ed014 1689
joeverbout 0:ea44dc9ed014 1690 The function can also be emulated using the matrix initializers and the
joeverbout 0:ea44dc9ed014 1691 matrix expressions:
joeverbout 0:ea44dc9ed014 1692 @code
joeverbout 0:ea44dc9ed014 1693 Mat A = Mat::eye(4, 3, CV_32F)*5;
joeverbout 0:ea44dc9ed014 1694 // A will be set to [[5, 0, 0], [0, 5, 0], [0, 0, 5], [0, 0, 0]]
joeverbout 0:ea44dc9ed014 1695 @endcode
joeverbout 0:ea44dc9ed014 1696 @param mtx matrix to initialize (not necessarily square).
joeverbout 0:ea44dc9ed014 1697 @param s value to assign to diagonal elements.
joeverbout 0:ea44dc9ed014 1698 @sa Mat::zeros, Mat::ones, Mat::setTo, Mat::operator=
joeverbout 0:ea44dc9ed014 1699 */
joeverbout 0:ea44dc9ed014 1700 CV_EXPORTS_W void setIdentity(InputOutputArray mtx, const Scalar& s = Scalar(1));
joeverbout 0:ea44dc9ed014 1701
joeverbout 0:ea44dc9ed014 1702 /** @brief Returns the determinant of a square floating-point matrix.
joeverbout 0:ea44dc9ed014 1703
joeverbout 0:ea44dc9ed014 1704 The function determinant calculates and returns the determinant of the
joeverbout 0:ea44dc9ed014 1705 specified matrix. For small matrices ( mtx.cols=mtx.rows\<=3 ), the
joeverbout 0:ea44dc9ed014 1706 direct method is used. For larger matrices, the function uses LU
joeverbout 0:ea44dc9ed014 1707 factorization with partial pivoting.
joeverbout 0:ea44dc9ed014 1708
joeverbout 0:ea44dc9ed014 1709 For symmetric positively-determined matrices, it is also possible to use
joeverbout 0:ea44dc9ed014 1710 eigen decomposition to calculate the determinant.
joeverbout 0:ea44dc9ed014 1711 @param mtx input matrix that must have CV_32FC1 or CV_64FC1 type and
joeverbout 0:ea44dc9ed014 1712 square size.
joeverbout 0:ea44dc9ed014 1713 @sa trace, invert, solve, eigen, @ref MatrixExpressions
joeverbout 0:ea44dc9ed014 1714 */
joeverbout 0:ea44dc9ed014 1715 CV_EXPORTS_W double determinant(InputArray mtx);
joeverbout 0:ea44dc9ed014 1716
joeverbout 0:ea44dc9ed014 1717 /** @brief Returns the trace of a matrix.
joeverbout 0:ea44dc9ed014 1718
joeverbout 0:ea44dc9ed014 1719 The function trace returns the sum of the diagonal elements of the
joeverbout 0:ea44dc9ed014 1720 matrix mtx .
joeverbout 0:ea44dc9ed014 1721 \f[\mathrm{tr} ( \texttt{mtx} ) = \sum _i \texttt{mtx} (i,i)\f]
joeverbout 0:ea44dc9ed014 1722 @param mtx input matrix.
joeverbout 0:ea44dc9ed014 1723 */
joeverbout 0:ea44dc9ed014 1724 CV_EXPORTS_W Scalar trace(InputArray mtx);
joeverbout 0:ea44dc9ed014 1725
joeverbout 0:ea44dc9ed014 1726 /** @brief Finds the inverse or pseudo-inverse of a matrix.
joeverbout 0:ea44dc9ed014 1727
joeverbout 0:ea44dc9ed014 1728 The function invert inverts the matrix src and stores the result in dst
joeverbout 0:ea44dc9ed014 1729 . When the matrix src is singular or non-square, the function calculates
joeverbout 0:ea44dc9ed014 1730 the pseudo-inverse matrix (the dst matrix) so that norm(src\*dst - I) is
joeverbout 0:ea44dc9ed014 1731 minimal, where I is an identity matrix.
joeverbout 0:ea44dc9ed014 1732
joeverbout 0:ea44dc9ed014 1733 In case of the DECOMP_LU method, the function returns non-zero value if
joeverbout 0:ea44dc9ed014 1734 the inverse has been successfully calculated and 0 if src is singular.
joeverbout 0:ea44dc9ed014 1735
joeverbout 0:ea44dc9ed014 1736 In case of the DECOMP_SVD method, the function returns the inverse
joeverbout 0:ea44dc9ed014 1737 condition number of src (the ratio of the smallest singular value to the
joeverbout 0:ea44dc9ed014 1738 largest singular value) and 0 if src is singular. The SVD method
joeverbout 0:ea44dc9ed014 1739 calculates a pseudo-inverse matrix if src is singular.
joeverbout 0:ea44dc9ed014 1740
joeverbout 0:ea44dc9ed014 1741 Similarly to DECOMP_LU, the method DECOMP_CHOLESKY works only with
joeverbout 0:ea44dc9ed014 1742 non-singular square matrices that should also be symmetrical and
joeverbout 0:ea44dc9ed014 1743 positively defined. In this case, the function stores the inverted
joeverbout 0:ea44dc9ed014 1744 matrix in dst and returns non-zero. Otherwise, it returns 0.
joeverbout 0:ea44dc9ed014 1745
joeverbout 0:ea44dc9ed014 1746 @param src input floating-point M x N matrix.
joeverbout 0:ea44dc9ed014 1747 @param dst output matrix of N x M size and the same type as src.
joeverbout 0:ea44dc9ed014 1748 @param flags inversion method (cv::DecompTypes)
joeverbout 0:ea44dc9ed014 1749 @sa solve, SVD
joeverbout 0:ea44dc9ed014 1750 */
joeverbout 0:ea44dc9ed014 1751 CV_EXPORTS_W double invert(InputArray src, OutputArray dst, int flags = DECOMP_LU);
joeverbout 0:ea44dc9ed014 1752
joeverbout 0:ea44dc9ed014 1753 /** @brief Solves one or more linear systems or least-squares problems.
joeverbout 0:ea44dc9ed014 1754
joeverbout 0:ea44dc9ed014 1755 The function solve solves a linear system or least-squares problem (the
joeverbout 0:ea44dc9ed014 1756 latter is possible with SVD or QR methods, or by specifying the flag
joeverbout 0:ea44dc9ed014 1757 DECOMP_NORMAL ):
joeverbout 0:ea44dc9ed014 1758 \f[\texttt{dst} = \arg \min _X \| \texttt{src1} \cdot \texttt{X} - \texttt{src2} \|\f]
joeverbout 0:ea44dc9ed014 1759
joeverbout 0:ea44dc9ed014 1760 If DECOMP_LU or DECOMP_CHOLESKY method is used, the function returns 1
joeverbout 0:ea44dc9ed014 1761 if src1 (or \f$\texttt{src1}^T\texttt{src1}\f$ ) is non-singular. Otherwise,
joeverbout 0:ea44dc9ed014 1762 it returns 0. In the latter case, dst is not valid. Other methods find a
joeverbout 0:ea44dc9ed014 1763 pseudo-solution in case of a singular left-hand side part.
joeverbout 0:ea44dc9ed014 1764
joeverbout 0:ea44dc9ed014 1765 @note If you want to find a unity-norm solution of an under-defined
joeverbout 0:ea44dc9ed014 1766 singular system \f$\texttt{src1}\cdot\texttt{dst}=0\f$ , the function solve
joeverbout 0:ea44dc9ed014 1767 will not do the work. Use SVD::solveZ instead.
joeverbout 0:ea44dc9ed014 1768
joeverbout 0:ea44dc9ed014 1769 @param src1 input matrix on the left-hand side of the system.
joeverbout 0:ea44dc9ed014 1770 @param src2 input matrix on the right-hand side of the system.
joeverbout 0:ea44dc9ed014 1771 @param dst output solution.
joeverbout 0:ea44dc9ed014 1772 @param flags solution (matrix inversion) method (cv::DecompTypes)
joeverbout 0:ea44dc9ed014 1773 @sa invert, SVD, eigen
joeverbout 0:ea44dc9ed014 1774 */
joeverbout 0:ea44dc9ed014 1775 CV_EXPORTS_W bool solve(InputArray src1, InputArray src2,
joeverbout 0:ea44dc9ed014 1776 OutputArray dst, int flags = DECOMP_LU);
joeverbout 0:ea44dc9ed014 1777
joeverbout 0:ea44dc9ed014 1778 /** @brief Sorts each row or each column of a matrix.
joeverbout 0:ea44dc9ed014 1779
joeverbout 0:ea44dc9ed014 1780 The function sort sorts each matrix row or each matrix column in
joeverbout 0:ea44dc9ed014 1781 ascending or descending order. So you should pass two operation flags to
joeverbout 0:ea44dc9ed014 1782 get desired behaviour. If you want to sort matrix rows or columns
joeverbout 0:ea44dc9ed014 1783 lexicographically, you can use STL std::sort generic function with the
joeverbout 0:ea44dc9ed014 1784 proper comparison predicate.
joeverbout 0:ea44dc9ed014 1785
joeverbout 0:ea44dc9ed014 1786 @param src input single-channel array.
joeverbout 0:ea44dc9ed014 1787 @param dst output array of the same size and type as src.
joeverbout 0:ea44dc9ed014 1788 @param flags operation flags, a combination of cv::SortFlags
joeverbout 0:ea44dc9ed014 1789 @sa sortIdx, randShuffle
joeverbout 0:ea44dc9ed014 1790 */
joeverbout 0:ea44dc9ed014 1791 CV_EXPORTS_W void sort(InputArray src, OutputArray dst, int flags);
joeverbout 0:ea44dc9ed014 1792
joeverbout 0:ea44dc9ed014 1793 /** @brief Sorts each row or each column of a matrix.
joeverbout 0:ea44dc9ed014 1794
joeverbout 0:ea44dc9ed014 1795 The function sortIdx sorts each matrix row or each matrix column in the
joeverbout 0:ea44dc9ed014 1796 ascending or descending order. So you should pass two operation flags to
joeverbout 0:ea44dc9ed014 1797 get desired behaviour. Instead of reordering the elements themselves, it
joeverbout 0:ea44dc9ed014 1798 stores the indices of sorted elements in the output array. For example:
joeverbout 0:ea44dc9ed014 1799 @code
joeverbout 0:ea44dc9ed014 1800 Mat A = Mat::eye(3,3,CV_32F), B;
joeverbout 0:ea44dc9ed014 1801 sortIdx(A, B, SORT_EVERY_ROW + SORT_ASCENDING);
joeverbout 0:ea44dc9ed014 1802 // B will probably contain
joeverbout 0:ea44dc9ed014 1803 // (because of equal elements in A some permutations are possible):
joeverbout 0:ea44dc9ed014 1804 // [[1, 2, 0], [0, 2, 1], [0, 1, 2]]
joeverbout 0:ea44dc9ed014 1805 @endcode
joeverbout 0:ea44dc9ed014 1806 @param src input single-channel array.
joeverbout 0:ea44dc9ed014 1807 @param dst output integer array of the same size as src.
joeverbout 0:ea44dc9ed014 1808 @param flags operation flags that could be a combination of cv::SortFlags
joeverbout 0:ea44dc9ed014 1809 @sa sort, randShuffle
joeverbout 0:ea44dc9ed014 1810 */
joeverbout 0:ea44dc9ed014 1811 CV_EXPORTS_W void sortIdx(InputArray src, OutputArray dst, int flags);
joeverbout 0:ea44dc9ed014 1812
joeverbout 0:ea44dc9ed014 1813 /** @brief Finds the real roots of a cubic equation.
joeverbout 0:ea44dc9ed014 1814
joeverbout 0:ea44dc9ed014 1815 The function solveCubic finds the real roots of a cubic equation:
joeverbout 0:ea44dc9ed014 1816 - if coeffs is a 4-element vector:
joeverbout 0:ea44dc9ed014 1817 \f[\texttt{coeffs} [0] x^3 + \texttt{coeffs} [1] x^2 + \texttt{coeffs} [2] x + \texttt{coeffs} [3] = 0\f]
joeverbout 0:ea44dc9ed014 1818 - if coeffs is a 3-element vector:
joeverbout 0:ea44dc9ed014 1819 \f[x^3 + \texttt{coeffs} [0] x^2 + \texttt{coeffs} [1] x + \texttt{coeffs} [2] = 0\f]
joeverbout 0:ea44dc9ed014 1820
joeverbout 0:ea44dc9ed014 1821 The roots are stored in the roots array.
joeverbout 0:ea44dc9ed014 1822 @param coeffs equation coefficients, an array of 3 or 4 elements.
joeverbout 0:ea44dc9ed014 1823 @param roots output array of real roots that has 1 or 3 elements.
joeverbout 0:ea44dc9ed014 1824 */
joeverbout 0:ea44dc9ed014 1825 CV_EXPORTS_W int solveCubic(InputArray coeffs, OutputArray roots);
joeverbout 0:ea44dc9ed014 1826
joeverbout 0:ea44dc9ed014 1827 /** @brief Finds the real or complex roots of a polynomial equation.
joeverbout 0:ea44dc9ed014 1828
joeverbout 0:ea44dc9ed014 1829 The function solvePoly finds real and complex roots of a polynomial equation:
joeverbout 0:ea44dc9ed014 1830 \f[\texttt{coeffs} [n] x^{n} + \texttt{coeffs} [n-1] x^{n-1} + ... + \texttt{coeffs} [1] x + \texttt{coeffs} [0] = 0\f]
joeverbout 0:ea44dc9ed014 1831 @param coeffs array of polynomial coefficients.
joeverbout 0:ea44dc9ed014 1832 @param roots output (complex) array of roots.
joeverbout 0:ea44dc9ed014 1833 @param maxIters maximum number of iterations the algorithm does.
joeverbout 0:ea44dc9ed014 1834 */
joeverbout 0:ea44dc9ed014 1835 CV_EXPORTS_W double solvePoly(InputArray coeffs, OutputArray roots, int maxIters = 300);
joeverbout 0:ea44dc9ed014 1836
joeverbout 0:ea44dc9ed014 1837 /** @brief Calculates eigenvalues and eigenvectors of a symmetric matrix.
joeverbout 0:ea44dc9ed014 1838
joeverbout 0:ea44dc9ed014 1839 The functions eigen calculate just eigenvalues, or eigenvalues and eigenvectors of the symmetric
joeverbout 0:ea44dc9ed014 1840 matrix src:
joeverbout 0:ea44dc9ed014 1841 @code
joeverbout 0:ea44dc9ed014 1842 src*eigenvectors.row(i).t() = eigenvalues.at<srcType>(i)*eigenvectors.row(i).t()
joeverbout 0:ea44dc9ed014 1843 @endcode
joeverbout 0:ea44dc9ed014 1844 @note in the new and the old interfaces different ordering of eigenvalues and eigenvectors
joeverbout 0:ea44dc9ed014 1845 parameters is used.
joeverbout 0:ea44dc9ed014 1846 @param src input matrix that must have CV_32FC1 or CV_64FC1 type, square size and be symmetrical
joeverbout 0:ea44dc9ed014 1847 (src ^T^ == src).
joeverbout 0:ea44dc9ed014 1848 @param eigenvalues output vector of eigenvalues of the same type as src; the eigenvalues are stored
joeverbout 0:ea44dc9ed014 1849 in the descending order.
joeverbout 0:ea44dc9ed014 1850 @param eigenvectors output matrix of eigenvectors; it has the same size and type as src; the
joeverbout 0:ea44dc9ed014 1851 eigenvectors are stored as subsequent matrix rows, in the same order as the corresponding
joeverbout 0:ea44dc9ed014 1852 eigenvalues.
joeverbout 0:ea44dc9ed014 1853 @sa completeSymm , PCA
joeverbout 0:ea44dc9ed014 1854 */
joeverbout 0:ea44dc9ed014 1855 CV_EXPORTS_W bool eigen(InputArray src, OutputArray eigenvalues,
joeverbout 0:ea44dc9ed014 1856 OutputArray eigenvectors = noArray());
joeverbout 0:ea44dc9ed014 1857
joeverbout 0:ea44dc9ed014 1858 /** @brief Calculates the covariance matrix of a set of vectors.
joeverbout 0:ea44dc9ed014 1859
joeverbout 0:ea44dc9ed014 1860 The functions calcCovarMatrix calculate the covariance matrix and, optionally, the mean vector of
joeverbout 0:ea44dc9ed014 1861 the set of input vectors.
joeverbout 0:ea44dc9ed014 1862 @param samples samples stored as separate matrices
joeverbout 0:ea44dc9ed014 1863 @param nsamples number of samples
joeverbout 0:ea44dc9ed014 1864 @param covar output covariance matrix of the type ctype and square size.
joeverbout 0:ea44dc9ed014 1865 @param mean input or output (depending on the flags) array as the average value of the input vectors.
joeverbout 0:ea44dc9ed014 1866 @param flags operation flags as a combination of cv::CovarFlags
joeverbout 0:ea44dc9ed014 1867 @param ctype type of the matrixl; it equals 'CV_64F' by default.
joeverbout 0:ea44dc9ed014 1868 @sa PCA, mulTransposed, Mahalanobis
joeverbout 0:ea44dc9ed014 1869 @todo InputArrayOfArrays
joeverbout 0:ea44dc9ed014 1870 */
joeverbout 0:ea44dc9ed014 1871 CV_EXPORTS void calcCovarMatrix( const Mat* samples, int nsamples, Mat& covar, Mat& mean,
joeverbout 0:ea44dc9ed014 1872 int flags, int ctype = CV_64F);
joeverbout 0:ea44dc9ed014 1873
joeverbout 0:ea44dc9ed014 1874 /** @overload
joeverbout 0:ea44dc9ed014 1875 @note use cv::COVAR_ROWS or cv::COVAR_COLS flag
joeverbout 0:ea44dc9ed014 1876 @param samples samples stored as rows/columns of a single matrix.
joeverbout 0:ea44dc9ed014 1877 @param covar output covariance matrix of the type ctype and square size.
joeverbout 0:ea44dc9ed014 1878 @param mean input or output (depending on the flags) array as the average value of the input vectors.
joeverbout 0:ea44dc9ed014 1879 @param flags operation flags as a combination of cv::CovarFlags
joeverbout 0:ea44dc9ed014 1880 @param ctype type of the matrixl; it equals 'CV_64F' by default.
joeverbout 0:ea44dc9ed014 1881 */
joeverbout 0:ea44dc9ed014 1882 CV_EXPORTS_W void calcCovarMatrix( InputArray samples, OutputArray covar,
joeverbout 0:ea44dc9ed014 1883 InputOutputArray mean, int flags, int ctype = CV_64F);
joeverbout 0:ea44dc9ed014 1884
joeverbout 0:ea44dc9ed014 1885 /** wrap PCA::operator() */
joeverbout 0:ea44dc9ed014 1886 CV_EXPORTS_W void PCACompute(InputArray data, InputOutputArray mean,
joeverbout 0:ea44dc9ed014 1887 OutputArray eigenvectors, int maxComponents = 0);
joeverbout 0:ea44dc9ed014 1888
joeverbout 0:ea44dc9ed014 1889 /** wrap PCA::operator() */
joeverbout 0:ea44dc9ed014 1890 CV_EXPORTS_W void PCACompute(InputArray data, InputOutputArray mean,
joeverbout 0:ea44dc9ed014 1891 OutputArray eigenvectors, double retainedVariance);
joeverbout 0:ea44dc9ed014 1892
joeverbout 0:ea44dc9ed014 1893 /** wrap PCA::project */
joeverbout 0:ea44dc9ed014 1894 CV_EXPORTS_W void PCAProject(InputArray data, InputArray mean,
joeverbout 0:ea44dc9ed014 1895 InputArray eigenvectors, OutputArray result);
joeverbout 0:ea44dc9ed014 1896
joeverbout 0:ea44dc9ed014 1897 /** wrap PCA::backProject */
joeverbout 0:ea44dc9ed014 1898 CV_EXPORTS_W void PCABackProject(InputArray data, InputArray mean,
joeverbout 0:ea44dc9ed014 1899 InputArray eigenvectors, OutputArray result);
joeverbout 0:ea44dc9ed014 1900
joeverbout 0:ea44dc9ed014 1901 /** wrap SVD::compute */
joeverbout 0:ea44dc9ed014 1902 CV_EXPORTS_W void SVDecomp( InputArray src, OutputArray w, OutputArray u, OutputArray vt, int flags = 0 );
joeverbout 0:ea44dc9ed014 1903
joeverbout 0:ea44dc9ed014 1904 /** wrap SVD::backSubst */
joeverbout 0:ea44dc9ed014 1905 CV_EXPORTS_W void SVBackSubst( InputArray w, InputArray u, InputArray vt,
joeverbout 0:ea44dc9ed014 1906 InputArray rhs, OutputArray dst );
joeverbout 0:ea44dc9ed014 1907
joeverbout 0:ea44dc9ed014 1908 /** @brief Calculates the Mahalanobis distance between two vectors.
joeverbout 0:ea44dc9ed014 1909
joeverbout 0:ea44dc9ed014 1910 The function Mahalanobis calculates and returns the weighted distance between two vectors:
joeverbout 0:ea44dc9ed014 1911 \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]
joeverbout 0:ea44dc9ed014 1912 The covariance matrix may be calculated using the cv::calcCovarMatrix function and then inverted using
joeverbout 0:ea44dc9ed014 1913 the invert function (preferably using the cv::DECOMP_SVD method, as the most accurate).
joeverbout 0:ea44dc9ed014 1914 @param v1 first 1D input vector.
joeverbout 0:ea44dc9ed014 1915 @param v2 second 1D input vector.
joeverbout 0:ea44dc9ed014 1916 @param icovar inverse covariance matrix.
joeverbout 0:ea44dc9ed014 1917 */
joeverbout 0:ea44dc9ed014 1918 CV_EXPORTS_W double Mahalanobis(InputArray v1, InputArray v2, InputArray icovar);
joeverbout 0:ea44dc9ed014 1919
joeverbout 0:ea44dc9ed014 1920 /** @brief Performs a forward or inverse Discrete Fourier transform of a 1D or 2D floating-point array.
joeverbout 0:ea44dc9ed014 1921
joeverbout 0:ea44dc9ed014 1922 The function performs one of the following:
joeverbout 0:ea44dc9ed014 1923 - Forward the Fourier transform of a 1D vector of N elements:
joeverbout 0:ea44dc9ed014 1924 \f[Y = F^{(N)} \cdot X,\f]
joeverbout 0:ea44dc9ed014 1925 where \f$F^{(N)}_{jk}=\exp(-2\pi i j k/N)\f$ and \f$i=\sqrt{-1}\f$
joeverbout 0:ea44dc9ed014 1926 - Inverse the Fourier transform of a 1D vector of N elements:
joeverbout 0:ea44dc9ed014 1927 \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]
joeverbout 0:ea44dc9ed014 1928 where \f$F^*=\left(\textrm{Re}(F^{(N)})-\textrm{Im}(F^{(N)})\right)^T\f$
joeverbout 0:ea44dc9ed014 1929 - Forward the 2D Fourier transform of a M x N matrix:
joeverbout 0:ea44dc9ed014 1930 \f[Y = F^{(M)} \cdot X \cdot F^{(N)}\f]
joeverbout 0:ea44dc9ed014 1931 - Inverse the 2D Fourier transform of a M x N matrix:
joeverbout 0:ea44dc9ed014 1932 \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]
joeverbout 0:ea44dc9ed014 1933
joeverbout 0:ea44dc9ed014 1934 In case of real (single-channel) data, the output spectrum of the forward Fourier transform or input
joeverbout 0:ea44dc9ed014 1935 spectrum of the inverse Fourier transform can be represented in a packed format called *CCS*
joeverbout 0:ea44dc9ed014 1936 (complex-conjugate-symmetrical). It was borrowed from IPL (Intel\* Image Processing Library). Here
joeverbout 0:ea44dc9ed014 1937 is how 2D *CCS* spectrum looks:
joeverbout 0:ea44dc9ed014 1938 \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]
joeverbout 0:ea44dc9ed014 1939
joeverbout 0:ea44dc9ed014 1940 In case of 1D transform of a real vector, the output looks like the first row of the matrix above.
joeverbout 0:ea44dc9ed014 1941
joeverbout 0:ea44dc9ed014 1942 So, the function chooses an operation mode depending on the flags and size of the input array:
joeverbout 0:ea44dc9ed014 1943 - If DFT_ROWS is set or the input array has a single row or single column, the function
joeverbout 0:ea44dc9ed014 1944 performs a 1D forward or inverse transform of each row of a matrix when DFT_ROWS is set.
joeverbout 0:ea44dc9ed014 1945 Otherwise, it performs a 2D transform.
joeverbout 0:ea44dc9ed014 1946 - If the input array is real and DFT_INVERSE is not set, the function performs a forward 1D or
joeverbout 0:ea44dc9ed014 1947 2D transform:
joeverbout 0:ea44dc9ed014 1948 - When DFT_COMPLEX_OUTPUT is set, the output is a complex matrix of the same size as
joeverbout 0:ea44dc9ed014 1949 input.
joeverbout 0:ea44dc9ed014 1950 - When DFT_COMPLEX_OUTPUT is not set, the output is a real matrix of the same size as
joeverbout 0:ea44dc9ed014 1951 input. In case of 2D transform, it uses the packed format as shown above. In case of a
joeverbout 0:ea44dc9ed014 1952 single 1D transform, it looks like the first row of the matrix above. In case of
joeverbout 0:ea44dc9ed014 1953 multiple 1D transforms (when using the DFT_ROWS flag), each row of the output matrix
joeverbout 0:ea44dc9ed014 1954 looks like the first row of the matrix above.
joeverbout 0:ea44dc9ed014 1955 - If the input array is complex and either DFT_INVERSE or DFT_REAL_OUTPUT are not set, the
joeverbout 0:ea44dc9ed014 1956 output is a complex array of the same size as input. The function performs a forward or
joeverbout 0:ea44dc9ed014 1957 inverse 1D or 2D transform of the whole input array or each row of the input array
joeverbout 0:ea44dc9ed014 1958 independently, depending on the flags DFT_INVERSE and DFT_ROWS.
joeverbout 0:ea44dc9ed014 1959 - When DFT_INVERSE is set and the input array is real, or it is complex but DFT_REAL_OUTPUT
joeverbout 0:ea44dc9ed014 1960 is set, the output is a real array of the same size as input. The function performs a 1D or 2D
joeverbout 0:ea44dc9ed014 1961 inverse transformation of the whole input array or each individual row, depending on the flags
joeverbout 0:ea44dc9ed014 1962 DFT_INVERSE and DFT_ROWS.
joeverbout 0:ea44dc9ed014 1963
joeverbout 0:ea44dc9ed014 1964 If DFT_SCALE is set, the scaling is done after the transformation.
joeverbout 0:ea44dc9ed014 1965
joeverbout 0:ea44dc9ed014 1966 Unlike dct , the function supports arrays of arbitrary size. But only those arrays are processed
joeverbout 0:ea44dc9ed014 1967 efficiently, whose sizes can be factorized in a product of small prime numbers (2, 3, and 5 in the
joeverbout 0:ea44dc9ed014 1968 current implementation). Such an efficient DFT size can be calculated using the getOptimalDFTSize
joeverbout 0:ea44dc9ed014 1969 method.
joeverbout 0:ea44dc9ed014 1970
joeverbout 0:ea44dc9ed014 1971 The sample below illustrates how to calculate a DFT-based convolution of two 2D real arrays:
joeverbout 0:ea44dc9ed014 1972 @code
joeverbout 0:ea44dc9ed014 1973 void convolveDFT(InputArray A, InputArray B, OutputArray C)
joeverbout 0:ea44dc9ed014 1974 {
joeverbout 0:ea44dc9ed014 1975 // reallocate the output array if needed
joeverbout 0:ea44dc9ed014 1976 C.create(abs(A.rows - B.rows)+1, abs(A.cols - B.cols)+1, A.type());
joeverbout 0:ea44dc9ed014 1977 Size dftSize;
joeverbout 0:ea44dc9ed014 1978 // calculate the size of DFT transform
joeverbout 0:ea44dc9ed014 1979 dftSize.width = getOptimalDFTSize(A.cols + B.cols - 1);
joeverbout 0:ea44dc9ed014 1980 dftSize.height = getOptimalDFTSize(A.rows + B.rows - 1);
joeverbout 0:ea44dc9ed014 1981
joeverbout 0:ea44dc9ed014 1982 // allocate temporary buffers and initialize them with 0's
joeverbout 0:ea44dc9ed014 1983 Mat tempA(dftSize, A.type(), Scalar::all(0));
joeverbout 0:ea44dc9ed014 1984 Mat tempB(dftSize, B.type(), Scalar::all(0));
joeverbout 0:ea44dc9ed014 1985
joeverbout 0:ea44dc9ed014 1986 // copy A and B to the top-left corners of tempA and tempB, respectively
joeverbout 0:ea44dc9ed014 1987 Mat roiA(tempA, Rect(0,0,A.cols,A.rows));
joeverbout 0:ea44dc9ed014 1988 A.copyTo(roiA);
joeverbout 0:ea44dc9ed014 1989 Mat roiB(tempB, Rect(0,0,B.cols,B.rows));
joeverbout 0:ea44dc9ed014 1990 B.copyTo(roiB);
joeverbout 0:ea44dc9ed014 1991
joeverbout 0:ea44dc9ed014 1992 // now transform the padded A & B in-place;
joeverbout 0:ea44dc9ed014 1993 // use "nonzeroRows" hint for faster processing
joeverbout 0:ea44dc9ed014 1994 dft(tempA, tempA, 0, A.rows);
joeverbout 0:ea44dc9ed014 1995 dft(tempB, tempB, 0, B.rows);
joeverbout 0:ea44dc9ed014 1996
joeverbout 0:ea44dc9ed014 1997 // multiply the spectrums;
joeverbout 0:ea44dc9ed014 1998 // the function handles packed spectrum representations well
joeverbout 0:ea44dc9ed014 1999 mulSpectrums(tempA, tempB, tempA);
joeverbout 0:ea44dc9ed014 2000
joeverbout 0:ea44dc9ed014 2001 // transform the product back from the frequency domain.
joeverbout 0:ea44dc9ed014 2002 // Even though all the result rows will be non-zero,
joeverbout 0:ea44dc9ed014 2003 // you need only the first C.rows of them, and thus you
joeverbout 0:ea44dc9ed014 2004 // pass nonzeroRows == C.rows
joeverbout 0:ea44dc9ed014 2005 dft(tempA, tempA, DFT_INVERSE + DFT_SCALE, C.rows);
joeverbout 0:ea44dc9ed014 2006
joeverbout 0:ea44dc9ed014 2007 // now copy the result back to C.
joeverbout 0:ea44dc9ed014 2008 tempA(Rect(0, 0, C.cols, C.rows)).copyTo(C);
joeverbout 0:ea44dc9ed014 2009
joeverbout 0:ea44dc9ed014 2010 // all the temporary buffers will be deallocated automatically
joeverbout 0:ea44dc9ed014 2011 }
joeverbout 0:ea44dc9ed014 2012 @endcode
joeverbout 0:ea44dc9ed014 2013 To optimize this sample, consider the following approaches:
joeverbout 0:ea44dc9ed014 2014 - Since nonzeroRows != 0 is passed to the forward transform calls and since A and B are copied to
joeverbout 0:ea44dc9ed014 2015 the top-left corners of tempA and tempB, respectively, it is not necessary to clear the whole
joeverbout 0:ea44dc9ed014 2016 tempA and tempB. It is only necessary to clear the tempA.cols - A.cols ( tempB.cols - B.cols)
joeverbout 0:ea44dc9ed014 2017 rightmost columns of the matrices.
joeverbout 0:ea44dc9ed014 2018 - This DFT-based convolution does not have to be applied to the whole big arrays, especially if B
joeverbout 0:ea44dc9ed014 2019 is significantly smaller than A or vice versa. Instead, you can calculate convolution by parts.
joeverbout 0:ea44dc9ed014 2020 To do this, you need to split the output array C into multiple tiles. For each tile, estimate
joeverbout 0:ea44dc9ed014 2021 which parts of A and B are required to calculate convolution in this tile. If the tiles in C are
joeverbout 0:ea44dc9ed014 2022 too small, the speed will decrease a lot because of repeated work. In the ultimate case, when
joeverbout 0:ea44dc9ed014 2023 each tile in C is a single pixel, the algorithm becomes equivalent to the naive convolution
joeverbout 0:ea44dc9ed014 2024 algorithm. If the tiles are too big, the temporary arrays tempA and tempB become too big and
joeverbout 0:ea44dc9ed014 2025 there is also a slowdown because of bad cache locality. So, there is an optimal tile size
joeverbout 0:ea44dc9ed014 2026 somewhere in the middle.
joeverbout 0:ea44dc9ed014 2027 - If different tiles in C can be calculated in parallel and, thus, the convolution is done by
joeverbout 0:ea44dc9ed014 2028 parts, the loop can be threaded.
joeverbout 0:ea44dc9ed014 2029
joeverbout 0:ea44dc9ed014 2030 All of the above improvements have been implemented in matchTemplate and filter2D . Therefore, by
joeverbout 0:ea44dc9ed014 2031 using them, you can get the performance even better than with the above theoretically optimal
joeverbout 0:ea44dc9ed014 2032 implementation. Though, those two functions actually calculate cross-correlation, not convolution,
joeverbout 0:ea44dc9ed014 2033 so you need to "flip" the second convolution operand B vertically and horizontally using flip .
joeverbout 0:ea44dc9ed014 2034 @note
joeverbout 0:ea44dc9ed014 2035 - An example using the discrete fourier transform can be found at
joeverbout 0:ea44dc9ed014 2036 opencv_source_code/samples/cpp/dft.cpp
joeverbout 0:ea44dc9ed014 2037 - (Python) An example using the dft functionality to perform Wiener deconvolution can be found
joeverbout 0:ea44dc9ed014 2038 at opencv_source/samples/python/deconvolution.py
joeverbout 0:ea44dc9ed014 2039 - (Python) An example rearranging the quadrants of a Fourier image can be found at
joeverbout 0:ea44dc9ed014 2040 opencv_source/samples/python/dft.py
joeverbout 0:ea44dc9ed014 2041 @param src input array that could be real or complex.
joeverbout 0:ea44dc9ed014 2042 @param dst output array whose size and type depends on the flags .
joeverbout 0:ea44dc9ed014 2043 @param flags transformation flags, representing a combination of the cv::DftFlags
joeverbout 0:ea44dc9ed014 2044 @param nonzeroRows when the parameter is not zero, the function assumes that only the first
joeverbout 0:ea44dc9ed014 2045 nonzeroRows rows of the input array (DFT_INVERSE is not set) or only the first nonzeroRows of the
joeverbout 0:ea44dc9ed014 2046 output array (DFT_INVERSE is set) contain non-zeros, thus, the function can handle the rest of the
joeverbout 0:ea44dc9ed014 2047 rows more efficiently and save some time; this technique is very useful for calculating array
joeverbout 0:ea44dc9ed014 2048 cross-correlation or convolution using DFT.
joeverbout 0:ea44dc9ed014 2049 @sa dct , getOptimalDFTSize , mulSpectrums, filter2D , matchTemplate , flip , cartToPolar ,
joeverbout 0:ea44dc9ed014 2050 magnitude , phase
joeverbout 0:ea44dc9ed014 2051 */
joeverbout 0:ea44dc9ed014 2052 CV_EXPORTS_W void dft(InputArray src, OutputArray dst, int flags = 0, int nonzeroRows = 0);
joeverbout 0:ea44dc9ed014 2053
joeverbout 0:ea44dc9ed014 2054 /** @brief Calculates the inverse Discrete Fourier Transform of a 1D or 2D array.
joeverbout 0:ea44dc9ed014 2055
joeverbout 0:ea44dc9ed014 2056 idft(src, dst, flags) is equivalent to dft(src, dst, flags | DFT_INVERSE) .
joeverbout 0:ea44dc9ed014 2057 @note None of dft and idft scales the result by default. So, you should pass DFT_SCALE to one of
joeverbout 0:ea44dc9ed014 2058 dft or idft explicitly to make these transforms mutually inverse.
joeverbout 0:ea44dc9ed014 2059 @sa dft, dct, idct, mulSpectrums, getOptimalDFTSize
joeverbout 0:ea44dc9ed014 2060 @param src input floating-point real or complex array.
joeverbout 0:ea44dc9ed014 2061 @param dst output array whose size and type depend on the flags.
joeverbout 0:ea44dc9ed014 2062 @param flags operation flags (see dft and cv::DftFlags).
joeverbout 0:ea44dc9ed014 2063 @param nonzeroRows number of dst rows to process; the rest of the rows have undefined content (see
joeverbout 0:ea44dc9ed014 2064 the convolution sample in dft description.
joeverbout 0:ea44dc9ed014 2065 */
joeverbout 0:ea44dc9ed014 2066 CV_EXPORTS_W void idft(InputArray src, OutputArray dst, int flags = 0, int nonzeroRows = 0);
joeverbout 0:ea44dc9ed014 2067
joeverbout 0:ea44dc9ed014 2068 /** @brief Performs a forward or inverse discrete Cosine transform of 1D or 2D array.
joeverbout 0:ea44dc9ed014 2069
joeverbout 0:ea44dc9ed014 2070 The function dct performs a forward or inverse discrete Cosine transform (DCT) of a 1D or 2D
joeverbout 0:ea44dc9ed014 2071 floating-point array:
joeverbout 0:ea44dc9ed014 2072 - Forward Cosine transform of a 1D vector of N elements:
joeverbout 0:ea44dc9ed014 2073 \f[Y = C^{(N)} \cdot X\f]
joeverbout 0:ea44dc9ed014 2074 where
joeverbout 0:ea44dc9ed014 2075 \f[C^{(N)}_{jk}= \sqrt{\alpha_j/N} \cos \left ( \frac{\pi(2k+1)j}{2N} \right )\f]
joeverbout 0:ea44dc9ed014 2076 and
joeverbout 0:ea44dc9ed014 2077 \f$\alpha_0=1\f$, \f$\alpha_j=2\f$ for *j \> 0*.
joeverbout 0:ea44dc9ed014 2078 - Inverse Cosine transform of a 1D vector of N elements:
joeverbout 0:ea44dc9ed014 2079 \f[X = \left (C^{(N)} \right )^{-1} \cdot Y = \left (C^{(N)} \right )^T \cdot Y\f]
joeverbout 0:ea44dc9ed014 2080 (since \f$C^{(N)}\f$ is an orthogonal matrix, \f$C^{(N)} \cdot \left(C^{(N)}\right)^T = I\f$ )
joeverbout 0:ea44dc9ed014 2081 - Forward 2D Cosine transform of M x N matrix:
joeverbout 0:ea44dc9ed014 2082 \f[Y = C^{(N)} \cdot X \cdot \left (C^{(N)} \right )^T\f]
joeverbout 0:ea44dc9ed014 2083 - Inverse 2D Cosine transform of M x N matrix:
joeverbout 0:ea44dc9ed014 2084 \f[X = \left (C^{(N)} \right )^T \cdot X \cdot C^{(N)}\f]
joeverbout 0:ea44dc9ed014 2085
joeverbout 0:ea44dc9ed014 2086 The function chooses the mode of operation by looking at the flags and size of the input array:
joeverbout 0:ea44dc9ed014 2087 - If (flags & DCT_INVERSE) == 0 , the function does a forward 1D or 2D transform. Otherwise, it
joeverbout 0:ea44dc9ed014 2088 is an inverse 1D or 2D transform.
joeverbout 0:ea44dc9ed014 2089 - If (flags & DCT_ROWS) != 0 , the function performs a 1D transform of each row.
joeverbout 0:ea44dc9ed014 2090 - If the array is a single column or a single row, the function performs a 1D transform.
joeverbout 0:ea44dc9ed014 2091 - If none of the above is true, the function performs a 2D transform.
joeverbout 0:ea44dc9ed014 2092
joeverbout 0:ea44dc9ed014 2093 @note Currently dct supports even-size arrays (2, 4, 6 ...). For data analysis and approximation, you
joeverbout 0:ea44dc9ed014 2094 can pad the array when necessary.
joeverbout 0:ea44dc9ed014 2095 Also, the function performance depends very much, and not monotonically, on the array size (see
joeverbout 0:ea44dc9ed014 2096 getOptimalDFTSize ). In the current implementation DCT of a vector of size N is calculated via DFT
joeverbout 0:ea44dc9ed014 2097 of a vector of size N/2 . Thus, the optimal DCT size N1 \>= N can be calculated as:
joeverbout 0:ea44dc9ed014 2098 @code
joeverbout 0:ea44dc9ed014 2099 size_t getOptimalDCTSize(size_t N) { return 2*getOptimalDFTSize((N+1)/2); }
joeverbout 0:ea44dc9ed014 2100 N1 = getOptimalDCTSize(N);
joeverbout 0:ea44dc9ed014 2101 @endcode
joeverbout 0:ea44dc9ed014 2102 @param src input floating-point array.
joeverbout 0:ea44dc9ed014 2103 @param dst output array of the same size and type as src .
joeverbout 0:ea44dc9ed014 2104 @param flags transformation flags as a combination of cv::DftFlags (DCT_*)
joeverbout 0:ea44dc9ed014 2105 @sa dft , getOptimalDFTSize , idct
joeverbout 0:ea44dc9ed014 2106 */
joeverbout 0:ea44dc9ed014 2107 CV_EXPORTS_W void dct(InputArray src, OutputArray dst, int flags = 0);
joeverbout 0:ea44dc9ed014 2108
joeverbout 0:ea44dc9ed014 2109 /** @brief Calculates the inverse Discrete Cosine Transform of a 1D or 2D array.
joeverbout 0:ea44dc9ed014 2110
joeverbout 0:ea44dc9ed014 2111 idct(src, dst, flags) is equivalent to dct(src, dst, flags | DCT_INVERSE).
joeverbout 0:ea44dc9ed014 2112 @param src input floating-point single-channel array.
joeverbout 0:ea44dc9ed014 2113 @param dst output array of the same size and type as src.
joeverbout 0:ea44dc9ed014 2114 @param flags operation flags.
joeverbout 0:ea44dc9ed014 2115 @sa dct, dft, idft, getOptimalDFTSize
joeverbout 0:ea44dc9ed014 2116 */
joeverbout 0:ea44dc9ed014 2117 CV_EXPORTS_W void idct(InputArray src, OutputArray dst, int flags = 0);
joeverbout 0:ea44dc9ed014 2118
joeverbout 0:ea44dc9ed014 2119 /** @brief Performs the per-element multiplication of two Fourier spectrums.
joeverbout 0:ea44dc9ed014 2120
joeverbout 0:ea44dc9ed014 2121 The function mulSpectrums performs the per-element multiplication of the two CCS-packed or complex
joeverbout 0:ea44dc9ed014 2122 matrices that are results of a real or complex Fourier transform.
joeverbout 0:ea44dc9ed014 2123
joeverbout 0:ea44dc9ed014 2124 The function, together with dft and idft , may be used to calculate convolution (pass conjB=false )
joeverbout 0:ea44dc9ed014 2125 or correlation (pass conjB=true ) of two arrays rapidly. When the arrays are complex, they are
joeverbout 0:ea44dc9ed014 2126 simply multiplied (per element) with an optional conjugation of the second-array elements. When the
joeverbout 0:ea44dc9ed014 2127 arrays are real, they are assumed to be CCS-packed (see dft for details).
joeverbout 0:ea44dc9ed014 2128 @param a first input array.
joeverbout 0:ea44dc9ed014 2129 @param b second input array of the same size and type as src1 .
joeverbout 0:ea44dc9ed014 2130 @param c output array of the same size and type as src1 .
joeverbout 0:ea44dc9ed014 2131 @param flags operation flags; currently, the only supported flag is cv::DFT_ROWS, which indicates that
joeverbout 0:ea44dc9ed014 2132 each 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.
joeverbout 0:ea44dc9ed014 2133 @param conjB optional flag that conjugates the second input array before the multiplication (true)
joeverbout 0:ea44dc9ed014 2134 or not (false).
joeverbout 0:ea44dc9ed014 2135 */
joeverbout 0:ea44dc9ed014 2136 CV_EXPORTS_W void mulSpectrums(InputArray a, InputArray b, OutputArray c,
joeverbout 0:ea44dc9ed014 2137 int flags, bool conjB = false);
joeverbout 0:ea44dc9ed014 2138
joeverbout 0:ea44dc9ed014 2139 /** @brief Returns the optimal DFT size for a given vector size.
joeverbout 0:ea44dc9ed014 2140
joeverbout 0:ea44dc9ed014 2141 DFT performance is not a monotonic function of a vector size. Therefore, when you calculate
joeverbout 0:ea44dc9ed014 2142 convolution of two arrays or perform the spectral analysis of an array, it usually makes sense to
joeverbout 0:ea44dc9ed014 2143 pad the input data with zeros to get a bit larger array that can be transformed much faster than the
joeverbout 0:ea44dc9ed014 2144 original one. Arrays whose size is a power-of-two (2, 4, 8, 16, 32, ...) are the fastest to process.
joeverbout 0:ea44dc9ed014 2145 Though, the arrays whose size is a product of 2's, 3's, and 5's (for example, 300 = 5\*5\*3\*2\*2)
joeverbout 0:ea44dc9ed014 2146 are also processed quite efficiently.
joeverbout 0:ea44dc9ed014 2147
joeverbout 0:ea44dc9ed014 2148 The function getOptimalDFTSize returns the minimum number N that is greater than or equal to vecsize
joeverbout 0:ea44dc9ed014 2149 so that the DFT of a vector of size N can be processed efficiently. In the current implementation N
joeverbout 0:ea44dc9ed014 2150 = 2 ^p^ \* 3 ^q^ \* 5 ^r^ for some integer p, q, r.
joeverbout 0:ea44dc9ed014 2151
joeverbout 0:ea44dc9ed014 2152 The function returns a negative number if vecsize is too large (very close to INT_MAX ).
joeverbout 0:ea44dc9ed014 2153
joeverbout 0:ea44dc9ed014 2154 While the function cannot be used directly to estimate the optimal vector size for DCT transform
joeverbout 0:ea44dc9ed014 2155 (since the current DCT implementation supports only even-size vectors), it can be easily processed
joeverbout 0:ea44dc9ed014 2156 as getOptimalDFTSize((vecsize+1)/2)\*2.
joeverbout 0:ea44dc9ed014 2157 @param vecsize vector size.
joeverbout 0:ea44dc9ed014 2158 @sa dft , dct , idft , idct , mulSpectrums
joeverbout 0:ea44dc9ed014 2159 */
joeverbout 0:ea44dc9ed014 2160 CV_EXPORTS_W int getOptimalDFTSize(int vecsize);
joeverbout 0:ea44dc9ed014 2161
joeverbout 0:ea44dc9ed014 2162 /** @brief Returns the default random number generator.
joeverbout 0:ea44dc9ed014 2163
joeverbout 0:ea44dc9ed014 2164 The function theRNG returns the default random number generator. For each thread, there is a
joeverbout 0:ea44dc9ed014 2165 separate random number generator, so you can use the function safely in multi-thread environments.
joeverbout 0:ea44dc9ed014 2166 If you just need to get a single random number using this generator or initialize an array, you can
joeverbout 0:ea44dc9ed014 2167 use randu or randn instead. But if you are going to generate many random numbers inside a loop, it
joeverbout 0:ea44dc9ed014 2168 is much faster to use this function to retrieve the generator and then use RNG::operator _Tp() .
joeverbout 0:ea44dc9ed014 2169 @sa RNG, randu, randn
joeverbout 0:ea44dc9ed014 2170 */
joeverbout 0:ea44dc9ed014 2171 CV_EXPORTS RNG& theRNG();
joeverbout 0:ea44dc9ed014 2172
joeverbout 0:ea44dc9ed014 2173 /** @brief Generates a single uniformly-distributed random number or an array of random numbers.
joeverbout 0:ea44dc9ed014 2174
joeverbout 0:ea44dc9ed014 2175 Non-template variant of the function fills the matrix dst with uniformly-distributed
joeverbout 0:ea44dc9ed014 2176 random numbers from the specified range:
joeverbout 0:ea44dc9ed014 2177 \f[\texttt{low} _c \leq \texttt{dst} (I)_c < \texttt{high} _c\f]
joeverbout 0:ea44dc9ed014 2178 @param dst output array of random numbers; the array must be pre-allocated.
joeverbout 0:ea44dc9ed014 2179 @param low inclusive lower boundary of the generated random numbers.
joeverbout 0:ea44dc9ed014 2180 @param high exclusive upper boundary of the generated random numbers.
joeverbout 0:ea44dc9ed014 2181 @sa RNG, randn, theRNG
joeverbout 0:ea44dc9ed014 2182 */
joeverbout 0:ea44dc9ed014 2183 CV_EXPORTS_W void randu(InputOutputArray dst, InputArray low, InputArray high);
joeverbout 0:ea44dc9ed014 2184
joeverbout 0:ea44dc9ed014 2185 /** @brief Fills the array with normally distributed random numbers.
joeverbout 0:ea44dc9ed014 2186
joeverbout 0:ea44dc9ed014 2187 The function randn fills the matrix dst with normally distributed random numbers with the specified
joeverbout 0:ea44dc9ed014 2188 mean vector and the standard deviation matrix. The generated random numbers are clipped to fit the
joeverbout 0:ea44dc9ed014 2189 value range of the output array data type.
joeverbout 0:ea44dc9ed014 2190 @param dst output array of random numbers; the array must be pre-allocated and have 1 to 4 channels.
joeverbout 0:ea44dc9ed014 2191 @param mean mean value (expectation) of the generated random numbers.
joeverbout 0:ea44dc9ed014 2192 @param stddev standard deviation of the generated random numbers; it can be either a vector (in
joeverbout 0:ea44dc9ed014 2193 which case a diagonal standard deviation matrix is assumed) or a square matrix.
joeverbout 0:ea44dc9ed014 2194 @sa RNG, randu
joeverbout 0:ea44dc9ed014 2195 */
joeverbout 0:ea44dc9ed014 2196 CV_EXPORTS_W void randn(InputOutputArray dst, InputArray mean, InputArray stddev);
joeverbout 0:ea44dc9ed014 2197
joeverbout 0:ea44dc9ed014 2198 /** @brief Shuffles the array elements randomly.
joeverbout 0:ea44dc9ed014 2199
joeverbout 0:ea44dc9ed014 2200 The function randShuffle shuffles the specified 1D array by randomly choosing pairs of elements and
joeverbout 0:ea44dc9ed014 2201 swapping them. The number of such swap operations will be dst.rows\*dst.cols\*iterFactor .
joeverbout 0:ea44dc9ed014 2202 @param dst input/output numerical 1D array.
joeverbout 0:ea44dc9ed014 2203 @param iterFactor scale factor that determines the number of random swap operations (see the details
joeverbout 0:ea44dc9ed014 2204 below).
joeverbout 0:ea44dc9ed014 2205 @param rng optional random number generator used for shuffling; if it is zero, theRNG () is used
joeverbout 0:ea44dc9ed014 2206 instead.
joeverbout 0:ea44dc9ed014 2207 @sa RNG, sort
joeverbout 0:ea44dc9ed014 2208 */
joeverbout 0:ea44dc9ed014 2209 CV_EXPORTS_W void randShuffle(InputOutputArray dst, double iterFactor = 1., RNG* rng = 0);
joeverbout 0:ea44dc9ed014 2210
joeverbout 0:ea44dc9ed014 2211 /** @brief Principal Component Analysis
joeverbout 0:ea44dc9ed014 2212
joeverbout 0:ea44dc9ed014 2213 The class is used to calculate a special basis for a set of vectors. The
joeverbout 0:ea44dc9ed014 2214 basis will consist of eigenvectors of the covariance matrix calculated
joeverbout 0:ea44dc9ed014 2215 from the input set of vectors. The class %PCA can also transform
joeverbout 0:ea44dc9ed014 2216 vectors to/from the new coordinate space defined by the basis. Usually,
joeverbout 0:ea44dc9ed014 2217 in this new coordinate system, each vector from the original set (and
joeverbout 0:ea44dc9ed014 2218 any linear combination of such vectors) can be quite accurately
joeverbout 0:ea44dc9ed014 2219 approximated by taking its first few components, corresponding to the
joeverbout 0:ea44dc9ed014 2220 eigenvectors of the largest eigenvalues of the covariance matrix.
joeverbout 0:ea44dc9ed014 2221 Geometrically it means that you calculate a projection of the vector to
joeverbout 0:ea44dc9ed014 2222 a subspace formed by a few eigenvectors corresponding to the dominant
joeverbout 0:ea44dc9ed014 2223 eigenvalues of the covariance matrix. And usually such a projection is
joeverbout 0:ea44dc9ed014 2224 very close to the original vector. So, you can represent the original
joeverbout 0:ea44dc9ed014 2225 vector from a high-dimensional space with a much shorter vector
joeverbout 0:ea44dc9ed014 2226 consisting of the projected vector's coordinates in the subspace. Such a
joeverbout 0:ea44dc9ed014 2227 transformation is also known as Karhunen-Loeve Transform, or KLT.
joeverbout 0:ea44dc9ed014 2228 See http://en.wikipedia.org/wiki/Principal_component_analysis
joeverbout 0:ea44dc9ed014 2229
joeverbout 0:ea44dc9ed014 2230 The sample below is the function that takes two matrices. The first
joeverbout 0:ea44dc9ed014 2231 function stores a set of vectors (a row per vector) that is used to
joeverbout 0:ea44dc9ed014 2232 calculate PCA. The second function stores another "test" set of vectors
joeverbout 0:ea44dc9ed014 2233 (a row per vector). First, these vectors are compressed with PCA, then
joeverbout 0:ea44dc9ed014 2234 reconstructed back, and then the reconstruction error norm is computed
joeverbout 0:ea44dc9ed014 2235 and printed for each vector. :
joeverbout 0:ea44dc9ed014 2236
joeverbout 0:ea44dc9ed014 2237 @code{.cpp}
joeverbout 0:ea44dc9ed014 2238 using namespace cv;
joeverbout 0:ea44dc9ed014 2239
joeverbout 0:ea44dc9ed014 2240 PCA compressPCA(const Mat& pcaset, int maxComponents,
joeverbout 0:ea44dc9ed014 2241 const Mat& testset, Mat& compressed)
joeverbout 0:ea44dc9ed014 2242 {
joeverbout 0:ea44dc9ed014 2243 PCA pca(pcaset, // pass the data
joeverbout 0:ea44dc9ed014 2244 Mat(), // we do not have a pre-computed mean vector,
joeverbout 0:ea44dc9ed014 2245 // so let the PCA engine to compute it
joeverbout 0:ea44dc9ed014 2246 PCA::DATA_AS_ROW, // indicate that the vectors
joeverbout 0:ea44dc9ed014 2247 // are stored as matrix rows
joeverbout 0:ea44dc9ed014 2248 // (use PCA::DATA_AS_COL if the vectors are
joeverbout 0:ea44dc9ed014 2249 // the matrix columns)
joeverbout 0:ea44dc9ed014 2250 maxComponents // specify, how many principal components to retain
joeverbout 0:ea44dc9ed014 2251 );
joeverbout 0:ea44dc9ed014 2252 // if there is no test data, just return the computed basis, ready-to-use
joeverbout 0:ea44dc9ed014 2253 if( !testset.data )
joeverbout 0:ea44dc9ed014 2254 return pca;
joeverbout 0:ea44dc9ed014 2255 CV_Assert( testset.cols == pcaset.cols );
joeverbout 0:ea44dc9ed014 2256
joeverbout 0:ea44dc9ed014 2257 compressed.create(testset.rows, maxComponents, testset.type());
joeverbout 0:ea44dc9ed014 2258
joeverbout 0:ea44dc9ed014 2259 Mat reconstructed;
joeverbout 0:ea44dc9ed014 2260 for( int i = 0; i < testset.rows; i++ )
joeverbout 0:ea44dc9ed014 2261 {
joeverbout 0:ea44dc9ed014 2262 Mat vec = testset.row(i), coeffs = compressed.row(i), reconstructed;
joeverbout 0:ea44dc9ed014 2263 // compress the vector, the result will be stored
joeverbout 0:ea44dc9ed014 2264 // in the i-th row of the output matrix
joeverbout 0:ea44dc9ed014 2265 pca.project(vec, coeffs);
joeverbout 0:ea44dc9ed014 2266 // and then reconstruct it
joeverbout 0:ea44dc9ed014 2267 pca.backProject(coeffs, reconstructed);
joeverbout 0:ea44dc9ed014 2268 // and measure the error
joeverbout 0:ea44dc9ed014 2269 printf("%d. diff = %g\n", i, norm(vec, reconstructed, NORM_L2));
joeverbout 0:ea44dc9ed014 2270 }
joeverbout 0:ea44dc9ed014 2271 return pca;
joeverbout 0:ea44dc9ed014 2272 }
joeverbout 0:ea44dc9ed014 2273 @endcode
joeverbout 0:ea44dc9ed014 2274 @sa calcCovarMatrix, mulTransposed, SVD, dft, dct
joeverbout 0:ea44dc9ed014 2275 */
joeverbout 0:ea44dc9ed014 2276 class CV_EXPORTS PCA
joeverbout 0:ea44dc9ed014 2277 {
joeverbout 0:ea44dc9ed014 2278 public:
joeverbout 0:ea44dc9ed014 2279 enum Flags { DATA_AS_ROW = 0, //!< indicates that the input samples are stored as matrix rows
joeverbout 0:ea44dc9ed014 2280 DATA_AS_COL = 1, //!< indicates that the input samples are stored as matrix columns
joeverbout 0:ea44dc9ed014 2281 USE_AVG = 2 //!
joeverbout 0:ea44dc9ed014 2282 };
joeverbout 0:ea44dc9ed014 2283
joeverbout 0:ea44dc9ed014 2284 /** @brief default constructor
joeverbout 0:ea44dc9ed014 2285
joeverbout 0:ea44dc9ed014 2286 The default constructor initializes an empty %PCA structure. The other
joeverbout 0:ea44dc9ed014 2287 constructors initialize the structure and call PCA::operator()().
joeverbout 0:ea44dc9ed014 2288 */
joeverbout 0:ea44dc9ed014 2289 PCA();
joeverbout 0:ea44dc9ed014 2290
joeverbout 0:ea44dc9ed014 2291 /** @overload
joeverbout 0:ea44dc9ed014 2292 @param data input samples stored as matrix rows or matrix columns.
joeverbout 0:ea44dc9ed014 2293 @param mean optional mean value; if the matrix is empty (@c noArray()),
joeverbout 0:ea44dc9ed014 2294 the mean is computed from the data.
joeverbout 0:ea44dc9ed014 2295 @param flags operation flags; currently the parameter is only used to
joeverbout 0:ea44dc9ed014 2296 specify the data layout (PCA::Flags)
joeverbout 0:ea44dc9ed014 2297 @param maxComponents maximum number of components that %PCA should
joeverbout 0:ea44dc9ed014 2298 retain; by default, all the components are retained.
joeverbout 0:ea44dc9ed014 2299 */
joeverbout 0:ea44dc9ed014 2300 PCA(InputArray data, InputArray mean, int flags, int maxComponents = 0);
joeverbout 0:ea44dc9ed014 2301
joeverbout 0:ea44dc9ed014 2302 /** @overload
joeverbout 0:ea44dc9ed014 2303 @param data input samples stored as matrix rows or matrix columns.
joeverbout 0:ea44dc9ed014 2304 @param mean optional mean value; if the matrix is empty (noArray()),
joeverbout 0:ea44dc9ed014 2305 the mean is computed from the data.
joeverbout 0:ea44dc9ed014 2306 @param flags operation flags; currently the parameter is only used to
joeverbout 0:ea44dc9ed014 2307 specify the data layout (PCA::Flags)
joeverbout 0:ea44dc9ed014 2308 @param retainedVariance Percentage of variance that PCA should retain.
joeverbout 0:ea44dc9ed014 2309 Using this parameter will let the PCA decided how many components to
joeverbout 0:ea44dc9ed014 2310 retain but it will always keep at least 2.
joeverbout 0:ea44dc9ed014 2311 */
joeverbout 0:ea44dc9ed014 2312 PCA(InputArray data, InputArray mean, int flags, double retainedVariance);
joeverbout 0:ea44dc9ed014 2313
joeverbout 0:ea44dc9ed014 2314 /** @brief performs %PCA
joeverbout 0:ea44dc9ed014 2315
joeverbout 0:ea44dc9ed014 2316 The operator performs %PCA of the supplied dataset. It is safe to reuse
joeverbout 0:ea44dc9ed014 2317 the same PCA structure for multiple datasets. That is, if the structure
joeverbout 0:ea44dc9ed014 2318 has been previously used with another dataset, the existing internal
joeverbout 0:ea44dc9ed014 2319 data is reclaimed and the new eigenvalues, @ref eigenvectors , and @ref
joeverbout 0:ea44dc9ed014 2320 mean are allocated and computed.
joeverbout 0:ea44dc9ed014 2321
joeverbout 0:ea44dc9ed014 2322 The computed eigenvalues are sorted from the largest to the smallest and
joeverbout 0:ea44dc9ed014 2323 the corresponding eigenvectors are stored as eigenvectors rows.
joeverbout 0:ea44dc9ed014 2324
joeverbout 0:ea44dc9ed014 2325 @param data input samples stored as the matrix rows or as the matrix
joeverbout 0:ea44dc9ed014 2326 columns.
joeverbout 0:ea44dc9ed014 2327 @param mean optional mean value; if the matrix is empty (noArray()),
joeverbout 0:ea44dc9ed014 2328 the mean is computed from the data.
joeverbout 0:ea44dc9ed014 2329 @param flags operation flags; currently the parameter is only used to
joeverbout 0:ea44dc9ed014 2330 specify the data layout. (Flags)
joeverbout 0:ea44dc9ed014 2331 @param maxComponents maximum number of components that PCA should
joeverbout 0:ea44dc9ed014 2332 retain; by default, all the components are retained.
joeverbout 0:ea44dc9ed014 2333 */
joeverbout 0:ea44dc9ed014 2334 PCA& operator()(InputArray data, InputArray mean, int flags, int maxComponents = 0);
joeverbout 0:ea44dc9ed014 2335
joeverbout 0:ea44dc9ed014 2336 /** @overload
joeverbout 0:ea44dc9ed014 2337 @param data input samples stored as the matrix rows or as the matrix
joeverbout 0:ea44dc9ed014 2338 columns.
joeverbout 0:ea44dc9ed014 2339 @param mean optional mean value; if the matrix is empty (noArray()),
joeverbout 0:ea44dc9ed014 2340 the mean is computed from the data.
joeverbout 0:ea44dc9ed014 2341 @param flags operation flags; currently the parameter is only used to
joeverbout 0:ea44dc9ed014 2342 specify the data layout. (PCA::Flags)
joeverbout 0:ea44dc9ed014 2343 @param retainedVariance Percentage of variance that %PCA should retain.
joeverbout 0:ea44dc9ed014 2344 Using this parameter will let the %PCA decided how many components to
joeverbout 0:ea44dc9ed014 2345 retain but it will always keep at least 2.
joeverbout 0:ea44dc9ed014 2346 */
joeverbout 0:ea44dc9ed014 2347 PCA& operator()(InputArray data, InputArray mean, int flags, double retainedVariance);
joeverbout 0:ea44dc9ed014 2348
joeverbout 0:ea44dc9ed014 2349 /** @brief Projects vector(s) to the principal component subspace.
joeverbout 0:ea44dc9ed014 2350
joeverbout 0:ea44dc9ed014 2351 The methods project one or more vectors to the principal component
joeverbout 0:ea44dc9ed014 2352 subspace, where each vector projection is represented by coefficients in
joeverbout 0:ea44dc9ed014 2353 the principal component basis. The first form of the method returns the
joeverbout 0:ea44dc9ed014 2354 matrix that the second form writes to the result. So the first form can
joeverbout 0:ea44dc9ed014 2355 be used as a part of expression while the second form can be more
joeverbout 0:ea44dc9ed014 2356 efficient in a processing loop.
joeverbout 0:ea44dc9ed014 2357 @param vec input vector(s); must have the same dimensionality and the
joeverbout 0:ea44dc9ed014 2358 same layout as the input data used at %PCA phase, that is, if
joeverbout 0:ea44dc9ed014 2359 DATA_AS_ROW are specified, then `vec.cols==data.cols`
joeverbout 0:ea44dc9ed014 2360 (vector dimensionality) and `vec.rows` is the number of vectors to
joeverbout 0:ea44dc9ed014 2361 project, and the same is true for the PCA::DATA_AS_COL case.
joeverbout 0:ea44dc9ed014 2362 */
joeverbout 0:ea44dc9ed014 2363 Mat project(InputArray vec) const;
joeverbout 0:ea44dc9ed014 2364
joeverbout 0:ea44dc9ed014 2365 /** @overload
joeverbout 0:ea44dc9ed014 2366 @param vec input vector(s); must have the same dimensionality and the
joeverbout 0:ea44dc9ed014 2367 same layout as the input data used at PCA phase, that is, if
joeverbout 0:ea44dc9ed014 2368 DATA_AS_ROW are specified, then `vec.cols==data.cols`
joeverbout 0:ea44dc9ed014 2369 (vector dimensionality) and `vec.rows` is the number of vectors to
joeverbout 0:ea44dc9ed014 2370 project, and the same is true for the PCA::DATA_AS_COL case.
joeverbout 0:ea44dc9ed014 2371 @param result output vectors; in case of PCA::DATA_AS_COL, the
joeverbout 0:ea44dc9ed014 2372 output matrix has as many columns as the number of input vectors, this
joeverbout 0:ea44dc9ed014 2373 means that `result.cols==vec.cols` and the number of rows match the
joeverbout 0:ea44dc9ed014 2374 number of principal components (for example, `maxComponents` parameter
joeverbout 0:ea44dc9ed014 2375 passed to the constructor).
joeverbout 0:ea44dc9ed014 2376 */
joeverbout 0:ea44dc9ed014 2377 void project(InputArray vec, OutputArray result) const;
joeverbout 0:ea44dc9ed014 2378
joeverbout 0:ea44dc9ed014 2379 /** @brief Reconstructs vectors from their PC projections.
joeverbout 0:ea44dc9ed014 2380
joeverbout 0:ea44dc9ed014 2381 The methods are inverse operations to PCA::project. They take PC
joeverbout 0:ea44dc9ed014 2382 coordinates of projected vectors and reconstruct the original vectors.
joeverbout 0:ea44dc9ed014 2383 Unless all the principal components have been retained, the
joeverbout 0:ea44dc9ed014 2384 reconstructed vectors are different from the originals. But typically,
joeverbout 0:ea44dc9ed014 2385 the difference is small if the number of components is large enough (but
joeverbout 0:ea44dc9ed014 2386 still much smaller than the original vector dimensionality). As a
joeverbout 0:ea44dc9ed014 2387 result, PCA is used.
joeverbout 0:ea44dc9ed014 2388 @param vec coordinates of the vectors in the principal component
joeverbout 0:ea44dc9ed014 2389 subspace, the layout and size are the same as of PCA::project output
joeverbout 0:ea44dc9ed014 2390 vectors.
joeverbout 0:ea44dc9ed014 2391 */
joeverbout 0:ea44dc9ed014 2392 Mat backProject(InputArray vec) const;
joeverbout 0:ea44dc9ed014 2393
joeverbout 0:ea44dc9ed014 2394 /** @overload
joeverbout 0:ea44dc9ed014 2395 @param vec coordinates of the vectors in the principal component
joeverbout 0:ea44dc9ed014 2396 subspace, the layout and size are the same as of PCA::project output
joeverbout 0:ea44dc9ed014 2397 vectors.
joeverbout 0:ea44dc9ed014 2398 @param result reconstructed vectors; the layout and size are the same as
joeverbout 0:ea44dc9ed014 2399 of PCA::project input vectors.
joeverbout 0:ea44dc9ed014 2400 */
joeverbout 0:ea44dc9ed014 2401 void backProject(InputArray vec, OutputArray result) const;
joeverbout 0:ea44dc9ed014 2402
joeverbout 0:ea44dc9ed014 2403 /** @brief write and load PCA matrix
joeverbout 0:ea44dc9ed014 2404
joeverbout 0:ea44dc9ed014 2405 */
joeverbout 0:ea44dc9ed014 2406 void write(FileStorage& fs ) const;
joeverbout 0:ea44dc9ed014 2407 void read(const FileNode& fs);
joeverbout 0:ea44dc9ed014 2408
joeverbout 0:ea44dc9ed014 2409 Mat eigenvectors; //!< eigenvectors of the covariation matrix
joeverbout 0:ea44dc9ed014 2410 Mat eigenvalues; //!< eigenvalues of the covariation matrix
joeverbout 0:ea44dc9ed014 2411 Mat mean; //!< mean value subtracted before the projection and added after the back projection
joeverbout 0:ea44dc9ed014 2412 };
joeverbout 0:ea44dc9ed014 2413
joeverbout 0:ea44dc9ed014 2414 /** @example pca.cpp
joeverbout 0:ea44dc9ed014 2415 An example using %PCA for dimensionality reduction while maintaining an amount of variance
joeverbout 0:ea44dc9ed014 2416 */
joeverbout 0:ea44dc9ed014 2417
joeverbout 0:ea44dc9ed014 2418 /**
joeverbout 0:ea44dc9ed014 2419 @brief Linear Discriminant Analysis
joeverbout 0:ea44dc9ed014 2420 @todo document this class
joeverbout 0:ea44dc9ed014 2421 */
joeverbout 0:ea44dc9ed014 2422 class CV_EXPORTS LDA
joeverbout 0:ea44dc9ed014 2423 {
joeverbout 0:ea44dc9ed014 2424 public:
joeverbout 0:ea44dc9ed014 2425 /** @brief constructor
joeverbout 0:ea44dc9ed014 2426 Initializes a LDA with num_components (default 0).
joeverbout 0:ea44dc9ed014 2427 */
joeverbout 0:ea44dc9ed014 2428 explicit LDA(int num_components = 0);
joeverbout 0:ea44dc9ed014 2429
joeverbout 0:ea44dc9ed014 2430 /** Initializes and performs a Discriminant Analysis with Fisher's
joeverbout 0:ea44dc9ed014 2431 Optimization Criterion on given data in src and corresponding labels
joeverbout 0:ea44dc9ed014 2432 in labels. If 0 (or less) number of components are given, they are
joeverbout 0:ea44dc9ed014 2433 automatically determined for given data in computation.
joeverbout 0:ea44dc9ed014 2434 */
joeverbout 0:ea44dc9ed014 2435 LDA(InputArrayOfArrays src, InputArray labels, int num_components = 0);
joeverbout 0:ea44dc9ed014 2436
joeverbout 0:ea44dc9ed014 2437 /** Serializes this object to a given filename.
joeverbout 0:ea44dc9ed014 2438 */
joeverbout 0:ea44dc9ed014 2439 void save(const String& filename) const;
joeverbout 0:ea44dc9ed014 2440
joeverbout 0:ea44dc9ed014 2441 /** Deserializes this object from a given filename.
joeverbout 0:ea44dc9ed014 2442 */
joeverbout 0:ea44dc9ed014 2443 void load(const String& filename);
joeverbout 0:ea44dc9ed014 2444
joeverbout 0:ea44dc9ed014 2445 /** Serializes this object to a given cv::FileStorage.
joeverbout 0:ea44dc9ed014 2446 */
joeverbout 0:ea44dc9ed014 2447 void save(FileStorage& fs) const;
joeverbout 0:ea44dc9ed014 2448
joeverbout 0:ea44dc9ed014 2449 /** Deserializes this object from a given cv::FileStorage.
joeverbout 0:ea44dc9ed014 2450 */
joeverbout 0:ea44dc9ed014 2451 void load(const FileStorage& node);
joeverbout 0:ea44dc9ed014 2452
joeverbout 0:ea44dc9ed014 2453 /** destructor
joeverbout 0:ea44dc9ed014 2454 */
joeverbout 0:ea44dc9ed014 2455 ~LDA();
joeverbout 0:ea44dc9ed014 2456
joeverbout 0:ea44dc9ed014 2457 /** Compute the discriminants for data in src (row aligned) and labels.
joeverbout 0:ea44dc9ed014 2458 */
joeverbout 0:ea44dc9ed014 2459 void compute(InputArrayOfArrays src, InputArray labels);
joeverbout 0:ea44dc9ed014 2460
joeverbout 0:ea44dc9ed014 2461 /** Projects samples into the LDA subspace.
joeverbout 0:ea44dc9ed014 2462 src may be one or more row aligned samples.
joeverbout 0:ea44dc9ed014 2463 */
joeverbout 0:ea44dc9ed014 2464 Mat project(InputArray src);
joeverbout 0:ea44dc9ed014 2465
joeverbout 0:ea44dc9ed014 2466 /** Reconstructs projections from the LDA subspace.
joeverbout 0:ea44dc9ed014 2467 src may be one or more row aligned projections.
joeverbout 0:ea44dc9ed014 2468 */
joeverbout 0:ea44dc9ed014 2469 Mat reconstruct(InputArray src);
joeverbout 0:ea44dc9ed014 2470
joeverbout 0:ea44dc9ed014 2471 /** Returns the eigenvectors of this LDA.
joeverbout 0:ea44dc9ed014 2472 */
joeverbout 0:ea44dc9ed014 2473 Mat eigenvectors() const { return _eigenvectors; }
joeverbout 0:ea44dc9ed014 2474
joeverbout 0:ea44dc9ed014 2475 /** Returns the eigenvalues of this LDA.
joeverbout 0:ea44dc9ed014 2476 */
joeverbout 0:ea44dc9ed014 2477 Mat eigenvalues() const { return _eigenvalues; }
joeverbout 0:ea44dc9ed014 2478
joeverbout 0:ea44dc9ed014 2479 static Mat subspaceProject(InputArray W, InputArray mean, InputArray src);
joeverbout 0:ea44dc9ed014 2480 static Mat subspaceReconstruct(InputArray W, InputArray mean, InputArray src);
joeverbout 0:ea44dc9ed014 2481
joeverbout 0:ea44dc9ed014 2482 protected:
joeverbout 0:ea44dc9ed014 2483 bool _dataAsRow; // unused, but needed for 3.0 ABI compatibility.
joeverbout 0:ea44dc9ed014 2484 int _num_components;
joeverbout 0:ea44dc9ed014 2485 Mat _eigenvectors;
joeverbout 0:ea44dc9ed014 2486 Mat _eigenvalues;
joeverbout 0:ea44dc9ed014 2487 void lda(InputArrayOfArrays src, InputArray labels);
joeverbout 0:ea44dc9ed014 2488 };
joeverbout 0:ea44dc9ed014 2489
joeverbout 0:ea44dc9ed014 2490 /** @brief Singular Value Decomposition
joeverbout 0:ea44dc9ed014 2491
joeverbout 0:ea44dc9ed014 2492 Class for computing Singular Value Decomposition of a floating-point
joeverbout 0:ea44dc9ed014 2493 matrix. The Singular Value Decomposition is used to solve least-square
joeverbout 0:ea44dc9ed014 2494 problems, under-determined linear systems, invert matrices, compute
joeverbout 0:ea44dc9ed014 2495 condition numbers, and so on.
joeverbout 0:ea44dc9ed014 2496
joeverbout 0:ea44dc9ed014 2497 If you want to compute a condition number of a matrix or an absolute value of
joeverbout 0:ea44dc9ed014 2498 its determinant, you do not need `u` and `vt`. You can pass
joeverbout 0:ea44dc9ed014 2499 flags=SVD::NO_UV|... . Another flag SVD::FULL_UV indicates that full-size u
joeverbout 0:ea44dc9ed014 2500 and vt must be computed, which is not necessary most of the time.
joeverbout 0:ea44dc9ed014 2501
joeverbout 0:ea44dc9ed014 2502 @sa invert, solve, eigen, determinant
joeverbout 0:ea44dc9ed014 2503 */
joeverbout 0:ea44dc9ed014 2504 class CV_EXPORTS SVD
joeverbout 0:ea44dc9ed014 2505 {
joeverbout 0:ea44dc9ed014 2506 public:
joeverbout 0:ea44dc9ed014 2507 enum Flags {
joeverbout 0:ea44dc9ed014 2508 /** allow the algorithm to modify the decomposed matrix; it can save space and speed up
joeverbout 0:ea44dc9ed014 2509 processing. currently ignored. */
joeverbout 0:ea44dc9ed014 2510 MODIFY_A = 1,
joeverbout 0:ea44dc9ed014 2511 /** indicates that only a vector of singular values `w` is to be processed, while u and vt
joeverbout 0:ea44dc9ed014 2512 will be set to empty matrices */
joeverbout 0:ea44dc9ed014 2513 NO_UV = 2,
joeverbout 0:ea44dc9ed014 2514 /** when the matrix is not square, by default the algorithm produces u and vt matrices of
joeverbout 0:ea44dc9ed014 2515 sufficiently large size for the further A reconstruction; if, however, FULL_UV flag is
joeverbout 0:ea44dc9ed014 2516 specified, u and vt will be full-size square orthogonal matrices.*/
joeverbout 0:ea44dc9ed014 2517 FULL_UV = 4
joeverbout 0:ea44dc9ed014 2518 };
joeverbout 0:ea44dc9ed014 2519
joeverbout 0:ea44dc9ed014 2520 /** @brief the default constructor
joeverbout 0:ea44dc9ed014 2521
joeverbout 0:ea44dc9ed014 2522 initializes an empty SVD structure
joeverbout 0:ea44dc9ed014 2523 */
joeverbout 0:ea44dc9ed014 2524 SVD();
joeverbout 0:ea44dc9ed014 2525
joeverbout 0:ea44dc9ed014 2526 /** @overload
joeverbout 0:ea44dc9ed014 2527 initializes an empty SVD structure and then calls SVD::operator()
joeverbout 0:ea44dc9ed014 2528 @param src decomposed matrix.
joeverbout 0:ea44dc9ed014 2529 @param flags operation flags (SVD::Flags)
joeverbout 0:ea44dc9ed014 2530 */
joeverbout 0:ea44dc9ed014 2531 SVD( InputArray src, int flags = 0 );
joeverbout 0:ea44dc9ed014 2532
joeverbout 0:ea44dc9ed014 2533 /** @brief the operator that performs SVD. The previously allocated u, w and vt are released.
joeverbout 0:ea44dc9ed014 2534
joeverbout 0:ea44dc9ed014 2535 The operator performs the singular value decomposition of the supplied
joeverbout 0:ea44dc9ed014 2536 matrix. The u,`vt` , and the vector of singular values w are stored in
joeverbout 0:ea44dc9ed014 2537 the structure. The same SVD structure can be reused many times with
joeverbout 0:ea44dc9ed014 2538 different matrices. Each time, if needed, the previous u,`vt` , and w
joeverbout 0:ea44dc9ed014 2539 are reclaimed and the new matrices are created, which is all handled by
joeverbout 0:ea44dc9ed014 2540 Mat::create.
joeverbout 0:ea44dc9ed014 2541 @param src decomposed matrix.
joeverbout 0:ea44dc9ed014 2542 @param flags operation flags (SVD::Flags)
joeverbout 0:ea44dc9ed014 2543 */
joeverbout 0:ea44dc9ed014 2544 SVD& operator ()( InputArray src, int flags = 0 );
joeverbout 0:ea44dc9ed014 2545
joeverbout 0:ea44dc9ed014 2546 /** @brief decomposes matrix and stores the results to user-provided matrices
joeverbout 0:ea44dc9ed014 2547
joeverbout 0:ea44dc9ed014 2548 The methods/functions perform SVD of matrix. Unlike SVD::SVD constructor
joeverbout 0:ea44dc9ed014 2549 and SVD::operator(), they store the results to the user-provided
joeverbout 0:ea44dc9ed014 2550 matrices:
joeverbout 0:ea44dc9ed014 2551
joeverbout 0:ea44dc9ed014 2552 @code{.cpp}
joeverbout 0:ea44dc9ed014 2553 Mat A, w, u, vt;
joeverbout 0:ea44dc9ed014 2554 SVD::compute(A, w, u, vt);
joeverbout 0:ea44dc9ed014 2555 @endcode
joeverbout 0:ea44dc9ed014 2556
joeverbout 0:ea44dc9ed014 2557 @param src decomposed matrix
joeverbout 0:ea44dc9ed014 2558 @param w calculated singular values
joeverbout 0:ea44dc9ed014 2559 @param u calculated left singular vectors
joeverbout 0:ea44dc9ed014 2560 @param vt transposed matrix of right singular values
joeverbout 0:ea44dc9ed014 2561 @param flags operation flags - see SVD::SVD.
joeverbout 0:ea44dc9ed014 2562 */
joeverbout 0:ea44dc9ed014 2563 static void compute( InputArray src, OutputArray w,
joeverbout 0:ea44dc9ed014 2564 OutputArray u, OutputArray vt, int flags = 0 );
joeverbout 0:ea44dc9ed014 2565
joeverbout 0:ea44dc9ed014 2566 /** @overload
joeverbout 0:ea44dc9ed014 2567 computes singular values of a matrix
joeverbout 0:ea44dc9ed014 2568 @param src decomposed matrix
joeverbout 0:ea44dc9ed014 2569 @param w calculated singular values
joeverbout 0:ea44dc9ed014 2570 @param flags operation flags - see SVD::Flags.
joeverbout 0:ea44dc9ed014 2571 */
joeverbout 0:ea44dc9ed014 2572 static void compute( InputArray src, OutputArray w, int flags = 0 );
joeverbout 0:ea44dc9ed014 2573
joeverbout 0:ea44dc9ed014 2574 /** @brief performs back substitution
joeverbout 0:ea44dc9ed014 2575 */
joeverbout 0:ea44dc9ed014 2576 static void backSubst( InputArray w, InputArray u,
joeverbout 0:ea44dc9ed014 2577 InputArray vt, InputArray rhs,
joeverbout 0:ea44dc9ed014 2578 OutputArray dst );
joeverbout 0:ea44dc9ed014 2579
joeverbout 0:ea44dc9ed014 2580 /** @brief solves an under-determined singular linear system
joeverbout 0:ea44dc9ed014 2581
joeverbout 0:ea44dc9ed014 2582 The method finds a unit-length solution x of a singular linear system
joeverbout 0:ea44dc9ed014 2583 A\*x = 0. Depending on the rank of A, there can be no solutions, a
joeverbout 0:ea44dc9ed014 2584 single solution or an infinite number of solutions. In general, the
joeverbout 0:ea44dc9ed014 2585 algorithm solves the following problem:
joeverbout 0:ea44dc9ed014 2586 \f[dst = \arg \min _{x: \| x \| =1} \| src \cdot x \|\f]
joeverbout 0:ea44dc9ed014 2587 @param src left-hand-side matrix.
joeverbout 0:ea44dc9ed014 2588 @param dst found solution.
joeverbout 0:ea44dc9ed014 2589 */
joeverbout 0:ea44dc9ed014 2590 static void solveZ( InputArray src, OutputArray dst );
joeverbout 0:ea44dc9ed014 2591
joeverbout 0:ea44dc9ed014 2592 /** @brief performs a singular value back substitution.
joeverbout 0:ea44dc9ed014 2593
joeverbout 0:ea44dc9ed014 2594 The method calculates a back substitution for the specified right-hand
joeverbout 0:ea44dc9ed014 2595 side:
joeverbout 0:ea44dc9ed014 2596
joeverbout 0:ea44dc9ed014 2597 \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]
joeverbout 0:ea44dc9ed014 2598
joeverbout 0:ea44dc9ed014 2599 Using this technique you can either get a very accurate solution of the
joeverbout 0:ea44dc9ed014 2600 convenient linear system, or the best (in the least-squares terms)
joeverbout 0:ea44dc9ed014 2601 pseudo-solution of an overdetermined linear system.
joeverbout 0:ea44dc9ed014 2602
joeverbout 0:ea44dc9ed014 2603 @param rhs right-hand side of a linear system (u\*w\*v')\*dst = rhs to
joeverbout 0:ea44dc9ed014 2604 be solved, where A has been previously decomposed.
joeverbout 0:ea44dc9ed014 2605
joeverbout 0:ea44dc9ed014 2606 @param dst found solution of the system.
joeverbout 0:ea44dc9ed014 2607
joeverbout 0:ea44dc9ed014 2608 @note Explicit SVD with the further back substitution only makes sense
joeverbout 0:ea44dc9ed014 2609 if you need to solve many linear systems with the same left-hand side
joeverbout 0:ea44dc9ed014 2610 (for example, src ). If all you need is to solve a single system
joeverbout 0:ea44dc9ed014 2611 (possibly with multiple rhs immediately available), simply call solve
joeverbout 0:ea44dc9ed014 2612 add pass DECOMP_SVD there. It does absolutely the same thing.
joeverbout 0:ea44dc9ed014 2613 */
joeverbout 0:ea44dc9ed014 2614 void backSubst( InputArray rhs, OutputArray dst ) const;
joeverbout 0:ea44dc9ed014 2615
joeverbout 0:ea44dc9ed014 2616 /** @todo document */
joeverbout 0:ea44dc9ed014 2617 template<typename _Tp, int m, int n, int nm> static
joeverbout 0:ea44dc9ed014 2618 void compute( const Matx<_Tp, m, n>& a, Matx<_Tp, nm, 1>& w, Matx<_Tp, m, nm>& u, Matx<_Tp, n, nm>& vt );
joeverbout 0:ea44dc9ed014 2619
joeverbout 0:ea44dc9ed014 2620 /** @todo document */
joeverbout 0:ea44dc9ed014 2621 template<typename _Tp, int m, int n, int nm> static
joeverbout 0:ea44dc9ed014 2622 void compute( const Matx<_Tp, m, n>& a, Matx<_Tp, nm, 1>& w );
joeverbout 0:ea44dc9ed014 2623
joeverbout 0:ea44dc9ed014 2624 /** @todo document */
joeverbout 0:ea44dc9ed014 2625 template<typename _Tp, int m, int n, int nm, int nb> static
joeverbout 0:ea44dc9ed014 2626 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 );
joeverbout 0:ea44dc9ed014 2627
joeverbout 0:ea44dc9ed014 2628 Mat u, w, vt;
joeverbout 0:ea44dc9ed014 2629 };
joeverbout 0:ea44dc9ed014 2630
joeverbout 0:ea44dc9ed014 2631 /** @brief Random Number Generator
joeverbout 0:ea44dc9ed014 2632
joeverbout 0:ea44dc9ed014 2633 Random number generator. It encapsulates the state (currently, a 64-bit
joeverbout 0:ea44dc9ed014 2634 integer) and has methods to return scalar random values and to fill
joeverbout 0:ea44dc9ed014 2635 arrays with random values. Currently it supports uniform and Gaussian
joeverbout 0:ea44dc9ed014 2636 (normal) distributions. The generator uses Multiply-With-Carry
joeverbout 0:ea44dc9ed014 2637 algorithm, introduced by G. Marsaglia (
joeverbout 0:ea44dc9ed014 2638 <http://en.wikipedia.org/wiki/Multiply-with-carry> ).
joeverbout 0:ea44dc9ed014 2639 Gaussian-distribution random numbers are generated using the Ziggurat
joeverbout 0:ea44dc9ed014 2640 algorithm ( <http://en.wikipedia.org/wiki/Ziggurat_algorithm> ),
joeverbout 0:ea44dc9ed014 2641 introduced by G. Marsaglia and W. W. Tsang.
joeverbout 0:ea44dc9ed014 2642 */
joeverbout 0:ea44dc9ed014 2643 class CV_EXPORTS RNG
joeverbout 0:ea44dc9ed014 2644 {
joeverbout 0:ea44dc9ed014 2645 public:
joeverbout 0:ea44dc9ed014 2646 enum { UNIFORM = 0,
joeverbout 0:ea44dc9ed014 2647 NORMAL = 1
joeverbout 0:ea44dc9ed014 2648 };
joeverbout 0:ea44dc9ed014 2649
joeverbout 0:ea44dc9ed014 2650 /** @brief constructor
joeverbout 0:ea44dc9ed014 2651
joeverbout 0:ea44dc9ed014 2652 These are the RNG constructors. The first form sets the state to some
joeverbout 0:ea44dc9ed014 2653 pre-defined value, equal to 2\*\*32-1 in the current implementation. The
joeverbout 0:ea44dc9ed014 2654 second form sets the state to the specified value. If you passed state=0
joeverbout 0:ea44dc9ed014 2655 , the constructor uses the above default value instead to avoid the
joeverbout 0:ea44dc9ed014 2656 singular random number sequence, consisting of all zeros.
joeverbout 0:ea44dc9ed014 2657 */
joeverbout 0:ea44dc9ed014 2658 RNG();
joeverbout 0:ea44dc9ed014 2659 /** @overload
joeverbout 0:ea44dc9ed014 2660 @param state 64-bit value used to initialize the RNG.
joeverbout 0:ea44dc9ed014 2661 */
joeverbout 0:ea44dc9ed014 2662 RNG(uint64 state);
joeverbout 0:ea44dc9ed014 2663 /**The method updates the state using the MWC algorithm and returns the
joeverbout 0:ea44dc9ed014 2664 next 32-bit random number.*/
joeverbout 0:ea44dc9ed014 2665 unsigned next();
joeverbout 0:ea44dc9ed014 2666
joeverbout 0:ea44dc9ed014 2667 /**Each of the methods updates the state using the MWC algorithm and
joeverbout 0:ea44dc9ed014 2668 returns the next random number of the specified type. In case of integer
joeverbout 0:ea44dc9ed014 2669 types, the returned number is from the available value range for the
joeverbout 0:ea44dc9ed014 2670 specified type. In case of floating-point types, the returned value is
joeverbout 0:ea44dc9ed014 2671 from [0,1) range.
joeverbout 0:ea44dc9ed014 2672 */
joeverbout 0:ea44dc9ed014 2673 operator uchar();
joeverbout 0:ea44dc9ed014 2674 /** @overload */
joeverbout 0:ea44dc9ed014 2675 operator schar();
joeverbout 0:ea44dc9ed014 2676 /** @overload */
joeverbout 0:ea44dc9ed014 2677 operator ushort();
joeverbout 0:ea44dc9ed014 2678 /** @overload */
joeverbout 0:ea44dc9ed014 2679 operator short();
joeverbout 0:ea44dc9ed014 2680 /** @overload */
joeverbout 0:ea44dc9ed014 2681 operator unsigned();
joeverbout 0:ea44dc9ed014 2682 /** @overload */
joeverbout 0:ea44dc9ed014 2683 operator int();
joeverbout 0:ea44dc9ed014 2684 /** @overload */
joeverbout 0:ea44dc9ed014 2685 operator float();
joeverbout 0:ea44dc9ed014 2686 /** @overload */
joeverbout 0:ea44dc9ed014 2687 operator double();
joeverbout 0:ea44dc9ed014 2688
joeverbout 0:ea44dc9ed014 2689 /** @brief returns a random integer sampled uniformly from [0, N).
joeverbout 0:ea44dc9ed014 2690
joeverbout 0:ea44dc9ed014 2691 The methods transform the state using the MWC algorithm and return the
joeverbout 0:ea44dc9ed014 2692 next random number. The first form is equivalent to RNG::next . The
joeverbout 0:ea44dc9ed014 2693 second form returns the random number modulo N , which means that the
joeverbout 0:ea44dc9ed014 2694 result is in the range [0, N) .
joeverbout 0:ea44dc9ed014 2695 */
joeverbout 0:ea44dc9ed014 2696 unsigned operator ()();
joeverbout 0:ea44dc9ed014 2697 /** @overload
joeverbout 0:ea44dc9ed014 2698 @param N upper non-inclusive boundary of the returned random number.
joeverbout 0:ea44dc9ed014 2699 */
joeverbout 0:ea44dc9ed014 2700 unsigned operator ()(unsigned N);
joeverbout 0:ea44dc9ed014 2701
joeverbout 0:ea44dc9ed014 2702 /** @brief returns uniformly distributed integer random number from [a,b) range
joeverbout 0:ea44dc9ed014 2703
joeverbout 0:ea44dc9ed014 2704 The methods transform the state using the MWC algorithm and return the
joeverbout 0:ea44dc9ed014 2705 next uniformly-distributed random number of the specified type, deduced
joeverbout 0:ea44dc9ed014 2706 from the input parameter type, from the range [a, b) . There is a nuance
joeverbout 0:ea44dc9ed014 2707 illustrated by the following sample:
joeverbout 0:ea44dc9ed014 2708
joeverbout 0:ea44dc9ed014 2709 @code{.cpp}
joeverbout 0:ea44dc9ed014 2710 RNG rng;
joeverbout 0:ea44dc9ed014 2711
joeverbout 0:ea44dc9ed014 2712 // always produces 0
joeverbout 0:ea44dc9ed014 2713 double a = rng.uniform(0, 1);
joeverbout 0:ea44dc9ed014 2714
joeverbout 0:ea44dc9ed014 2715 // produces double from [0, 1)
joeverbout 0:ea44dc9ed014 2716 double a1 = rng.uniform((double)0, (double)1);
joeverbout 0:ea44dc9ed014 2717
joeverbout 0:ea44dc9ed014 2718 // produces float from [0, 1)
joeverbout 0:ea44dc9ed014 2719 double b = rng.uniform(0.f, 1.f);
joeverbout 0:ea44dc9ed014 2720
joeverbout 0:ea44dc9ed014 2721 // produces double from [0, 1)
joeverbout 0:ea44dc9ed014 2722 double c = rng.uniform(0., 1.);
joeverbout 0:ea44dc9ed014 2723
joeverbout 0:ea44dc9ed014 2724 // may cause compiler error because of ambiguity:
joeverbout 0:ea44dc9ed014 2725 // RNG::uniform(0, (int)0.999999)? or RNG::uniform((double)0, 0.99999)?
joeverbout 0:ea44dc9ed014 2726 double d = rng.uniform(0, 0.999999);
joeverbout 0:ea44dc9ed014 2727 @endcode
joeverbout 0:ea44dc9ed014 2728
joeverbout 0:ea44dc9ed014 2729 The compiler does not take into account the type of the variable to
joeverbout 0:ea44dc9ed014 2730 which you assign the result of RNG::uniform . The only thing that
joeverbout 0:ea44dc9ed014 2731 matters to the compiler is the type of a and b parameters. So, if you
joeverbout 0:ea44dc9ed014 2732 want a floating-point random number, but the range boundaries are
joeverbout 0:ea44dc9ed014 2733 integer numbers, either put dots in the end, if they are constants, or
joeverbout 0:ea44dc9ed014 2734 use explicit type cast operators, as in the a1 initialization above.
joeverbout 0:ea44dc9ed014 2735 @param a lower inclusive boundary of the returned random numbers.
joeverbout 0:ea44dc9ed014 2736 @param b upper non-inclusive boundary of the returned random numbers.
joeverbout 0:ea44dc9ed014 2737 */
joeverbout 0:ea44dc9ed014 2738 int uniform(int a, int b);
joeverbout 0:ea44dc9ed014 2739 /** @overload */
joeverbout 0:ea44dc9ed014 2740 float uniform(float a, float b);
joeverbout 0:ea44dc9ed014 2741 /** @overload */
joeverbout 0:ea44dc9ed014 2742 double uniform(double a, double b);
joeverbout 0:ea44dc9ed014 2743
joeverbout 0:ea44dc9ed014 2744 /** @brief Fills arrays with random numbers.
joeverbout 0:ea44dc9ed014 2745
joeverbout 0:ea44dc9ed014 2746 @param mat 2D or N-dimensional matrix; currently matrices with more than
joeverbout 0:ea44dc9ed014 2747 4 channels are not supported by the methods, use Mat::reshape as a
joeverbout 0:ea44dc9ed014 2748 possible workaround.
joeverbout 0:ea44dc9ed014 2749 @param distType distribution type, RNG::UNIFORM or RNG::NORMAL.
joeverbout 0:ea44dc9ed014 2750 @param a first distribution parameter; in case of the uniform
joeverbout 0:ea44dc9ed014 2751 distribution, this is an inclusive lower boundary, in case of the normal
joeverbout 0:ea44dc9ed014 2752 distribution, this is a mean value.
joeverbout 0:ea44dc9ed014 2753 @param b second distribution parameter; in case of the uniform
joeverbout 0:ea44dc9ed014 2754 distribution, this is a non-inclusive upper boundary, in case of the
joeverbout 0:ea44dc9ed014 2755 normal distribution, this is a standard deviation (diagonal of the
joeverbout 0:ea44dc9ed014 2756 standard deviation matrix or the full standard deviation matrix).
joeverbout 0:ea44dc9ed014 2757 @param saturateRange pre-saturation flag; for uniform distribution only;
joeverbout 0:ea44dc9ed014 2758 if true, the method will first convert a and b to the acceptable value
joeverbout 0:ea44dc9ed014 2759 range (according to the mat datatype) and then will generate uniformly
joeverbout 0:ea44dc9ed014 2760 distributed random numbers within the range [saturate(a), saturate(b)),
joeverbout 0:ea44dc9ed014 2761 if saturateRange=false, the method will generate uniformly distributed
joeverbout 0:ea44dc9ed014 2762 random numbers in the original range [a, b) and then will saturate them,
joeverbout 0:ea44dc9ed014 2763 it means, for example, that
joeverbout 0:ea44dc9ed014 2764 <tt>theRNG().fill(mat_8u, RNG::UNIFORM, -DBL_MAX, DBL_MAX)</tt> will likely
joeverbout 0:ea44dc9ed014 2765 produce array mostly filled with 0's and 255's, since the range (0, 255)
joeverbout 0:ea44dc9ed014 2766 is significantly smaller than [-DBL_MAX, DBL_MAX).
joeverbout 0:ea44dc9ed014 2767
joeverbout 0:ea44dc9ed014 2768 Each of the methods fills the matrix with the random values from the
joeverbout 0:ea44dc9ed014 2769 specified distribution. As the new numbers are generated, the RNG state
joeverbout 0:ea44dc9ed014 2770 is updated accordingly. In case of multiple-channel images, every
joeverbout 0:ea44dc9ed014 2771 channel is filled independently, which means that RNG cannot generate
joeverbout 0:ea44dc9ed014 2772 samples from the multi-dimensional Gaussian distribution with
joeverbout 0:ea44dc9ed014 2773 non-diagonal covariance matrix directly. To do that, the method
joeverbout 0:ea44dc9ed014 2774 generates samples from multi-dimensional standard Gaussian distribution
joeverbout 0:ea44dc9ed014 2775 with zero mean and identity covariation matrix, and then transforms them
joeverbout 0:ea44dc9ed014 2776 using transform to get samples from the specified Gaussian distribution.
joeverbout 0:ea44dc9ed014 2777 */
joeverbout 0:ea44dc9ed014 2778 void fill( InputOutputArray mat, int distType, InputArray a, InputArray b, bool saturateRange = false );
joeverbout 0:ea44dc9ed014 2779
joeverbout 0:ea44dc9ed014 2780 /** @brief Returns the next random number sampled from the Gaussian distribution
joeverbout 0:ea44dc9ed014 2781 @param sigma standard deviation of the distribution.
joeverbout 0:ea44dc9ed014 2782
joeverbout 0:ea44dc9ed014 2783 The method transforms the state using the MWC algorithm and returns the
joeverbout 0:ea44dc9ed014 2784 next random number from the Gaussian distribution N(0,sigma) . That is,
joeverbout 0:ea44dc9ed014 2785 the mean value of the returned random numbers is zero and the standard
joeverbout 0:ea44dc9ed014 2786 deviation is the specified sigma .
joeverbout 0:ea44dc9ed014 2787 */
joeverbout 0:ea44dc9ed014 2788 double gaussian(double sigma);
joeverbout 0:ea44dc9ed014 2789
joeverbout 0:ea44dc9ed014 2790 uint64 state;
joeverbout 0:ea44dc9ed014 2791 };
joeverbout 0:ea44dc9ed014 2792
joeverbout 0:ea44dc9ed014 2793 /** @brief Mersenne Twister random number generator
joeverbout 0:ea44dc9ed014 2794
joeverbout 0:ea44dc9ed014 2795 Inspired by http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/CODES/mt19937ar.c
joeverbout 0:ea44dc9ed014 2796 @todo document
joeverbout 0:ea44dc9ed014 2797 */
joeverbout 0:ea44dc9ed014 2798 class CV_EXPORTS RNG_MT19937
joeverbout 0:ea44dc9ed014 2799 {
joeverbout 0:ea44dc9ed014 2800 public:
joeverbout 0:ea44dc9ed014 2801 RNG_MT19937();
joeverbout 0:ea44dc9ed014 2802 RNG_MT19937(unsigned s);
joeverbout 0:ea44dc9ed014 2803 void seed(unsigned s);
joeverbout 0:ea44dc9ed014 2804
joeverbout 0:ea44dc9ed014 2805 unsigned next();
joeverbout 0:ea44dc9ed014 2806
joeverbout 0:ea44dc9ed014 2807 operator int();
joeverbout 0:ea44dc9ed014 2808 operator unsigned();
joeverbout 0:ea44dc9ed014 2809 operator float();
joeverbout 0:ea44dc9ed014 2810 operator double();
joeverbout 0:ea44dc9ed014 2811
joeverbout 0:ea44dc9ed014 2812 unsigned operator ()(unsigned N);
joeverbout 0:ea44dc9ed014 2813 unsigned operator ()();
joeverbout 0:ea44dc9ed014 2814
joeverbout 0:ea44dc9ed014 2815 /** @brief returns uniformly distributed integer random number from [a,b) range
joeverbout 0:ea44dc9ed014 2816
joeverbout 0:ea44dc9ed014 2817 */
joeverbout 0:ea44dc9ed014 2818 int uniform(int a, int b);
joeverbout 0:ea44dc9ed014 2819 /** @brief returns uniformly distributed floating-point random number from [a,b) range
joeverbout 0:ea44dc9ed014 2820
joeverbout 0:ea44dc9ed014 2821 */
joeverbout 0:ea44dc9ed014 2822 float uniform(float a, float b);
joeverbout 0:ea44dc9ed014 2823 /** @brief returns uniformly distributed double-precision floating-point random number from [a,b) range
joeverbout 0:ea44dc9ed014 2824
joeverbout 0:ea44dc9ed014 2825 */
joeverbout 0:ea44dc9ed014 2826 double uniform(double a, double b);
joeverbout 0:ea44dc9ed014 2827
joeverbout 0:ea44dc9ed014 2828 private:
joeverbout 0:ea44dc9ed014 2829 enum PeriodParameters {N = 624, M = 397};
joeverbout 0:ea44dc9ed014 2830 unsigned state[N];
joeverbout 0:ea44dc9ed014 2831 int mti;
joeverbout 0:ea44dc9ed014 2832 };
joeverbout 0:ea44dc9ed014 2833
joeverbout 0:ea44dc9ed014 2834 //! @} core_array
joeverbout 0:ea44dc9ed014 2835
joeverbout 0:ea44dc9ed014 2836 //! @addtogroup core_cluster
joeverbout 0:ea44dc9ed014 2837 //! @{
joeverbout 0:ea44dc9ed014 2838
joeverbout 0:ea44dc9ed014 2839 /** @example kmeans.cpp
joeverbout 0:ea44dc9ed014 2840 An example on K-means clustering
joeverbout 0:ea44dc9ed014 2841 */
joeverbout 0:ea44dc9ed014 2842
joeverbout 0:ea44dc9ed014 2843 /** @brief Finds centers of clusters and groups input samples around the clusters.
joeverbout 0:ea44dc9ed014 2844
joeverbout 0:ea44dc9ed014 2845 The function kmeans implements a k-means algorithm that finds the centers of cluster_count clusters
joeverbout 0:ea44dc9ed014 2846 and groups the input samples around the clusters. As an output, \f$\texttt{labels}_i\f$ contains a
joeverbout 0:ea44dc9ed014 2847 0-based cluster index for the sample stored in the \f$i^{th}\f$ row of the samples matrix.
joeverbout 0:ea44dc9ed014 2848
joeverbout 0:ea44dc9ed014 2849 @note
joeverbout 0:ea44dc9ed014 2850 - (Python) An example on K-means clustering can be found at
joeverbout 0:ea44dc9ed014 2851 opencv_source_code/samples/python/kmeans.py
joeverbout 0:ea44dc9ed014 2852 @param data Data for clustering. An array of N-Dimensional points with float coordinates is needed.
joeverbout 0:ea44dc9ed014 2853 Examples of this array can be:
joeverbout 0:ea44dc9ed014 2854 - Mat points(count, 2, CV_32F);
joeverbout 0:ea44dc9ed014 2855 - Mat points(count, 1, CV_32FC2);
joeverbout 0:ea44dc9ed014 2856 - Mat points(1, count, CV_32FC2);
joeverbout 0:ea44dc9ed014 2857 - std::vector\<cv::Point2f\> points(sampleCount);
joeverbout 0:ea44dc9ed014 2858 @param K Number of clusters to split the set by.
joeverbout 0:ea44dc9ed014 2859 @param bestLabels Input/output integer array that stores the cluster indices for every sample.
joeverbout 0:ea44dc9ed014 2860 @param criteria The algorithm termination criteria, that is, the maximum number of iterations and/or
joeverbout 0:ea44dc9ed014 2861 the desired accuracy. The accuracy is specified as criteria.epsilon. As soon as each of the cluster
joeverbout 0:ea44dc9ed014 2862 centers moves by less than criteria.epsilon on some iteration, the algorithm stops.
joeverbout 0:ea44dc9ed014 2863 @param attempts Flag to specify the number of times the algorithm is executed using different
joeverbout 0:ea44dc9ed014 2864 initial labellings. The algorithm returns the labels that yield the best compactness (see the last
joeverbout 0:ea44dc9ed014 2865 function parameter).
joeverbout 0:ea44dc9ed014 2866 @param flags Flag that can take values of cv::KmeansFlags
joeverbout 0:ea44dc9ed014 2867 @param centers Output matrix of the cluster centers, one row per each cluster center.
joeverbout 0:ea44dc9ed014 2868 @return The function returns the compactness measure that is computed as
joeverbout 0:ea44dc9ed014 2869 \f[\sum _i \| \texttt{samples} _i - \texttt{centers} _{ \texttt{labels} _i} \| ^2\f]
joeverbout 0:ea44dc9ed014 2870 after every attempt. The best (minimum) value is chosen and the corresponding labels and the
joeverbout 0:ea44dc9ed014 2871 compactness value are returned by the function. Basically, you can use only the core of the
joeverbout 0:ea44dc9ed014 2872 function, set the number of attempts to 1, initialize labels each time using a custom algorithm,
joeverbout 0:ea44dc9ed014 2873 pass them with the ( flags = KMEANS_USE_INITIAL_LABELS ) flag, and then choose the best
joeverbout 0:ea44dc9ed014 2874 (most-compact) clustering.
joeverbout 0:ea44dc9ed014 2875 */
joeverbout 0:ea44dc9ed014 2876 CV_EXPORTS_W double kmeans( InputArray data, int K, InputOutputArray bestLabels,
joeverbout 0:ea44dc9ed014 2877 TermCriteria criteria, int attempts,
joeverbout 0:ea44dc9ed014 2878 int flags, OutputArray centers = noArray() );
joeverbout 0:ea44dc9ed014 2879
joeverbout 0:ea44dc9ed014 2880 //! @} core_cluster
joeverbout 0:ea44dc9ed014 2881
joeverbout 0:ea44dc9ed014 2882 //! @addtogroup core_basic
joeverbout 0:ea44dc9ed014 2883 //! @{
joeverbout 0:ea44dc9ed014 2884
joeverbout 0:ea44dc9ed014 2885 /////////////////////////////// Formatted output of cv::Mat ///////////////////////////
joeverbout 0:ea44dc9ed014 2886
joeverbout 0:ea44dc9ed014 2887 /** @todo document */
joeverbout 0:ea44dc9ed014 2888 class CV_EXPORTS Formatted
joeverbout 0:ea44dc9ed014 2889 {
joeverbout 0:ea44dc9ed014 2890 public:
joeverbout 0:ea44dc9ed014 2891 virtual const char* next() = 0;
joeverbout 0:ea44dc9ed014 2892 virtual void reset() = 0;
joeverbout 0:ea44dc9ed014 2893 virtual ~Formatted();
joeverbout 0:ea44dc9ed014 2894 };
joeverbout 0:ea44dc9ed014 2895
joeverbout 0:ea44dc9ed014 2896 /** @todo document */
joeverbout 0:ea44dc9ed014 2897 class CV_EXPORTS Formatter
joeverbout 0:ea44dc9ed014 2898 {
joeverbout 0:ea44dc9ed014 2899 public:
joeverbout 0:ea44dc9ed014 2900 enum { FMT_DEFAULT = 0,
joeverbout 0:ea44dc9ed014 2901 FMT_MATLAB = 1,
joeverbout 0:ea44dc9ed014 2902 FMT_CSV = 2,
joeverbout 0:ea44dc9ed014 2903 FMT_PYTHON = 3,
joeverbout 0:ea44dc9ed014 2904 FMT_NUMPY = 4,
joeverbout 0:ea44dc9ed014 2905 FMT_C = 5
joeverbout 0:ea44dc9ed014 2906 };
joeverbout 0:ea44dc9ed014 2907
joeverbout 0:ea44dc9ed014 2908 virtual ~Formatter();
joeverbout 0:ea44dc9ed014 2909
joeverbout 0:ea44dc9ed014 2910 virtual Ptr<Formatted> format(const Mat& mtx) const = 0;
joeverbout 0:ea44dc9ed014 2911
joeverbout 0:ea44dc9ed014 2912 virtual void set32fPrecision(int p = 8) = 0;
joeverbout 0:ea44dc9ed014 2913 virtual void set64fPrecision(int p = 16) = 0;
joeverbout 0:ea44dc9ed014 2914 virtual void setMultiline(bool ml = true) = 0;
joeverbout 0:ea44dc9ed014 2915
joeverbout 0:ea44dc9ed014 2916 static Ptr<Formatter> get(int fmt = FMT_DEFAULT);
joeverbout 0:ea44dc9ed014 2917
joeverbout 0:ea44dc9ed014 2918 };
joeverbout 0:ea44dc9ed014 2919
joeverbout 0:ea44dc9ed014 2920 static inline
joeverbout 0:ea44dc9ed014 2921 String& operator << (String& out, Ptr<Formatted> fmtd)
joeverbout 0:ea44dc9ed014 2922 {
joeverbout 0:ea44dc9ed014 2923 fmtd->reset();
joeverbout 0:ea44dc9ed014 2924 for(const char* str = fmtd->next(); str; str = fmtd->next())
joeverbout 0:ea44dc9ed014 2925 out += cv::String(str);
joeverbout 0:ea44dc9ed014 2926 return out;
joeverbout 0:ea44dc9ed014 2927 }
joeverbout 0:ea44dc9ed014 2928
joeverbout 0:ea44dc9ed014 2929 static inline
joeverbout 0:ea44dc9ed014 2930 String& operator << (String& out, const Mat& mtx)
joeverbout 0:ea44dc9ed014 2931 {
joeverbout 0:ea44dc9ed014 2932 return out << Formatter::get()->format(mtx);
joeverbout 0:ea44dc9ed014 2933 }
joeverbout 0:ea44dc9ed014 2934
joeverbout 0:ea44dc9ed014 2935 //////////////////////////////////////// Algorithm ////////////////////////////////////
joeverbout 0:ea44dc9ed014 2936
joeverbout 0:ea44dc9ed014 2937 class CV_EXPORTS Algorithm;
joeverbout 0:ea44dc9ed014 2938
joeverbout 0:ea44dc9ed014 2939 template<typename _Tp> struct ParamType {};
joeverbout 0:ea44dc9ed014 2940
joeverbout 0:ea44dc9ed014 2941
joeverbout 0:ea44dc9ed014 2942 /** @brief This is a base class for all more or less complex algorithms in OpenCV
joeverbout 0:ea44dc9ed014 2943
joeverbout 0:ea44dc9ed014 2944 especially for classes of algorithms, for which there can be multiple implementations. The examples
joeverbout 0:ea44dc9ed014 2945 are stereo correspondence (for which there are algorithms like block matching, semi-global block
joeverbout 0:ea44dc9ed014 2946 matching, graph-cut etc.), background subtraction (which can be done using mixture-of-gaussians
joeverbout 0:ea44dc9ed014 2947 models, codebook-based algorithm etc.), optical flow (block matching, Lucas-Kanade, Horn-Schunck
joeverbout 0:ea44dc9ed014 2948 etc.).
joeverbout 0:ea44dc9ed014 2949
joeverbout 0:ea44dc9ed014 2950 Here is example of SIFT use in your application via Algorithm interface:
joeverbout 0:ea44dc9ed014 2951 @code
joeverbout 0:ea44dc9ed014 2952 #include "opencv2/opencv.hpp"
joeverbout 0:ea44dc9ed014 2953 #include "opencv2/xfeatures2d.hpp"
joeverbout 0:ea44dc9ed014 2954 using namespace cv::xfeatures2d;
joeverbout 0:ea44dc9ed014 2955
joeverbout 0:ea44dc9ed014 2956 Ptr<Feature2D> sift = SIFT::create();
joeverbout 0:ea44dc9ed014 2957 FileStorage fs("sift_params.xml", FileStorage::READ);
joeverbout 0:ea44dc9ed014 2958 if( fs.isOpened() ) // if we have file with parameters, read them
joeverbout 0:ea44dc9ed014 2959 {
joeverbout 0:ea44dc9ed014 2960 sift->read(fs["sift_params"]);
joeverbout 0:ea44dc9ed014 2961 fs.release();
joeverbout 0:ea44dc9ed014 2962 }
joeverbout 0:ea44dc9ed014 2963 else // else modify the parameters and store them; user can later edit the file to use different parameters
joeverbout 0:ea44dc9ed014 2964 {
joeverbout 0:ea44dc9ed014 2965 sift->setContrastThreshold(0.01f); // lower the contrast threshold, compared to the default value
joeverbout 0:ea44dc9ed014 2966 {
joeverbout 0:ea44dc9ed014 2967 WriteStructContext ws(fs, "sift_params", CV_NODE_MAP);
joeverbout 0:ea44dc9ed014 2968 sift->write(fs);
joeverbout 0:ea44dc9ed014 2969 }
joeverbout 0:ea44dc9ed014 2970 }
joeverbout 0:ea44dc9ed014 2971 Mat image = imread("myimage.png", 0), descriptors;
joeverbout 0:ea44dc9ed014 2972 vector<KeyPoint> keypoints;
joeverbout 0:ea44dc9ed014 2973 sift->detectAndCompute(image, noArray(), keypoints, descriptors);
joeverbout 0:ea44dc9ed014 2974 @endcode
joeverbout 0:ea44dc9ed014 2975 */
joeverbout 0:ea44dc9ed014 2976 class CV_EXPORTS_W Algorithm
joeverbout 0:ea44dc9ed014 2977 {
joeverbout 0:ea44dc9ed014 2978 public:
joeverbout 0:ea44dc9ed014 2979 Algorithm();
joeverbout 0:ea44dc9ed014 2980 virtual ~Algorithm();
joeverbout 0:ea44dc9ed014 2981
joeverbout 0:ea44dc9ed014 2982 /** @brief Clears the algorithm state
joeverbout 0:ea44dc9ed014 2983 */
joeverbout 0:ea44dc9ed014 2984 CV_WRAP virtual void clear() {}
joeverbout 0:ea44dc9ed014 2985
joeverbout 0:ea44dc9ed014 2986 /** @brief Stores algorithm parameters in a file storage
joeverbout 0:ea44dc9ed014 2987 */
joeverbout 0:ea44dc9ed014 2988 virtual void write(FileStorage& fs) const { (void)fs; }
joeverbout 0:ea44dc9ed014 2989
joeverbout 0:ea44dc9ed014 2990 /** @brief Reads algorithm parameters from a file storage
joeverbout 0:ea44dc9ed014 2991 */
joeverbout 0:ea44dc9ed014 2992 virtual void read(const FileNode& fn) { (void)fn; }
joeverbout 0:ea44dc9ed014 2993
joeverbout 0:ea44dc9ed014 2994 /** @brief Returns true if the Algorithm is empty (e.g. in the very beginning or after unsuccessful read
joeverbout 0:ea44dc9ed014 2995 */
joeverbout 0:ea44dc9ed014 2996 virtual bool empty() const { return false; }
joeverbout 0:ea44dc9ed014 2997
joeverbout 0:ea44dc9ed014 2998 /** @brief Reads algorithm from the file node
joeverbout 0:ea44dc9ed014 2999
joeverbout 0:ea44dc9ed014 3000 This is static template method of Algorithm. It's usage is following (in the case of SVM):
joeverbout 0:ea44dc9ed014 3001 @code
joeverbout 0:ea44dc9ed014 3002 Ptr<SVM> svm = Algorithm::read<SVM>(fn);
joeverbout 0:ea44dc9ed014 3003 @endcode
joeverbout 0:ea44dc9ed014 3004 In order to make this method work, the derived class must overwrite Algorithm::read(const
joeverbout 0:ea44dc9ed014 3005 FileNode& fn) and also have static create() method without parameters
joeverbout 0:ea44dc9ed014 3006 (or with all the optional parameters)
joeverbout 0:ea44dc9ed014 3007 */
joeverbout 0:ea44dc9ed014 3008 template<typename _Tp> static Ptr<_Tp> read(const FileNode& fn)
joeverbout 0:ea44dc9ed014 3009 {
joeverbout 0:ea44dc9ed014 3010 Ptr<_Tp> obj = _Tp::create();
joeverbout 0:ea44dc9ed014 3011 obj->read(fn);
joeverbout 0:ea44dc9ed014 3012 return !obj->empty() ? obj : Ptr<_Tp>();
joeverbout 0:ea44dc9ed014 3013 }
joeverbout 0:ea44dc9ed014 3014
joeverbout 0:ea44dc9ed014 3015 /** @brief Loads algorithm from the file
joeverbout 0:ea44dc9ed014 3016
joeverbout 0:ea44dc9ed014 3017 @param filename Name of the file to read.
joeverbout 0:ea44dc9ed014 3018 @param objname The optional name of the node to read (if empty, the first top-level node will be used)
joeverbout 0:ea44dc9ed014 3019
joeverbout 0:ea44dc9ed014 3020 This is static template method of Algorithm. It's usage is following (in the case of SVM):
joeverbout 0:ea44dc9ed014 3021 @code
joeverbout 0:ea44dc9ed014 3022 Ptr<SVM> svm = Algorithm::load<SVM>("my_svm_model.xml");
joeverbout 0:ea44dc9ed014 3023 @endcode
joeverbout 0:ea44dc9ed014 3024 In order to make this method work, the derived class must overwrite Algorithm::read(const
joeverbout 0:ea44dc9ed014 3025 FileNode& fn).
joeverbout 0:ea44dc9ed014 3026 */
joeverbout 0:ea44dc9ed014 3027 template<typename _Tp> static Ptr<_Tp> load(const String& filename, const String& objname=String())
joeverbout 0:ea44dc9ed014 3028 {
joeverbout 0:ea44dc9ed014 3029 FileStorage fs(filename, FileStorage::READ);
joeverbout 0:ea44dc9ed014 3030 FileNode fn = objname.empty() ? fs.getFirstTopLevelNode() : fs[objname];
joeverbout 0:ea44dc9ed014 3031 Ptr<_Tp> obj = _Tp::create();
joeverbout 0:ea44dc9ed014 3032 obj->read(fn);
joeverbout 0:ea44dc9ed014 3033 return !obj->empty() ? obj : Ptr<_Tp>();
joeverbout 0:ea44dc9ed014 3034 }
joeverbout 0:ea44dc9ed014 3035
joeverbout 0:ea44dc9ed014 3036 /** @brief Loads algorithm from a String
joeverbout 0:ea44dc9ed014 3037
joeverbout 0:ea44dc9ed014 3038 @param strModel The string variable containing the model you want to load.
joeverbout 0:ea44dc9ed014 3039 @param objname The optional name of the node to read (if empty, the first top-level node will be used)
joeverbout 0:ea44dc9ed014 3040
joeverbout 0:ea44dc9ed014 3041 This is static template method of Algorithm. It's usage is following (in the case of SVM):
joeverbout 0:ea44dc9ed014 3042 @code
joeverbout 0:ea44dc9ed014 3043 Ptr<SVM> svm = Algorithm::loadFromString<SVM>(myStringModel);
joeverbout 0:ea44dc9ed014 3044 @endcode
joeverbout 0:ea44dc9ed014 3045 */
joeverbout 0:ea44dc9ed014 3046 template<typename _Tp> static Ptr<_Tp> loadFromString(const String& strModel, const String& objname=String())
joeverbout 0:ea44dc9ed014 3047 {
joeverbout 0:ea44dc9ed014 3048 FileStorage fs(strModel, FileStorage::READ + FileStorage::MEMORY);
joeverbout 0:ea44dc9ed014 3049 FileNode fn = objname.empty() ? fs.getFirstTopLevelNode() : fs[objname];
joeverbout 0:ea44dc9ed014 3050 Ptr<_Tp> obj = _Tp::create();
joeverbout 0:ea44dc9ed014 3051 obj->read(fn);
joeverbout 0:ea44dc9ed014 3052 return !obj->empty() ? obj : Ptr<_Tp>();
joeverbout 0:ea44dc9ed014 3053 }
joeverbout 0:ea44dc9ed014 3054
joeverbout 0:ea44dc9ed014 3055 /** Saves the algorithm to a file.
joeverbout 0:ea44dc9ed014 3056 In order to make this method work, the derived class must implement Algorithm::write(FileStorage& fs). */
joeverbout 0:ea44dc9ed014 3057 CV_WRAP virtual void save(const String& filename) const;
joeverbout 0:ea44dc9ed014 3058
joeverbout 0:ea44dc9ed014 3059 /** Returns the algorithm string identifier.
joeverbout 0:ea44dc9ed014 3060 This string is used as top level xml/yml node tag when the object is saved to a file or string. */
joeverbout 0:ea44dc9ed014 3061 CV_WRAP virtual String getDefaultName() const;
joeverbout 0:ea44dc9ed014 3062 };
joeverbout 0:ea44dc9ed014 3063
joeverbout 0:ea44dc9ed014 3064 struct Param {
joeverbout 0:ea44dc9ed014 3065 enum { INT=0, BOOLEAN=1, REAL=2, STRING=3, MAT=4, MAT_VECTOR=5, ALGORITHM=6, FLOAT=7,
joeverbout 0:ea44dc9ed014 3066 UNSIGNED_INT=8, UINT64=9, UCHAR=11 };
joeverbout 0:ea44dc9ed014 3067 };
joeverbout 0:ea44dc9ed014 3068
joeverbout 0:ea44dc9ed014 3069
joeverbout 0:ea44dc9ed014 3070
joeverbout 0:ea44dc9ed014 3071 template<> struct ParamType<bool>
joeverbout 0:ea44dc9ed014 3072 {
joeverbout 0:ea44dc9ed014 3073 typedef bool const_param_type;
joeverbout 0:ea44dc9ed014 3074 typedef bool member_type;
joeverbout 0:ea44dc9ed014 3075
joeverbout 0:ea44dc9ed014 3076 enum { type = Param::BOOLEAN };
joeverbout 0:ea44dc9ed014 3077 };
joeverbout 0:ea44dc9ed014 3078
joeverbout 0:ea44dc9ed014 3079 template<> struct ParamType<int>
joeverbout 0:ea44dc9ed014 3080 {
joeverbout 0:ea44dc9ed014 3081 typedef int const_param_type;
joeverbout 0:ea44dc9ed014 3082 typedef int member_type;
joeverbout 0:ea44dc9ed014 3083
joeverbout 0:ea44dc9ed014 3084 enum { type = Param::INT };
joeverbout 0:ea44dc9ed014 3085 };
joeverbout 0:ea44dc9ed014 3086
joeverbout 0:ea44dc9ed014 3087 template<> struct ParamType<double>
joeverbout 0:ea44dc9ed014 3088 {
joeverbout 0:ea44dc9ed014 3089 typedef double const_param_type;
joeverbout 0:ea44dc9ed014 3090 typedef double member_type;
joeverbout 0:ea44dc9ed014 3091
joeverbout 0:ea44dc9ed014 3092 enum { type = Param::REAL };
joeverbout 0:ea44dc9ed014 3093 };
joeverbout 0:ea44dc9ed014 3094
joeverbout 0:ea44dc9ed014 3095 template<> struct ParamType<String>
joeverbout 0:ea44dc9ed014 3096 {
joeverbout 0:ea44dc9ed014 3097 typedef const String& const_param_type;
joeverbout 0:ea44dc9ed014 3098 typedef String member_type;
joeverbout 0:ea44dc9ed014 3099
joeverbout 0:ea44dc9ed014 3100 enum { type = Param::STRING };
joeverbout 0:ea44dc9ed014 3101 };
joeverbout 0:ea44dc9ed014 3102
joeverbout 0:ea44dc9ed014 3103 template<> struct ParamType<Mat>
joeverbout 0:ea44dc9ed014 3104 {
joeverbout 0:ea44dc9ed014 3105 typedef const Mat& const_param_type;
joeverbout 0:ea44dc9ed014 3106 typedef Mat member_type;
joeverbout 0:ea44dc9ed014 3107
joeverbout 0:ea44dc9ed014 3108 enum { type = Param::MAT };
joeverbout 0:ea44dc9ed014 3109 };
joeverbout 0:ea44dc9ed014 3110
joeverbout 0:ea44dc9ed014 3111 template<> struct ParamType<std::vector<Mat> >
joeverbout 0:ea44dc9ed014 3112 {
joeverbout 0:ea44dc9ed014 3113 typedef const std::vector<Mat>& const_param_type;
joeverbout 0:ea44dc9ed014 3114 typedef std::vector<Mat> member_type;
joeverbout 0:ea44dc9ed014 3115
joeverbout 0:ea44dc9ed014 3116 enum { type = Param::MAT_VECTOR };
joeverbout 0:ea44dc9ed014 3117 };
joeverbout 0:ea44dc9ed014 3118
joeverbout 0:ea44dc9ed014 3119 template<> struct ParamType<Algorithm>
joeverbout 0:ea44dc9ed014 3120 {
joeverbout 0:ea44dc9ed014 3121 typedef const Ptr<Algorithm>& const_param_type;
joeverbout 0:ea44dc9ed014 3122 typedef Ptr<Algorithm> member_type;
joeverbout 0:ea44dc9ed014 3123
joeverbout 0:ea44dc9ed014 3124 enum { type = Param::ALGORITHM };
joeverbout 0:ea44dc9ed014 3125 };
joeverbout 0:ea44dc9ed014 3126
joeverbout 0:ea44dc9ed014 3127 template<> struct ParamType<float>
joeverbout 0:ea44dc9ed014 3128 {
joeverbout 0:ea44dc9ed014 3129 typedef float const_param_type;
joeverbout 0:ea44dc9ed014 3130 typedef float member_type;
joeverbout 0:ea44dc9ed014 3131
joeverbout 0:ea44dc9ed014 3132 enum { type = Param::FLOAT };
joeverbout 0:ea44dc9ed014 3133 };
joeverbout 0:ea44dc9ed014 3134
joeverbout 0:ea44dc9ed014 3135 template<> struct ParamType<unsigned>
joeverbout 0:ea44dc9ed014 3136 {
joeverbout 0:ea44dc9ed014 3137 typedef unsigned const_param_type;
joeverbout 0:ea44dc9ed014 3138 typedef unsigned member_type;
joeverbout 0:ea44dc9ed014 3139
joeverbout 0:ea44dc9ed014 3140 enum { type = Param::UNSIGNED_INT };
joeverbout 0:ea44dc9ed014 3141 };
joeverbout 0:ea44dc9ed014 3142
joeverbout 0:ea44dc9ed014 3143 template<> struct ParamType<uint64>
joeverbout 0:ea44dc9ed014 3144 {
joeverbout 0:ea44dc9ed014 3145 typedef uint64 const_param_type;
joeverbout 0:ea44dc9ed014 3146 typedef uint64 member_type;
joeverbout 0:ea44dc9ed014 3147
joeverbout 0:ea44dc9ed014 3148 enum { type = Param::UINT64 };
joeverbout 0:ea44dc9ed014 3149 };
joeverbout 0:ea44dc9ed014 3150
joeverbout 0:ea44dc9ed014 3151 template<> struct ParamType<uchar>
joeverbout 0:ea44dc9ed014 3152 {
joeverbout 0:ea44dc9ed014 3153 typedef uchar const_param_type;
joeverbout 0:ea44dc9ed014 3154 typedef uchar member_type;
joeverbout 0:ea44dc9ed014 3155
joeverbout 0:ea44dc9ed014 3156 enum { type = Param::UCHAR };
joeverbout 0:ea44dc9ed014 3157 };
joeverbout 0:ea44dc9ed014 3158
joeverbout 0:ea44dc9ed014 3159 //! @} core_basic
joeverbout 0:ea44dc9ed014 3160
joeverbout 0:ea44dc9ed014 3161 } //namespace cv
joeverbout 0:ea44dc9ed014 3162
joeverbout 0:ea44dc9ed014 3163 #include "opencv2/core/operations.hpp"
joeverbout 0:ea44dc9ed014 3164 #include "opencv2/core/cvstd.inl.hpp"
joeverbout 0:ea44dc9ed014 3165 #include "opencv2/core/utility.hpp"
joeverbout 0:ea44dc9ed014 3166 #include "opencv2/core/optim.hpp"
joeverbout 0:ea44dc9ed014 3167
joeverbout 0:ea44dc9ed014 3168 #endif /*__OPENCV_CORE_HPP__*/
joeverbout 0:ea44dc9ed014 3169