Renesas / opencv-lib

Dependents:   RZ_A2M_Mbed_samples

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers base.hpp Source File

base.hpp

00001 /*M///////////////////////////////////////////////////////////////////////////////////////
00002 //
00003 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
00004 //
00005 //  By downloading, copying, installing or using the software you agree to this license.
00006 //  If you do not agree to this license, do not download, install,
00007 //  copy or use the software.
00008 //
00009 //
00010 //                          License Agreement
00011 //                For Open Source Computer Vision Library
00012 //
00013 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
00014 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
00015 // Copyright (C) 2013, OpenCV Foundation, all rights reserved.
00016 // Copyright (C) 2014, Itseez Inc., all rights reserved.
00017 // Third party copyrights are property of their respective owners.
00018 //
00019 // Redistribution and use in source and binary forms, with or without modification,
00020 // are permitted provided that the following conditions are met:
00021 //
00022 //   * Redistribution's of source code must retain the above copyright notice,
00023 //     this list of conditions and the following disclaimer.
00024 //
00025 //   * Redistribution's in binary form must reproduce the above copyright notice,
00026 //     this list of conditions and the following disclaimer in the documentation
00027 //     and/or other materials provided with the distribution.
00028 //
00029 //   * The name of the copyright holders may not be used to endorse or promote products
00030 //     derived from this software without specific prior written permission.
00031 //
00032 // This software is provided by the copyright holders and contributors "as is" and
00033 // any express or implied warranties, including, but not limited to, the implied
00034 // warranties of merchantability and fitness for a particular purpose are disclaimed.
00035 // In no event shall the Intel Corporation or contributors be liable for any direct,
00036 // indirect, incidental, special, exemplary, or consequential damages
00037 // (including, but not limited to, procurement of substitute goods or services;
00038 // loss of use, data, or profits; or business interruption) however caused
00039 // and on any theory of liability, whether in contract, strict liability,
00040 // or tort (including negligence or otherwise) arising in any way out of
00041 // the use of this software, even if advised of the possibility of such damage.
00042 //
00043 //M*/
00044 
00045 #ifndef OPENCV_CORE_BASE_HPP
00046 #define OPENCV_CORE_BASE_HPP
00047 
00048 #ifndef __cplusplus
00049 #  error base.hpp header must be compiled as C++
00050 #endif
00051 
00052 #include "opencv2/opencv_modules.hpp"
00053 
00054 #include <climits>
00055 #include <algorithm>
00056 
00057 #include "opencv2/core/cvdef.h"
00058 #include "opencv2/core/cvstd.hpp"
00059 
00060 namespace cv
00061 {
00062 
00063 //! @addtogroup core_utils
00064 //! @{
00065 
00066 namespace Error {
00067 //! error codes
00068 enum Code {
00069     StsOk=                       0,  //!< everithing is ok
00070     StsBackTrace=               -1,  //!< pseudo error for back trace
00071     StsError=                   -2,  //!< unknown /unspecified error
00072     StsInternal=                -3,  //!< internal error (bad state)
00073     StsNoMem=                   -4,  //!< insufficient memory
00074     StsBadArg=                  -5,  //!< function arg/param is bad
00075     StsBadFunc=                 -6,  //!< unsupported function
00076     StsNoConv=                  -7,  //!< iter. didn't converge
00077     StsAutoTrace=               -8,  //!< tracing
00078     HeaderIsNull=               -9,  //!< image header is NULL
00079     BadImageSize=              -10,  //!< image size is invalid
00080     BadOffset=                 -11,  //!< offset is invalid
00081     BadDataPtr=                -12,  //!<
00082     BadStep=                   -13,  //!<
00083     BadModelOrChSeq=           -14,  //!<
00084     BadNumChannels=            -15,  //!<
00085     BadNumChannel1U=           -16,  //!<
00086     BadDepth=                  -17,  //!<
00087     BadAlphaChannel=           -18,  //!<
00088     BadOrder=                  -19,  //!<
00089     BadOrigin=                 -20,  //!<
00090     BadAlign=                  -21,  //!<
00091     BadCallBack=               -22,  //!<
00092     BadTileSize=               -23,  //!<
00093     BadCOI=                    -24,  //!<
00094     BadROISize=                -25,  //!<
00095     MaskIsTiled=               -26,  //!<
00096     StsNullPtr=                -27,  //!< null pointer
00097     StsVecLengthErr=           -28,  //!< incorrect vector length
00098     StsFilterStructContentErr= -29,  //!< incorr. filter structure content
00099     StsKernelStructContentErr= -30,  //!< incorr. transform kernel content
00100     StsFilterOffsetErr=        -31,  //!< incorrect filter ofset value
00101     StsBadSize=                -201, //!< the input/output structure size is incorrect
00102     StsDivByZero=              -202, //!< division by zero
00103     StsInplaceNotSupported=    -203, //!< in-place operation is not supported
00104     StsObjectNotFound=         -204, //!< request can't be completed
00105     StsUnmatchedFormats=       -205, //!< formats of input/output arrays differ
00106     StsBadFlag=                -206, //!< flag is wrong or not supported
00107     StsBadPoint=               -207, //!< bad CvPoint
00108     StsBadMask=                -208, //!< bad format of mask (neither 8uC1 nor 8sC1)
00109     StsUnmatchedSizes=         -209, //!< sizes of input/output structures do not match
00110     StsUnsupportedFormat=      -210, //!< the data format/type is not supported by the function
00111     StsOutOfRange=             -211, //!< some of parameters are out of range
00112     StsParseError=             -212, //!< invalid syntax/structure of the parsed file
00113     StsNotImplemented=         -213, //!< the requested function/feature is not implemented
00114     StsBadMemBlock=            -214, //!< an allocated block has been corrupted
00115     StsAssert=                 -215, //!< assertion failed
00116     GpuNotSupported=           -216,
00117     GpuApiCallError=           -217,
00118     OpenGlNotSupported=        -218,
00119     OpenGlApiCallError=        -219,
00120     OpenCLApiCallError=        -220,
00121     OpenCLDoubleNotSupported=  -221,
00122     OpenCLInitError=           -222,
00123     OpenCLNoAMDBlasFft=        -223
00124 };
00125 } //Error
00126 
00127 //! @} core_utils
00128 
00129 //! @addtogroup core_array
00130 //! @{
00131 
00132 //! matrix decomposition types
00133 enum DecompTypes {
00134     /** Gaussian elimination with the optimal pivot element chosen. */
00135     DECOMP_LU       = 0,
00136     /** singular value decomposition (SVD) method; the system can be over-defined and/or the matrix
00137     src1 can be singular */
00138     DECOMP_SVD      = 1,
00139     /** eigenvalue decomposition; the matrix src1 must be symmetrical */
00140     DECOMP_EIG      = 2,
00141     /** Cholesky \f$LL^T\f$ factorization; the matrix src1 must be symmetrical and positively
00142     defined */
00143     DECOMP_CHOLESKY = 3,
00144     /** QR factorization; the system can be over-defined and/or the matrix src1 can be singular */
00145     DECOMP_QR       = 4,
00146     /** while all the previous flags are mutually exclusive, this flag can be used together with
00147     any of the previous; it means that the normal equations
00148     \f$\texttt{src1}^T\cdot\texttt{src1}\cdot\texttt{dst}=\texttt{src1}^T\texttt{src2}\f$ are
00149     solved instead of the original system
00150     \f$\texttt{src1}\cdot\texttt{dst}=\texttt{src2}\f$ */
00151     DECOMP_NORMAL   = 16
00152 };
00153 
00154 /** norm types
00155 - For one array:
00156 \f[norm =  \forkthree{\|\texttt{src1}\|_{L_{\infty}} =  \max _I | \texttt{src1} (I)|}{if  \(\texttt{normType} = \texttt{NORM_INF}\) }
00157 { \| \texttt{src1} \| _{L_1} =  \sum _I | \texttt{src1} (I)|}{if  \(\texttt{normType} = \texttt{NORM_L1}\) }
00158 { \| \texttt{src1} \| _{L_2} =  \sqrt{\sum_I \texttt{src1}(I)^2} }{if  \(\texttt{normType} = \texttt{NORM_L2}\) }\f]
00159 
00160 - Absolute norm for two arrays
00161 \f[norm =  \forkthree{\|\texttt{src1}-\texttt{src2}\|_{L_{\infty}} =  \max _I | \texttt{src1} (I) -  \texttt{src2} (I)|}{if  \(\texttt{normType} = \texttt{NORM_INF}\) }
00162 { \| \texttt{src1} - \texttt{src2} \| _{L_1} =  \sum _I | \texttt{src1} (I) -  \texttt{src2} (I)|}{if  \(\texttt{normType} = \texttt{NORM_L1}\) }
00163 { \| \texttt{src1} - \texttt{src2} \| _{L_2} =  \sqrt{\sum_I (\texttt{src1}(I) - \texttt{src2}(I))^2} }{if  \(\texttt{normType} = \texttt{NORM_L2}\) }\f]
00164 
00165 - Relative norm for two arrays
00166 \f[norm =  \forkthree{\frac{\|\texttt{src1}-\texttt{src2}\|_{L_{\infty}}    }{\|\texttt{src2}\|_{L_{\infty}} }}{if  \(\texttt{normType} = \texttt{NORM_RELATIVE_INF}\) }
00167 { \frac{\|\texttt{src1}-\texttt{src2}\|_{L_1} }{\|\texttt{src2}\|_{L_1}} }{if  \(\texttt{normType} = \texttt{NORM_RELATIVE_L1}\) }
00168 { \frac{\|\texttt{src1}-\texttt{src2}\|_{L_2} }{\|\texttt{src2}\|_{L_2}} }{if  \(\texttt{normType} = \texttt{NORM_RELATIVE_L2}\) }\f]
00169 
00170 As example for one array consider the function \f$r(x)= \begin{pmatrix} x \\ 1-x \end{pmatrix}, x \in [-1;1]\f$.
00171 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$
00172 is calculated as follows
00173 \f{align*}
00174     \| r(-1) \|_{L_1} &= |-1| + |2| = 3 \\
00175     \| r(-1) \|_{L_2} &= \sqrt{(-1)^{2} + (2)^{2}} = \sqrt{5} \\
00176     \| r(-1) \|_{L_\infty} &= \max(|-1|,|2|) = 2
00177 \f}
00178 and for \f$r(0.5) = \begin{pmatrix} 0.5 \\ 0.5 \end{pmatrix}\f$ the calculation is
00179 \f{align*}
00180     \| r(0.5) \|_{L_1} &= |0.5| + |0.5| = 1 \\
00181     \| r(0.5) \|_{L_2} &= \sqrt{(0.5)^{2} + (0.5)^{2}} = \sqrt{0.5} \\
00182     \| r(0.5) \|_{L_\infty} &= \max(|0.5|,|0.5|) = 0.5.
00183 \f}
00184 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$.
00185 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$.
00186 ![Graphs for the different norm functions from the above example](pics/NormTypes_OneArray_1-2-INF.png)
00187  */
00188 enum NormTypes { NORM_INF       = 1,
00189                  NORM_L1        = 2,
00190                  NORM_L2        = 4,
00191                  NORM_L2SQR     = 5,
00192                  NORM_HAMMING   = 6,
00193                  NORM_HAMMING2  = 7,
00194                  NORM_TYPE_MASK = 7,
00195                  NORM_RELATIVE  = 8, //!< flag
00196                  NORM_MINMAX    = 32 //!< flag
00197                };
00198 
00199 //! comparison types
00200 enum CmpTypes { CMP_EQ = 0, //!< src1 is equal to src2.
00201                 CMP_GT = 1, //!< src1 is greater than src2.
00202                 CMP_GE = 2, //!< src1 is greater than or equal to src2.
00203                 CMP_LT = 3, //!< src1 is less than src2.
00204                 CMP_LE = 4, //!< src1 is less than or equal to src2.
00205                 CMP_NE = 5  //!< src1 is unequal to src2.
00206               };
00207 
00208 //! generalized matrix multiplication flags
00209 enum GemmFlags { GEMM_1_T = 1, //!< transposes src1
00210                  GEMM_2_T = 2, //!< transposes src2
00211                  GEMM_3_T = 4 //!< transposes src3
00212                };
00213 
00214 enum DftFlags  {
00215     /** performs an inverse 1D or 2D transform instead of the default forward
00216         transform. */
00217     DFT_INVERSE        = 1,
00218     /** scales the result: divide it by the number of array elements. Normally, it is
00219         combined with DFT_INVERSE. */
00220     DFT_SCALE          = 2,
00221     /** performs a forward or inverse transform of every individual row of the input
00222         matrix; this flag enables you to transform multiple vectors simultaneously and can be used to
00223         decrease the overhead (which is sometimes several times larger than the processing itself) to
00224         perform 3D and higher-dimensional transformations and so forth.*/
00225     DFT_ROWS           = 4,
00226     /** performs a forward transformation of 1D or 2D real array; the result,
00227         though being a complex array, has complex-conjugate symmetry (*CCS*, see the function
00228         description below for details), and such an array can be packed into a real array of the same
00229         size as input, which is the fastest option and which is what the function does by default;
00230         however, you may wish to get a full complex array (for simpler spectrum analysis, and so on) -
00231         pass the flag to enable the function to produce a full-size complex output array. */
00232     DFT_COMPLEX_OUTPUT = 16,
00233     /** performs an inverse transformation of a 1D or 2D complex array; the
00234         result is normally a complex array of the same size, however, if the input array has
00235         conjugate-complex symmetry (for example, it is a result of forward transformation with
00236         DFT_COMPLEX_OUTPUT flag), the output is a real array; while the function itself does not
00237         check whether the input is symmetrical or not, you can pass the flag and then the function
00238         will assume the symmetry and produce the real output array (note that when the input is packed
00239         into a real array and inverse transformation is executed, the function treats the input as a
00240         packed complex-conjugate symmetrical array, and the output will also be a real array). */
00241     DFT_REAL_OUTPUT    = 32,
00242     /** performs an inverse 1D or 2D transform instead of the default forward transform. */
00243     DCT_INVERSE        = DFT_INVERSE,
00244     /** performs a forward or inverse transform of every individual row of the input
00245         matrix. This flag enables you to transform multiple vectors simultaneously and can be used to
00246         decrease the overhead (which is sometimes several times larger than the processing itself) to
00247         perform 3D and higher-dimensional transforms and so forth.*/
00248     DCT_ROWS           = DFT_ROWS
00249 };
00250 
00251 //! Various border types, image boundaries are denoted with `|`
00252 //! @see borderInterpolate, copyMakeBorder
00253 enum BorderTypes {
00254     BORDER_CONSTANT    = 0, //!< `iiiiii|abcdefgh|iiiiiii`  with some specified `i`
00255     BORDER_REPLICATE   = 1, //!< `aaaaaa|abcdefgh|hhhhhhh`
00256     BORDER_REFLECT     = 2, //!< `fedcba|abcdefgh|hgfedcb`
00257     BORDER_WRAP        = 3, //!< `cdefgh|abcdefgh|abcdefg`
00258     BORDER_REFLECT_101 = 4, //!< `gfedcb|abcdefgh|gfedcba`
00259     BORDER_TRANSPARENT = 5, //!< `uvwxyz|absdefgh|ijklmno`
00260 
00261     BORDER_REFLECT101  = BORDER_REFLECT_101, //!< same as BORDER_REFLECT_101
00262     BORDER_DEFAULT     = BORDER_REFLECT_101, //!< same as BORDER_REFLECT_101
00263     BORDER_ISOLATED    = 16 //!< do not look outside of ROI
00264 };
00265 
00266 //! @} core_array
00267 
00268 //! @addtogroup core_utils
00269 //! @{
00270 
00271 //! @cond IGNORED
00272 
00273 //////////////// static assert /////////////////
00274 #define CVAUX_CONCAT_EXP(a, b) a##b
00275 #define CVAUX_CONCAT(a, b) CVAUX_CONCAT_EXP(a,b)
00276 
00277 #if defined(__clang__)
00278 #  ifndef __has_extension
00279 #    define __has_extension __has_feature /* compatibility, for older versions of clang */
00280 #  endif
00281 #  if __has_extension(cxx_static_assert)
00282 #    define CV_StaticAssert(condition, reason)    static_assert((condition), reason " " #condition)
00283 #  elif __has_extension(c_static_assert)
00284 #    define CV_StaticAssert(condition, reason)    _Static_assert((condition), reason " " #condition)
00285 #  endif
00286 #elif defined(__GNUC__)
00287 #  if (defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L)
00288 #    define CV_StaticAssert(condition, reason)    static_assert((condition), reason " " #condition)
00289 #  endif
00290 #elif defined(_MSC_VER)
00291 #  if _MSC_VER >= 1600 /* MSVC 10 */
00292 #    define CV_StaticAssert(condition, reason)    static_assert((condition), reason " " #condition)
00293 #  endif
00294 #endif
00295 #ifndef CV_StaticAssert
00296 #  if !defined(__clang__) && defined(__GNUC__) && (__GNUC__*100 + __GNUC_MINOR__ > 302)
00297 #    define CV_StaticAssert(condition, reason) ({ extern int __attribute__((error("CV_StaticAssert: " reason " " #condition))) CV_StaticAssert(); ((condition) ? 0 : CV_StaticAssert()); })
00298 #  else
00299      template <bool x> struct CV_StaticAssert_failed;
00300      template <> struct CV_StaticAssert_failed<true> { enum { val = 1 }; };
00301      template<int x> struct CV_StaticAssert_test {};
00302 #    define CV_StaticAssert(condition, reason)\
00303        typedef cv::CV_StaticAssert_test< sizeof(cv::CV_StaticAssert_failed< static_cast<bool>(condition) >) > CVAUX_CONCAT(CV_StaticAssert_failed_at_, __LINE__)
00304 #  endif
00305 #endif
00306 
00307 // Suppress warning "-Wdeprecated-declarations" / C4996
00308 #if defined(_MSC_VER)
00309     #define CV_DO_PRAGMA(x) __pragma(x)
00310 #elif defined(__GNUC__)
00311     #define CV_DO_PRAGMA(x) _Pragma (#x)
00312 #else
00313     #define CV_DO_PRAGMA(x)
00314 #endif
00315 
00316 #ifdef _MSC_VER
00317 #define CV_SUPPRESS_DEPRECATED_START \
00318     CV_DO_PRAGMA(warning(push)) \
00319     CV_DO_PRAGMA(warning(disable: 4996))
00320 #define CV_SUPPRESS_DEPRECATED_END CV_DO_PRAGMA(warning(pop))
00321 #elif defined (__clang__) || ((__GNUC__)  && (__GNUC__*100 + __GNUC_MINOR__ > 405))
00322 #define CV_SUPPRESS_DEPRECATED_START \
00323     CV_DO_PRAGMA(GCC diagnostic push) \
00324     CV_DO_PRAGMA(GCC diagnostic ignored "-Wdeprecated-declarations")
00325 #define CV_SUPPRESS_DEPRECATED_END CV_DO_PRAGMA(GCC diagnostic pop)
00326 #else
00327 #define CV_SUPPRESS_DEPRECATED_START
00328 #define CV_SUPPRESS_DEPRECATED_END
00329 #endif
00330 #define CV_UNUSED(name) (void)name
00331 //! @endcond
00332 
00333 /*! @brief Signals an error and raises the exception.
00334 
00335 By default the function prints information about the error to stderr,
00336 then it either stops if setBreakOnError() had been called before or raises the exception.
00337 It is possible to alternate error processing by using redirectError().
00338 @param _code - error code (Error::Code)
00339 @param _err - error description
00340 @param _func - function name. Available only when the compiler supports getting it
00341 @param _file - source file name where the error has occured
00342 @param _line - line number in the source file where the error has occured
00343 @see CV_Error, CV_Error_, CV_ErrorNoReturn, CV_ErrorNoReturn_, CV_Assert, CV_DbgAssert
00344  */
00345 CV_EXPORTS void error(int _code, const String& _err, const char* _func, const char* _file, int _line);
00346 
00347 #ifdef __GNUC__
00348 # if defined __clang__ || defined __APPLE__
00349 #   pragma GCC diagnostic push
00350 #   pragma GCC diagnostic ignored "-Winvalid-noreturn"
00351 # endif
00352 #endif
00353 
00354 /** same as cv::error, but does not return */
00355 CV_INLINE CV_NORETURN void errorNoReturn(int _code, const String& _err, const char* _func, const char* _file, int _line)
00356 {
00357     error(_code, _err, _func, _file, _line);
00358 #ifdef __GNUC__
00359 # if !defined __clang__ && !defined __APPLE__
00360     // this suppresses this warning: "noreturn" function does return [enabled by default]
00361     __builtin_trap();
00362     // or use infinite loop: for (;;) {}
00363 # endif
00364 #endif
00365 }
00366 #ifdef __GNUC__
00367 # if defined __clang__ || defined __APPLE__
00368 #   pragma GCC diagnostic pop
00369 # endif
00370 #endif
00371 
00372 #if defined __GNUC__
00373 #define CV_Func __func__
00374 #elif defined _MSC_VER
00375 #define CV_Func __FUNCTION__
00376 #else
00377 #define CV_Func ""
00378 #endif
00379 
00380 /** @brief Call the error handler.
00381 
00382 Currently, the error handler prints the error code and the error message to the standard
00383 error stream `stderr`. In the Debug configuration, it then provokes memory access violation, so that
00384 the execution stack and all the parameters can be analyzed by the debugger. In the Release
00385 configuration, the exception is thrown.
00386 
00387 @param code one of Error::Code
00388 @param msg error message
00389 */
00390 #define CV_Error( code, msg ) cv::error( code, msg, CV_Func, __FILE__, __LINE__ )
00391 
00392 /**  @brief Call the error handler.
00393 
00394 This macro can be used to construct an error message on-fly to include some dynamic information,
00395 for example:
00396 @code
00397     // note the extra parentheses around the formatted text message
00398     CV_Error_( CV_StsOutOfRange,
00399     ("the value at (%d, %d)=%g is out of range", badPt.x, badPt.y, badValue));
00400 @endcode
00401 @param code one of Error::Code
00402 @param args printf-like formatted error message in parentheses
00403 */
00404 #define CV_Error_( code, args ) cv::error( code, cv::format args, CV_Func, __FILE__, __LINE__ )
00405 
00406 /** @brief Checks a condition at runtime and throws exception if it fails
00407 
00408 The macros CV_Assert (and CV_DbgAssert(expr)) evaluate the specified expression. If it is 0, the macros
00409 raise an error (see cv::error). The macro CV_Assert checks the condition in both Debug and Release
00410 configurations while CV_DbgAssert is only retained in the Debug configuration.
00411 */
00412 #define CV_Assert( expr ) if(!!(expr)) ; else cv::error( cv::Error::StsAssert, #expr, CV_Func, __FILE__, __LINE__ )
00413 
00414 /** same as CV_Error(code,msg), but does not return */
00415 #define CV_ErrorNoReturn( code, msg ) cv::errorNoReturn( code, msg, CV_Func, __FILE__, __LINE__ )
00416 
00417 /** same as CV_Error_(code,args), but does not return */
00418 #define CV_ErrorNoReturn_( code, args ) cv::errorNoReturn( code, cv::format args, CV_Func, __FILE__, __LINE__ )
00419 
00420 /** replaced with CV_Assert(expr) in Debug configuration */
00421 #ifdef _DEBUG
00422 #  define CV_DbgAssert(expr) CV_Assert(expr)
00423 #else
00424 #  define CV_DbgAssert(expr)
00425 #endif
00426 
00427 /*
00428  * Hamming distance functor - counts the bit differences between two strings - useful for the Brief descriptor
00429  * bit count of A exclusive XOR'ed with B
00430  */
00431 struct CV_EXPORTS Hamming
00432 {
00433     enum { normType = NORM_HAMMING };
00434     typedef unsigned char ValueType;
00435     typedef int ResultType;
00436 
00437     /** this will count the bits in a ^ b
00438      */
00439     ResultType operator()( const unsigned char* a, const unsigned char* b, int size ) const;
00440 };
00441 
00442 typedef Hamming HammingLUT;
00443 
00444 /////////////////////////////////// inline norms ////////////////////////////////////
00445 
00446 template<typename _Tp> inline _Tp cv_abs(_Tp x) { return std::abs(x); }
00447 inline int cv_abs(uchar x) { return x; }
00448 inline int cv_abs(schar x) { return std::abs(x); }
00449 inline int cv_abs(ushort x) { return x; }
00450 inline int cv_abs(short x) { return std::abs(x); }
00451 
00452 template<typename _Tp, typename _AccTp> static inline
00453 _AccTp normL2Sqr(const _Tp* a, int n)
00454 {
00455     _AccTp s = 0;
00456     int i=0;
00457 #if CV_ENABLE_UNROLLED
00458     for( ; i <= n - 4; i += 4 )
00459     {
00460         _AccTp v0 = a[i], v1 = a[i+1], v2 = a[i+2], v3 = a[i+3];
00461         s += v0*v0 + v1*v1 + v2*v2 + v3*v3;
00462     }
00463 #endif
00464     for( ; i < n; i++ )
00465     {
00466         _AccTp v = a[i];
00467         s += v*v;
00468     }
00469     return s;
00470 }
00471 
00472 template<typename _Tp, typename _AccTp> static inline
00473 _AccTp normL1(const _Tp* a, int n)
00474 {
00475     _AccTp s = 0;
00476     int i = 0;
00477 #if CV_ENABLE_UNROLLED
00478     for(; i <= n - 4; i += 4 )
00479     {
00480         s += (_AccTp)cv_abs(a[i]) + (_AccTp)cv_abs(a[i+1]) +
00481             (_AccTp)cv_abs(a[i+2]) + (_AccTp)cv_abs(a[i+3]);
00482     }
00483 #endif
00484     for( ; i < n; i++ )
00485         s += cv_abs(a[i]);
00486     return s;
00487 }
00488 
00489 template<typename _Tp, typename _AccTp> static inline
00490 _AccTp normInf(const _Tp* a, int n)
00491 {
00492     _AccTp s = 0;
00493     for( int i = 0; i < n; i++ )
00494         s = std::max(s, (_AccTp)cv_abs(a[i]));
00495     return s;
00496 }
00497 
00498 template<typename _Tp, typename _AccTp> static inline
00499 _AccTp normL2Sqr(const _Tp* a, const _Tp* b, int n)
00500 {
00501     _AccTp s = 0;
00502     int i= 0;
00503 #if CV_ENABLE_UNROLLED
00504     for(; i <= n - 4; i += 4 )
00505     {
00506         _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]);
00507         s += v0*v0 + v1*v1 + v2*v2 + v3*v3;
00508     }
00509 #endif
00510     for( ; i < n; i++ )
00511     {
00512         _AccTp v = _AccTp(a[i] - b[i]);
00513         s += v*v;
00514     }
00515     return s;
00516 }
00517 
00518 static inline float normL2Sqr(const float* a, const float* b, int n)
00519 {
00520     float s = 0.f;
00521     for( int i = 0; i < n; i++ )
00522     {
00523         float v = a[i] - b[i];
00524         s += v*v;
00525     }
00526     return s;
00527 }
00528 
00529 template<typename _Tp, typename _AccTp> static inline
00530 _AccTp normL1(const _Tp* a, const _Tp* b, int n)
00531 {
00532     _AccTp s = 0;
00533     int i= 0;
00534 #if CV_ENABLE_UNROLLED
00535     for(; i <= n - 4; i += 4 )
00536     {
00537         _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]);
00538         s += std::abs(v0) + std::abs(v1) + std::abs(v2) + std::abs(v3);
00539     }
00540 #endif
00541     for( ; i < n; i++ )
00542     {
00543         _AccTp v = _AccTp(a[i] - b[i]);
00544         s += std::abs(v);
00545     }
00546     return s;
00547 }
00548 
00549 inline float normL1(const float* a, const float* b, int n)
00550 {
00551     float s = 0.f;
00552     for( int i = 0; i < n; i++ )
00553     {
00554         s += std::abs(a[i] - b[i]);
00555     }
00556     return s;
00557 }
00558 
00559 inline int normL1(const uchar* a, const uchar* b, int n)
00560 {
00561     int s = 0;
00562     for( int i = 0; i < n; i++ )
00563     {
00564         s += std::abs(a[i] - b[i]);
00565     }
00566     return s;
00567 }
00568 
00569 template<typename _Tp, typename _AccTp> static inline
00570 _AccTp normInf(const _Tp* a, const _Tp* b, int n)
00571 {
00572     _AccTp s = 0;
00573     for( int i = 0; i < n; i++ )
00574     {
00575         _AccTp v0 = a[i] - b[i];
00576         s = std::max(s, std::abs(v0));
00577     }
00578     return s;
00579 }
00580 
00581 /** @brief Computes the cube root of an argument.
00582 
00583  The function cubeRoot computes \f$\sqrt[3]{\texttt{val}}\f$. Negative arguments are handled correctly.
00584  NaN and Inf are not handled. The accuracy approaches the maximum possible accuracy for
00585  single-precision data.
00586  @param val A function argument.
00587  */
00588 CV_EXPORTS_W float cubeRoot(float val);
00589 
00590 /** @brief Calculates the angle of a 2D vector in degrees.
00591 
00592  The function fastAtan2 calculates the full-range angle of an input 2D vector. The angle is measured
00593  in degrees and varies from 0 to 360 degrees. The accuracy is about 0.3 degrees.
00594  @param x x-coordinate of the vector.
00595  @param y y-coordinate of the vector.
00596  */
00597 CV_EXPORTS_W float fastAtan2(float y, float x);
00598 
00599 /** proxy for hal::LU */
00600 CV_EXPORTS int LU(float* A, size_t astep, int m, float* b, size_t bstep, int n);
00601 /** proxy for hal::LU */
00602 CV_EXPORTS int LU(double* A, size_t astep, int m, double* b, size_t bstep, int n);
00603 /** proxy for hal::Cholesky */
00604 CV_EXPORTS bool Cholesky(float* A, size_t astep, int m, float* b, size_t bstep, int n);
00605 /** proxy for hal::Cholesky */
00606 CV_EXPORTS bool Cholesky(double* A, size_t astep, int m, double* b, size_t bstep, int n);
00607 
00608 ////////////////// forward declarations for important OpenCV types //////////////////
00609 
00610 //! @cond IGNORED
00611 
00612 template<typename _Tp, int cn> class Vec;
00613 template<typename _Tp, int m, int n> class Matx;
00614 
00615 template<typename _Tp> class Complex;
00616 template<typename _Tp> class Point_;
00617 template<typename _Tp> class Point3_;
00618 template<typename _Tp> class Size_;
00619 template<typename _Tp> class Rect_;
00620 template<typename _Tp> class Scalar_;
00621 
00622 class CV_EXPORTS RotatedRect;
00623 class CV_EXPORTS Range;
00624 class CV_EXPORTS TermCriteria;
00625 class CV_EXPORTS KeyPoint;
00626 class CV_EXPORTS DMatch;
00627 class CV_EXPORTS RNG;
00628 
00629 class CV_EXPORTS Mat;
00630 class CV_EXPORTS MatExpr;
00631 
00632 class CV_EXPORTS UMat;
00633 
00634 class CV_EXPORTS SparseMat;
00635 typedef Mat MatND;
00636 
00637 template<typename _Tp> class Mat_;
00638 template<typename _Tp> class SparseMat_;
00639 
00640 class CV_EXPORTS MatConstIterator;
00641 class CV_EXPORTS SparseMatIterator;
00642 class CV_EXPORTS SparseMatConstIterator;
00643 template<typename _Tp> class MatIterator_;
00644 template<typename _Tp> class MatConstIterator_;
00645 template<typename _Tp> class SparseMatIterator_;
00646 template<typename _Tp> class SparseMatConstIterator_;
00647 
00648 namespace ogl
00649 {
00650     class CV_EXPORTS Buffer;
00651     class CV_EXPORTS Texture2D;
00652     class CV_EXPORTS Arrays;
00653 }
00654 
00655 namespace cuda
00656 {
00657     class CV_EXPORTS GpuMat;
00658     class CV_EXPORTS HostMem;
00659     class CV_EXPORTS Stream;
00660     class CV_EXPORTS Event;
00661 }
00662 
00663 namespace cudev
00664 {
00665     template <typename _Tp> class GpuMat_;
00666 }
00667 
00668 namespace ipp
00669 {
00670 CV_EXPORTS int getIppFeatures();
00671 CV_EXPORTS void setIppStatus(int status, const char * const funcname = NULL, const char * const filename = NULL,
00672                              int line = 0);
00673 CV_EXPORTS int getIppStatus();
00674 CV_EXPORTS String getIppErrorLocation();
00675 CV_EXPORTS bool useIPP();
00676 CV_EXPORTS void setUseIPP(bool flag);
00677 
00678 } // ipp
00679 
00680 //! @endcond
00681 
00682 //! @} core_utils
00683 
00684 
00685 
00686 
00687 } // cv
00688 
00689 #include "opencv2/core/neon_utils.hpp"
00690 
00691 #endif //OPENCV_CORE_BASE_HPP