Renesas GR-PEACH OpenCV Development / gr-peach-opencv-project-sd-card_update

Fork of gr-peach-opencv-project-sd-card by the do

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