| 1 | /*M/////////////////////////////////////////////////////////////////////////////////////// |
| 2 | // |
| 3 | // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. |
| 4 | // |
| 5 | // By downloading, copying, installing or using the software you agree to this license. |
| 6 | // If you do not agree to this license, do not download, install, |
| 7 | // copy or use the software. |
| 8 | // |
| 9 | // |
| 10 | // License Agreement |
| 11 | // For Open Source Computer Vision Library |
| 12 | // |
| 13 | // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. |
| 14 | // Copyright (C) 2009, Willow Garage Inc., all rights reserved. |
| 15 | // Copyright (C) 2013, OpenCV Foundation, all rights reserved. |
| 16 | // Copyright (C) 2014, Itseez Inc., all rights reserved. |
| 17 | // Third party copyrights are property of their respective owners. |
| 18 | // |
| 19 | // Redistribution and use in source and binary forms, with or without modification, |
| 20 | // are permitted provided that the following conditions are met: |
| 21 | // |
| 22 | // * Redistribution's of source code must retain the above copyright notice, |
| 23 | // this list of conditions and the following disclaimer. |
| 24 | // |
| 25 | // * Redistribution's in binary form must reproduce the above copyright notice, |
| 26 | // this list of conditions and the following disclaimer in the documentation |
| 27 | // and/or other materials provided with the distribution. |
| 28 | // |
| 29 | // * The name of the copyright holders may not be used to endorse or promote products |
| 30 | // derived from this software without specific prior written permission. |
| 31 | // |
| 32 | // This software is provided by the copyright holders and contributors "as is" and |
| 33 | // any express or implied warranties, including, but not limited to, the implied |
| 34 | // warranties of merchantability and fitness for a particular purpose are disclaimed. |
| 35 | // In no event shall the Intel Corporation or contributors be liable for any direct, |
| 36 | // indirect, incidental, special, exemplary, or consequential damages |
| 37 | // (including, but not limited to, procurement of substitute goods or services; |
| 38 | // loss of use, data, or profits; or business interruption) however caused |
| 39 | // and on any theory of liability, whether in contract, strict liability, |
| 40 | // or tort (including negligence or otherwise) arising in any way out of |
| 41 | // the use of this software, even if advised of the possibility of such damage. |
| 42 | // |
| 43 | //M*/ |
| 44 | |
| 45 | #ifndef OPENCV_CORE_BASE_HPP |
| 46 | #define OPENCV_CORE_BASE_HPP |
| 47 | |
| 48 | #ifndef __cplusplus |
| 49 | # error base.hpp header must be compiled as C++ |
| 50 | #endif |
| 51 | |
| 52 | #include "opencv2/opencv_modules.hpp" |
| 53 | |
| 54 | #include <climits> |
| 55 | #include <algorithm> |
| 56 | |
| 57 | #include "opencv2/core/cvdef.h" |
| 58 | #include "opencv2/core/cvstd.hpp" |
| 59 | |
| 60 | namespace cv |
| 61 | { |
| 62 | |
| 63 | //! @addtogroup core_utils |
| 64 | //! @{ |
| 65 | |
| 66 | namespace Error { |
| 67 | //! error codes |
| 68 | enum Code { |
| 69 | StsOk= 0, //!< everything is ok |
| 70 | StsBackTrace= -1, //!< pseudo error for back trace |
| 71 | StsError= -2, //!< unknown /unspecified error |
| 72 | StsInternal= -3, //!< internal error (bad state) |
| 73 | StsNoMem= -4, //!< insufficient memory |
| 74 | StsBadArg= -5, //!< function arg/param is bad |
| 75 | StsBadFunc= -6, //!< unsupported function |
| 76 | StsNoConv= -7, //!< iteration didn't converge |
| 77 | StsAutoTrace= -8, //!< tracing |
| 78 | = -9, //!< image header is NULL |
| 79 | BadImageSize= -10, //!< image size is invalid |
| 80 | BadOffset= -11, //!< offset is invalid |
| 81 | BadDataPtr= -12, //!< |
| 82 | BadStep= -13, //!< image step is wrong, this may happen for a non-continuous matrix. |
| 83 | BadModelOrChSeq= -14, //!< |
| 84 | BadNumChannels= -15, //!< bad number of channels, for example, some functions accept only single channel matrices. |
| 85 | BadNumChannel1U= -16, //!< |
| 86 | BadDepth= -17, //!< input image depth is not supported by the function |
| 87 | BadAlphaChannel= -18, //!< |
| 88 | BadOrder= -19, //!< number of dimensions is out of range |
| 89 | BadOrigin= -20, //!< incorrect input origin |
| 90 | BadAlign= -21, //!< incorrect input align |
| 91 | BadCallBack= -22, //!< |
| 92 | BadTileSize= -23, //!< |
| 93 | BadCOI= -24, //!< input COI is not supported |
| 94 | BadROISize= -25, //!< incorrect input roi |
| 95 | MaskIsTiled= -26, //!< |
| 96 | StsNullPtr= -27, //!< null pointer |
| 97 | StsVecLengthErr= -28, //!< incorrect vector length |
| 98 | StsFilterStructContentErr= -29, //!< incorrect filter structure content |
| 99 | StsKernelStructContentErr= -30, //!< incorrect transform kernel content |
| 100 | StsFilterOffsetErr= -31, //!< incorrect filter offset value |
| 101 | StsBadSize= -201, //!< the input/output structure size is incorrect |
| 102 | StsDivByZero= -202, //!< division by zero |
| 103 | StsInplaceNotSupported= -203, //!< in-place operation is not supported |
| 104 | StsObjectNotFound= -204, //!< request can't be completed |
| 105 | StsUnmatchedFormats= -205, //!< formats of input/output arrays differ |
| 106 | StsBadFlag= -206, //!< flag is wrong or not supported |
| 107 | StsBadPoint= -207, //!< bad CvPoint |
| 108 | StsBadMask= -208, //!< bad format of mask (neither 8uC1 nor 8sC1) |
| 109 | StsUnmatchedSizes= -209, //!< sizes of input/output structures do not match |
| 110 | StsUnsupportedFormat= -210, //!< the data format/type is not supported by the function |
| 111 | StsOutOfRange= -211, //!< some of parameters are out of range |
| 112 | StsParseError= -212, //!< invalid syntax/structure of the parsed file |
| 113 | StsNotImplemented= -213, //!< the requested function/feature is not implemented |
| 114 | StsBadMemBlock= -214, //!< an allocated block has been corrupted |
| 115 | StsAssert= -215, //!< assertion failed |
| 116 | GpuNotSupported= -216, //!< no CUDA support |
| 117 | GpuApiCallError= -217, //!< GPU API call error |
| 118 | OpenGlNotSupported= -218, //!< no OpenGL support |
| 119 | OpenGlApiCallError= -219, //!< OpenGL API call error |
| 120 | OpenCLApiCallError= -220, //!< OpenCL API call error |
| 121 | OpenCLDoubleNotSupported= -221, |
| 122 | OpenCLInitError= -222, //!< OpenCL initialization error |
| 123 | OpenCLNoAMDBlasFft= -223 |
| 124 | }; |
| 125 | } //Error |
| 126 | |
| 127 | //! @} core_utils |
| 128 | |
| 129 | //! @addtogroup core_array |
| 130 | //! @{ |
| 131 | |
| 132 | //! matrix decomposition types |
| 133 | enum DecompTypes { |
| 134 | /** Gaussian elimination with the optimal pivot element chosen. */ |
| 135 | DECOMP_LU = 0, |
| 136 | /** singular value decomposition (SVD) method; the system can be over-defined and/or the matrix |
| 137 | src1 can be singular */ |
| 138 | DECOMP_SVD = 1, |
| 139 | /** eigenvalue decomposition; the matrix src1 must be symmetrical */ |
| 140 | DECOMP_EIG = 2, |
| 141 | /** Cholesky \f$LL^T\f$ factorization; the matrix src1 must be symmetrical and positively |
| 142 | defined */ |
| 143 | DECOMP_CHOLESKY = 3, |
| 144 | /** QR factorization; the system can be over-defined and/or the matrix src1 can be singular */ |
| 145 | DECOMP_QR = 4, |
| 146 | /** while all the previous flags are mutually exclusive, this flag can be used together with |
| 147 | any of the previous; it means that the normal equations |
| 148 | \f$\texttt{src1}^T\cdot\texttt{src1}\cdot\texttt{dst}=\texttt{src1}^T\texttt{src2}\f$ are |
| 149 | solved instead of the original system |
| 150 | \f$\texttt{src1}\cdot\texttt{dst}=\texttt{src2}\f$ */ |
| 151 | DECOMP_NORMAL = 16 |
| 152 | }; |
| 153 | |
| 154 | /** norm types |
| 155 | |
| 156 | src1 and src2 denote input arrays. |
| 157 | */ |
| 158 | |
| 159 | enum NormTypes { |
| 160 | /** |
| 161 | \f[ |
| 162 | norm = \forkthree |
| 163 | {\|\texttt{src1}\|_{L_{\infty}} = \max _I | \texttt{src1} (I)|}{if \(\texttt{normType} = \texttt{NORM_INF}\) } |
| 164 | {\|\texttt{src1}-\texttt{src2}\|_{L_{\infty}} = \max _I | \texttt{src1} (I) - \texttt{src2} (I)|}{if \(\texttt{normType} = \texttt{NORM_INF}\) } |
| 165 | {\frac{\|\texttt{src1}-\texttt{src2}\|_{L_{\infty}} }{\|\texttt{src2}\|_{L_{\infty}} }}{if \(\texttt{normType} = \texttt{NORM_RELATIVE | NORM_INF}\) } |
| 166 | \f] |
| 167 | */ |
| 168 | NORM_INF = 1, |
| 169 | /** |
| 170 | \f[ |
| 171 | norm = \forkthree |
| 172 | {\| \texttt{src1} \| _{L_1} = \sum _I | \texttt{src1} (I)|}{if \(\texttt{normType} = \texttt{NORM_L1}\)} |
| 173 | { \| \texttt{src1} - \texttt{src2} \| _{L_1} = \sum _I | \texttt{src1} (I) - \texttt{src2} (I)|}{if \(\texttt{normType} = \texttt{NORM_L1}\) } |
| 174 | { \frac{\|\texttt{src1}-\texttt{src2}\|_{L_1} }{\|\texttt{src2}\|_{L_1}} }{if \(\texttt{normType} = \texttt{NORM_RELATIVE | NORM_L1}\) } |
| 175 | \f]*/ |
| 176 | NORM_L1 = 2, |
| 177 | /** |
| 178 | \f[ |
| 179 | norm = \forkthree |
| 180 | { \| \texttt{src1} \| _{L_2} = \sqrt{\sum_I \texttt{src1}(I)^2} }{if \(\texttt{normType} = \texttt{NORM_L2}\) } |
| 181 | { \| \texttt{src1} - \texttt{src2} \| _{L_2} = \sqrt{\sum_I (\texttt{src1}(I) - \texttt{src2}(I))^2} }{if \(\texttt{normType} = \texttt{NORM_L2}\) } |
| 182 | { \frac{\|\texttt{src1}-\texttt{src2}\|_{L_2} }{\|\texttt{src2}\|_{L_2}} }{if \(\texttt{normType} = \texttt{NORM_RELATIVE | NORM_L2}\) } |
| 183 | \f] |
| 184 | */ |
| 185 | NORM_L2 = 4, |
| 186 | /** |
| 187 | \f[ |
| 188 | norm = \forkthree |
| 189 | { \| \texttt{src1} \| _{L_2} ^{2} = \sum_I \texttt{src1}(I)^2} {if \(\texttt{normType} = \texttt{NORM_L2SQR}\)} |
| 190 | { \| \texttt{src1} - \texttt{src2} \| _{L_2} ^{2} = \sum_I (\texttt{src1}(I) - \texttt{src2}(I))^2 }{if \(\texttt{normType} = \texttt{NORM_L2SQR}\) } |
| 191 | { \left(\frac{\|\texttt{src1}-\texttt{src2}\|_{L_2} }{\|\texttt{src2}\|_{L_2}}\right)^2 }{if \(\texttt{normType} = \texttt{NORM_RELATIVE | NORM_L2SQR}\) } |
| 192 | \f] |
| 193 | */ |
| 194 | NORM_L2SQR = 5, |
| 195 | /** |
| 196 | In the case of one input array, calculates the Hamming distance of the array from zero, |
| 197 | In the case of two input arrays, calculates the Hamming distance between the arrays. |
| 198 | */ |
| 199 | NORM_HAMMING = 6, |
| 200 | /** |
| 201 | Similar to NORM_HAMMING, but in the calculation, each two bits of the input sequence will |
| 202 | be added and treated as a single bit to be used in the same calculation as NORM_HAMMING. |
| 203 | */ |
| 204 | NORM_HAMMING2 = 7, |
| 205 | NORM_TYPE_MASK = 7, //!< bit-mask which can be used to separate norm type from norm flags |
| 206 | NORM_RELATIVE = 8, //!< flag |
| 207 | NORM_MINMAX = 32 //!< flag |
| 208 | }; |
| 209 | |
| 210 | //! comparison types |
| 211 | enum CmpTypes { CMP_EQ = 0, //!< src1 is equal to src2. |
| 212 | CMP_GT = 1, //!< src1 is greater than src2. |
| 213 | CMP_GE = 2, //!< src1 is greater than or equal to src2. |
| 214 | CMP_LT = 3, //!< src1 is less than src2. |
| 215 | CMP_LE = 4, //!< src1 is less than or equal to src2. |
| 216 | CMP_NE = 5 //!< src1 is unequal to src2. |
| 217 | }; |
| 218 | |
| 219 | //! generalized matrix multiplication flags |
| 220 | enum GemmFlags { GEMM_1_T = 1, //!< transposes src1 |
| 221 | GEMM_2_T = 2, //!< transposes src2 |
| 222 | GEMM_3_T = 4 //!< transposes src3 |
| 223 | }; |
| 224 | |
| 225 | enum DftFlags { |
| 226 | /** performs an inverse 1D or 2D transform instead of the default forward |
| 227 | transform. */ |
| 228 | DFT_INVERSE = 1, |
| 229 | /** scales the result: divide it by the number of array elements. Normally, it is |
| 230 | combined with DFT_INVERSE. */ |
| 231 | DFT_SCALE = 2, |
| 232 | /** performs a forward or inverse transform of every individual row of the input |
| 233 | matrix; this flag enables you to transform multiple vectors simultaneously and can be used to |
| 234 | decrease the overhead (which is sometimes several times larger than the processing itself) to |
| 235 | perform 3D and higher-dimensional transformations and so forth.*/ |
| 236 | DFT_ROWS = 4, |
| 237 | /** performs a forward transformation of 1D or 2D real array; the result, |
| 238 | though being a complex array, has complex-conjugate symmetry (*CCS*, see the function |
| 239 | description below for details), and such an array can be packed into a real array of the same |
| 240 | size as input, which is the fastest option and which is what the function does by default; |
| 241 | however, you may wish to get a full complex array (for simpler spectrum analysis, and so on) - |
| 242 | pass the flag to enable the function to produce a full-size complex output array. */ |
| 243 | DFT_COMPLEX_OUTPUT = 16, |
| 244 | /** performs an inverse transformation of a 1D or 2D complex array; the |
| 245 | result is normally a complex array of the same size, however, if the input array has |
| 246 | conjugate-complex symmetry (for example, it is a result of forward transformation with |
| 247 | DFT_COMPLEX_OUTPUT flag), the output is a real array; while the function itself does not |
| 248 | check whether the input is symmetrical or not, you can pass the flag and then the function |
| 249 | will assume the symmetry and produce the real output array (note that when the input is packed |
| 250 | into a real array and inverse transformation is executed, the function treats the input as a |
| 251 | packed complex-conjugate symmetrical array, and the output will also be a real array). */ |
| 252 | DFT_REAL_OUTPUT = 32, |
| 253 | /** specifies that input is complex input. If this flag is set, the input must have 2 channels. |
| 254 | On the other hand, for backwards compatibility reason, if input has 2 channels, input is |
| 255 | already considered complex. */ |
| 256 | DFT_COMPLEX_INPUT = 64, |
| 257 | /** performs an inverse 1D or 2D transform instead of the default forward transform. */ |
| 258 | DCT_INVERSE = DFT_INVERSE, |
| 259 | /** performs a forward or inverse transform of every individual row of the input |
| 260 | matrix. This flag enables you to transform multiple vectors simultaneously and can be used to |
| 261 | decrease the overhead (which is sometimes several times larger than the processing itself) to |
| 262 | perform 3D and higher-dimensional transforms and so forth.*/ |
| 263 | DCT_ROWS = DFT_ROWS |
| 264 | }; |
| 265 | |
| 266 | /*! Various border types, image boundaries are denoted with the `|` character in the table below, when describing each method. |
| 267 | |
| 268 | The following examples show the result of the @ref copyMakeBorder call according to different methods. |
| 269 | Input image is `6x4` (width x height) size and the @ref copyMakeBorder function is used with a border size of 2 pixels |
| 270 | in each direction, giving a resulting image of `10x8` resolution. |
| 271 | |
| 272 | @code |
| 273 | Input image: |
| 274 | [[ 0 1 2 3 4 5] |
| 275 | [ 6 7 8 9 10 11] |
| 276 | [12 13 14 15 16 17] |
| 277 | [18 19 20 21 22 23]] |
| 278 | |
| 279 | Border type: BORDER_CONSTANT (a constant value of 255 is used) |
| 280 | [[255 255 255 255 255 255 255 255 255 255] |
| 281 | [255 255 255 255 255 255 255 255 255 255] |
| 282 | [255 255 0 1 2 3 4 5 255 255] |
| 283 | [255 255 6 7 8 9 10 11 255 255] |
| 284 | [255 255 12 13 14 15 16 17 255 255] |
| 285 | [255 255 18 19 20 21 22 23 255 255] |
| 286 | [255 255 255 255 255 255 255 255 255 255] |
| 287 | [255 255 255 255 255 255 255 255 255 255]] |
| 288 | |
| 289 | Border type: BORDER_REPLICATE |
| 290 | [[ 0 0 0 1 2 3 4 5 5 5] |
| 291 | [ 0 0 0 1 2 3 4 5 5 5] |
| 292 | [ 0 0 0 1 2 3 4 5 5 5] |
| 293 | [ 6 6 6 7 8 9 10 11 11 11] |
| 294 | [12 12 12 13 14 15 16 17 17 17] |
| 295 | [18 18 18 19 20 21 22 23 23 23] |
| 296 | [18 18 18 19 20 21 22 23 23 23] |
| 297 | [18 18 18 19 20 21 22 23 23 23]] |
| 298 | |
| 299 | Border type: BORDER_REFLECT |
| 300 | [[ 7 6 6 7 8 9 10 11 11 10] |
| 301 | [ 1 0 0 1 2 3 4 5 5 4] |
| 302 | [ 1 0 0 1 2 3 4 5 5 4] |
| 303 | [ 7 6 6 7 8 9 10 11 11 10] |
| 304 | [13 12 12 13 14 15 16 17 17 16] |
| 305 | [19 18 18 19 20 21 22 23 23 22] |
| 306 | [19 18 18 19 20 21 22 23 23 22] |
| 307 | [13 12 12 13 14 15 16 17 17 16]] |
| 308 | |
| 309 | Border type: BORDER_WRAP |
| 310 | [[16 17 12 13 14 15 16 17 12 13] |
| 311 | [22 23 18 19 20 21 22 23 18 19] |
| 312 | [ 4 5 0 1 2 3 4 5 0 1] |
| 313 | [10 11 6 7 8 9 10 11 6 7] |
| 314 | [16 17 12 13 14 15 16 17 12 13] |
| 315 | [22 23 18 19 20 21 22 23 18 19] |
| 316 | [ 4 5 0 1 2 3 4 5 0 1] |
| 317 | [10 11 6 7 8 9 10 11 6 7]] |
| 318 | |
| 319 | Border type: BORDER_REFLECT_101 |
| 320 | [[14 13 12 13 14 15 16 17 16 15] |
| 321 | [ 8 7 6 7 8 9 10 11 10 9] |
| 322 | [ 2 1 0 1 2 3 4 5 4 3] |
| 323 | [ 8 7 6 7 8 9 10 11 10 9] |
| 324 | [14 13 12 13 14 15 16 17 16 15] |
| 325 | [20 19 18 19 20 21 22 23 22 21] |
| 326 | [14 13 12 13 14 15 16 17 16 15] |
| 327 | [ 8 7 6 7 8 9 10 11 10 9]] |
| 328 | @endcode |
| 329 | |
| 330 | @see borderInterpolate, copyMakeBorder |
| 331 | */ |
| 332 | enum BorderTypes { |
| 333 | BORDER_CONSTANT = 0, //!< `iiiiii|abcdefgh|iiiiiii` with some specified `i` |
| 334 | BORDER_REPLICATE = 1, //!< `aaaaaa|abcdefgh|hhhhhhh` |
| 335 | BORDER_REFLECT = 2, //!< `fedcba|abcdefgh|hgfedcb` |
| 336 | BORDER_WRAP = 3, //!< `cdefgh|abcdefgh|abcdefg` |
| 337 | BORDER_REFLECT_101 = 4, //!< `gfedcb|abcdefgh|gfedcba` |
| 338 | BORDER_TRANSPARENT = 5, //!< `uvwxyz|abcdefgh|ijklmno` - Treats outliers as transparent. |
| 339 | |
| 340 | BORDER_REFLECT101 = BORDER_REFLECT_101, //!< same as BORDER_REFLECT_101 |
| 341 | BORDER_DEFAULT = BORDER_REFLECT_101, //!< same as BORDER_REFLECT_101 |
| 342 | BORDER_ISOLATED = 16 //!< Interpolation restricted within the ROI boundaries. |
| 343 | }; |
| 344 | |
| 345 | //! @} core_array |
| 346 | |
| 347 | //! @addtogroup core_utils |
| 348 | //! @{ |
| 349 | |
| 350 | /*! @brief Signals an error and raises the exception. |
| 351 | |
| 352 | By default the function prints information about the error to stderr, |
| 353 | then it either stops if setBreakOnError() had been called before or raises the exception. |
| 354 | It is possible to alternate error processing by using redirectError(). |
| 355 | @param code - error code (Error::Code) |
| 356 | @param err - error description |
| 357 | @param func - function name. Available only when the compiler supports getting it |
| 358 | @param file - source file name where the error has occurred |
| 359 | @param line - line number in the source file where the error has occurred |
| 360 | @see CV_Error, CV_Error_, CV_Assert, CV_DbgAssert |
| 361 | */ |
| 362 | CV_EXPORTS CV_NORETURN void error(int code, const String& err, const char* func, const char* file, int line); |
| 363 | |
| 364 | /*! @brief Signals an error and terminate application. |
| 365 | |
| 366 | By default the function prints information about the error to stderr, then it terminates application |
| 367 | with std::terminate. The function is designed for invariants check in functions and methods with |
| 368 | noexcept attribute. |
| 369 | @param code - error code (Error::Code) |
| 370 | @param err - error description |
| 371 | @param func - function name. Available only when the compiler supports getting it |
| 372 | @param file - source file name where the error has occurred |
| 373 | @param line - line number in the source file where the error has occurred |
| 374 | @see CV_AssertTerminate |
| 375 | */ |
| 376 | CV_EXPORTS CV_NORETURN void terminate(int code, const String& err, const char* func, const char* file, int line) CV_NOEXCEPT; |
| 377 | |
| 378 | |
| 379 | #ifdef CV_STATIC_ANALYSIS |
| 380 | |
| 381 | // In practice, some macro are not processed correctly (noreturn is not detected). |
| 382 | // We need to use simplified definition for them. |
| 383 | #define CV_Error(code, msg) do { (void)(code); (void)(msg); abort(); } while (0) |
| 384 | #define CV_Error_(code, args) do { (void)(code); (void)(cv::format args); abort(); } while (0) |
| 385 | #define CV_Assert( expr ) do { if (!(expr)) abort(); } while (0) |
| 386 | |
| 387 | #else // CV_STATIC_ANALYSIS |
| 388 | |
| 389 | /** @brief Call the error handler. |
| 390 | |
| 391 | Currently, the error handler prints the error code and the error message to the standard |
| 392 | error stream `stderr`. In the Debug configuration, it then provokes memory access violation, so that |
| 393 | the execution stack and all the parameters can be analyzed by the debugger. In the Release |
| 394 | configuration, the exception is thrown. |
| 395 | |
| 396 | @param code one of Error::Code |
| 397 | @param msg error message |
| 398 | */ |
| 399 | #define CV_Error( code, msg ) cv::error( code, msg, CV_Func, __FILE__, __LINE__ ) |
| 400 | |
| 401 | /** @brief Call the error handler. |
| 402 | |
| 403 | This macro can be used to construct an error message on-fly to include some dynamic information, |
| 404 | for example: |
| 405 | @code |
| 406 | // note the extra parentheses around the formatted text message |
| 407 | CV_Error_(Error::StsOutOfRange, |
| 408 | ("the value at (%d, %d)=%g is out of range", badPt.x, badPt.y, badValue)); |
| 409 | @endcode |
| 410 | @param code one of Error::Code |
| 411 | @param args printf-like formatted error message in parentheses |
| 412 | */ |
| 413 | #define CV_Error_( code, args ) cv::error( code, cv::format args, CV_Func, __FILE__, __LINE__ ) |
| 414 | |
| 415 | /** @brief Checks a condition at runtime and throws exception if it fails |
| 416 | |
| 417 | The macros CV_Assert (and CV_DbgAssert(expr)) evaluate the specified expression. If it is 0, the macros |
| 418 | raise an error (see cv::error). The macro CV_Assert checks the condition in both Debug and Release |
| 419 | configurations while CV_DbgAssert is only retained in the Debug configuration. |
| 420 | CV_AssertTerminate is analog of CV_Assert for invariants check in functions with noexcept attribute. |
| 421 | It does not throw exception, but terminates the application. |
| 422 | */ |
| 423 | #define CV_Assert( expr ) do { if(!!(expr)) ; else cv::error( cv::Error::StsAssert, #expr, CV_Func, __FILE__, __LINE__ ); } while(0) |
| 424 | #define CV_AssertTerminate( expr ) do { if(!!(expr)) ; else cv::terminate( #expr, CV_Func, __FILE__, __LINE__ ); } while(0) |
| 425 | |
| 426 | #endif // CV_STATIC_ANALYSIS |
| 427 | |
| 428 | //! @cond IGNORED |
| 429 | #if !defined(__OPENCV_BUILD) // TODO: backward compatibility only |
| 430 | #ifndef CV_ErrorNoReturn |
| 431 | #define CV_ErrorNoReturn CV_Error |
| 432 | #endif |
| 433 | #ifndef CV_ErrorNoReturn_ |
| 434 | #define CV_ErrorNoReturn_ CV_Error_ |
| 435 | #endif |
| 436 | #endif |
| 437 | |
| 438 | #define CV_Assert_1 CV_Assert |
| 439 | #define CV_Assert_2( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_1( __VA_ARGS__ )) |
| 440 | #define CV_Assert_3( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_2( __VA_ARGS__ )) |
| 441 | #define CV_Assert_4( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_3( __VA_ARGS__ )) |
| 442 | #define CV_Assert_5( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_4( __VA_ARGS__ )) |
| 443 | #define CV_Assert_6( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_5( __VA_ARGS__ )) |
| 444 | #define CV_Assert_7( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_6( __VA_ARGS__ )) |
| 445 | #define CV_Assert_8( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_7( __VA_ARGS__ )) |
| 446 | #define CV_Assert_9( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_8( __VA_ARGS__ )) |
| 447 | #define CV_Assert_10( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_9( __VA_ARGS__ )) |
| 448 | |
| 449 | #define CV_Assert_N(...) do { __CV_EXPAND(__CV_CAT(CV_Assert_, __CV_VA_NUM_ARGS(__VA_ARGS__)) (__VA_ARGS__)); } while(0) |
| 450 | |
| 451 | //! @endcond |
| 452 | |
| 453 | #if !defined(NDEBUG) || defined(CV_STATIC_ANALYSIS) |
| 454 | # define CV_DbgAssert(expr) CV_Assert(expr) |
| 455 | #else |
| 456 | /** replaced with CV_Assert(expr) in Debug configuration */ |
| 457 | # define CV_DbgAssert(expr) |
| 458 | #endif |
| 459 | |
| 460 | /* |
| 461 | * Hamming distance functor - counts the bit differences between two strings - useful for the Brief descriptor |
| 462 | * bit count of A exclusive XOR'ed with B |
| 463 | */ |
| 464 | struct CV_EXPORTS Hamming |
| 465 | { |
| 466 | static const NormTypes normType = NORM_HAMMING; |
| 467 | typedef unsigned char ValueType; |
| 468 | typedef int ResultType; |
| 469 | |
| 470 | /** this will count the bits in a ^ b |
| 471 | */ |
| 472 | ResultType operator()( const unsigned char* a, const unsigned char* b, int size ) const; |
| 473 | }; |
| 474 | |
| 475 | typedef Hamming HammingLUT; |
| 476 | |
| 477 | /////////////////////////////////// inline norms //////////////////////////////////// |
| 478 | |
| 479 | template<typename _Tp> inline _Tp cv_abs(_Tp x) { return std::abs(x); } |
| 480 | inline int cv_abs(uchar x) { return x; } |
| 481 | inline int cv_abs(schar x) { return std::abs(x: x); } |
| 482 | inline int cv_abs(ushort x) { return x; } |
| 483 | inline int cv_abs(short x) { return std::abs(x: x); } |
| 484 | |
| 485 | template<typename _Tp, typename _AccTp> static inline |
| 486 | _AccTp normL2Sqr(const _Tp* a, int n) |
| 487 | { |
| 488 | _AccTp s = 0; |
| 489 | int i=0; |
| 490 | #if CV_ENABLE_UNROLLED |
| 491 | for( ; i <= n - 4; i += 4 ) |
| 492 | { |
| 493 | _AccTp v0 = a[i], v1 = a[i+1], v2 = a[i+2], v3 = a[i+3]; |
| 494 | s += v0*v0 + v1*v1 + v2*v2 + v3*v3; |
| 495 | } |
| 496 | #endif |
| 497 | for( ; i < n; i++ ) |
| 498 | { |
| 499 | _AccTp v = a[i]; |
| 500 | s += v*v; |
| 501 | } |
| 502 | return s; |
| 503 | } |
| 504 | |
| 505 | template<typename _Tp, typename _AccTp> static inline |
| 506 | _AccTp normL1(const _Tp* a, int n) |
| 507 | { |
| 508 | _AccTp s = 0; |
| 509 | int i = 0; |
| 510 | #if CV_ENABLE_UNROLLED |
| 511 | for(; i <= n - 4; i += 4 ) |
| 512 | { |
| 513 | s += (_AccTp)cv_abs(a[i]) + (_AccTp)cv_abs(a[i+1]) + |
| 514 | (_AccTp)cv_abs(a[i+2]) + (_AccTp)cv_abs(a[i+3]); |
| 515 | } |
| 516 | #endif |
| 517 | for( ; i < n; i++ ) |
| 518 | s += cv_abs(a[i]); |
| 519 | return s; |
| 520 | } |
| 521 | |
| 522 | template<typename _Tp, typename _AccTp> static inline |
| 523 | _AccTp normInf(const _Tp* a, int n) |
| 524 | { |
| 525 | _AccTp s = 0; |
| 526 | for( int i = 0; i < n; i++ ) |
| 527 | s = std::max(s, (_AccTp)cv_abs(a[i])); |
| 528 | return s; |
| 529 | } |
| 530 | |
| 531 | template<typename _Tp, typename _AccTp> static inline |
| 532 | _AccTp normL2Sqr(const _Tp* a, const _Tp* b, int n) |
| 533 | { |
| 534 | _AccTp s = 0; |
| 535 | int i= 0; |
| 536 | #if CV_ENABLE_UNROLLED |
| 537 | for(; i <= n - 4; i += 4 ) |
| 538 | { |
| 539 | _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]); |
| 540 | s += v0*v0 + v1*v1 + v2*v2 + v3*v3; |
| 541 | } |
| 542 | #endif |
| 543 | for( ; i < n; i++ ) |
| 544 | { |
| 545 | _AccTp v = _AccTp(a[i] - b[i]); |
| 546 | s += v*v; |
| 547 | } |
| 548 | return s; |
| 549 | } |
| 550 | |
| 551 | static inline float normL2Sqr(const float* a, const float* b, int n) |
| 552 | { |
| 553 | float s = 0.f; |
| 554 | for( int i = 0; i < n; i++ ) |
| 555 | { |
| 556 | float v = a[i] - b[i]; |
| 557 | s += v*v; |
| 558 | } |
| 559 | return s; |
| 560 | } |
| 561 | |
| 562 | template<typename _Tp, typename _AccTp> static inline |
| 563 | _AccTp normL1(const _Tp* a, const _Tp* b, int n) |
| 564 | { |
| 565 | _AccTp s = 0; |
| 566 | int i= 0; |
| 567 | #if CV_ENABLE_UNROLLED |
| 568 | for(; i <= n - 4; i += 4 ) |
| 569 | { |
| 570 | _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]); |
| 571 | s += std::abs(v0) + std::abs(v1) + std::abs(v2) + std::abs(v3); |
| 572 | } |
| 573 | #endif |
| 574 | for( ; i < n; i++ ) |
| 575 | { |
| 576 | _AccTp v = _AccTp(a[i] - b[i]); |
| 577 | s += std::abs(v); |
| 578 | } |
| 579 | return s; |
| 580 | } |
| 581 | |
| 582 | inline float normL1(const float* a, const float* b, int n) |
| 583 | { |
| 584 | float s = 0.f; |
| 585 | for( int i = 0; i < n; i++ ) |
| 586 | { |
| 587 | s += std::abs(x: a[i] - b[i]); |
| 588 | } |
| 589 | return s; |
| 590 | } |
| 591 | |
| 592 | inline int normL1(const uchar* a, const uchar* b, int n) |
| 593 | { |
| 594 | int s = 0; |
| 595 | for( int i = 0; i < n; i++ ) |
| 596 | { |
| 597 | s += std::abs(x: a[i] - b[i]); |
| 598 | } |
| 599 | return s; |
| 600 | } |
| 601 | |
| 602 | template<typename _Tp, typename _AccTp> static inline |
| 603 | _AccTp normInf(const _Tp* a, const _Tp* b, int n) |
| 604 | { |
| 605 | _AccTp s = 0; |
| 606 | for( int i = 0; i < n; i++ ) |
| 607 | { |
| 608 | _AccTp v0 = a[i] - b[i]; |
| 609 | s = std::max(s, std::abs(v0)); |
| 610 | } |
| 611 | return s; |
| 612 | } |
| 613 | |
| 614 | /** @brief Computes the cube root of an argument. |
| 615 | |
| 616 | The function cubeRoot computes \f$\sqrt[3]{\texttt{val}}\f$. Negative arguments are handled correctly. |
| 617 | NaN and Inf are not handled. The accuracy approaches the maximum possible accuracy for |
| 618 | single-precision data. |
| 619 | @param val A function argument. |
| 620 | */ |
| 621 | CV_EXPORTS_W float cubeRoot(float val); |
| 622 | |
| 623 | /** @overload |
| 624 | |
| 625 | cubeRoot with argument of `double` type calls `std::cbrt(double)` |
| 626 | */ |
| 627 | static inline |
| 628 | double cubeRoot(double val) |
| 629 | { |
| 630 | return std::cbrt(x: val); |
| 631 | } |
| 632 | |
| 633 | /** @brief Calculates the angle of a 2D vector in degrees. |
| 634 | |
| 635 | The function fastAtan2 calculates the full-range angle of an input 2D vector. The angle is measured |
| 636 | in degrees and varies from 0 to 360 degrees. The accuracy is about 0.3 degrees. |
| 637 | @param x x-coordinate of the vector. |
| 638 | @param y y-coordinate of the vector. |
| 639 | */ |
| 640 | CV_EXPORTS_W float fastAtan2(float y, float x); |
| 641 | |
| 642 | /** proxy for hal::LU */ |
| 643 | CV_EXPORTS int LU(float* A, size_t astep, int m, float* b, size_t bstep, int n); |
| 644 | /** proxy for hal::LU */ |
| 645 | CV_EXPORTS int LU(double* A, size_t astep, int m, double* b, size_t bstep, int n); |
| 646 | /** proxy for hal::Cholesky */ |
| 647 | CV_EXPORTS bool Cholesky(float* A, size_t astep, int m, float* b, size_t bstep, int n); |
| 648 | /** proxy for hal::Cholesky */ |
| 649 | CV_EXPORTS bool Cholesky(double* A, size_t astep, int m, double* b, size_t bstep, int n); |
| 650 | |
| 651 | ////////////////// forward declarations for important OpenCV types ////////////////// |
| 652 | |
| 653 | //! @cond IGNORED |
| 654 | |
| 655 | template<typename _Tp, int cn> class Vec; |
| 656 | template<typename _Tp, int m, int n> class Matx; |
| 657 | |
| 658 | template<typename _Tp> class Complex; |
| 659 | template<typename _Tp> class Point_; |
| 660 | template<typename _Tp> class Point3_; |
| 661 | template<typename _Tp> class Size_; |
| 662 | template<typename _Tp> class Rect_; |
| 663 | template<typename _Tp> class Scalar_; |
| 664 | |
| 665 | class CV_EXPORTS RotatedRect; |
| 666 | class CV_EXPORTS Range; |
| 667 | class CV_EXPORTS TermCriteria; |
| 668 | class CV_EXPORTS KeyPoint; |
| 669 | class CV_EXPORTS DMatch; |
| 670 | class CV_EXPORTS RNG; |
| 671 | |
| 672 | class CV_EXPORTS Mat; |
| 673 | class CV_EXPORTS MatExpr; |
| 674 | |
| 675 | class CV_EXPORTS UMat; |
| 676 | |
| 677 | class CV_EXPORTS SparseMat; |
| 678 | typedef Mat MatND; |
| 679 | |
| 680 | template<typename _Tp> class Mat_; |
| 681 | template<typename _Tp> class SparseMat_; |
| 682 | |
| 683 | class CV_EXPORTS MatConstIterator; |
| 684 | class CV_EXPORTS SparseMatIterator; |
| 685 | class CV_EXPORTS SparseMatConstIterator; |
| 686 | template<typename _Tp> class MatIterator_; |
| 687 | template<typename _Tp> class MatConstIterator_; |
| 688 | template<typename _Tp> class SparseMatIterator_; |
| 689 | template<typename _Tp> class SparseMatConstIterator_; |
| 690 | |
| 691 | namespace ogl |
| 692 | { |
| 693 | class CV_EXPORTS Buffer; |
| 694 | class CV_EXPORTS Texture2D; |
| 695 | class CV_EXPORTS Arrays; |
| 696 | } |
| 697 | |
| 698 | namespace cuda |
| 699 | { |
| 700 | class CV_EXPORTS GpuMat; |
| 701 | class CV_EXPORTS HostMem; |
| 702 | class CV_EXPORTS Stream; |
| 703 | class CV_EXPORTS Event; |
| 704 | } |
| 705 | |
| 706 | namespace cudev |
| 707 | { |
| 708 | template <typename _Tp> class GpuMat_; |
| 709 | } |
| 710 | |
| 711 | namespace ipp |
| 712 | { |
| 713 | CV_EXPORTS unsigned long long getIppFeatures(); |
| 714 | CV_EXPORTS void setIppStatus(int status, const char * const funcname = NULL, const char * const filename = NULL, |
| 715 | int line = 0); |
| 716 | CV_EXPORTS int getIppStatus(); |
| 717 | CV_EXPORTS String getIppErrorLocation(); |
| 718 | CV_EXPORTS_W bool useIPP(); |
| 719 | CV_EXPORTS_W void setUseIPP(bool flag); |
| 720 | CV_EXPORTS_W String getIppVersion(); |
| 721 | |
| 722 | // IPP Not-Exact mode. This function may force use of IPP then both IPP and OpenCV provide proper results |
| 723 | // but have internal accuracy differences which have too much direct or indirect impact on accuracy tests. |
| 724 | CV_EXPORTS_W bool useIPP_NotExact(); |
| 725 | CV_EXPORTS_W void setUseIPP_NotExact(bool flag); |
| 726 | #ifndef DISABLE_OPENCV_3_COMPATIBILITY |
| 727 | static inline bool useIPP_NE() { return useIPP_NotExact(); } |
| 728 | static inline void setUseIPP_NE(bool flag) { setUseIPP_NotExact(flag); } |
| 729 | #endif |
| 730 | |
| 731 | } // ipp |
| 732 | |
| 733 | //! @endcond |
| 734 | |
| 735 | //! @} core_utils |
| 736 | |
| 737 | |
| 738 | |
| 739 | |
| 740 | } // cv |
| 741 | |
| 742 | #include "opencv2/core/neon_utils.hpp" |
| 743 | #include "opencv2/core/vsx_utils.hpp" |
| 744 | #include "opencv2/core/check.hpp" |
| 745 | |
| 746 | #endif //OPENCV_CORE_BASE_HPP |
| 747 | |