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-2008, Intel Corporation, all rights reserved.
joeverbout 0:ea44dc9ed014 14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
joeverbout 0:ea44dc9ed014 15 // Copyright (C) 2013, OpenCV Foundation, all rights reserved.
joeverbout 0:ea44dc9ed014 16 // Copyright (C) 2014, 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_BASE_HPP__
joeverbout 0:ea44dc9ed014 46 #define __OPENCV_CORE_BASE_HPP__
joeverbout 0:ea44dc9ed014 47
joeverbout 0:ea44dc9ed014 48 #ifndef __cplusplus
joeverbout 0:ea44dc9ed014 49 # error base.hpp header must be compiled as C++
joeverbout 0:ea44dc9ed014 50 #endif
joeverbout 0:ea44dc9ed014 51
joeverbout 0:ea44dc9ed014 52 #include <climits>
joeverbout 0:ea44dc9ed014 53 #include <algorithm>
joeverbout 0:ea44dc9ed014 54
joeverbout 0:ea44dc9ed014 55 #include "opencv2/core/cvdef.h"
joeverbout 0:ea44dc9ed014 56 #include "opencv2/core/cvstd.hpp"
joeverbout 0:ea44dc9ed014 57
joeverbout 0:ea44dc9ed014 58 namespace cv
joeverbout 0:ea44dc9ed014 59 {
joeverbout 0:ea44dc9ed014 60
joeverbout 0:ea44dc9ed014 61 //! @addtogroup core_utils
joeverbout 0:ea44dc9ed014 62 //! @{
joeverbout 0:ea44dc9ed014 63
joeverbout 0:ea44dc9ed014 64 namespace Error {
joeverbout 0:ea44dc9ed014 65 //! error codes
joeverbout 0:ea44dc9ed014 66 enum Code {
joeverbout 0:ea44dc9ed014 67 StsOk= 0, //!< everithing is ok
joeverbout 0:ea44dc9ed014 68 StsBackTrace= -1, //!< pseudo error for back trace
joeverbout 0:ea44dc9ed014 69 StsError= -2, //!< unknown /unspecified error
joeverbout 0:ea44dc9ed014 70 StsInternal= -3, //!< internal error (bad state)
joeverbout 0:ea44dc9ed014 71 StsNoMem= -4, //!< insufficient memory
joeverbout 0:ea44dc9ed014 72 StsBadArg= -5, //!< function arg/param is bad
joeverbout 0:ea44dc9ed014 73 StsBadFunc= -6, //!< unsupported function
joeverbout 0:ea44dc9ed014 74 StsNoConv= -7, //!< iter. didn't converge
joeverbout 0:ea44dc9ed014 75 StsAutoTrace= -8, //!< tracing
joeverbout 0:ea44dc9ed014 76 HeaderIsNull= -9, //!< image header is NULL
joeverbout 0:ea44dc9ed014 77 BadImageSize= -10, //!< image size is invalid
joeverbout 0:ea44dc9ed014 78 BadOffset= -11, //!< offset is invalid
joeverbout 0:ea44dc9ed014 79 BadDataPtr= -12, //!<
joeverbout 0:ea44dc9ed014 80 BadStep= -13, //!<
joeverbout 0:ea44dc9ed014 81 BadModelOrChSeq= -14, //!<
joeverbout 0:ea44dc9ed014 82 BadNumChannels= -15, //!<
joeverbout 0:ea44dc9ed014 83 BadNumChannel1U= -16, //!<
joeverbout 0:ea44dc9ed014 84 BadDepth= -17, //!<
joeverbout 0:ea44dc9ed014 85 BadAlphaChannel= -18, //!<
joeverbout 0:ea44dc9ed014 86 BadOrder= -19, //!<
joeverbout 0:ea44dc9ed014 87 BadOrigin= -20, //!<
joeverbout 0:ea44dc9ed014 88 BadAlign= -21, //!<
joeverbout 0:ea44dc9ed014 89 BadCallBack= -22, //!<
joeverbout 0:ea44dc9ed014 90 BadTileSize= -23, //!<
joeverbout 0:ea44dc9ed014 91 BadCOI= -24, //!<
joeverbout 0:ea44dc9ed014 92 BadROISize= -25, //!<
joeverbout 0:ea44dc9ed014 93 MaskIsTiled= -26, //!<
joeverbout 0:ea44dc9ed014 94 StsNullPtr= -27, //!< null pointer
joeverbout 0:ea44dc9ed014 95 StsVecLengthErr= -28, //!< incorrect vector length
joeverbout 0:ea44dc9ed014 96 StsFilterStructContentErr= -29, //!< incorr. filter structure content
joeverbout 0:ea44dc9ed014 97 StsKernelStructContentErr= -30, //!< incorr. transform kernel content
joeverbout 0:ea44dc9ed014 98 StsFilterOffsetErr= -31, //!< incorrect filter ofset value
joeverbout 0:ea44dc9ed014 99 StsBadSize= -201, //!< the input/output structure size is incorrect
joeverbout 0:ea44dc9ed014 100 StsDivByZero= -202, //!< division by zero
joeverbout 0:ea44dc9ed014 101 StsInplaceNotSupported= -203, //!< in-place operation is not supported
joeverbout 0:ea44dc9ed014 102 StsObjectNotFound= -204, //!< request can't be completed
joeverbout 0:ea44dc9ed014 103 StsUnmatchedFormats= -205, //!< formats of input/output arrays differ
joeverbout 0:ea44dc9ed014 104 StsBadFlag= -206, //!< flag is wrong or not supported
joeverbout 0:ea44dc9ed014 105 StsBadPoint= -207, //!< bad CvPoint
joeverbout 0:ea44dc9ed014 106 StsBadMask= -208, //!< bad format of mask (neither 8uC1 nor 8sC1)
joeverbout 0:ea44dc9ed014 107 StsUnmatchedSizes= -209, //!< sizes of input/output structures do not match
joeverbout 0:ea44dc9ed014 108 StsUnsupportedFormat= -210, //!< the data format/type is not supported by the function
joeverbout 0:ea44dc9ed014 109 StsOutOfRange= -211, //!< some of parameters are out of range
joeverbout 0:ea44dc9ed014 110 StsParseError= -212, //!< invalid syntax/structure of the parsed file
joeverbout 0:ea44dc9ed014 111 StsNotImplemented= -213, //!< the requested function/feature is not implemented
joeverbout 0:ea44dc9ed014 112 StsBadMemBlock= -214, //!< an allocated block has been corrupted
joeverbout 0:ea44dc9ed014 113 StsAssert= -215, //!< assertion failed
joeverbout 0:ea44dc9ed014 114 GpuNotSupported= -216,
joeverbout 0:ea44dc9ed014 115 GpuApiCallError= -217,
joeverbout 0:ea44dc9ed014 116 OpenGlNotSupported= -218,
joeverbout 0:ea44dc9ed014 117 OpenGlApiCallError= -219,
joeverbout 0:ea44dc9ed014 118 OpenCLApiCallError= -220,
joeverbout 0:ea44dc9ed014 119 OpenCLDoubleNotSupported= -221,
joeverbout 0:ea44dc9ed014 120 OpenCLInitError= -222,
joeverbout 0:ea44dc9ed014 121 OpenCLNoAMDBlasFft= -223
joeverbout 0:ea44dc9ed014 122 };
joeverbout 0:ea44dc9ed014 123 } //Error
joeverbout 0:ea44dc9ed014 124
joeverbout 0:ea44dc9ed014 125 //! @} core_utils
joeverbout 0:ea44dc9ed014 126
joeverbout 0:ea44dc9ed014 127 //! @addtogroup core_array
joeverbout 0:ea44dc9ed014 128 //! @{
joeverbout 0:ea44dc9ed014 129
joeverbout 0:ea44dc9ed014 130 //! matrix decomposition types
joeverbout 0:ea44dc9ed014 131 enum DecompTypes {
joeverbout 0:ea44dc9ed014 132 /** Gaussian elimination with the optimal pivot element chosen. */
joeverbout 0:ea44dc9ed014 133 DECOMP_LU = 0,
joeverbout 0:ea44dc9ed014 134 /** singular value decomposition (SVD) method; the system can be over-defined and/or the matrix
joeverbout 0:ea44dc9ed014 135 src1 can be singular */
joeverbout 0:ea44dc9ed014 136 DECOMP_SVD = 1,
joeverbout 0:ea44dc9ed014 137 /** eigenvalue decomposition; the matrix src1 must be symmetrical */
joeverbout 0:ea44dc9ed014 138 DECOMP_EIG = 2,
joeverbout 0:ea44dc9ed014 139 /** Cholesky \f$LL^T\f$ factorization; the matrix src1 must be symmetrical and positively
joeverbout 0:ea44dc9ed014 140 defined */
joeverbout 0:ea44dc9ed014 141 DECOMP_CHOLESKY = 3,
joeverbout 0:ea44dc9ed014 142 /** QR factorization; the system can be over-defined and/or the matrix src1 can be singular */
joeverbout 0:ea44dc9ed014 143 DECOMP_QR = 4,
joeverbout 0:ea44dc9ed014 144 /** while all the previous flags are mutually exclusive, this flag can be used together with
joeverbout 0:ea44dc9ed014 145 any of the previous; it means that the normal equations
joeverbout 0:ea44dc9ed014 146 \f$\texttt{src1}^T\cdot\texttt{src1}\cdot\texttt{dst}=\texttt{src1}^T\texttt{src2}\f$ are
joeverbout 0:ea44dc9ed014 147 solved instead of the original system
joeverbout 0:ea44dc9ed014 148 \f$\texttt{src1}\cdot\texttt{dst}=\texttt{src2}\f$ */
joeverbout 0:ea44dc9ed014 149 DECOMP_NORMAL = 16
joeverbout 0:ea44dc9ed014 150 };
joeverbout 0:ea44dc9ed014 151
joeverbout 0:ea44dc9ed014 152 /** norm types
joeverbout 0:ea44dc9ed014 153 - For one array:
joeverbout 0:ea44dc9ed014 154 \f[norm = \forkthree{\|\texttt{src1}\|_{L_{\infty}} = \max _I | \texttt{src1} (I)|}{if \(\texttt{normType} = \texttt{NORM_INF}\) }
joeverbout 0:ea44dc9ed014 155 { \| \texttt{src1} \| _{L_1} = \sum _I | \texttt{src1} (I)|}{if \(\texttt{normType} = \texttt{NORM_L1}\) }
joeverbout 0:ea44dc9ed014 156 { \| \texttt{src1} \| _{L_2} = \sqrt{\sum_I \texttt{src1}(I)^2} }{if \(\texttt{normType} = \texttt{NORM_L2}\) }\f]
joeverbout 0:ea44dc9ed014 157
joeverbout 0:ea44dc9ed014 158 - Absolute norm for two arrays
joeverbout 0:ea44dc9ed014 159 \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 160 { \| \texttt{src1} - \texttt{src2} \| _{L_1} = \sum _I | \texttt{src1} (I) - \texttt{src2} (I)|}{if \(\texttt{normType} = \texttt{NORM_L1}\) }
joeverbout 0:ea44dc9ed014 161 { \| \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 162
joeverbout 0:ea44dc9ed014 163 - Relative norm for two arrays
joeverbout 0:ea44dc9ed014 164 \f[norm = \forkthree{\frac{\|\texttt{src1}-\texttt{src2}\|_{L_{\infty}} }{\|\texttt{src2}\|_{L_{\infty}} }}{if \(\texttt{normType} = \texttt{NORM_RELATIVE_INF}\) }
joeverbout 0:ea44dc9ed014 165 { \frac{\|\texttt{src1}-\texttt{src2}\|_{L_1} }{\|\texttt{src2}\|_{L_1}} }{if \(\texttt{normType} = \texttt{NORM_RELATIVE_L1}\) }
joeverbout 0:ea44dc9ed014 166 { \frac{\|\texttt{src1}-\texttt{src2}\|_{L_2} }{\|\texttt{src2}\|_{L_2}} }{if \(\texttt{normType} = \texttt{NORM_RELATIVE_L2}\) }\f]
joeverbout 0:ea44dc9ed014 167
joeverbout 0:ea44dc9ed014 168 As example for one array consider the function \f$r(x)= \begin{pmatrix} x \\ 1-x \end{pmatrix}, x \in [-1;1]\f$.
joeverbout 0:ea44dc9ed014 169 The \f$ L_{1}, L_{2} \f$ and \f$ L_{\infty} \f$ norm for the sample value \f$r(-1) = \begin{pmatrix} -1 \\ 2 \end{pmatrix}\f$
joeverbout 0:ea44dc9ed014 170 is calculated as follows
joeverbout 0:ea44dc9ed014 171 \f{align*}
joeverbout 0:ea44dc9ed014 172 \| r(-1) \|_{L_1} &= |-1| + |2| = 3 \\
joeverbout 0:ea44dc9ed014 173 \| r(-1) \|_{L_2} &= \sqrt{(-1)^{2} + (2)^{2}} = \sqrt{5} \\
joeverbout 0:ea44dc9ed014 174 \| r(-1) \|_{L_\infty} &= \max(|-1|,|2|) = 2
joeverbout 0:ea44dc9ed014 175 \f}
joeverbout 0:ea44dc9ed014 176 and for \f$r(0.5) = \begin{pmatrix} 0.5 \\ 0.5 \end{pmatrix}\f$ the calculation is
joeverbout 0:ea44dc9ed014 177 \f{align*}
joeverbout 0:ea44dc9ed014 178 \| r(0.5) \|_{L_1} &= |0.5| + |0.5| = 1 \\
joeverbout 0:ea44dc9ed014 179 \| r(0.5) \|_{L_2} &= \sqrt{(0.5)^{2} + (0.5)^{2}} = \sqrt{0.5} \\
joeverbout 0:ea44dc9ed014 180 \| r(0.5) \|_{L_\infty} &= \max(|0.5|,|0.5|) = 0.5.
joeverbout 0:ea44dc9ed014 181 \f}
joeverbout 0:ea44dc9ed014 182 The following graphic shows all values for the three norm functions \f$\| r(x) \|_{L_1}, \| r(x) \|_{L_2}\f$ and \f$\| r(x) \|_{L_\infty}\f$.
joeverbout 0:ea44dc9ed014 183 It is notable that the \f$ L_{1} \f$ norm forms the upper and the \f$ L_{\infty} \f$ norm forms the lower border for the example function \f$ r(x) \f$.
joeverbout 0:ea44dc9ed014 184 ![Graphs for the different norm functions from the above example](pics/NormTypes_OneArray_1-2-INF.png)
joeverbout 0:ea44dc9ed014 185 */
joeverbout 0:ea44dc9ed014 186 enum NormTypes { NORM_INF = 1,
joeverbout 0:ea44dc9ed014 187 NORM_L1 = 2,
joeverbout 0:ea44dc9ed014 188 NORM_L2 = 4,
joeverbout 0:ea44dc9ed014 189 NORM_L2SQR = 5,
joeverbout 0:ea44dc9ed014 190 NORM_HAMMING = 6,
joeverbout 0:ea44dc9ed014 191 NORM_HAMMING2 = 7,
joeverbout 0:ea44dc9ed014 192 NORM_TYPE_MASK = 7,
joeverbout 0:ea44dc9ed014 193 NORM_RELATIVE = 8, //!< flag
joeverbout 0:ea44dc9ed014 194 NORM_MINMAX = 32 //!< flag
joeverbout 0:ea44dc9ed014 195 };
joeverbout 0:ea44dc9ed014 196
joeverbout 0:ea44dc9ed014 197 //! comparison types
joeverbout 0:ea44dc9ed014 198 enum CmpTypes { CMP_EQ = 0, //!< src1 is equal to src2.
joeverbout 0:ea44dc9ed014 199 CMP_GT = 1, //!< src1 is greater than src2.
joeverbout 0:ea44dc9ed014 200 CMP_GE = 2, //!< src1 is greater than or equal to src2.
joeverbout 0:ea44dc9ed014 201 CMP_LT = 3, //!< src1 is less than src2.
joeverbout 0:ea44dc9ed014 202 CMP_LE = 4, //!< src1 is less than or equal to src2.
joeverbout 0:ea44dc9ed014 203 CMP_NE = 5 //!< src1 is unequal to src2.
joeverbout 0:ea44dc9ed014 204 };
joeverbout 0:ea44dc9ed014 205
joeverbout 0:ea44dc9ed014 206 //! generalized matrix multiplication flags
joeverbout 0:ea44dc9ed014 207 enum GemmFlags { GEMM_1_T = 1, //!< transposes src1
joeverbout 0:ea44dc9ed014 208 GEMM_2_T = 2, //!< transposes src2
joeverbout 0:ea44dc9ed014 209 GEMM_3_T = 4 //!< transposes src3
joeverbout 0:ea44dc9ed014 210 };
joeverbout 0:ea44dc9ed014 211
joeverbout 0:ea44dc9ed014 212 enum DftFlags {
joeverbout 0:ea44dc9ed014 213 /** performs an inverse 1D or 2D transform instead of the default forward
joeverbout 0:ea44dc9ed014 214 transform. */
joeverbout 0:ea44dc9ed014 215 DFT_INVERSE = 1,
joeverbout 0:ea44dc9ed014 216 /** scales the result: divide it by the number of array elements. Normally, it is
joeverbout 0:ea44dc9ed014 217 combined with DFT_INVERSE. */
joeverbout 0:ea44dc9ed014 218 DFT_SCALE = 2,
joeverbout 0:ea44dc9ed014 219 /** performs a forward or inverse transform of every individual row of the input
joeverbout 0:ea44dc9ed014 220 matrix; this flag enables you to transform multiple vectors simultaneously and can be used to
joeverbout 0:ea44dc9ed014 221 decrease the overhead (which is sometimes several times larger than the processing itself) to
joeverbout 0:ea44dc9ed014 222 perform 3D and higher-dimensional transformations and so forth.*/
joeverbout 0:ea44dc9ed014 223 DFT_ROWS = 4,
joeverbout 0:ea44dc9ed014 224 /** performs a forward transformation of 1D or 2D real array; the result,
joeverbout 0:ea44dc9ed014 225 though being a complex array, has complex-conjugate symmetry (*CCS*, see the function
joeverbout 0:ea44dc9ed014 226 description below for details), and such an array can be packed into a real array of the same
joeverbout 0:ea44dc9ed014 227 size as input, which is the fastest option and which is what the function does by default;
joeverbout 0:ea44dc9ed014 228 however, you may wish to get a full complex array (for simpler spectrum analysis, and so on) -
joeverbout 0:ea44dc9ed014 229 pass the flag to enable the function to produce a full-size complex output array. */
joeverbout 0:ea44dc9ed014 230 DFT_COMPLEX_OUTPUT = 16,
joeverbout 0:ea44dc9ed014 231 /** performs an inverse transformation of a 1D or 2D complex array; the
joeverbout 0:ea44dc9ed014 232 result is normally a complex array of the same size, however, if the input array has
joeverbout 0:ea44dc9ed014 233 conjugate-complex symmetry (for example, it is a result of forward transformation with
joeverbout 0:ea44dc9ed014 234 DFT_COMPLEX_OUTPUT flag), the output is a real array; while the function itself does not
joeverbout 0:ea44dc9ed014 235 check whether the input is symmetrical or not, you can pass the flag and then the function
joeverbout 0:ea44dc9ed014 236 will assume the symmetry and produce the real output array (note that when the input is packed
joeverbout 0:ea44dc9ed014 237 into a real array and inverse transformation is executed, the function treats the input as a
joeverbout 0:ea44dc9ed014 238 packed complex-conjugate symmetrical array, and the output will also be a real array). */
joeverbout 0:ea44dc9ed014 239 DFT_REAL_OUTPUT = 32,
joeverbout 0:ea44dc9ed014 240 /** performs an inverse 1D or 2D transform instead of the default forward transform. */
joeverbout 0:ea44dc9ed014 241 DCT_INVERSE = DFT_INVERSE,
joeverbout 0:ea44dc9ed014 242 /** performs a forward or inverse transform of every individual row of the input
joeverbout 0:ea44dc9ed014 243 matrix. This flag enables you to transform multiple vectors simultaneously and can be used to
joeverbout 0:ea44dc9ed014 244 decrease the overhead (which is sometimes several times larger than the processing itself) to
joeverbout 0:ea44dc9ed014 245 perform 3D and higher-dimensional transforms and so forth.*/
joeverbout 0:ea44dc9ed014 246 DCT_ROWS = DFT_ROWS
joeverbout 0:ea44dc9ed014 247 };
joeverbout 0:ea44dc9ed014 248
joeverbout 0:ea44dc9ed014 249 //! Various border types, image boundaries are denoted with `|`
joeverbout 0:ea44dc9ed014 250 //! @see borderInterpolate, copyMakeBorder
joeverbout 0:ea44dc9ed014 251 enum BorderTypes {
joeverbout 0:ea44dc9ed014 252 BORDER_CONSTANT = 0, //!< `iiiiii|abcdefgh|iiiiiii` with some specified `i`
joeverbout 0:ea44dc9ed014 253 BORDER_REPLICATE = 1, //!< `aaaaaa|abcdefgh|hhhhhhh`
joeverbout 0:ea44dc9ed014 254 BORDER_REFLECT = 2, //!< `fedcba|abcdefgh|hgfedcb`
joeverbout 0:ea44dc9ed014 255 BORDER_WRAP = 3, //!< `cdefgh|abcdefgh|abcdefg`
joeverbout 0:ea44dc9ed014 256 BORDER_REFLECT_101 = 4, //!< `gfedcb|abcdefgh|gfedcba`
joeverbout 0:ea44dc9ed014 257 BORDER_TRANSPARENT = 5, //!< `uvwxyz|absdefgh|ijklmno`
joeverbout 0:ea44dc9ed014 258
joeverbout 0:ea44dc9ed014 259 BORDER_REFLECT101 = BORDER_REFLECT_101, //!< same as BORDER_REFLECT_101
joeverbout 0:ea44dc9ed014 260 BORDER_DEFAULT = BORDER_REFLECT_101, //!< same as BORDER_REFLECT_101
joeverbout 0:ea44dc9ed014 261 BORDER_ISOLATED = 16 //!< do not look outside of ROI
joeverbout 0:ea44dc9ed014 262 };
joeverbout 0:ea44dc9ed014 263
joeverbout 0:ea44dc9ed014 264 //! @} core_array
joeverbout 0:ea44dc9ed014 265
joeverbout 0:ea44dc9ed014 266 //! @addtogroup core_utils
joeverbout 0:ea44dc9ed014 267 //! @{
joeverbout 0:ea44dc9ed014 268
joeverbout 0:ea44dc9ed014 269 //! @cond IGNORED
joeverbout 0:ea44dc9ed014 270
joeverbout 0:ea44dc9ed014 271 //////////////// static assert /////////////////
joeverbout 0:ea44dc9ed014 272 #define CVAUX_CONCAT_EXP(a, b) a##b
joeverbout 0:ea44dc9ed014 273 #define CVAUX_CONCAT(a, b) CVAUX_CONCAT_EXP(a,b)
joeverbout 0:ea44dc9ed014 274
joeverbout 0:ea44dc9ed014 275 #if defined(__clang__)
joeverbout 0:ea44dc9ed014 276 # ifndef __has_extension
joeverbout 0:ea44dc9ed014 277 # define __has_extension __has_feature /* compatibility, for older versions of clang */
joeverbout 0:ea44dc9ed014 278 # endif
joeverbout 0:ea44dc9ed014 279 # if __has_extension(cxx_static_assert)
joeverbout 0:ea44dc9ed014 280 # define CV_StaticAssert(condition, reason) static_assert((condition), reason " " #condition)
joeverbout 0:ea44dc9ed014 281 # elif __has_extension(c_static_assert)
joeverbout 0:ea44dc9ed014 282 # define CV_StaticAssert(condition, reason) _Static_assert((condition), reason " " #condition)
joeverbout 0:ea44dc9ed014 283 # endif
joeverbout 0:ea44dc9ed014 284 #elif defined(__GNUC__)
joeverbout 0:ea44dc9ed014 285 # if (defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L)
joeverbout 0:ea44dc9ed014 286 # define CV_StaticAssert(condition, reason) static_assert((condition), reason " " #condition)
joeverbout 0:ea44dc9ed014 287 # endif
joeverbout 0:ea44dc9ed014 288 #elif defined(_MSC_VER)
joeverbout 0:ea44dc9ed014 289 # if _MSC_VER >= 1600 /* MSVC 10 */
joeverbout 0:ea44dc9ed014 290 # define CV_StaticAssert(condition, reason) static_assert((condition), reason " " #condition)
joeverbout 0:ea44dc9ed014 291 # endif
joeverbout 0:ea44dc9ed014 292 #endif
joeverbout 0:ea44dc9ed014 293 #ifndef CV_StaticAssert
joeverbout 0:ea44dc9ed014 294 # if !defined(__clang__) && defined(__GNUC__) && (__GNUC__*100 + __GNUC_MINOR__ > 302)
joeverbout 0:ea44dc9ed014 295 # define CV_StaticAssert(condition, reason) ({ extern int __attribute__((error("CV_StaticAssert: " reason " " #condition))) CV_StaticAssert(); ((condition) ? 0 : CV_StaticAssert()); })
joeverbout 0:ea44dc9ed014 296 # else
joeverbout 0:ea44dc9ed014 297 template <bool x> struct CV_StaticAssert_failed;
joeverbout 0:ea44dc9ed014 298 template <> struct CV_StaticAssert_failed<true> { enum { val = 1 }; };
joeverbout 0:ea44dc9ed014 299 template<int x> struct CV_StaticAssert_test {};
joeverbout 0:ea44dc9ed014 300 # define CV_StaticAssert(condition, reason)\
joeverbout 0:ea44dc9ed014 301 typedef cv::CV_StaticAssert_test< sizeof(cv::CV_StaticAssert_failed< static_cast<bool>(condition) >) > CVAUX_CONCAT(CV_StaticAssert_failed_at_, __LINE__)
joeverbout 0:ea44dc9ed014 302 # endif
joeverbout 0:ea44dc9ed014 303 #endif
joeverbout 0:ea44dc9ed014 304
joeverbout 0:ea44dc9ed014 305 // Suppress warning "-Wdeprecated-declarations" / C4996
joeverbout 0:ea44dc9ed014 306 #if defined(_MSC_VER)
joeverbout 0:ea44dc9ed014 307 #define CV_DO_PRAGMA(x) __pragma(x)
joeverbout 0:ea44dc9ed014 308 #elif defined(__GNUC__)
joeverbout 0:ea44dc9ed014 309 #define CV_DO_PRAGMA(x) _Pragma (#x)
joeverbout 0:ea44dc9ed014 310 #else
joeverbout 0:ea44dc9ed014 311 #define CV_DO_PRAGMA(x)
joeverbout 0:ea44dc9ed014 312 #endif
joeverbout 0:ea44dc9ed014 313
joeverbout 0:ea44dc9ed014 314 #ifdef _MSC_VER
joeverbout 0:ea44dc9ed014 315 #define CV_SUPPRESS_DEPRECATED_START \
joeverbout 0:ea44dc9ed014 316 CV_DO_PRAGMA(warning(push)) \
joeverbout 0:ea44dc9ed014 317 CV_DO_PRAGMA(warning(disable: 4996))
joeverbout 0:ea44dc9ed014 318 #define CV_SUPPRESS_DEPRECATED_END CV_DO_PRAGMA(warning(pop))
joeverbout 0:ea44dc9ed014 319 #elif defined (__clang__) || ((__GNUC__) && (__GNUC__*100 + __GNUC_MINOR__ > 405))
joeverbout 0:ea44dc9ed014 320 #define CV_SUPPRESS_DEPRECATED_START \
joeverbout 0:ea44dc9ed014 321 CV_DO_PRAGMA(GCC diagnostic push) \
joeverbout 0:ea44dc9ed014 322 CV_DO_PRAGMA(GCC diagnostic ignored "-Wdeprecated-declarations")
joeverbout 0:ea44dc9ed014 323 #define CV_SUPPRESS_DEPRECATED_END CV_DO_PRAGMA(GCC diagnostic pop)
joeverbout 0:ea44dc9ed014 324 #else
joeverbout 0:ea44dc9ed014 325 #define CV_SUPPRESS_DEPRECATED_START
joeverbout 0:ea44dc9ed014 326 #define CV_SUPPRESS_DEPRECATED_END
joeverbout 0:ea44dc9ed014 327 #endif
joeverbout 0:ea44dc9ed014 328 #define CV_UNUSED(name) (void)name
joeverbout 0:ea44dc9ed014 329 //! @endcond
joeverbout 0:ea44dc9ed014 330
joeverbout 0:ea44dc9ed014 331 /*! @brief Signals an error and raises the exception.
joeverbout 0:ea44dc9ed014 332
joeverbout 0:ea44dc9ed014 333 By default the function prints information about the error to stderr,
joeverbout 0:ea44dc9ed014 334 then it either stops if setBreakOnError() had been called before or raises the exception.
joeverbout 0:ea44dc9ed014 335 It is possible to alternate error processing by using redirectError().
joeverbout 0:ea44dc9ed014 336 @param _code - error code (Error::Code)
joeverbout 0:ea44dc9ed014 337 @param _err - error description
joeverbout 0:ea44dc9ed014 338 @param _func - function name. Available only when the compiler supports getting it
joeverbout 0:ea44dc9ed014 339 @param _file - source file name where the error has occured
joeverbout 0:ea44dc9ed014 340 @param _line - line number in the source file where the error has occured
joeverbout 0:ea44dc9ed014 341 @see CV_Error, CV_Error_, CV_ErrorNoReturn, CV_ErrorNoReturn_, CV_Assert, CV_DbgAssert
joeverbout 0:ea44dc9ed014 342 */
joeverbout 0:ea44dc9ed014 343 CV_EXPORTS void error(int _code, const String& _err, const char* _func, const char* _file, int _line);
joeverbout 0:ea44dc9ed014 344
joeverbout 0:ea44dc9ed014 345 #ifdef __GNUC__
joeverbout 0:ea44dc9ed014 346 # if defined __clang__ || defined __APPLE__
joeverbout 0:ea44dc9ed014 347 # pragma GCC diagnostic push
joeverbout 0:ea44dc9ed014 348 # pragma GCC diagnostic ignored "-Winvalid-noreturn"
joeverbout 0:ea44dc9ed014 349 # endif
joeverbout 0:ea44dc9ed014 350 #endif
joeverbout 0:ea44dc9ed014 351
joeverbout 0:ea44dc9ed014 352 /** same as cv::error, but does not return */
joeverbout 0:ea44dc9ed014 353 CV_INLINE CV_NORETURN void errorNoReturn(int _code, const String& _err, const char* _func, const char* _file, int _line)
joeverbout 0:ea44dc9ed014 354 {
joeverbout 0:ea44dc9ed014 355 error(_code, _err, _func, _file, _line);
joeverbout 0:ea44dc9ed014 356 #ifdef __GNUC__
joeverbout 0:ea44dc9ed014 357 # if !defined __clang__ && !defined __APPLE__
joeverbout 0:ea44dc9ed014 358 // this suppresses this warning: "noreturn" function does return [enabled by default]
joeverbout 0:ea44dc9ed014 359 __builtin_trap();
joeverbout 0:ea44dc9ed014 360 // or use infinite loop: for (;;) {}
joeverbout 0:ea44dc9ed014 361 # endif
joeverbout 0:ea44dc9ed014 362 #endif
joeverbout 0:ea44dc9ed014 363 }
joeverbout 0:ea44dc9ed014 364 #ifdef __GNUC__
joeverbout 0:ea44dc9ed014 365 # if defined __clang__ || defined __APPLE__
joeverbout 0:ea44dc9ed014 366 # pragma GCC diagnostic pop
joeverbout 0:ea44dc9ed014 367 # endif
joeverbout 0:ea44dc9ed014 368 #endif
joeverbout 0:ea44dc9ed014 369
joeverbout 0:ea44dc9ed014 370 #if defined __GNUC__
joeverbout 0:ea44dc9ed014 371 #define CV_Func __func__
joeverbout 0:ea44dc9ed014 372 #elif defined _MSC_VER
joeverbout 0:ea44dc9ed014 373 #define CV_Func __FUNCTION__
joeverbout 0:ea44dc9ed014 374 #else
joeverbout 0:ea44dc9ed014 375 #define CV_Func ""
joeverbout 0:ea44dc9ed014 376 #endif
joeverbout 0:ea44dc9ed014 377
joeverbout 0:ea44dc9ed014 378 /** @brief Call the error handler.
joeverbout 0:ea44dc9ed014 379
joeverbout 0:ea44dc9ed014 380 Currently, the error handler prints the error code and the error message to the standard
joeverbout 0:ea44dc9ed014 381 error stream `stderr`. In the Debug configuration, it then provokes memory access violation, so that
joeverbout 0:ea44dc9ed014 382 the execution stack and all the parameters can be analyzed by the debugger. In the Release
joeverbout 0:ea44dc9ed014 383 configuration, the exception is thrown.
joeverbout 0:ea44dc9ed014 384
joeverbout 0:ea44dc9ed014 385 @param code one of Error::Code
joeverbout 0:ea44dc9ed014 386 @param msg error message
joeverbout 0:ea44dc9ed014 387 */
joeverbout 0:ea44dc9ed014 388 #define CV_Error( code, msg ) cv::error( code, msg, CV_Func, __FILE__, __LINE__ )
joeverbout 0:ea44dc9ed014 389
joeverbout 0:ea44dc9ed014 390 /** @brief Call the error handler.
joeverbout 0:ea44dc9ed014 391
joeverbout 0:ea44dc9ed014 392 This macro can be used to construct an error message on-fly to include some dynamic information,
joeverbout 0:ea44dc9ed014 393 for example:
joeverbout 0:ea44dc9ed014 394 @code
joeverbout 0:ea44dc9ed014 395 // note the extra parentheses around the formatted text message
joeverbout 0:ea44dc9ed014 396 CV_Error_( CV_StsOutOfRange,
joeverbout 0:ea44dc9ed014 397 ("the value at (%d, %d)=%g is out of range", badPt.x, badPt.y, badValue));
joeverbout 0:ea44dc9ed014 398 @endcode
joeverbout 0:ea44dc9ed014 399 @param code one of Error::Code
joeverbout 0:ea44dc9ed014 400 @param args printf-like formatted error message in parentheses
joeverbout 0:ea44dc9ed014 401 */
joeverbout 0:ea44dc9ed014 402 #define CV_Error_( code, args ) cv::error( code, cv::format args, CV_Func, __FILE__, __LINE__ )
joeverbout 0:ea44dc9ed014 403
joeverbout 0:ea44dc9ed014 404 /** @brief Checks a condition at runtime and throws exception if it fails
joeverbout 0:ea44dc9ed014 405
joeverbout 0:ea44dc9ed014 406 The macros CV_Assert (and CV_DbgAssert(expr)) evaluate the specified expression. If it is 0, the macros
joeverbout 0:ea44dc9ed014 407 raise an error (see cv::error). The macro CV_Assert checks the condition in both Debug and Release
joeverbout 0:ea44dc9ed014 408 configurations while CV_DbgAssert is only retained in the Debug configuration.
joeverbout 0:ea44dc9ed014 409 */
joeverbout 0:ea44dc9ed014 410 #define CV_Assert( expr ) if(!!(expr)) ; else cv::error( cv::Error::StsAssert, #expr, CV_Func, __FILE__, __LINE__ )
joeverbout 0:ea44dc9ed014 411
joeverbout 0:ea44dc9ed014 412 /** same as CV_Error(code,msg), but does not return */
joeverbout 0:ea44dc9ed014 413 #define CV_ErrorNoReturn( code, msg ) cv::errorNoReturn( code, msg, CV_Func, __FILE__, __LINE__ )
joeverbout 0:ea44dc9ed014 414
joeverbout 0:ea44dc9ed014 415 /** same as CV_Error_(code,args), but does not return */
joeverbout 0:ea44dc9ed014 416 #define CV_ErrorNoReturn_( code, args ) cv::errorNoReturn( code, cv::format args, CV_Func, __FILE__, __LINE__ )
joeverbout 0:ea44dc9ed014 417
joeverbout 0:ea44dc9ed014 418 /** replaced with CV_Assert(expr) in Debug configuration */
joeverbout 0:ea44dc9ed014 419 #ifdef _DEBUG
joeverbout 0:ea44dc9ed014 420 # define CV_DbgAssert(expr) CV_Assert(expr)
joeverbout 0:ea44dc9ed014 421 #else
joeverbout 0:ea44dc9ed014 422 # define CV_DbgAssert(expr)
joeverbout 0:ea44dc9ed014 423 #endif
joeverbout 0:ea44dc9ed014 424
joeverbout 0:ea44dc9ed014 425 /*
joeverbout 0:ea44dc9ed014 426 * Hamming distance functor - counts the bit differences between two strings - useful for the Brief descriptor
joeverbout 0:ea44dc9ed014 427 * bit count of A exclusive XOR'ed with B
joeverbout 0:ea44dc9ed014 428 */
joeverbout 0:ea44dc9ed014 429 struct CV_EXPORTS Hamming
joeverbout 0:ea44dc9ed014 430 {
joeverbout 0:ea44dc9ed014 431 enum { normType = NORM_HAMMING };
joeverbout 0:ea44dc9ed014 432 typedef unsigned char ValueType;
joeverbout 0:ea44dc9ed014 433 typedef int ResultType;
joeverbout 0:ea44dc9ed014 434
joeverbout 0:ea44dc9ed014 435 /** this will count the bits in a ^ b
joeverbout 0:ea44dc9ed014 436 */
joeverbout 0:ea44dc9ed014 437 ResultType operator()( const unsigned char* a, const unsigned char* b, int size ) const;
joeverbout 0:ea44dc9ed014 438 };
joeverbout 0:ea44dc9ed014 439
joeverbout 0:ea44dc9ed014 440 typedef Hamming HammingLUT;
joeverbout 0:ea44dc9ed014 441
joeverbout 0:ea44dc9ed014 442 /////////////////////////////////// inline norms ////////////////////////////////////
joeverbout 0:ea44dc9ed014 443
joeverbout 0:ea44dc9ed014 444 template<typename _Tp> inline _Tp cv_abs(_Tp x) { return std::abs(x); }
joeverbout 0:ea44dc9ed014 445 inline int cv_abs(uchar x) { return x; }
joeverbout 0:ea44dc9ed014 446 inline int cv_abs(schar x) { return std::abs(x); }
joeverbout 0:ea44dc9ed014 447 inline int cv_abs(ushort x) { return x; }
joeverbout 0:ea44dc9ed014 448 inline int cv_abs(short x) { return std::abs(x); }
joeverbout 0:ea44dc9ed014 449
joeverbout 0:ea44dc9ed014 450 template<typename _Tp, typename _AccTp> static inline
joeverbout 0:ea44dc9ed014 451 _AccTp normL2Sqr(const _Tp* a, int n)
joeverbout 0:ea44dc9ed014 452 {
joeverbout 0:ea44dc9ed014 453 _AccTp s = 0;
joeverbout 0:ea44dc9ed014 454 int i=0;
joeverbout 0:ea44dc9ed014 455 #if CV_ENABLE_UNROLLED
joeverbout 0:ea44dc9ed014 456 for( ; i <= n - 4; i += 4 )
joeverbout 0:ea44dc9ed014 457 {
joeverbout 0:ea44dc9ed014 458 _AccTp v0 = a[i], v1 = a[i+1], v2 = a[i+2], v3 = a[i+3];
joeverbout 0:ea44dc9ed014 459 s += v0*v0 + v1*v1 + v2*v2 + v3*v3;
joeverbout 0:ea44dc9ed014 460 }
joeverbout 0:ea44dc9ed014 461 #endif
joeverbout 0:ea44dc9ed014 462 for( ; i < n; i++ )
joeverbout 0:ea44dc9ed014 463 {
joeverbout 0:ea44dc9ed014 464 _AccTp v = a[i];
joeverbout 0:ea44dc9ed014 465 s += v*v;
joeverbout 0:ea44dc9ed014 466 }
joeverbout 0:ea44dc9ed014 467 return s;
joeverbout 0:ea44dc9ed014 468 }
joeverbout 0:ea44dc9ed014 469
joeverbout 0:ea44dc9ed014 470 template<typename _Tp, typename _AccTp> static inline
joeverbout 0:ea44dc9ed014 471 _AccTp normL1(const _Tp* a, int n)
joeverbout 0:ea44dc9ed014 472 {
joeverbout 0:ea44dc9ed014 473 _AccTp s = 0;
joeverbout 0:ea44dc9ed014 474 int i = 0;
joeverbout 0:ea44dc9ed014 475 #if CV_ENABLE_UNROLLED
joeverbout 0:ea44dc9ed014 476 for(; i <= n - 4; i += 4 )
joeverbout 0:ea44dc9ed014 477 {
joeverbout 0:ea44dc9ed014 478 s += (_AccTp)cv_abs(a[i]) + (_AccTp)cv_abs(a[i+1]) +
joeverbout 0:ea44dc9ed014 479 (_AccTp)cv_abs(a[i+2]) + (_AccTp)cv_abs(a[i+3]);
joeverbout 0:ea44dc9ed014 480 }
joeverbout 0:ea44dc9ed014 481 #endif
joeverbout 0:ea44dc9ed014 482 for( ; i < n; i++ )
joeverbout 0:ea44dc9ed014 483 s += cv_abs(a[i]);
joeverbout 0:ea44dc9ed014 484 return s;
joeverbout 0:ea44dc9ed014 485 }
joeverbout 0:ea44dc9ed014 486
joeverbout 0:ea44dc9ed014 487 template<typename _Tp, typename _AccTp> static inline
joeverbout 0:ea44dc9ed014 488 _AccTp normInf(const _Tp* a, int n)
joeverbout 0:ea44dc9ed014 489 {
joeverbout 0:ea44dc9ed014 490 _AccTp s = 0;
joeverbout 0:ea44dc9ed014 491 for( int i = 0; i < n; i++ )
joeverbout 0:ea44dc9ed014 492 s = std::max(s, (_AccTp)cv_abs(a[i]));
joeverbout 0:ea44dc9ed014 493 return s;
joeverbout 0:ea44dc9ed014 494 }
joeverbout 0:ea44dc9ed014 495
joeverbout 0:ea44dc9ed014 496 template<typename _Tp, typename _AccTp> static inline
joeverbout 0:ea44dc9ed014 497 _AccTp normL2Sqr(const _Tp* a, const _Tp* b, int n)
joeverbout 0:ea44dc9ed014 498 {
joeverbout 0:ea44dc9ed014 499 _AccTp s = 0;
joeverbout 0:ea44dc9ed014 500 int i= 0;
joeverbout 0:ea44dc9ed014 501 #if CV_ENABLE_UNROLLED
joeverbout 0:ea44dc9ed014 502 for(; i <= n - 4; i += 4 )
joeverbout 0:ea44dc9ed014 503 {
joeverbout 0:ea44dc9ed014 504 _AccTp v0 = _AccTp(a[i] - b[i]), v1 = _AccTp(a[i+1] - b[i+1]), v2 = _AccTp(a[i+2] - b[i+2]), v3 = _AccTp(a[i+3] - b[i+3]);
joeverbout 0:ea44dc9ed014 505 s += v0*v0 + v1*v1 + v2*v2 + v3*v3;
joeverbout 0:ea44dc9ed014 506 }
joeverbout 0:ea44dc9ed014 507 #endif
joeverbout 0:ea44dc9ed014 508 for( ; i < n; i++ )
joeverbout 0:ea44dc9ed014 509 {
joeverbout 0:ea44dc9ed014 510 _AccTp v = _AccTp(a[i] - b[i]);
joeverbout 0:ea44dc9ed014 511 s += v*v;
joeverbout 0:ea44dc9ed014 512 }
joeverbout 0:ea44dc9ed014 513 return s;
joeverbout 0:ea44dc9ed014 514 }
joeverbout 0:ea44dc9ed014 515
joeverbout 0:ea44dc9ed014 516 static inline float normL2Sqr(const float* a, const float* b, int n)
joeverbout 0:ea44dc9ed014 517 {
joeverbout 0:ea44dc9ed014 518 float s = 0.f;
joeverbout 0:ea44dc9ed014 519 for( int i = 0; i < n; i++ )
joeverbout 0:ea44dc9ed014 520 {
joeverbout 0:ea44dc9ed014 521 float v = a[i] - b[i];
joeverbout 0:ea44dc9ed014 522 s += v*v;
joeverbout 0:ea44dc9ed014 523 }
joeverbout 0:ea44dc9ed014 524 return s;
joeverbout 0:ea44dc9ed014 525 }
joeverbout 0:ea44dc9ed014 526
joeverbout 0:ea44dc9ed014 527 template<typename _Tp, typename _AccTp> static inline
joeverbout 0:ea44dc9ed014 528 _AccTp normL1(const _Tp* a, const _Tp* b, int n)
joeverbout 0:ea44dc9ed014 529 {
joeverbout 0:ea44dc9ed014 530 _AccTp s = 0;
joeverbout 0:ea44dc9ed014 531 int i= 0;
joeverbout 0:ea44dc9ed014 532 #if CV_ENABLE_UNROLLED
joeverbout 0:ea44dc9ed014 533 for(; i <= n - 4; i += 4 )
joeverbout 0:ea44dc9ed014 534 {
joeverbout 0:ea44dc9ed014 535 _AccTp v0 = _AccTp(a[i] - b[i]), v1 = _AccTp(a[i+1] - b[i+1]), v2 = _AccTp(a[i+2] - b[i+2]), v3 = _AccTp(a[i+3] - b[i+3]);
joeverbout 0:ea44dc9ed014 536 s += std::abs(v0) + std::abs(v1) + std::abs(v2) + std::abs(v3);
joeverbout 0:ea44dc9ed014 537 }
joeverbout 0:ea44dc9ed014 538 #endif
joeverbout 0:ea44dc9ed014 539 for( ; i < n; i++ )
joeverbout 0:ea44dc9ed014 540 {
joeverbout 0:ea44dc9ed014 541 _AccTp v = _AccTp(a[i] - b[i]);
joeverbout 0:ea44dc9ed014 542 s += std::abs(v);
joeverbout 0:ea44dc9ed014 543 }
joeverbout 0:ea44dc9ed014 544 return s;
joeverbout 0:ea44dc9ed014 545 }
joeverbout 0:ea44dc9ed014 546
joeverbout 0:ea44dc9ed014 547 inline float normL1(const float* a, const float* b, int n)
joeverbout 0:ea44dc9ed014 548 {
joeverbout 0:ea44dc9ed014 549 float s = 0.f;
joeverbout 0:ea44dc9ed014 550 for( int i = 0; i < n; i++ )
joeverbout 0:ea44dc9ed014 551 {
joeverbout 0:ea44dc9ed014 552 s += std::abs(a[i] - b[i]);
joeverbout 0:ea44dc9ed014 553 }
joeverbout 0:ea44dc9ed014 554 return s;
joeverbout 0:ea44dc9ed014 555 }
joeverbout 0:ea44dc9ed014 556
joeverbout 0:ea44dc9ed014 557 inline int normL1(const uchar* a, const uchar* b, int n)
joeverbout 0:ea44dc9ed014 558 {
joeverbout 0:ea44dc9ed014 559 int s = 0;
joeverbout 0:ea44dc9ed014 560 for( int i = 0; i < n; i++ )
joeverbout 0:ea44dc9ed014 561 {
joeverbout 0:ea44dc9ed014 562 s += std::abs(a[i] - b[i]);
joeverbout 0:ea44dc9ed014 563 }
joeverbout 0:ea44dc9ed014 564 return s;
joeverbout 0:ea44dc9ed014 565 }
joeverbout 0:ea44dc9ed014 566
joeverbout 0:ea44dc9ed014 567 template<typename _Tp, typename _AccTp> static inline
joeverbout 0:ea44dc9ed014 568 _AccTp normInf(const _Tp* a, const _Tp* b, int n)
joeverbout 0:ea44dc9ed014 569 {
joeverbout 0:ea44dc9ed014 570 _AccTp s = 0;
joeverbout 0:ea44dc9ed014 571 for( int i = 0; i < n; i++ )
joeverbout 0:ea44dc9ed014 572 {
joeverbout 0:ea44dc9ed014 573 _AccTp v0 = a[i] - b[i];
joeverbout 0:ea44dc9ed014 574 s = std::max(s, std::abs(v0));
joeverbout 0:ea44dc9ed014 575 }
joeverbout 0:ea44dc9ed014 576 return s;
joeverbout 0:ea44dc9ed014 577 }
joeverbout 0:ea44dc9ed014 578
joeverbout 0:ea44dc9ed014 579 /** @brief Computes the cube root of an argument.
joeverbout 0:ea44dc9ed014 580
joeverbout 0:ea44dc9ed014 581 The function cubeRoot computes \f$\sqrt[3]{\texttt{val}}\f$. Negative arguments are handled correctly.
joeverbout 0:ea44dc9ed014 582 NaN and Inf are not handled. The accuracy approaches the maximum possible accuracy for
joeverbout 0:ea44dc9ed014 583 single-precision data.
joeverbout 0:ea44dc9ed014 584 @param val A function argument.
joeverbout 0:ea44dc9ed014 585 */
joeverbout 0:ea44dc9ed014 586 CV_EXPORTS_W float cubeRoot(float val);
joeverbout 0:ea44dc9ed014 587
joeverbout 0:ea44dc9ed014 588 /** @brief Calculates the angle of a 2D vector in degrees.
joeverbout 0:ea44dc9ed014 589
joeverbout 0:ea44dc9ed014 590 The function fastAtan2 calculates the full-range angle of an input 2D vector. The angle is measured
joeverbout 0:ea44dc9ed014 591 in degrees and varies from 0 to 360 degrees. The accuracy is about 0.3 degrees.
joeverbout 0:ea44dc9ed014 592 @param x x-coordinate of the vector.
joeverbout 0:ea44dc9ed014 593 @param y y-coordinate of the vector.
joeverbout 0:ea44dc9ed014 594 */
joeverbout 0:ea44dc9ed014 595 CV_EXPORTS_W float fastAtan2(float y, float x);
joeverbout 0:ea44dc9ed014 596
joeverbout 0:ea44dc9ed014 597 /** proxy for hal::LU */
joeverbout 0:ea44dc9ed014 598 CV_EXPORTS int LU(float* A, size_t astep, int m, float* b, size_t bstep, int n);
joeverbout 0:ea44dc9ed014 599 /** proxy for hal::LU */
joeverbout 0:ea44dc9ed014 600 CV_EXPORTS int LU(double* A, size_t astep, int m, double* b, size_t bstep, int n);
joeverbout 0:ea44dc9ed014 601 /** proxy for hal::Cholesky */
joeverbout 0:ea44dc9ed014 602 CV_EXPORTS bool Cholesky(float* A, size_t astep, int m, float* b, size_t bstep, int n);
joeverbout 0:ea44dc9ed014 603 /** proxy for hal::Cholesky */
joeverbout 0:ea44dc9ed014 604 CV_EXPORTS bool Cholesky(double* A, size_t astep, int m, double* b, size_t bstep, int n);
joeverbout 0:ea44dc9ed014 605
joeverbout 0:ea44dc9ed014 606 ////////////////// forward declarations for important OpenCV types //////////////////
joeverbout 0:ea44dc9ed014 607
joeverbout 0:ea44dc9ed014 608 //! @cond IGNORED
joeverbout 0:ea44dc9ed014 609
joeverbout 0:ea44dc9ed014 610 template<typename _Tp, int cn> class Vec;
joeverbout 0:ea44dc9ed014 611 template<typename _Tp, int m, int n> class Matx;
joeverbout 0:ea44dc9ed014 612
joeverbout 0:ea44dc9ed014 613 template<typename _Tp> class Complex;
joeverbout 0:ea44dc9ed014 614 template<typename _Tp> class Point_;
joeverbout 0:ea44dc9ed014 615 template<typename _Tp> class Point3_;
joeverbout 0:ea44dc9ed014 616 template<typename _Tp> class Size_;
joeverbout 0:ea44dc9ed014 617 template<typename _Tp> class Rect_;
joeverbout 0:ea44dc9ed014 618 template<typename _Tp> class Scalar_;
joeverbout 0:ea44dc9ed014 619
joeverbout 0:ea44dc9ed014 620 class CV_EXPORTS RotatedRect;
joeverbout 0:ea44dc9ed014 621 class CV_EXPORTS Range;
joeverbout 0:ea44dc9ed014 622 class CV_EXPORTS TermCriteria;
joeverbout 0:ea44dc9ed014 623 class CV_EXPORTS KeyPoint;
joeverbout 0:ea44dc9ed014 624 class CV_EXPORTS DMatch;
joeverbout 0:ea44dc9ed014 625 class CV_EXPORTS RNG;
joeverbout 0:ea44dc9ed014 626
joeverbout 0:ea44dc9ed014 627 class CV_EXPORTS Mat;
joeverbout 0:ea44dc9ed014 628 class CV_EXPORTS MatExpr;
joeverbout 0:ea44dc9ed014 629
joeverbout 0:ea44dc9ed014 630 class CV_EXPORTS UMat;
joeverbout 0:ea44dc9ed014 631
joeverbout 0:ea44dc9ed014 632 class CV_EXPORTS SparseMat;
joeverbout 0:ea44dc9ed014 633 typedef Mat MatND;
joeverbout 0:ea44dc9ed014 634
joeverbout 0:ea44dc9ed014 635 template<typename _Tp> class Mat_;
joeverbout 0:ea44dc9ed014 636 template<typename _Tp> class SparseMat_;
joeverbout 0:ea44dc9ed014 637
joeverbout 0:ea44dc9ed014 638 class CV_EXPORTS MatConstIterator;
joeverbout 0:ea44dc9ed014 639 class CV_EXPORTS SparseMatIterator;
joeverbout 0:ea44dc9ed014 640 class CV_EXPORTS SparseMatConstIterator;
joeverbout 0:ea44dc9ed014 641 template<typename _Tp> class MatIterator_;
joeverbout 0:ea44dc9ed014 642 template<typename _Tp> class MatConstIterator_;
joeverbout 0:ea44dc9ed014 643 template<typename _Tp> class SparseMatIterator_;
joeverbout 0:ea44dc9ed014 644 template<typename _Tp> class SparseMatConstIterator_;
joeverbout 0:ea44dc9ed014 645
joeverbout 0:ea44dc9ed014 646 namespace ogl
joeverbout 0:ea44dc9ed014 647 {
joeverbout 0:ea44dc9ed014 648 class CV_EXPORTS Buffer;
joeverbout 0:ea44dc9ed014 649 class CV_EXPORTS Texture2D;
joeverbout 0:ea44dc9ed014 650 class CV_EXPORTS Arrays;
joeverbout 0:ea44dc9ed014 651 }
joeverbout 0:ea44dc9ed014 652
joeverbout 0:ea44dc9ed014 653 namespace cuda
joeverbout 0:ea44dc9ed014 654 {
joeverbout 0:ea44dc9ed014 655 class CV_EXPORTS GpuMat;
joeverbout 0:ea44dc9ed014 656 class CV_EXPORTS HostMem;
joeverbout 0:ea44dc9ed014 657 class CV_EXPORTS Stream;
joeverbout 0:ea44dc9ed014 658 class CV_EXPORTS Event;
joeverbout 0:ea44dc9ed014 659 }
joeverbout 0:ea44dc9ed014 660
joeverbout 0:ea44dc9ed014 661 namespace cudev
joeverbout 0:ea44dc9ed014 662 {
joeverbout 0:ea44dc9ed014 663 template <typename _Tp> class GpuMat_;
joeverbout 0:ea44dc9ed014 664 }
joeverbout 0:ea44dc9ed014 665
joeverbout 0:ea44dc9ed014 666 namespace ipp
joeverbout 0:ea44dc9ed014 667 {
joeverbout 0:ea44dc9ed014 668 CV_EXPORTS int getIppFeatures();
joeverbout 0:ea44dc9ed014 669 CV_EXPORTS void setIppStatus(int status, const char * const funcname = NULL, const char * const filename = NULL,
joeverbout 0:ea44dc9ed014 670 int line = 0);
joeverbout 0:ea44dc9ed014 671 CV_EXPORTS int getIppStatus();
joeverbout 0:ea44dc9ed014 672 CV_EXPORTS String getIppErrorLocation();
joeverbout 0:ea44dc9ed014 673 CV_EXPORTS bool useIPP();
joeverbout 0:ea44dc9ed014 674 CV_EXPORTS void setUseIPP(bool flag);
joeverbout 0:ea44dc9ed014 675
joeverbout 0:ea44dc9ed014 676 } // ipp
joeverbout 0:ea44dc9ed014 677
joeverbout 0:ea44dc9ed014 678 //! @endcond
joeverbout 0:ea44dc9ed014 679
joeverbout 0:ea44dc9ed014 680 //! @} core_utils
joeverbout 0:ea44dc9ed014 681
joeverbout 0:ea44dc9ed014 682
joeverbout 0:ea44dc9ed014 683
joeverbout 0:ea44dc9ed014 684
joeverbout 0:ea44dc9ed014 685 } // cv
joeverbout 0:ea44dc9ed014 686
joeverbout 0:ea44dc9ed014 687 #include "opencv2/core/neon_utils.hpp"
joeverbout 0:ea44dc9ed014 688
joeverbout 0:ea44dc9ed014 689 #endif //__OPENCV_CORE_BASE_HPP__
joeverbout 0:ea44dc9ed014 690