include/opencv2/core/core.hpp
Go to the documentation of this file.
00001 
00004 /*M///////////////////////////////////////////////////////////////////////////////////////
00005 //
00006 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
00007 //
00008 //  By downloading, copying, installing or using the software you agree to this license.
00009 //  If you do not agree to this license, do not download, install,
00010 //  copy or use the software.
00011 //
00012 //
00013 //                           License Agreement
00014 //                For Open Source Computer Vision Library
00015 //
00016 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
00017 // Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved.
00018 // Third party copyrights are property of their respective owners.
00019 //
00020 // Redistribution and use in source and binary forms, with or without modification,
00021 // are permitted provided that the following conditions are met:
00022 //
00023 //   * Redistribution's of source code must retain the above copyright notice,
00024 //     this list of conditions and the following disclaimer.
00025 //
00026 //   * Redistribution's in binary form must reproduce the above copyright notice,
00027 //     this list of conditions and the following disclaimer in the documentation
00028 //     and/or other materials provided with the distribution.
00029 //
00030 //   * The name of the copyright holders may not be used to endorse or promote products
00031 //     derived from this software without specific prior written permission.
00032 //
00033 // This software is provided by the copyright holders and contributors "as is" and
00034 // any express or implied warranties, including, but not limited to, the implied
00035 // warranties of merchantability and fitness for a particular purpose are disclaimed.
00036 // In no event shall the Intel Corporation or contributors be liable for any direct,
00037 // indirect, incidental, special, exemplary, or consequential damages
00038 // (including, but not limited to, procurement of substitute goods or services;
00039 // loss of use, data, or profits; or business interruption) however caused
00040 // and on any theory of liability, whether in contract, strict liability,
00041 // or tort (including negligence or otherwise) arising in any way out of
00042 // the use of this software, even if advised of the possibility of such damage.
00043 //
00044 //M*/
00045 
00046 #ifndef __OPENCV_CORE_HPP__
00047 #define __OPENCV_CORE_HPP__
00048 
00049 #include "opencv2/core/types_c.h"
00050 #include "opencv2/core/version.hpp"
00051 
00052 #ifdef __cplusplus
00053 
00054 #ifndef SKIP_INCLUDES
00055 #include <limits.h>
00056 #include <algorithm>
00057 #include <cmath>
00058 #include <cstddef>
00059 #include <complex>
00060 #include <map>
00061 #include <new>
00062 #include <string>
00063 #include <vector>
00064 #include <sstream>
00065 #endif // SKIP_INCLUDES
00066 
00070 namespace cv {
00071 
00072 #undef abs
00073 #undef min
00074 #undef max
00075 #undef Complex
00076 
00077 using std::vector;
00078 using std::string;
00079 using std::ptrdiff_t;
00080 
00081 template<typename _Tp> class CV_EXPORTS Size_;
00082 template<typename _Tp> class CV_EXPORTS Point_;
00083 template<typename _Tp> class CV_EXPORTS Rect_;
00084 template<typename _Tp, int cn> class CV_EXPORTS Vec;
00085 template<typename _Tp, int m, int n> class CV_EXPORTS Matx;
00086 
00087 typedef std::string String;
00088 
00089 class Mat;
00090 class SparseMat;
00091 typedef Mat MatND;
00092 
00093 class GlBuffer;
00094 class GlTexture;
00095 class GlArrays;
00096 class GlCamera;
00097 
00098 namespace gpu {
00099     class GpuMat;
00100 }
00101 
00102 class CV_EXPORTS MatExpr;
00103 class CV_EXPORTS MatOp_Base;
00104 class CV_EXPORTS MatArg;
00105 class CV_EXPORTS MatConstIterator;
00106 
00107 template<typename _Tp> class CV_EXPORTS Mat_;
00108 template<typename _Tp> class CV_EXPORTS MatIterator_;
00109 template<typename _Tp> class CV_EXPORTS MatConstIterator_;
00110 template<typename _Tp> class CV_EXPORTS MatCommaInitializer_;
00111 
00112 #if !defined(ANDROID) || (defined(_GLIBCXX_USE_WCHAR_T) && _GLIBCXX_USE_WCHAR_T)
00113 typedef std::basic_string<wchar_t> WString;
00114 
00115 CV_EXPORTS string fromUtf16(const WString& str);
00116 CV_EXPORTS WString toUtf16(const string& str);
00117 #endif
00118 
00119 CV_EXPORTS string format( const char* fmt, ... );
00120 CV_EXPORTS string tempfile( const char* suffix CV_DEFAULT(0));
00121 
00122 // matrix decomposition types
00123 enum { DECOMP_LU=0, DECOMP_SVD=1, DECOMP_EIG=2, DECOMP_CHOLESKY=3, DECOMP_QR=4, DECOMP_NORMAL=16 };
00124 enum { NORM_INF=1, NORM_L1=2, NORM_L2=4, NORM_L2SQR=5, NORM_HAMMING=6, NORM_HAMMING2=7, NORM_TYPE_MASK=7, NORM_RELATIVE=8, NORM_MINMAX=32 };
00125 enum { CMP_EQ=0, CMP_GT=1, CMP_GE=2, CMP_LT=3, CMP_LE=4, CMP_NE=5 };
00126 enum { GEMM_1_T=1, GEMM_2_T=2, GEMM_3_T=4 };
00127 enum { DFT_INVERSE=1, DFT_SCALE=2, DFT_ROWS=4, DFT_COMPLEX_OUTPUT=16, DFT_REAL_OUTPUT=32,
00128     DCT_INVERSE = DFT_INVERSE, DCT_ROWS=DFT_ROWS };
00129 
00130 
00135 class CV_EXPORTS Exception : public std::exception
00136 {
00137 public:
00141     Exception();
00146     Exception(int _code, const string& _err, const string& _func, const string& _file, int _line);
00147     virtual ~Exception() throw();
00148 
00152     virtual const char *what() const throw();
00153     void formatMessage();
00154 
00155     string msg; 
00156 
00157     int code; 
00158     string err; 
00159     string func; 
00160     string file; 
00161     int line; 
00162 };
00163 
00164 
00166 
00174 CV_EXPORTS void error( const Exception& exc );
00175 
00177 
00184 CV_EXPORTS bool setBreakOnError(bool flag);
00185 
00186 typedef int (CV_CDECL *ErrorCallback)( int status, const char* func_name,
00187                                        const char* err_msg, const char* file_name,
00188                                        int line, void* userdata );
00189 
00191 
00201 CV_EXPORTS ErrorCallback redirectError( ErrorCallback errCallback,
00202                                         void* userdata=0, void** prevUserdata=0);
00203 
00204 #ifdef __GNUC__
00205 #define CV_Error( code, msg ) cv::error( cv::Exception(code, msg, __func__, __FILE__, __LINE__) )
00206 #define CV_Error_( code, args ) cv::error( cv::Exception(code, cv::format args, __func__, __FILE__, __LINE__) )
00207 #define CV_Assert( expr ) if((expr)) ; else cv::error( cv::Exception(CV_StsAssert, #expr, __func__, __FILE__, __LINE__) )
00208 #else
00209 #define CV_Error( code, msg ) cv::error( cv::Exception(code, msg, "", __FILE__, __LINE__) )
00210 #define CV_Error_( code, args ) cv::error( cv::Exception(code, cv::format args, "", __FILE__, __LINE__) )
00211 #define CV_Assert( expr ) if((expr)) ; else cv::error( cv::Exception(CV_StsAssert, #expr, "", __FILE__, __LINE__) )
00212 #endif
00213 
00214 #ifdef _DEBUG
00215 #define CV_DbgAssert(expr) CV_Assert(expr)
00216 #else
00217 #define CV_DbgAssert(expr)
00218 #endif
00219 
00220 CV_EXPORTS void setNumThreads(int nthreads);
00221 CV_EXPORTS int getNumThreads();
00222 CV_EXPORTS int getThreadNum();
00223 
00224 CV_EXPORTS_W const string& getBuildInformation();
00225 
00227 
00234 CV_EXPORTS_W int64 getTickCount();
00235 
00248 CV_EXPORTS_W double getTickFrequency();
00249 
00258 CV_EXPORTS_W int64 getCPUTickCount();
00259 
00279 CV_EXPORTS_W bool checkHardwareSupport(int feature);
00280 
00282 CV_EXPORTS_W int getNumberOfCPUs();
00283 
00294 CV_EXPORTS void* fastMalloc(size_t bufSize);
00295 
00302 CV_EXPORTS void fastFree(void* ptr);
00303 
00304 template<typename _Tp> static inline _Tp* allocate(size_t n)
00305 {
00306     return new _Tp[n];
00307 }
00308 
00309 template<typename _Tp> static inline void deallocate(_Tp* ptr, size_t)
00310 {
00311     delete[] ptr;
00312 }
00313 
00320 template<typename _Tp> static inline _Tp* alignPtr(_Tp* ptr, int n=(int)sizeof(_Tp))
00321 {
00322     return (_Tp*)(((size_t)ptr + n-1) & -n);
00323 }
00324 
00330 static inline size_t alignSize(size_t sz, int n)
00331 {
00332     return (sz + n-1) & -n;
00333 }
00334 
00344 CV_EXPORTS_W void setUseOptimized(bool onoff);
00345 
00351 CV_EXPORTS_W bool useOptimized();
00352 
00356 template<typename _Tp> class CV_EXPORTS Allocator
00357 {
00358 public:
00359     typedef _Tp value_type;
00360     typedef value_type* pointer;
00361     typedef const value_type* const_pointer;
00362     typedef value_type& reference;
00363     typedef const value_type& const_reference;
00364     typedef size_t size_type;
00365     typedef ptrdiff_t difference_type;
00366     template<typename U> class rebind { typedef Allocator<U> other; };
00367 
00368     explicit Allocator() {}
00369     ~Allocator() {}
00370     explicit Allocator(Allocator const&) {}
00371     template<typename U>
00372     explicit Allocator(Allocator<U> const&) {}
00373 
00374     // address
00375     pointer address(reference r) { return &r; }
00376     const_pointer address(const_reference r) { return &r; }
00377 
00378     pointer allocate(size_type count, const void* =0)
00379     { return reinterpret_cast<pointer>(fastMalloc(count * sizeof (_Tp))); }
00380 
00381     void deallocate(pointer p, size_type) {fastFree(p); }
00382 
00383     size_type max_size() const
00384     { return max(static_cast<_Tp>(-1)/sizeof(_Tp), 1); }
00385 
00386     void construct(pointer p, const _Tp& v) { new(static_cast<void*>(p)) _Tp(v); }
00387     void destroy(pointer p) { p->~_Tp(); }
00388 };
00389 
00391 
00398 template<typename _Tp> class CV_EXPORTS DataDepth {};
00399 
00400 template<> class DataDepth<bool> { public: enum { value = CV_8U, fmt=(int)'u' }; };
00401 template<> class DataDepth<uchar> { public: enum { value = CV_8U, fmt=(int)'u' }; };
00402 template<> class DataDepth<schar> { public: enum { value = CV_8S, fmt=(int)'c' }; };
00403 template<> class DataDepth<char> { public: enum { value = CV_8S, fmt=(int)'c' }; };
00404 template<> class DataDepth<ushort> { public: enum { value = CV_16U, fmt=(int)'w' }; };
00405 template<> class DataDepth<short> { public: enum { value = CV_16S, fmt=(int)'s' }; };
00406 template<> class DataDepth<int> { public: enum { value = CV_32S, fmt=(int)'i' }; };
00407 // this is temporary solution to support 32-bit unsigned integers
00408 template<> class DataDepth<unsigned> { public: enum { value = CV_32S, fmt=(int)'i' }; };
00409 template<> class DataDepth<float> { public: enum { value = CV_32F, fmt=(int)'f' }; };
00410 template<> class DataDepth<double> { public: enum { value = CV_64F, fmt=(int)'d' }; };
00411 template<typename _Tp> class DataDepth<_Tp*> { public: enum { value = CV_USRTYPE1, fmt=(int)'r' }; };
00412 
00413 
00415 
00432 struct CV_EXPORTS Matx_AddOp {};
00433 struct CV_EXPORTS Matx_SubOp {};
00434 struct CV_EXPORTS Matx_ScaleOp {};
00435 struct CV_EXPORTS Matx_MulOp {};
00436 struct CV_EXPORTS Matx_MatMulOp {};
00437 struct CV_EXPORTS Matx_TOp {};
00438 
00439 template<typename _Tp, int m, int n> class CV_EXPORTS Matx
00440 {
00441 public:
00442     typedef _Tp value_type;
00443     typedef Matx<_Tp, (m < n ? m : n), 1> diag_type;
00444     typedef Matx<_Tp, m, n> mat_type;
00445     enum { depth = DataDepth<_Tp>::value, rows = m, cols = n, channels = rows*cols,
00446            type = CV_MAKETYPE(depth, channels) };
00447 
00449     Matx();
00450 
00451     Matx(_Tp v0); 
00452     Matx(_Tp v0, _Tp v1); 
00453     Matx(_Tp v0, _Tp v1, _Tp v2); 
00454     Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3); 
00455     Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4); 
00456     Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5); 
00457     Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6); 
00458     Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7); 
00459     Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8); 
00460     Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8, _Tp v9); 
00461     Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3,
00462          _Tp v4, _Tp v5, _Tp v6, _Tp v7,
00463          _Tp v8, _Tp v9, _Tp v10, _Tp v11); 
00464     Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3,
00465          _Tp v4, _Tp v5, _Tp v6, _Tp v7,
00466          _Tp v8, _Tp v9, _Tp v10, _Tp v11,
00467          _Tp v12, _Tp v13, _Tp v14, _Tp v15); 
00468     explicit Matx(const _Tp* vals); 
00469 
00470     static Matx all(_Tp alpha);
00471     static Matx zeros();
00472     static Matx ones();
00473     static Matx eye();
00474     static Matx diag(const diag_type& d);
00475     static Matx randu(_Tp a, _Tp b);
00476     static Matx randn(_Tp a, _Tp b);
00477 
00479     _Tp dot(const Matx<_Tp, m, n>& v) const;
00480 
00482     double ddot(const Matx<_Tp, m, n>& v) const;
00483 
00485     template<typename T2> operator Matx<T2, m, n>() const;
00486 
00488     template<int m1, int n1> Matx<_Tp, m1, n1> reshape() const;
00489 
00491     template<int m1, int n1> Matx<_Tp, m1, n1> get_minor(int i, int j) const;
00492 
00494     Matx<_Tp, 1, n> row(int i) const;
00495 
00497     Matx<_Tp, m, 1> col(int i) const;
00498 
00500     diag_type diag() const;
00501 
00503     Matx<_Tp, n, m> t() const;
00504 
00506     Matx<_Tp, n, m> inv(int method=DECOMP_LU) const;
00507 
00509     template<int l> Matx<_Tp, n, l> solve(const Matx<_Tp, m, l>& rhs, int flags=DECOMP_LU) const;
00510     Vec<_Tp, n> solve(const Vec<_Tp, m>& rhs, int method) const;
00511 
00513     Matx<_Tp, m, n> mul(const Matx<_Tp, m, n>& a) const;
00514 
00516     const _Tp& operator ()(int i, int j) const;
00517     _Tp& operator ()(int i, int j);
00518 
00520     const _Tp& operator ()(int i) const;
00521     _Tp& operator ()(int i);
00522 
00523     Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_AddOp);
00524     Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_SubOp);
00525     template<typename _T2> Matx(const Matx<_Tp, m, n>& a, _T2 alpha, Matx_ScaleOp);
00526     Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_MulOp);
00527     template<int l> Matx(const Matx<_Tp, m, l>& a, const Matx<_Tp, l, n>& b, Matx_MatMulOp);
00528     Matx(const Matx<_Tp, n, m>& a, Matx_TOp);
00529 
00530     _Tp val[m*n]; //< matrix elements
00531 };
00532 
00533 
00534 typedef Matx<float, 1, 2> Matx12f;
00535 typedef Matx<double, 1, 2> Matx12d;
00536 typedef Matx<float, 1, 3> Matx13f;
00537 typedef Matx<double, 1, 3> Matx13d;
00538 typedef Matx<float, 1, 4> Matx14f;
00539 typedef Matx<double, 1, 4> Matx14d;
00540 typedef Matx<float, 1, 6> Matx16f;
00541 typedef Matx<double, 1, 6> Matx16d;
00542 
00543 typedef Matx<float, 2, 1> Matx21f;
00544 typedef Matx<double, 2, 1> Matx21d;
00545 typedef Matx<float, 3, 1> Matx31f;
00546 typedef Matx<double, 3, 1> Matx31d;
00547 typedef Matx<float, 4, 1> Matx41f;
00548 typedef Matx<double, 4, 1> Matx41d;
00549 typedef Matx<float, 6, 1> Matx61f;
00550 typedef Matx<double, 6, 1> Matx61d;
00551 
00552 typedef Matx<float, 2, 2> Matx22f;
00553 typedef Matx<double, 2, 2> Matx22d;
00554 typedef Matx<float, 2, 3> Matx23f;
00555 typedef Matx<double, 2, 3> Matx23d;
00556 typedef Matx<float, 3, 2> Matx32f;
00557 typedef Matx<double, 3, 2> Matx32d;
00558 
00559 typedef Matx<float, 3, 3> Matx33f;
00560 typedef Matx<double, 3, 3> Matx33d;
00561 
00562 typedef Matx<float, 3, 4> Matx34f;
00563 typedef Matx<double, 3, 4> Matx34d;
00564 typedef Matx<float, 4, 3> Matx43f;
00565 typedef Matx<double, 4, 3> Matx43d;
00566 
00567 typedef Matx<float, 4, 4> Matx44f;
00568 typedef Matx<double, 4, 4> Matx44d;
00569 typedef Matx<float, 6, 6> Matx66f;
00570 typedef Matx<double, 6, 6> Matx66d;
00571 
00572 
00588 template<typename _Tp, int cn> class CV_EXPORTS Vec : public Matx<_Tp, cn, 1>
00589 {
00590 public:
00591     typedef _Tp value_type;
00592     enum { depth = DataDepth<_Tp>::value, channels = cn, type = CV_MAKETYPE(depth, channels) };
00593 
00595     Vec();
00596 
00597     Vec(_Tp v0); 
00598     Vec(_Tp v0, _Tp v1); 
00599     Vec(_Tp v0, _Tp v1, _Tp v2); 
00600     Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3); 
00601     Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4); 
00602     Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5); 
00603     Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6); 
00604     Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7); 
00605     Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8); 
00606     Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8, _Tp v9); 
00607     explicit Vec(const _Tp* values);
00608 
00609     Vec(const Vec<_Tp, cn>& v);
00610 
00611     static Vec all(_Tp alpha);
00612 
00614     Vec mul(const Vec<_Tp, cn>& v) const;
00615 
00617     Vec conj() const;
00618 
00624     Vec cross(const Vec& v) const;
00626     template<typename T2> operator Vec<T2, cn>() const;
00628     operator CvScalar() const;
00629 
00631     const _Tp& operator [](int i) const;
00632     _Tp& operator[](int i);
00633     const _Tp& operator ()(int i) const;
00634     _Tp& operator ()(int i);
00635 
00636     Vec(const Matx<_Tp, cn, 1>& a, const Matx<_Tp, cn, 1>& b, Matx_AddOp);
00637     Vec(const Matx<_Tp, cn, 1>& a, const Matx<_Tp, cn, 1>& b, Matx_SubOp);
00638     template<typename _T2> Vec(const Matx<_Tp, cn, 1>& a, _T2 alpha, Matx_ScaleOp);
00639 };
00640 
00641 
00642 /* \typedef
00643 
00644    Shorter aliases for the most popular specializations of Vec<T,n>
00645 */
00646 typedef Vec<uchar, 2> Vec2b;
00647 typedef Vec<uchar, 3> Vec3b;
00648 typedef Vec<uchar, 4> Vec4b;
00649 
00650 typedef Vec<short, 2> Vec2s;
00651 typedef Vec<short, 3> Vec3s;
00652 typedef Vec<short, 4> Vec4s;
00653 
00654 typedef Vec<ushort, 2> Vec2w;
00655 typedef Vec<ushort, 3> Vec3w;
00656 typedef Vec<ushort, 4> Vec4w;
00657 
00658 typedef Vec<int, 2> Vec2i;
00659 typedef Vec<int, 3> Vec3i;
00660 typedef Vec<int, 4> Vec4i;
00661 typedef Vec<int, 6> Vec6i;
00662 typedef Vec<int, 8> Vec8i;
00663 
00664 typedef Vec<float, 2> Vec2f;
00665 typedef Vec<float, 3> Vec3f;
00666 typedef Vec<float, 4> Vec4f;
00667 typedef Vec<float, 6> Vec6f;
00668 
00669 typedef Vec<double, 2> Vec2d;
00670 typedef Vec<double, 3> Vec3d;
00671 typedef Vec<double, 4> Vec4d;
00672 typedef Vec<double, 6> Vec6d;
00673 
00674 
00676 
00684 template<typename _Tp> class CV_EXPORTS Complex
00685 {
00686 public:
00687 
00689     Complex();
00690     Complex( _Tp _re, _Tp _im=0 );
00691     Complex( const std::complex<_Tp>& c );
00692 
00694     template<typename T2> operator Complex<T2>() const;
00696     Complex conj() const;
00698     operator std::complex<_Tp>() const;
00699 
00700     _Tp re, im; //< the real and the imaginary parts
00701 };
00702 
00703 
00707 typedef Complex<float> Complexf;
00708 typedef Complex<double> Complexd;
00709 
00710 
00712 
00720 template<typename _Tp> class CV_EXPORTS Point_
00721 {
00722 public:
00723     typedef _Tp value_type;
00724 
00725     // various constructors
00726     Point_();
00727     Point_(_Tp _x, _Tp _y);
00728     Point_(const Point_& pt);
00729     Point_(const CvPoint& pt);
00730     Point_(const CvPoint2D32f& pt);
00731     Point_(const Size_<_Tp>& sz);
00732     Point_(const Vec<_Tp, 2>& v);
00733 
00734     Point_& operator = (const Point_& pt);
00736     template<typename _Tp2> operator Point_<_Tp2>() const;
00737 
00739     operator CvPoint() const;
00740     operator CvPoint2D32f() const;
00741     operator Vec<_Tp, 2>() const;
00742 
00744     _Tp dot(const Point_& pt) const;
00746     double ddot(const Point_& pt) const;
00748     double cross(const Point_& pt) const;
00750     bool inside(const Rect_<_Tp>& r) const;
00751 
00752     _Tp x, y; //< the point coordinates
00753 };
00754 
00763 template<typename _Tp> class CV_EXPORTS Point3_
00764 {
00765 public:
00766     typedef _Tp value_type;
00767 
00768     // various constructors
00769     Point3_();
00770     Point3_(_Tp _x, _Tp _y, _Tp _z);
00771     Point3_(const Point3_& pt);
00772     explicit Point3_(const Point_<_Tp>& pt);
00773     Point3_(const CvPoint3D32f& pt);
00774     Point3_(const Vec<_Tp, 3>& v);
00775 
00776     Point3_& operator = (const Point3_& pt);
00778     template<typename _Tp2> operator Point3_<_Tp2>() const;
00780     operator CvPoint3D32f() const;
00782     operator Vec<_Tp, 3>() const;
00783 
00785     _Tp dot(const Point3_& pt) const;
00787     double ddot(const Point3_& pt) const;
00789     Point3_ cross(const Point3_& pt) const;
00790 
00791     _Tp x, y, z; //< the point coordinates
00792 };
00793 
00795 
00802 template<typename _Tp> class CV_EXPORTS Size_
00803 {
00804 public:
00805     typedef _Tp value_type;
00806 
00808     Size_();
00809     Size_(_Tp _width, _Tp _height);
00810     Size_(const Size_& sz);
00811     Size_(const CvSize& sz);
00812     Size_(const CvSize2D32f& sz);
00813     Size_(const Point_<_Tp>& pt);
00814 
00815     Size_& operator = (const Size_& sz);
00817     _Tp area() const;
00818 
00820     template<typename _Tp2> operator Size_<_Tp2>() const;
00821 
00823     operator CvSize() const;
00824     operator CvSize2D32f() const;
00825 
00826     _Tp width, height; // the width and the height
00827 };
00828 
00830 
00837 template<typename _Tp> class CV_EXPORTS Rect_
00838 {
00839 public:
00840     typedef _Tp value_type;
00841 
00843     Rect_();
00844     Rect_(_Tp _x, _Tp _y, _Tp _width, _Tp _height);
00845     Rect_(const Rect_& r);
00846     Rect_(const CvRect& r);
00847     Rect_(const Point_<_Tp>& org, const Size_<_Tp>& sz);
00848     Rect_(const Point_<_Tp>& pt1, const Point_<_Tp>& pt2);
00849 
00850     Rect_& operator = ( const Rect_& r );
00852     Point_<_Tp> tl() const;
00854     Point_<_Tp> br() const;
00855 
00857     Size_<_Tp> size() const;
00859     _Tp area() const;
00860 
00862     template<typename _Tp2> operator Rect_<_Tp2>() const;
00864     operator CvRect() const;
00865 
00867     bool contains(const Point_<_Tp>& pt) const;
00868 
00869     _Tp x, y, width, height; //< the top-left corner, as well as width and height of the rectangle
00870 };
00871 
00872 
00878 typedef Point_<int> Point2i;
00879 typedef Point2i Point;
00880 typedef Size_<int> Size2i;
00881 typedef Size2i Size;
00882 typedef Rect_<int> Rect;
00883 typedef Point_<float> Point2f;
00884 typedef Point_<double> Point2d;
00885 typedef Size_<float> Size2f;
00886 typedef Point3_<int> Point3i;
00887 typedef Point3_<float> Point3f;
00888 typedef Point3_<double> Point3d;
00889 
00890 
00898 class CV_EXPORTS RotatedRect
00899 {
00900 public:
00902     RotatedRect();
00903     RotatedRect(const Point2f& center, const Size2f& size, float angle);
00904     RotatedRect(const CvBox2D& box);
00905 
00907     void points(Point2f pts[]) const;
00909     Rect boundingRect() const;
00911     operator CvBox2D() const;
00912 
00913     Point2f center; //< the rectangle mass center
00914     Size2f size;    //< width and height of the rectangle
00915     float angle;    //< the rotation angle. When the angle is 0, 90, 180, 270 etc., the rectangle becomes an up-right rectangle.
00916 };
00917 
00919 
00926 template<typename _Tp> class CV_EXPORTS Scalar_ : public Vec<_Tp, 4>
00927 {
00928 public:
00930     Scalar_();
00931     Scalar_(_Tp v0, _Tp v1, _Tp v2=0, _Tp v3=0);
00932     Scalar_(const CvScalar& s);
00933     Scalar_(_Tp v0);
00934 
00936     static Scalar_<_Tp> all(_Tp v0);
00938     operator CvScalar() const;
00939 
00941     template<typename T2> operator Scalar_<T2>() const;
00942 
00944     Scalar_<_Tp> mul(const Scalar_<_Tp>& t, double scale=1 ) const;
00945 
00946     // returns (v0, -v1, -v2, -v3)
00947     Scalar_<_Tp> conj() const;
00948 
00949     // returns true iff v1 == v2 == v3 == 0
00950     bool isReal() const;
00951 };
00952 
00953 typedef Scalar_<double> Scalar;
00954 
00955 CV_EXPORTS void scalarToRawData(const Scalar& s, void* buf, int type, int unroll_to=0);
00956 
00958 
00964 class CV_EXPORTS Range
00965 {
00966 public:
00967     Range();
00968     Range(int _start, int _end);
00969     Range(const CvSlice& slice);
00970     int size() const;
00971     bool empty() const;
00972     static Range all();
00973     operator CvSlice() const;
00974 
00975     int start, end;
00976 };
00977 
00979 
00991 template<typename _Tp> class DataType
00992 {
00993 public:
00994     typedef _Tp value_type;
00995     typedef value_type work_type;
00996     typedef value_type channel_type;
00997     typedef value_type vec_type;
00998     enum { generic_type = 1, depth = -1, channels = 1, fmt=0,
00999         type = CV_MAKETYPE(depth, channels) };
01000 };
01001 
01002 template<> class DataType<bool>
01003 {
01004 public:
01005     typedef bool value_type;
01006     typedef int work_type;
01007     typedef value_type channel_type;
01008     typedef value_type vec_type;
01009     enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 1,
01010            fmt=DataDepth<channel_type>::fmt,
01011            type = CV_MAKETYPE(depth, channels) };
01012 };
01013 
01014 template<> class DataType<uchar>
01015 {
01016 public:
01017     typedef uchar value_type;
01018     typedef int work_type;
01019     typedef value_type channel_type;
01020     typedef value_type vec_type;
01021     enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 1,
01022            fmt=DataDepth<channel_type>::fmt,
01023            type = CV_MAKETYPE(depth, channels) };
01024 };
01025 
01026 template<> class DataType<schar>
01027 {
01028 public:
01029     typedef schar value_type;
01030     typedef int work_type;
01031     typedef value_type channel_type;
01032     typedef value_type vec_type;
01033     enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 1,
01034            fmt=DataDepth<channel_type>::fmt,
01035            type = CV_MAKETYPE(depth, channels) };
01036 };
01037 
01038 template<> class DataType<char>
01039 {
01040 public:
01041     typedef schar value_type;
01042     typedef int work_type;
01043     typedef value_type channel_type;
01044     typedef value_type vec_type;
01045     enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 1,
01046            fmt=DataDepth<channel_type>::fmt,
01047            type = CV_MAKETYPE(depth, channels) };
01048 };
01049 
01050 template<> class DataType<ushort>
01051 {
01052 public:
01053     typedef ushort value_type;
01054     typedef int work_type;
01055     typedef value_type channel_type;
01056     typedef value_type vec_type;
01057     enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 1,
01058            fmt=DataDepth<channel_type>::fmt,
01059            type = CV_MAKETYPE(depth, channels) };
01060 };
01061 
01062 template<> class DataType<short>
01063 {
01064 public:
01065     typedef short value_type;
01066     typedef int work_type;
01067     typedef value_type channel_type;
01068     typedef value_type vec_type;
01069     enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 1,
01070            fmt=DataDepth<channel_type>::fmt,
01071            type = CV_MAKETYPE(depth, channels) };
01072 };
01073 
01074 template<> class DataType<int>
01075 {
01076 public:
01077     typedef int value_type;
01078     typedef value_type work_type;
01079     typedef value_type channel_type;
01080     typedef value_type vec_type;
01081     enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 1,
01082            fmt=DataDepth<channel_type>::fmt,
01083            type = CV_MAKETYPE(depth, channels) };
01084 };
01085 
01086 template<> class DataType<float>
01087 {
01088 public:
01089     typedef float value_type;
01090     typedef value_type work_type;
01091     typedef value_type channel_type;
01092     typedef value_type vec_type;
01093     enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 1,
01094            fmt=DataDepth<channel_type>::fmt,
01095            type = CV_MAKETYPE(depth, channels) };
01096 };
01097 
01098 template<> class DataType<double>
01099 {
01100 public:
01101     typedef double value_type;
01102     typedef value_type work_type;
01103     typedef value_type channel_type;
01104     typedef value_type vec_type;
01105     enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 1,
01106            fmt=DataDepth<channel_type>::fmt,
01107            type = CV_MAKETYPE(depth, channels) };
01108 };
01109 
01110 template<typename _Tp, int m, int n> class DataType<Matx<_Tp, m, n> >
01111 {
01112 public:
01113     typedef Matx<_Tp, m, n> value_type;
01114     typedef Matx<typename DataType<_Tp>::work_type, m, n> work_type;
01115     typedef _Tp channel_type;
01116     typedef value_type vec_type;
01117     enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = m*n,
01118         fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt,
01119         type = CV_MAKETYPE(depth, channels) };
01120 };
01121 
01122 template<typename _Tp, int cn> class DataType<Vec<_Tp, cn> >
01123 {
01124 public:
01125     typedef Vec<_Tp, cn> value_type;
01126     typedef Vec<typename DataType<_Tp>::work_type, cn> work_type;
01127     typedef _Tp channel_type;
01128     typedef value_type vec_type;
01129     enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = cn,
01130            fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt,
01131            type = CV_MAKETYPE(depth, channels) };
01132 };
01133 
01134 template<typename _Tp> class DataType<std::complex<_Tp> >
01135 {
01136 public:
01137     typedef std::complex<_Tp> value_type;
01138     typedef value_type work_type;
01139     typedef _Tp channel_type;
01140     enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 2,
01141            fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt,
01142            type = CV_MAKETYPE(depth, channels) };
01143     typedef Vec<channel_type, channels> vec_type;
01144 };
01145 
01146 template<typename _Tp> class DataType<Complex<_Tp> >
01147 {
01148 public:
01149     typedef Complex<_Tp> value_type;
01150     typedef value_type work_type;
01151     typedef _Tp channel_type;
01152     enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 2,
01153            fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt,
01154            type = CV_MAKETYPE(depth, channels) };
01155     typedef Vec<channel_type, channels> vec_type;
01156 };
01157 
01158 template<typename _Tp> class DataType<Point_<_Tp> >
01159 {
01160 public:
01161     typedef Point_<_Tp> value_type;
01162     typedef Point_<typename DataType<_Tp>::work_type> work_type;
01163     typedef _Tp channel_type;
01164     enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 2,
01165            fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt,
01166            type = CV_MAKETYPE(depth, channels) };
01167     typedef Vec<channel_type, channels> vec_type;
01168 };
01169 
01170 template<typename _Tp> class DataType<Point3_<_Tp> >
01171 {
01172 public:
01173     typedef Point3_<_Tp> value_type;
01174     typedef Point3_<typename DataType<_Tp>::work_type> work_type;
01175     typedef _Tp channel_type;
01176     enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 3,
01177            fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt,
01178            type = CV_MAKETYPE(depth, channels) };
01179     typedef Vec<channel_type, channels> vec_type;
01180 };
01181 
01182 template<typename _Tp> class DataType<Size_<_Tp> >
01183 {
01184 public:
01185     typedef Size_<_Tp> value_type;
01186     typedef Size_<typename DataType<_Tp>::work_type> work_type;
01187     typedef _Tp channel_type;
01188     enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 2,
01189            fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt,
01190            type = CV_MAKETYPE(depth, channels) };
01191     typedef Vec<channel_type, channels> vec_type;
01192 };
01193 
01194 template<typename _Tp> class DataType<Rect_<_Tp> >
01195 {
01196 public:
01197     typedef Rect_<_Tp> value_type;
01198     typedef Rect_<typename DataType<_Tp>::work_type> work_type;
01199     typedef _Tp channel_type;
01200     enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 4,
01201            fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt,
01202            type = CV_MAKETYPE(depth, channels) };
01203     typedef Vec<channel_type, channels> vec_type;
01204 };
01205 
01206 template<typename _Tp> class DataType<Scalar_<_Tp> >
01207 {
01208 public:
01209     typedef Scalar_<_Tp> value_type;
01210     typedef Scalar_<typename DataType<_Tp>::work_type> work_type;
01211     typedef _Tp channel_type;
01212     enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 4,
01213            fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt,
01214            type = CV_MAKETYPE(depth, channels) };
01215     typedef Vec<channel_type, channels> vec_type;
01216 };
01217 
01218 template<> class DataType<Range>
01219 {
01220 public:
01221     typedef Range value_type;
01222     typedef value_type work_type;
01223     typedef int channel_type;
01224     enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 2,
01225            fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt,
01226            type = CV_MAKETYPE(depth, channels) };
01227     typedef Vec<channel_type, channels> vec_type;
01228 };
01229 
01231 
01253 template<typename _Tp> class CV_EXPORTS Ptr
01254 {
01255 public:
01257     Ptr();
01259     Ptr(_Tp* _obj);
01261     ~Ptr();
01263     Ptr(const Ptr& ptr);
01264     template<typename _Tp2> Ptr(const Ptr<_Tp2>& ptr);
01266     Ptr& operator = (const Ptr& ptr);
01268     void addref();
01270     void release();
01272     void delete_obj();
01274     bool empty() const;
01275 
01277     template<typename _Tp2> Ptr<_Tp2> ptr();
01278     template<typename _Tp2> const Ptr<_Tp2> ptr() const;
01279 
01281     _Tp* operator -> ();
01282     const _Tp* operator -> () const;
01283 
01284     operator _Tp* ();
01285     operator const _Tp*() const;
01286 
01287     _Tp* obj; //< the object pointer.
01288     int* refcount; //< the associated reference counter
01289 };
01290 
01291 
01293 
01297 class CV_EXPORTS _InputArray
01298 {
01299 public:
01300     enum {
01301         KIND_SHIFT = 16,
01302         FIXED_TYPE = 0x8000 << KIND_SHIFT,
01303         FIXED_SIZE = 0x4000 << KIND_SHIFT,
01304         KIND_MASK = ~(FIXED_TYPE|FIXED_SIZE) - (1 << KIND_SHIFT) + 1,
01305 
01306         NONE              = 0 << KIND_SHIFT,
01307         MAT               = 1 << KIND_SHIFT,
01308         MATX              = 2 << KIND_SHIFT,
01309         STD_VECTOR        = 3 << KIND_SHIFT,
01310         STD_VECTOR_VECTOR = 4 << KIND_SHIFT,
01311         STD_VECTOR_MAT    = 5 << KIND_SHIFT,
01312         EXPR              = 6 << KIND_SHIFT,
01313         OPENGL_BUFFER     = 7 << KIND_SHIFT,
01314         OPENGL_TEXTURE    = 8 << KIND_SHIFT,
01315         GPU_MAT           = 9 << KIND_SHIFT
01316     };
01317     _InputArray();
01318 
01319     _InputArray(const Mat& m);
01320     _InputArray(const MatExpr& expr);
01321     template<typename _Tp> _InputArray(const _Tp* vec, int n);
01322     template<typename _Tp> _InputArray(const vector<_Tp>& vec);
01323     template<typename _Tp> _InputArray(const vector<vector<_Tp> >& vec);
01324     _InputArray(const vector<Mat>& vec);
01325     template<typename _Tp> _InputArray(const vector<Mat_<_Tp> >& vec);
01326     template<typename _Tp> _InputArray(const Mat_<_Tp>& m);
01327     template<typename _Tp, int m, int n> _InputArray(const Matx<_Tp, m, n>& matx);
01328     _InputArray(const Scalar& s);
01329     _InputArray(const double& val);
01330     _InputArray(const GlBuffer& buf);
01331     _InputArray(const GlTexture& tex);
01332     _InputArray(const gpu::GpuMat& d_mat);
01333 
01334     virtual Mat getMat(int i=-1) const;
01335     virtual void getMatVector(vector<Mat>& mv) const;
01336     virtual GlBuffer getGlBuffer() const;
01337     virtual GlTexture getGlTexture() const;
01338     virtual gpu::GpuMat getGpuMat() const;
01339 
01340     virtual int kind() const;
01341     virtual Size size(int i=-1) const;
01342     virtual size_t total(int i=-1) const;
01343     virtual int type(int i=-1) const;
01344     virtual int depth(int i=-1) const;
01345     virtual int channels(int i=-1) const;
01346     virtual bool empty() const;
01347 
01348 #ifdef OPENCV_CAN_BREAK_BINARY_COMPATIBILITY
01349     virtual ~_InputArray();
01350 #endif
01351 
01352     int flags;
01353     void* obj;
01354     Size sz;
01355 };
01356 
01357 
01358 enum
01359 {
01360     DEPTH_MASK_8U = 1 << CV_8U,
01361     DEPTH_MASK_8S = 1 << CV_8S,
01362     DEPTH_MASK_16U = 1 << CV_16U,
01363     DEPTH_MASK_16S = 1 << CV_16S,
01364     DEPTH_MASK_32S = 1 << CV_32S,
01365     DEPTH_MASK_32F = 1 << CV_32F,
01366     DEPTH_MASK_64F = 1 << CV_64F,
01367     DEPTH_MASK_ALL = (DEPTH_MASK_64F<<1)-1,
01368     DEPTH_MASK_ALL_BUT_8S = DEPTH_MASK_ALL & ~DEPTH_MASK_8S,
01369     DEPTH_MASK_FLT = DEPTH_MASK_32F + DEPTH_MASK_64F
01370 };
01371 
01372 
01376 class CV_EXPORTS _OutputArray : public _InputArray
01377 {
01378 public:
01379     _OutputArray();
01380 
01381     _OutputArray(Mat& m);
01382     template<typename _Tp> _OutputArray(vector<_Tp>& vec);
01383     template<typename _Tp> _OutputArray(vector<vector<_Tp> >& vec);
01384     _OutputArray(vector<Mat>& vec);
01385     template<typename _Tp> _OutputArray(vector<Mat_<_Tp> >& vec);
01386     template<typename _Tp> _OutputArray(Mat_<_Tp>& m);
01387     template<typename _Tp, int m, int n> _OutputArray(Matx<_Tp, m, n>& matx);
01388     template<typename _Tp> _OutputArray(_Tp* vec, int n);
01389     _OutputArray(gpu::GpuMat& d_mat);
01390 
01391     _OutputArray(const Mat& m);
01392     template<typename _Tp> _OutputArray(const vector<_Tp>& vec);
01393     template<typename _Tp> _OutputArray(const vector<vector<_Tp> >& vec);
01394     _OutputArray(const vector<Mat>& vec);
01395     template<typename _Tp> _OutputArray(const vector<Mat_<_Tp> >& vec);
01396     template<typename _Tp> _OutputArray(const Mat_<_Tp>& m);
01397     template<typename _Tp, int m, int n> _OutputArray(const Matx<_Tp, m, n>& matx);
01398     template<typename _Tp> _OutputArray(const _Tp* vec, int n);
01399     _OutputArray(const gpu::GpuMat& d_mat);
01400 
01401     virtual bool fixedSize() const;
01402     virtual bool fixedType() const;
01403     virtual bool needed() const;
01404     virtual Mat& getMatRef(int i=-1) const;
01405     /*virtual*/ gpu::GpuMat& getGpuMatRef() const;
01406     virtual void create(Size sz, int type, int i=-1, bool allowTransposed=false, int fixedDepthMask=0) const;
01407     virtual void create(int rows, int cols, int type, int i=-1, bool allowTransposed=false, int fixedDepthMask=0) const;
01408     virtual void create(int dims, const int* size, int type, int i=-1, bool allowTransposed=false, int fixedDepthMask=0) const;
01409     virtual void release() const;
01410     virtual void clear() const;
01411 
01412 #ifdef OPENCV_CAN_BREAK_BINARY_COMPATIBILITY
01413     virtual ~_OutputArray();
01414 #endif
01415 };
01416 
01417 typedef const _InputArray& InputArray;
01418 typedef InputArray InputArrayOfArrays;
01419 typedef const _OutputArray& OutputArray;
01420 typedef OutputArray OutputArrayOfArrays;
01421 typedef OutputArray InputOutputArray;
01422 typedef OutputArray InputOutputArrayOfArrays;
01423 
01424 CV_EXPORTS OutputArray noArray();
01425 
01427 
01428 enum { MAGIC_MASK=0xFFFF0000, TYPE_MASK=0x00000FFF, DEPTH_MASK=7 };
01429 
01430 static inline size_t getElemSize(int type) { return CV_ELEM_SIZE(type); }
01431 
01436 class CV_EXPORTS MatAllocator
01437 {
01438 public:
01439     MatAllocator() {}
01440     virtual ~MatAllocator() {}
01441     virtual void allocate(int dims, const int* sizes, int type, int*& refcount,
01442                           uchar*& datastart, uchar*& data, size_t* step) = 0;
01443     virtual void deallocate(int* refcount, uchar* datastart, uchar* data) = 0;
01444 };
01445 
01658 class CV_EXPORTS Mat
01659 {
01660 public:
01662     Mat();
01664     // (_type is CV_8UC1, CV_64FC3, CV_32SC(12) etc.)
01665     Mat(int rows, int cols, int type);
01666     Mat(Size size, int type);
01668     Mat(int rows, int cols, int type, const Scalar& s);
01669     Mat(Size size, int type, const Scalar& s);
01670 
01672     Mat(int ndims, const int* sizes, int type);
01673     Mat(int ndims, const int* sizes, int type, const Scalar& s);
01674 
01676     Mat(const Mat& m);
01678     Mat(int rows, int cols, int type, void* data, size_t step=AUTO_STEP);
01679     Mat(Size size, int type, void* data, size_t step=AUTO_STEP);
01680     Mat(int ndims, const int* sizes, int type, void* data, const size_t* steps=0);
01681 
01683     Mat(const Mat& m, const Range& rowRange, const Range& colRange=Range::all());
01684     Mat(const Mat& m, const Rect& roi);
01685     Mat(const Mat& m, const Range* ranges);
01687     Mat(const CvMat* m, bool copyData=false);
01689     Mat(const CvMatND* m, bool copyData=false);
01691     Mat(const IplImage* img, bool copyData=false);
01693     template<typename _Tp> explicit Mat(const vector<_Tp>& vec, bool copyData=false);
01695     template<typename _Tp, int n> explicit Mat(const Vec<_Tp, n>& vec, bool copyData=true);
01697     template<typename _Tp, int m, int n> explicit Mat(const Matx<_Tp, m, n>& mtx, bool copyData=true);
01699     template<typename _Tp> explicit Mat(const Point_<_Tp>& pt, bool copyData=true);
01701     template<typename _Tp> explicit Mat(const Point3_<_Tp>& pt, bool copyData=true);
01703     template<typename _Tp> explicit Mat(const MatCommaInitializer_<_Tp>& commaInitializer);
01704 
01706     explicit Mat(const gpu::GpuMat& m);
01707 
01709     ~Mat();
01711     Mat& operator = (const Mat& m);
01712     Mat& operator = (const MatExpr& expr);
01713 
01715     Mat row(int y) const;
01717     Mat col(int x) const;
01719     Mat rowRange(int startrow, int endrow) const;
01720     Mat rowRange(const Range& r) const;
01722     Mat colRange(int startcol, int endcol) const;
01723     Mat colRange(const Range& r) const;
01725     // (d=0 - the main diagonal,
01726     //  >0 - a diagonal from the lower half,
01727     //  <0 - a diagonal from the upper half)
01728     Mat diag(int d=0) const;
01730     static Mat diag(const Mat& d);
01731 
01733     Mat clone() const;
01735     // It calls m.create(this->size(), this->type()).
01736     void copyTo( OutputArray m ) const;
01738     void copyTo( OutputArray m, InputArray mask ) const;
01740     void convertTo( OutputArray m, int rtype, double alpha=1, double beta=0 ) const;
01741 
01742     void assignTo( Mat& m, int type=-1 ) const;
01743 
01745     Mat& operator = (const Scalar& s);
01747     Mat& setTo(InputArray value, InputArray mask=noArray());
01749     // number of channels and/or different number of rows. see cvReshape.
01750     Mat reshape(int cn, int rows=0) const;
01751     Mat reshape(int cn, int newndims, const int* newsz) const;
01752 
01754     MatExpr t() const;
01756     MatExpr inv(int method=DECOMP_LU) const;
01758     MatExpr mul(InputArray m, double scale=1) const;
01759 
01761     Mat cross(InputArray m) const;
01763     double dot(InputArray m) const;
01764 
01766     static MatExpr zeros(int rows, int cols, int type);
01767     static MatExpr zeros(Size size, int type);
01768     static MatExpr zeros(int ndims, const int* sz, int type);
01769     static MatExpr ones(int rows, int cols, int type);
01770     static MatExpr ones(Size size, int type);
01771     static MatExpr ones(int ndims, const int* sz, int type);
01772     static MatExpr eye(int rows, int cols, int type);
01773     static MatExpr eye(Size size, int type);
01774 
01776     // previous data is unreferenced if needed.
01777     void create(int rows, int cols, int type);
01778     void create(Size size, int type);
01779     void create(int ndims, const int* sizes, int type);
01780 
01782     void addref();
01784     // deallocates the data when reference counter reaches 0.
01785     void release();
01786 
01788     void deallocate();
01790     void copySize(const Mat& m);
01791 
01793     void reserve(size_t sz);
01795     void resize(size_t sz);
01797     void resize(size_t sz, const Scalar& s);
01799     void push_back_(const void* elem);
01801     template<typename _Tp> void push_back(const _Tp& elem);
01802     template<typename _Tp> void push_back(const Mat_<_Tp>& elem);
01803     void push_back(const Mat& m);
01805     void pop_back(size_t nelems=1);
01806 
01808     void locateROI( Size& wholeSize, Point& ofs ) const;
01810     Mat& adjustROI( int dtop, int dbottom, int dleft, int dright );
01812     // (this is a generalized form of row, rowRange etc.)
01813     Mat operator()( Range rowRange, Range colRange ) const;
01814     Mat operator()( const Rect& roi ) const;
01815     Mat operator()( const Range* ranges ) const;
01816 
01818     operator CvMat() const;
01820     operator CvMatND() const;
01822     operator IplImage() const;
01823 
01824     template<typename _Tp> operator vector<_Tp>() const;
01825     template<typename _Tp, int n> operator Vec<_Tp, n>() const;
01826     template<typename _Tp, int m, int n> operator Matx<_Tp, m, n>() const;
01827 
01829     // (i.e. when there are no gaps between successive rows).
01830     // similar to CV_IS_MAT_CONT(cvmat->type)
01831     bool isContinuous() const;
01832 
01834     bool isSubmatrix() const;
01835 
01837     // similar to CV_ELEM_SIZE(cvmat->type)
01838     size_t elemSize() const;
01840     size_t elemSize1() const;
01842     int type() const;
01844     int depth() const;
01846     int channels() const;
01848     size_t step1(int i=0) const;
01850     bool empty() const;
01852     size_t total() const;
01853 
01855     int checkVector(int elemChannels, int depth=-1, bool requireContinuous=true) const;
01856 
01858     uchar* ptr(int i0=0);
01859     const uchar* ptr(int i0=0) const;
01860 
01862     uchar* ptr(int i0, int i1);
01863     const uchar* ptr(int i0, int i1) const;
01864 
01866     uchar* ptr(int i0, int i1, int i2);
01867     const uchar* ptr(int i0, int i1, int i2) const;
01868 
01870     uchar* ptr(const int* idx);
01872     const uchar* ptr(const int* idx) const;
01873 
01874     template<int n> uchar* ptr(const Vec<int, n>& idx);
01875     template<int n> const uchar* ptr(const Vec<int, n>& idx) const;
01876 
01878     template<typename _Tp> _Tp* ptr(int i0=0);
01879     template<typename _Tp> const _Tp* ptr(int i0=0) const;
01880 
01881     template<typename _Tp> _Tp* ptr(int i0, int i1);
01882     template<typename _Tp> const _Tp* ptr(int i0, int i1) const;
01883 
01884     template<typename _Tp> _Tp* ptr(int i0, int i1, int i2);
01885     template<typename _Tp> const _Tp* ptr(int i0, int i1, int i2) const;
01886 
01887     template<typename _Tp> _Tp* ptr(const int* idx);
01888     template<typename _Tp> const _Tp* ptr(const int* idx) const;
01889 
01890     template<typename _Tp, int n> _Tp* ptr(const Vec<int, n>& idx);
01891     template<typename _Tp, int n> const _Tp* ptr(const Vec<int, n>& idx) const;
01892 
01894     template<typename _Tp> _Tp& at(int i0=0);
01895     template<typename _Tp> const _Tp& at(int i0=0) const;
01896 
01897     template<typename _Tp> _Tp& at(int i0, int i1);
01898     template<typename _Tp> const _Tp& at(int i0, int i1) const;
01899 
01900     template<typename _Tp> _Tp& at(int i0, int i1, int i2);
01901     template<typename _Tp> const _Tp& at(int i0, int i1, int i2) const;
01902 
01903     template<typename _Tp> _Tp& at(const int* idx);
01904     template<typename _Tp> const _Tp& at(const int* idx) const;
01905 
01906     template<typename _Tp, int n> _Tp& at(const Vec<int, n>& idx);
01907     template<typename _Tp, int n> const _Tp& at(const Vec<int, n>& idx) const;
01908 
01910     template<typename _Tp> _Tp& at(Point pt);
01911     template<typename _Tp> const _Tp& at(Point pt) const;
01912 
01914     // the iterators take care of skipping gaps in the end of rows (if any)
01915     template<typename _Tp> MatIterator_<_Tp> begin();
01916     template<typename _Tp> MatIterator_<_Tp> end();
01917     template<typename _Tp> MatConstIterator_<_Tp> begin() const;
01918     template<typename _Tp> MatConstIterator_<_Tp> end() const;
01919 
01920     enum { MAGIC_VAL=0x42FF0000, AUTO_STEP=0, CONTINUOUS_FLAG=CV_MAT_CONT_FLAG, SUBMATRIX_FLAG=CV_SUBMAT_FLAG };
01921 
01928     int flags;
01930     int dims;
01932     int rows, cols;
01934     uchar* data;
01935 
01937     // when matrix points to user-allocated data, the pointer is NULL
01938     int* refcount;
01939 
01941     uchar* datastart;
01942     uchar* dataend;
01943     uchar* datalimit;
01944 
01946     MatAllocator* allocator;
01947 
01948     struct CV_EXPORTS MSize
01949     {
01950         MSize(int* _p);
01951         Size operator()() const;
01952         const int& operator[](int i) const;
01953         int& operator[](int i);
01954         operator const int*() const;
01955         bool operator == (const MSize& sz) const;
01956         bool operator != (const MSize& sz) const;
01957 
01958         int* p;
01959     };
01960 
01961     struct CV_EXPORTS MStep
01962     {
01963         MStep();
01964         MStep(size_t s);
01965         const size_t& operator[](int i) const;
01966         size_t& operator[](int i);
01967         operator size_t() const;
01968         MStep& operator = (size_t s);
01969 
01970         size_t* p;
01971         size_t buf[2];
01972     protected:
01973         MStep& operator = (const MStep&);
01974     };
01975 
01976     MSize size;
01977     MStep step;
01978 
01979 protected:
01980     void initEmpty();
01981 };
01982 
01983 
01989 class CV_EXPORTS RNG
01990 {
01991 public:
01992     enum { UNIFORM=0, NORMAL=1 };
01993 
01994     RNG();
01995     RNG(uint64 state);
01997     unsigned next();
01998 
01999     operator uchar();
02000     operator schar();
02001     operator ushort();
02002     operator short();
02003     operator unsigned();
02005     unsigned operator ()(unsigned N);
02006     unsigned operator ()();
02007     operator int();
02008     operator float();
02009     operator double();
02011     int uniform(int a, int b);
02013     float uniform(float a, float b);
02015     double uniform(double a, double b);
02016     void fill( InputOutputArray mat, int distType, InputArray a, InputArray b, bool saturateRange=false );
02018     double gaussian(double sigma);
02019 
02020     uint64 state;
02021 };
02022 
02023 
02027 class CV_EXPORTS TermCriteria
02028 {
02029 public:
02030     enum
02031     {
02032         COUNT=1, 
02033         MAX_ITER=COUNT, 
02034         EPS=2 
02035     };
02036 
02038     TermCriteria();
02040     TermCriteria(int _type, int _maxCount, double _epsilon);
02042     TermCriteria(const CvTermCriteria& criteria);
02044     operator CvTermCriteria() const;
02045 
02046     int type; 
02047     int maxCount; // the maximum number of iterations/elements
02048     double epsilon; // the desired accuracy
02049 };
02050 
02051 
02052 typedef void (*BinaryFunc)(const uchar* src1, size_t step1,
02053                            const uchar* src2, size_t step2,
02054                            uchar* dst, size_t step, Size sz,
02055                            void*);
02056 
02057 CV_EXPORTS BinaryFunc getConvertFunc(int sdepth, int ddepth);
02058 CV_EXPORTS BinaryFunc getConvertScaleFunc(int sdepth, int ddepth);
02059 CV_EXPORTS BinaryFunc getCopyMaskFunc(size_t esz);
02060 
02062 CV_EXPORTS void swap(Mat& a, Mat& b);
02063 
02065 CV_EXPORTS Mat cvarrToMat(const CvArr* arr, bool copyData=false,
02066                           bool allowND=true, int coiMode=0);
02068 CV_EXPORTS void extractImageCOI(const CvArr* arr, OutputArray coiimg, int coi=-1);
02070 CV_EXPORTS void insertImageCOI(InputArray coiimg, CvArr* arr, int coi=-1);
02071 
02073 CV_EXPORTS_W void add(InputArray src1, InputArray src2, OutputArray dst,
02074                       InputArray mask=noArray(), int dtype=-1);
02076 CV_EXPORTS_W void subtract(InputArray src1, InputArray src2, OutputArray dst,
02077                            InputArray mask=noArray(), int dtype=-1);
02078 
02080 CV_EXPORTS_W void multiply(InputArray src1, InputArray src2,
02081                            OutputArray dst, double scale=1, int dtype=-1);
02082 
02084 CV_EXPORTS_W void divide(InputArray src1, InputArray src2, OutputArray dst,
02085                          double scale=1, int dtype=-1);
02086 
02088 CV_EXPORTS_W void divide(double scale, InputArray src2,
02089                          OutputArray dst, int dtype=-1);
02090 
02092 CV_EXPORTS_W void scaleAdd(InputArray src1, double alpha, InputArray src2, OutputArray dst);
02093 
02095 CV_EXPORTS_W void addWeighted(InputArray src1, double alpha, InputArray src2,
02096                               double beta, double gamma, OutputArray dst, int dtype=-1);
02097 
02099 CV_EXPORTS_W void convertScaleAbs(InputArray src, OutputArray dst,
02100                                   double alpha=1, double beta=0);
02102 CV_EXPORTS_W void LUT(InputArray src, InputArray lut, OutputArray dst,
02103                       int interpolation=0);
02104 
02106 CV_EXPORTS_AS(sumElems) Scalar sum(InputArray src);
02108 CV_EXPORTS_W int countNonZero( InputArray src );
02110 CV_EXPORTS_W void findNonZero( InputArray src, OutputArray idx );
02111 
02113 CV_EXPORTS_W Scalar mean(InputArray src, InputArray mask=noArray());
02115 CV_EXPORTS_W void meanStdDev(InputArray src, OutputArray mean, OutputArray stddev,
02116                              InputArray mask=noArray());
02118 CV_EXPORTS_W double norm(InputArray src1, int normType=NORM_L2, InputArray mask=noArray());
02120 CV_EXPORTS_W double norm(InputArray src1, InputArray src2,
02121                          int normType=NORM_L2, InputArray mask=noArray());
02122 
02124 CV_EXPORTS_W void batchDistance(InputArray src1, InputArray src2,
02125                                 OutputArray dist, int dtype, OutputArray nidx,
02126                                 int normType=NORM_L2, int K=0,
02127                                 InputArray mask=noArray(), int update=0,
02128                                 bool crosscheck=false);
02129 
02131 CV_EXPORTS_W void normalize( InputArray src, OutputArray dst, double alpha=1, double beta=0,
02132                              int norm_type=NORM_L2, int dtype=-1, InputArray mask=noArray());
02133 
02135 CV_EXPORTS_W void minMaxLoc(InputArray src, CV_OUT double* minVal,
02136                            CV_OUT double* maxVal=0, CV_OUT Point* minLoc=0,
02137                            CV_OUT Point* maxLoc=0, InputArray mask=noArray());
02138 CV_EXPORTS void minMaxIdx(InputArray src, double* minVal, double* maxVal,
02139                           int* minIdx=0, int* maxIdx=0, InputArray mask=noArray());
02140 
02142 CV_EXPORTS_W void reduce(InputArray src, OutputArray dst, int dim, int rtype, int dtype=-1);
02143 
02145 CV_EXPORTS void merge(const Mat* mv, size_t count, OutputArray dst);
02146 CV_EXPORTS void merge(const vector<Mat>& mv, OutputArray dst );
02147 
02149 CV_EXPORTS_W void merge(InputArrayOfArrays mv, OutputArray dst);
02150 
02152 CV_EXPORTS void split(const Mat& src, Mat* mvbegin);
02153 CV_EXPORTS void split(const Mat& m, vector<Mat>& mv );
02154 
02156 CV_EXPORTS_W void split(InputArray m, OutputArrayOfArrays mv);
02157 
02159 CV_EXPORTS void mixChannels(const Mat* src, size_t nsrcs, Mat* dst, size_t ndsts,
02160                             const int* fromTo, size_t npairs);
02161 CV_EXPORTS void mixChannels(const vector<Mat>& src, vector<Mat>& dst,
02162                             const int* fromTo, size_t npairs);
02163 CV_EXPORTS_W void mixChannels(InputArrayOfArrays src, InputArrayOfArrays dst,
02164                               const vector<int>& fromTo);
02165 
02167 CV_EXPORTS_W void extractChannel(InputArray src, OutputArray dst, int coi);
02168 
02170 CV_EXPORTS_W void insertChannel(InputArray src, InputOutputArray dst, int coi);
02171 
02173 CV_EXPORTS_W void flip(InputArray src, OutputArray dst, int flipCode);
02174 
02176 CV_EXPORTS_W void repeat(InputArray src, int ny, int nx, OutputArray dst);
02177 CV_EXPORTS Mat repeat(const Mat& src, int ny, int nx);
02178 
02179 CV_EXPORTS void hconcat(const Mat* src, size_t nsrc, OutputArray dst);
02180 CV_EXPORTS void hconcat(InputArray src1, InputArray src2, OutputArray dst);
02181 CV_EXPORTS_W void hconcat(InputArrayOfArrays src, OutputArray dst);
02182 
02183 CV_EXPORTS void vconcat(const Mat* src, size_t nsrc, OutputArray dst);
02184 CV_EXPORTS void vconcat(InputArray src1, InputArray src2, OutputArray dst);
02185 CV_EXPORTS_W void vconcat(InputArrayOfArrays src, OutputArray dst);
02186 
02188 CV_EXPORTS_W void bitwise_and(InputArray src1, InputArray src2,
02189                               OutputArray dst, InputArray mask=noArray());
02191 CV_EXPORTS_W void bitwise_or(InputArray src1, InputArray src2,
02192                              OutputArray dst, InputArray mask=noArray());
02194 CV_EXPORTS_W void bitwise_xor(InputArray src1, InputArray src2,
02195                               OutputArray dst, InputArray mask=noArray());
02197 CV_EXPORTS_W void bitwise_not(InputArray src, OutputArray dst,
02198                               InputArray mask=noArray());
02200 CV_EXPORTS_W void absdiff(InputArray src1, InputArray src2, OutputArray dst);
02202 CV_EXPORTS_W void inRange(InputArray src, InputArray lowerb,
02203                           InputArray upperb, OutputArray dst);
02205 CV_EXPORTS_W void compare(InputArray src1, InputArray src2, OutputArray dst, int cmpop);
02207 CV_EXPORTS_W void min(InputArray src1, InputArray src2, OutputArray dst);
02209 CV_EXPORTS_W void max(InputArray src1, InputArray src2, OutputArray dst);
02210 
02212 CV_EXPORTS void min(const Mat& src1, const Mat& src2, Mat& dst);
02214 CV_EXPORTS void min(const Mat& src1, double src2, Mat& dst);
02216 CV_EXPORTS void max(const Mat& src1, const Mat& src2, Mat& dst);
02218 CV_EXPORTS void max(const Mat& src1, double src2, Mat& dst);
02219 
02221 CV_EXPORTS_W void sqrt(InputArray src, OutputArray dst);
02223 CV_EXPORTS_W void pow(InputArray src, double power, OutputArray dst);
02225 CV_EXPORTS_W void exp(InputArray src, OutputArray dst);
02227 CV_EXPORTS_W void log(InputArray src, OutputArray dst);
02229 CV_EXPORTS_W float cubeRoot(float val);
02231 CV_EXPORTS_W float fastAtan2(float y, float x);
02232 
02233 CV_EXPORTS void exp(const float* src, float* dst, int n);
02234 CV_EXPORTS void log(const float* src, float* dst, int n);
02235 CV_EXPORTS void fastAtan2(const float* y, const float* x, float* dst, int n, bool angleInDegrees);
02236 CV_EXPORTS void magnitude(const float* x, const float* y, float* dst, int n);
02237 
02239 CV_EXPORTS_W void polarToCart(InputArray magnitude, InputArray angle,
02240                               OutputArray x, OutputArray y, bool angleInDegrees=false);
02242 CV_EXPORTS_W void cartToPolar(InputArray x, InputArray y,
02243                               OutputArray magnitude, OutputArray angle,
02244                               bool angleInDegrees=false);
02246 CV_EXPORTS_W void phase(InputArray x, InputArray y, OutputArray angle,
02247                         bool angleInDegrees=false);
02249 CV_EXPORTS_W void magnitude(InputArray x, InputArray y, OutputArray magnitude);
02251 CV_EXPORTS_W bool checkRange(InputArray a, bool quiet=true, CV_OUT Point* pos=0,
02252                             double minVal=-DBL_MAX, double maxVal=DBL_MAX);
02254 CV_EXPORTS_W void patchNaNs(InputOutputArray a, double val=0);
02255 
02257 CV_EXPORTS_W void gemm(InputArray src1, InputArray src2, double alpha,
02258                        InputArray src3, double gamma, OutputArray dst, int flags=0);
02260 CV_EXPORTS_W void mulTransposed( InputArray src, OutputArray dst, bool aTa,
02261                                  InputArray delta=noArray(),
02262                                  double scale=1, int dtype=-1 );
02264 CV_EXPORTS_W void transpose(InputArray src, OutputArray dst);
02266 CV_EXPORTS_W void transform(InputArray src, OutputArray dst, InputArray m );
02268 CV_EXPORTS_W void perspectiveTransform(InputArray src, OutputArray dst, InputArray m );
02269 
02271 CV_EXPORTS_W void completeSymm(InputOutputArray mtx, bool lowerToUpper=false);
02273 CV_EXPORTS_W void setIdentity(InputOutputArray mtx, const Scalar& s=Scalar(1));
02275 CV_EXPORTS_W double determinant(InputArray mtx);
02277 CV_EXPORTS_W Scalar trace(InputArray mtx);
02279 CV_EXPORTS_W double invert(InputArray src, OutputArray dst, int flags=DECOMP_LU);
02281 CV_EXPORTS_W bool solve(InputArray src1, InputArray src2,
02282                         OutputArray dst, int flags=DECOMP_LU);
02283 
02284 enum
02285 {
02286     SORT_EVERY_ROW=0,
02287     SORT_EVERY_COLUMN=1,
02288     SORT_ASCENDING=0,
02289     SORT_DESCENDING=16
02290 };
02291 
02293 CV_EXPORTS_W void sort(InputArray src, OutputArray dst, int flags);
02295 CV_EXPORTS_W void sortIdx(InputArray src, OutputArray dst, int flags);
02297 CV_EXPORTS_W int solveCubic(InputArray coeffs, OutputArray roots);
02299 CV_EXPORTS_W double solvePoly(InputArray coeffs, OutputArray roots, int maxIters=300);
02301 CV_EXPORTS bool eigen(InputArray src, OutputArray eigenvalues, int lowindex=-1,
02302                       int highindex=-1);
02304 CV_EXPORTS bool eigen(InputArray src, OutputArray eigenvalues,
02305                       OutputArray eigenvectors,
02306                       int lowindex=-1, int highindex=-1);
02307 CV_EXPORTS_W bool eigen(InputArray src, bool computeEigenvectors,
02308                         OutputArray eigenvalues, OutputArray eigenvectors);
02309 
02310 enum
02311 {
02312     COVAR_SCRAMBLED=0,
02313     COVAR_NORMAL=1,
02314     COVAR_USE_AVG=2,
02315     COVAR_SCALE=4,
02316     COVAR_ROWS=8,
02317     COVAR_COLS=16
02318 };
02319 
02321 CV_EXPORTS void calcCovarMatrix( const Mat* samples, int nsamples, Mat& covar, Mat& mean,
02322                                  int flags, int ctype=CV_64F);
02324 CV_EXPORTS_W void calcCovarMatrix( InputArray samples, OutputArray covar,
02325                                    OutputArray mean, int flags, int ctype=CV_64F);
02326 
02381 class CV_EXPORTS PCA
02382 {
02383 public:
02385     PCA();
02387     PCA(InputArray data, InputArray mean, int flags, int maxComponents=0);
02388     PCA(InputArray data, InputArray mean, int flags, double retainedVariance);
02390     PCA& operator()(InputArray data, InputArray mean, int flags, int maxComponents=0);
02391     PCA& computeVar(InputArray data, InputArray mean, int flags, double retainedVariance);
02393     Mat project(InputArray vec) const;
02395     void project(InputArray vec, OutputArray result) const;
02397     Mat backProject(InputArray vec) const;
02399     void backProject(InputArray vec, OutputArray result) const;
02400 
02401     Mat eigenvectors; 
02402     Mat eigenvalues; 
02403     Mat mean; 
02404 };
02405 
02406 CV_EXPORTS_W void PCACompute(InputArray data, CV_OUT InputOutputArray mean,
02407                              OutputArray eigenvectors, int maxComponents=0);
02408 
02409 CV_EXPORTS_W void PCAComputeVar(InputArray data, CV_OUT InputOutputArray mean,
02410                              OutputArray eigenvectors, double retainedVariance);
02411 
02412 CV_EXPORTS_W void PCAProject(InputArray data, InputArray mean,
02413                              InputArray eigenvectors, OutputArray result);
02414 
02415 CV_EXPORTS_W void PCABackProject(InputArray data, InputArray mean,
02416                                  InputArray eigenvectors, OutputArray result);
02417 
02418 
02432 class CV_EXPORTS SVD
02433 {
02434 public:
02435     enum { MODIFY_A=1, NO_UV=2, FULL_UV=4 };
02437     SVD();
02439     SVD( InputArray src, int flags=0 );
02441     SVD& operator ()( InputArray src, int flags=0 );
02442 
02444     static void compute( InputArray src, OutputArray w,
02445                          OutputArray u, OutputArray vt, int flags=0 );
02447     static void compute( InputArray src, OutputArray w, int flags=0 );
02449     static void backSubst( InputArray w, InputArray u,
02450                            InputArray vt, InputArray rhs,
02451                            OutputArray dst );
02452 
02453     template<typename _Tp, int m, int n, int nm> static void compute( const Matx<_Tp, m, n>& a,
02454         Matx<_Tp, nm, 1>& w, Matx<_Tp, m, nm>& u, Matx<_Tp, n, nm>& vt );
02455     template<typename _Tp, int m, int n, int nm> static void compute( const Matx<_Tp, m, n>& a,
02456         Matx<_Tp, nm, 1>& w );
02457     template<typename _Tp, int m, int n, int nm, int nb> static void backSubst( const Matx<_Tp, nm, 1>& w,
02458         const Matx<_Tp, m, nm>& u, const Matx<_Tp, n, nm>& vt, const Matx<_Tp, m, nb>& rhs, Matx<_Tp, n, nb>& dst );
02459 
02461     static void solveZ( InputArray src, OutputArray dst );
02463     void backSubst( InputArray rhs, OutputArray dst ) const;
02464 
02465     Mat u, w, vt;
02466 };
02467 
02469 CV_EXPORTS_W void SVDecomp( InputArray src, CV_OUT OutputArray w,
02470     CV_OUT OutputArray u, CV_OUT OutputArray vt, int flags=0 );
02471 
02473 CV_EXPORTS_W void SVBackSubst( InputArray w, InputArray u, InputArray vt,
02474                                InputArray rhs, CV_OUT OutputArray dst );
02475 
02477 CV_EXPORTS_W double Mahalanobis(InputArray v1, InputArray v2, InputArray icovar);
02479 CV_EXPORTS double Mahalonobis(InputArray v1, InputArray v2, InputArray icovar);
02480 
02482 CV_EXPORTS_W void dft(InputArray src, OutputArray dst, int flags=0, int nonzeroRows=0);
02484 CV_EXPORTS_W void idft(InputArray src, OutputArray dst, int flags=0, int nonzeroRows=0);
02486 CV_EXPORTS_W void dct(InputArray src, OutputArray dst, int flags=0);
02488 CV_EXPORTS_W void idct(InputArray src, OutputArray dst, int flags=0);
02490 CV_EXPORTS_W void mulSpectrums(InputArray a, InputArray b, OutputArray c,
02491                                int flags, bool conjB=false);
02493 CV_EXPORTS_W int getOptimalDFTSize(int vecsize);
02494 
02498 enum
02499 {
02500     KMEANS_RANDOM_CENTERS=0, // Chooses random centers for k-Means initialization
02501     KMEANS_PP_CENTERS=2,     // Uses k-Means++ algorithm for initialization
02502     KMEANS_USE_INITIAL_LABELS=1 // Uses the user-provided labels for K-Means initialization
02503 };
02505 CV_EXPORTS_W double kmeans( InputArray data, int K, CV_OUT InputOutputArray bestLabels,
02506                             TermCriteria criteria, int attempts,
02507                             int flags, OutputArray centers=noArray() );
02508 
02510 CV_EXPORTS RNG& theRNG();
02511 
02513 template<typename _Tp> static inline _Tp randu() { return (_Tp)theRNG(); }
02514 
02516 CV_EXPORTS_W void randu(InputOutputArray dst, InputArray low, InputArray high);
02517 
02519 CV_EXPORTS_W void randn(InputOutputArray dst, InputArray mean, InputArray stddev);
02520 
02522 CV_EXPORTS void randShuffle(InputOutputArray dst, double iterFactor=1., RNG* rng=0);
02523 CV_EXPORTS_AS(randShuffle) void randShuffle_(InputOutputArray dst, double iterFactor=1.);
02524 
02526 CV_EXPORTS_W void line(CV_IN_OUT Mat& img, Point pt1, Point pt2, const Scalar& color,
02527                      int thickness=1, int lineType=8, int shift=0);
02528 
02530 CV_EXPORTS_W void rectangle(CV_IN_OUT Mat& img, Point pt1, Point pt2,
02531                           const Scalar& color, int thickness=1,
02532                           int lineType=8, int shift=0);
02533 
02535 CV_EXPORTS void rectangle(CV_IN_OUT Mat& img, Rect rec,
02536                           const Scalar& color, int thickness=1,
02537                           int lineType=8, int shift=0);
02538 
02540 CV_EXPORTS_W void circle(CV_IN_OUT Mat& img, Point center, int radius,
02541                        const Scalar& color, int thickness=1,
02542                        int lineType=8, int shift=0);
02543 
02545 CV_EXPORTS_W void ellipse(CV_IN_OUT Mat& img, Point center, Size axes,
02546                         double angle, double startAngle, double endAngle,
02547                         const Scalar& color, int thickness=1,
02548                         int lineType=8, int shift=0);
02549 
02551 CV_EXPORTS_W void ellipse(CV_IN_OUT Mat& img, const RotatedRect& box, const Scalar& color,
02552                         int thickness=1, int lineType=8);
02553 
02555 CV_EXPORTS void fillConvexPoly(Mat& img, const Point* pts, int npts,
02556                                const Scalar& color, int lineType=8,
02557                                int shift=0);
02558 CV_EXPORTS_W void fillConvexPoly(InputOutputArray img, InputArray points,
02559                                  const Scalar& color, int lineType=8,
02560                                  int shift=0);
02561 
02563 CV_EXPORTS void fillPoly(Mat& img, const Point** pts,
02564                          const int* npts, int ncontours,
02565                          const Scalar& color, int lineType=8, int shift=0,
02566                          Point offset=Point() );
02567 
02568 CV_EXPORTS_W void fillPoly(InputOutputArray img, InputArrayOfArrays pts,
02569                            const Scalar& color, int lineType=8, int shift=0,
02570                            Point offset=Point() );
02571 
02573 CV_EXPORTS void polylines(Mat& img, const Point** pts, const int* npts,
02574                           int ncontours, bool isClosed, const Scalar& color,
02575                           int thickness=1, int lineType=8, int shift=0 );
02576 
02577 CV_EXPORTS_W void polylines(InputOutputArray img, InputArrayOfArrays pts,
02578                             bool isClosed, const Scalar& color,
02579                             int thickness=1, int lineType=8, int shift=0 );
02580 
02582 CV_EXPORTS bool clipLine(Size imgSize, CV_IN_OUT Point& pt1, CV_IN_OUT Point& pt2);
02583 
02585 CV_EXPORTS_W bool clipLine(Rect imgRect, CV_OUT CV_IN_OUT Point& pt1, CV_OUT CV_IN_OUT Point& pt2);
02586 
02593 class CV_EXPORTS LineIterator
02594 {
02595 public:
02597     LineIterator( const Mat& img, Point pt1, Point pt2,
02598                   int connectivity=8, bool leftToRight=false );
02600     uchar* operator *();
02602     LineIterator& operator ++();
02604     LineIterator operator ++(int);
02606     Point pos() const;
02607 
02608     uchar* ptr;
02609     const uchar* ptr0;
02610     int step, elemSize;
02611     int err, count;
02612     int minusDelta, plusDelta;
02613     int minusStep, plusStep;
02614 };
02615 
02617 CV_EXPORTS_W void ellipse2Poly( Point center, Size axes, int angle,
02618                                 int arcStart, int arcEnd, int delta,
02619                                 CV_OUT vector<Point>& pts );
02620 
02621 enum
02622 {
02623     FONT_HERSHEY_SIMPLEX = 0,
02624     FONT_HERSHEY_PLAIN = 1,
02625     FONT_HERSHEY_DUPLEX = 2,
02626     FONT_HERSHEY_COMPLEX = 3,
02627     FONT_HERSHEY_TRIPLEX = 4,
02628     FONT_HERSHEY_COMPLEX_SMALL = 5,
02629     FONT_HERSHEY_SCRIPT_SIMPLEX = 6,
02630     FONT_HERSHEY_SCRIPT_COMPLEX = 7,
02631     FONT_ITALIC = 16
02632 };
02633 
02635 CV_EXPORTS_W void putText( Mat& img, const string& text, Point org,
02636                          int fontFace, double fontScale, Scalar color,
02637                          int thickness=1, int lineType=8,
02638                          bool bottomLeftOrigin=false );
02639 
02641 CV_EXPORTS_W Size getTextSize(const string& text, int fontFace,
02642                             double fontScale, int thickness,
02643                             CV_OUT int* baseLine);
02644 
02646 
02692 template<typename _Tp> class CV_EXPORTS Mat_ : public Mat
02693 {
02694 public:
02695     typedef _Tp value_type;
02696     typedef typename DataType<_Tp>::channel_type channel_type;
02697     typedef MatIterator_<_Tp> iterator;
02698     typedef MatConstIterator_<_Tp> const_iterator;
02699 
02701     Mat_();
02703     Mat_(int _rows, int _cols);
02705     Mat_(int _rows, int _cols, const _Tp& value);
02707     explicit Mat_(Size _size);
02709     Mat_(Size _size, const _Tp& value);
02711     Mat_(int _ndims, const int* _sizes);
02713     Mat_(int _ndims, const int* _sizes, const _Tp& value);
02715     Mat_(const Mat& m);
02717     Mat_(const Mat_& m);
02719     Mat_(int _rows, int _cols, _Tp* _data, size_t _step=AUTO_STEP);
02721     Mat_(int _ndims, const int* _sizes, _Tp* _data, const size_t* _steps=0);
02723     Mat_(const Mat_& m, const Range& rowRange, const Range& colRange=Range::all());
02725     Mat_(const Mat_& m, const Rect& roi);
02727     Mat_(const Mat_& m, const Range* ranges);
02729     explicit Mat_(const MatExpr& e);
02731     explicit Mat_(const vector<_Tp>& vec, bool copyData=false);
02732     template<int n> explicit Mat_(const Vec<typename DataType<_Tp>::channel_type, n>& vec, bool copyData=true);
02733     template<int m, int n> explicit Mat_(const Matx<typename DataType<_Tp>::channel_type, m, n>& mtx, bool copyData=true);
02734     explicit Mat_(const Point_<typename DataType<_Tp>::channel_type>& pt, bool copyData=true);
02735     explicit Mat_(const Point3_<typename DataType<_Tp>::channel_type>& pt, bool copyData=true);
02736     explicit Mat_(const MatCommaInitializer_<_Tp>& commaInitializer);
02737 
02738     Mat_& operator = (const Mat& m);
02739     Mat_& operator = (const Mat_& m);
02741     Mat_& operator = (const _Tp& s);
02743     Mat_& operator = (const MatExpr& e);
02744 
02746     iterator begin();
02747     iterator end();
02748     const_iterator begin() const;
02749     const_iterator end() const;
02750 
02752     void create(int _rows, int _cols);
02754     void create(Size _size);
02756     void create(int _ndims, const int* _sizes);
02758     Mat_ cross(const Mat_& m) const;
02760     template<typename T2> operator Mat_<T2>() const;
02762     Mat_ row(int y) const;
02763     Mat_ col(int x) const;
02764     Mat_ diag(int d=0) const;
02765     Mat_ clone() const;
02766 
02768     size_t elemSize() const;
02769     size_t elemSize1() const;
02770     int type() const;
02771     int depth() const;
02772     int channels() const;
02773     size_t step1(int i=0) const;
02775     size_t stepT(int i=0) const;
02776 
02778     static MatExpr zeros(int rows, int cols);
02779     static MatExpr zeros(Size size);
02780     static MatExpr zeros(int _ndims, const int* _sizes);
02781     static MatExpr ones(int rows, int cols);
02782     static MatExpr ones(Size size);
02783     static MatExpr ones(int _ndims, const int* _sizes);
02784     static MatExpr eye(int rows, int cols);
02785     static MatExpr eye(Size size);
02786 
02788     Mat_& adjustROI( int dtop, int dbottom, int dleft, int dright );
02789     Mat_ operator()( const Range& rowRange, const Range& colRange ) const;
02790     Mat_ operator()( const Rect& roi ) const;
02791     Mat_ operator()( const Range* ranges ) const;
02792 
02794     _Tp* operator [](int y);
02795     const _Tp* operator [](int y) const;
02796 
02798     _Tp& operator ()(const int* idx);
02800     const _Tp& operator ()(const int* idx) const;
02801 
02803     template<int n> _Tp& operator ()(const Vec<int, n>& idx);
02805     template<int n> const _Tp& operator ()(const Vec<int, n>& idx) const;
02806 
02808     _Tp& operator ()(int idx0);
02810     const _Tp& operator ()(int idx0) const;
02812     _Tp& operator ()(int idx0, int idx1);
02814     const _Tp& operator ()(int idx0, int idx1) const;
02816     _Tp& operator ()(int idx0, int idx1, int idx2);
02818     const _Tp& operator ()(int idx0, int idx1, int idx2) const;
02819 
02820     _Tp& operator ()(Point pt);
02821     const _Tp& operator ()(Point pt) const;
02822 
02824     operator vector<_Tp>() const;
02826     template<int n> operator Vec<typename DataType<_Tp>::channel_type, n>() const;
02828     template<int m, int n> operator Matx<typename DataType<_Tp>::channel_type, m, n>() const;
02829 };
02830 
02831 typedef Mat_<uchar> Mat1b;
02832 typedef Mat_<Vec2b> Mat2b;
02833 typedef Mat_<Vec3b> Mat3b;
02834 typedef Mat_<Vec4b> Mat4b;
02835 
02836 typedef Mat_<short> Mat1s;
02837 typedef Mat_<Vec2s> Mat2s;
02838 typedef Mat_<Vec3s> Mat3s;
02839 typedef Mat_<Vec4s> Mat4s;
02840 
02841 typedef Mat_<ushort> Mat1w;
02842 typedef Mat_<Vec2w> Mat2w;
02843 typedef Mat_<Vec3w> Mat3w;
02844 typedef Mat_<Vec4w> Mat4w;
02845 
02846 typedef Mat_<int>   Mat1i;
02847 typedef Mat_<Vec2i> Mat2i;
02848 typedef Mat_<Vec3i> Mat3i;
02849 typedef Mat_<Vec4i> Mat4i;
02850 
02851 typedef Mat_<float> Mat1f;
02852 typedef Mat_<Vec2f> Mat2f;
02853 typedef Mat_<Vec3f> Mat3f;
02854 typedef Mat_<Vec4f> Mat4f;
02855 
02856 typedef Mat_<double> Mat1d;
02857 typedef Mat_<Vec2d> Mat2d;
02858 typedef Mat_<Vec3d> Mat3d;
02859 typedef Mat_<Vec4d> Mat4d;
02860 
02862 
02863 class CV_EXPORTS MatConstIterator
02864 {
02865 public:
02866     typedef uchar* value_type;
02867     typedef ptrdiff_t difference_type;
02868     typedef const uchar** pointer;
02869     typedef uchar* reference;
02870     typedef std::random_access_iterator_tag iterator_category;
02871 
02873     MatConstIterator();
02875     MatConstIterator(const Mat* _m);
02877     MatConstIterator(const Mat* _m, int _row, int _col=0);
02879     MatConstIterator(const Mat* _m, Point _pt);
02881     MatConstIterator(const Mat* _m, const int* _idx);
02883     MatConstIterator(const MatConstIterator& it);
02884 
02886     MatConstIterator& operator = (const MatConstIterator& it);
02888     uchar* operator *() const;
02890     uchar* operator [](ptrdiff_t i) const;
02891 
02893     MatConstIterator& operator += (ptrdiff_t ofs);
02895     MatConstIterator& operator -= (ptrdiff_t ofs);
02897     MatConstIterator& operator --();
02899     MatConstIterator operator --(int);
02901     MatConstIterator& operator ++();
02903     MatConstIterator operator ++(int);
02905     Point pos() const;
02907     void pos(int* _idx) const;
02908     ptrdiff_t lpos() const;
02909     void seek(ptrdiff_t ofs, bool relative=false);
02910     void seek(const int* _idx, bool relative=false);
02911 
02912     const Mat* m;
02913     size_t elemSize;
02914     uchar* ptr;
02915     uchar* sliceStart;
02916     uchar* sliceEnd;
02917 };
02918 
02923 template<typename _Tp>
02924 class CV_EXPORTS MatConstIterator_ : public MatConstIterator
02925 {
02926 public:
02927     typedef _Tp value_type;
02928     typedef ptrdiff_t difference_type;
02929     typedef const _Tp* pointer;
02930     typedef const _Tp& reference;
02931     typedef std::random_access_iterator_tag iterator_category;
02932 
02934     MatConstIterator_();
02936     MatConstIterator_(const Mat_<_Tp>* _m);
02938     MatConstIterator_(const Mat_<_Tp>* _m, int _row, int _col=0);
02940     MatConstIterator_(const Mat_<_Tp>* _m, Point _pt);
02942     MatConstIterator_(const Mat_<_Tp>* _m, const int* _idx);
02944     MatConstIterator_(const MatConstIterator_& it);
02945 
02947     MatConstIterator_& operator = (const MatConstIterator_& it);
02949     _Tp operator *() const;
02951     _Tp operator [](ptrdiff_t i) const;
02952 
02954     MatConstIterator_& operator += (ptrdiff_t ofs);
02956     MatConstIterator_& operator -= (ptrdiff_t ofs);
02958     MatConstIterator_& operator --();
02960     MatConstIterator_ operator --(int);
02962     MatConstIterator_& operator ++();
02964     MatConstIterator_ operator ++(int);
02966     Point pos() const;
02967 };
02968 
02969 
02974 template<typename _Tp>
02975 class CV_EXPORTS MatIterator_ : public MatConstIterator_<_Tp>
02976 {
02977 public:
02978     typedef _Tp* pointer;
02979     typedef _Tp& reference;
02980     typedef std::random_access_iterator_tag iterator_category;
02981 
02983     MatIterator_();
02985     MatIterator_(Mat_<_Tp>* _m);
02987     MatIterator_(Mat_<_Tp>* _m, int _row, int _col=0);
02989     MatIterator_(const Mat_<_Tp>* _m, Point _pt);
02991     MatIterator_(const Mat_<_Tp>* _m, const int* _idx);
02993     MatIterator_(const MatIterator_& it);
02995     MatIterator_& operator = (const MatIterator_<_Tp>& it );
02996 
02998     _Tp& operator *() const;
03000     _Tp& operator [](ptrdiff_t i) const;
03001 
03003     MatIterator_& operator += (ptrdiff_t ofs);
03005     MatIterator_& operator -= (ptrdiff_t ofs);
03007     MatIterator_& operator --();
03009     MatIterator_ operator --(int);
03011     MatIterator_& operator ++();
03013     MatIterator_ operator ++(int);
03014 };
03015 
03016 template<typename _Tp> class CV_EXPORTS MatOp_Iter_;
03017 
03031 template<typename _Tp> class CV_EXPORTS MatCommaInitializer_
03032 {
03033 public:
03035     MatCommaInitializer_(Mat_<_Tp>* _m);
03037     template<typename T2> MatCommaInitializer_<_Tp>& operator , (T2 v);
03039     Mat_<_Tp> operator *() const;
03040     operator Mat_<_Tp>() const;
03041 protected:
03042     MatIterator_<_Tp> it;
03043 };
03044 
03045 
03046 template<typename _Tp, int m, int n> class CV_EXPORTS MatxCommaInitializer
03047 {
03048 public:
03049     MatxCommaInitializer(Matx<_Tp, m, n>* _mtx);
03050     template<typename T2> MatxCommaInitializer<_Tp, m, n>& operator , (T2 val);
03051     Matx<_Tp, m, n> operator *() const;
03052 
03053     Matx<_Tp, m, n>* dst;
03054     int idx;
03055 };
03056 
03057 template<typename _Tp, int m> class CV_EXPORTS VecCommaInitializer : public MatxCommaInitializer<_Tp, m, 1>
03058 {
03059 public:
03060     VecCommaInitializer(Vec<_Tp, m>* _vec);
03061     template<typename T2> VecCommaInitializer<_Tp, m>& operator , (T2 val);
03062     Vec<_Tp, m> operator *() const;
03063 };
03064 
03092 template<typename _Tp, size_t fixed_size=4096/sizeof(_Tp)+8> class CV_EXPORTS AutoBuffer
03093 {
03094 public:
03095     typedef _Tp value_type;
03096     enum { buffer_padding = (int)((16 + sizeof(_Tp) - 1)/sizeof(_Tp)) };
03097 
03099     AutoBuffer();
03101     AutoBuffer(size_t _size);
03103     ~AutoBuffer();
03104 
03106     void allocate(size_t _size);
03108     void deallocate();
03110     operator _Tp* ();
03112     operator const _Tp* () const;
03113 
03114 protected:
03116     _Tp* ptr;
03118     size_t size;
03120     _Tp buf[fixed_size+buffer_padding];
03121 };
03122 
03124 
03175 class CV_EXPORTS NAryMatIterator
03176 {
03177 public:
03179     NAryMatIterator();
03181     NAryMatIterator(const Mat** arrays, uchar** ptrs, int narrays=-1);
03183     NAryMatIterator(const Mat** arrays, Mat* planes, int narrays=-1);
03185     void init(const Mat** arrays, Mat* planes, uchar** ptrs, int narrays=-1);
03186 
03188     NAryMatIterator& operator ++();
03190     NAryMatIterator operator ++(int);
03191 
03193     const Mat** arrays;
03195     Mat* planes;
03197     uchar** ptrs;
03199     int narrays;
03201     size_t nplanes;
03203     size_t size;
03204 protected:
03205     int iterdepth;
03206     size_t idx;
03207 };
03208 
03209 //typedef NAryMatIterator NAryMatNDIterator;
03210 
03211 typedef void (*ConvertData)(const void* from, void* to, int cn);
03212 typedef void (*ConvertScaleData)(const void* from, void* to, int cn, double alpha, double beta);
03213 
03215 CV_EXPORTS ConvertData getConvertElem(int fromType, int toType);
03217 CV_EXPORTS ConvertScaleData getConvertScaleElem(int fromType, int toType);
03218 
03219 
03221 
03222 class SparseMatIterator;
03223 class SparseMatConstIterator;
03224 template<typename _Tp> class SparseMatIterator_;
03225 template<typename _Tp> class SparseMatConstIterator_;
03226 
03312 class CV_EXPORTS SparseMat
03313 {
03314 public:
03315     typedef SparseMatIterator iterator;
03316     typedef SparseMatConstIterator const_iterator;
03317 
03319     struct CV_EXPORTS Hdr
03320     {
03321         Hdr(int _dims, const int* _sizes, int _type);
03322         void clear();
03323         int refcount;
03324         int dims;
03325         int valueOffset;
03326         size_t nodeSize;
03327         size_t nodeCount;
03328         size_t freeList;
03329         vector<uchar> pool;
03330         vector<size_t> hashtab;
03331         int size[CV_MAX_DIM];
03332     };
03333 
03335     struct CV_EXPORTS Node
03336     {
03338         size_t hashval;
03340         size_t next;
03342         int idx[CV_MAX_DIM];
03343     };
03344 
03346     SparseMat();
03348     SparseMat(int dims, const int* _sizes, int _type);
03350     SparseMat(const SparseMat& m);
03352 
03357     explicit SparseMat(const Mat& m);
03359     SparseMat(const CvSparseMat* m);
03361     ~SparseMat();
03362 
03364     SparseMat& operator = (const SparseMat& m);
03366     SparseMat& operator = (const Mat& m);
03367 
03369     SparseMat clone() const;
03370 
03372     void copyTo( SparseMat& m ) const;
03374     void copyTo( Mat& m ) const;
03376     void convertTo( SparseMat& m, int rtype, double alpha=1 ) const;
03378 
03383     void convertTo( Mat& m, int rtype, double alpha=1, double beta=0 ) const;
03384 
03385     // not used now
03386     void assignTo( SparseMat& m, int type=-1 ) const;
03387 
03389 
03394     void create(int dims, const int* _sizes, int _type);
03396     void clear();
03398     void addref();
03399     // decrements the header reference counter. When the counter reaches 0, the header and all the underlying data are deallocated.
03400     void release();
03401 
03403     operator CvSparseMat*() const;
03405     size_t elemSize() const;
03407     size_t elemSize1() const;
03408 
03410     int type() const;
03412     int depth() const;
03414     int channels() const;
03415 
03417     const int* size() const;
03419     int size(int i) const;
03421     int dims() const;
03423     size_t nzcount() const;
03424 
03426     size_t hash(int i0) const;
03428     size_t hash(int i0, int i1) const;
03430     size_t hash(int i0, int i1, int i2) const;
03432     size_t hash(const int* idx) const;
03433 
03435 
03448 
03449     uchar* ptr(int i0, bool createMissing, size_t* hashval=0);
03451     uchar* ptr(int i0, int i1, bool createMissing, size_t* hashval=0);
03453     uchar* ptr(int i0, int i1, int i2, bool createMissing, size_t* hashval=0);
03455     uchar* ptr(const int* idx, bool createMissing, size_t* hashval=0);
03457 
03459 
03466 
03467     template<typename _Tp> _Tp& ref(int i0, size_t* hashval=0);
03469     template<typename _Tp> _Tp& ref(int i0, int i1, size_t* hashval=0);
03471     template<typename _Tp> _Tp& ref(int i0, int i1, int i2, size_t* hashval=0);
03473     template<typename _Tp> _Tp& ref(const int* idx, size_t* hashval=0);
03475 
03477 
03488 
03489     template<typename _Tp> _Tp value(int i0, size_t* hashval=0) const;
03491     template<typename _Tp> _Tp value(int i0, int i1, size_t* hashval=0) const;
03493     template<typename _Tp> _Tp value(int i0, int i1, int i2, size_t* hashval=0) const;
03495     template<typename _Tp> _Tp value(const int* idx, size_t* hashval=0) const;
03497 
03499 
03506 
03507     template<typename _Tp> const _Tp* find(int i0, size_t* hashval=0) const;
03509     template<typename _Tp> const _Tp* find(int i0, int i1, size_t* hashval=0) const;
03511     template<typename _Tp> const _Tp* find(int i0, int i1, int i2, size_t* hashval=0) const;
03513     template<typename _Tp> const _Tp* find(const int* idx, size_t* hashval=0) const;
03514 
03516     void erase(int i0, int i1, size_t* hashval=0);
03518     void erase(int i0, int i1, int i2, size_t* hashval=0);
03520     void erase(const int* idx, size_t* hashval=0);
03521 
03523 
03526 
03527     SparseMatIterator begin();
03529     template<typename _Tp> SparseMatIterator_<_Tp> begin();
03531     SparseMatConstIterator begin() const;
03533     template<typename _Tp> SparseMatConstIterator_<_Tp> begin() const;
03535 
03538 
03539     SparseMatIterator end();
03541     SparseMatConstIterator end() const;
03543     template<typename _Tp> SparseMatIterator_<_Tp> end();
03545     template<typename _Tp> SparseMatConstIterator_<_Tp> end() const;
03546 
03548     template<typename _Tp> _Tp& value(Node* n);
03550     template<typename _Tp> const _Tp& value(const Node* n) const;
03551 
03553     Node* node(size_t nidx);
03554     const Node* node(size_t nidx) const;
03555 
03556     uchar* newNode(const int* idx, size_t hashval);
03557     void removeNode(size_t hidx, size_t nidx, size_t previdx);
03558     void resizeHashTab(size_t newsize);
03559 
03560     enum { MAGIC_VAL=0x42FD0000, MAX_DIM=CV_MAX_DIM, HASH_SCALE=0x5bd1e995, HASH_BIT=0x80000000 };
03561 
03562     int flags;
03563     Hdr* hdr;
03564 };
03565 
03567 CV_EXPORTS void minMaxLoc(const SparseMat& a, double* minVal,
03568                           double* maxVal, int* minIdx=0, int* maxIdx=0);
03570 CV_EXPORTS double norm( const SparseMat& src, int normType );
03572 CV_EXPORTS void normalize( const SparseMat& src, SparseMat& dst, double alpha, int normType );
03573 
03586 class CV_EXPORTS SparseMatConstIterator
03587 {
03588 public:
03590     SparseMatConstIterator();
03592     SparseMatConstIterator(const SparseMat* _m);
03594     SparseMatConstIterator(const SparseMatConstIterator& it);
03595 
03597     SparseMatConstIterator& operator = (const SparseMatConstIterator& it);
03598 
03600     template<typename _Tp> const _Tp& value() const;
03602     const SparseMat::Node* node() const;
03603 
03605     SparseMatConstIterator& operator --();
03607     SparseMatConstIterator operator --(int);
03609     SparseMatConstIterator& operator ++();
03611     SparseMatConstIterator operator ++(int);
03612 
03614     void seekEnd();
03615 
03616     const SparseMat* m;
03617     size_t hashidx;
03618     uchar* ptr;
03619 };
03620 
03627 class CV_EXPORTS SparseMatIterator : public SparseMatConstIterator
03628 {
03629 public:
03631     SparseMatIterator();
03633     SparseMatIterator(SparseMat* _m);
03635     SparseMatIterator(SparseMat* _m, const int* idx);
03637     SparseMatIterator(const SparseMatIterator& it);
03638 
03640     SparseMatIterator& operator = (const SparseMatIterator& it);
03642     template<typename _Tp> _Tp& value() const;
03644     SparseMat::Node* node() const;
03645 
03647     SparseMatIterator& operator ++();
03649     SparseMatIterator operator ++(int);
03650 };
03651 
03665 template<typename _Tp> class CV_EXPORTS SparseMat_ : public SparseMat
03666 {
03667 public:
03668     typedef SparseMatIterator_<_Tp> iterator;
03669     typedef SparseMatConstIterator_<_Tp> const_iterator;
03670 
03672     SparseMat_();
03674     SparseMat_(int dims, const int* _sizes);
03676     SparseMat_(const SparseMat& m);
03678     SparseMat_(const SparseMat_& m);
03680     SparseMat_(const Mat& m);
03682     SparseMat_(const CvSparseMat* m);
03684     SparseMat_& operator = (const SparseMat& m);
03686     SparseMat_& operator = (const SparseMat_& m);
03688     SparseMat_& operator = (const Mat& m);
03689 
03691     SparseMat_ clone() const;
03693     void create(int dims, const int* _sizes);
03695     operator CvSparseMat*() const;
03696 
03698     int type() const;
03700     int depth() const;
03702     int channels() const;
03703 
03705     _Tp& ref(int i0, size_t* hashval=0);
03707     _Tp& ref(int i0, int i1, size_t* hashval=0);
03709     _Tp& ref(int i0, int i1, int i2, size_t* hashval=0);
03711     _Tp& ref(const int* idx, size_t* hashval=0);
03712 
03714     _Tp operator()(int i0, size_t* hashval=0) const;
03716     _Tp operator()(int i0, int i1, size_t* hashval=0) const;
03718     _Tp operator()(int i0, int i1, int i2, size_t* hashval=0) const;
03720     _Tp operator()(const int* idx, size_t* hashval=0) const;
03721 
03723     SparseMatIterator_<_Tp> begin();
03725     SparseMatConstIterator_<_Tp> begin() const;
03727     SparseMatIterator_<_Tp> end();
03729     SparseMatConstIterator_<_Tp> end() const;
03730 };
03731 
03732 
03739 template<typename _Tp> class CV_EXPORTS SparseMatConstIterator_ : public SparseMatConstIterator
03740 {
03741 public:
03742     typedef std::forward_iterator_tag iterator_category;
03743 
03745     SparseMatConstIterator_();
03747     SparseMatConstIterator_(const SparseMat_<_Tp>* _m);
03749     SparseMatConstIterator_(const SparseMatConstIterator_& it);
03750 
03752     SparseMatConstIterator_& operator = (const SparseMatConstIterator_& it);
03754     const _Tp& operator *() const;
03755 
03757     SparseMatConstIterator_& operator ++();
03759     SparseMatConstIterator_ operator ++(int);
03760 };
03761 
03768 template<typename _Tp> class CV_EXPORTS SparseMatIterator_ : public SparseMatConstIterator_<_Tp>
03769 {
03770 public:
03771     typedef std::forward_iterator_tag iterator_category;
03772 
03774     SparseMatIterator_();
03776     SparseMatIterator_(SparseMat_<_Tp>* _m);
03778     SparseMatIterator_(const SparseMatIterator_& it);
03779 
03781     SparseMatIterator_& operator = (const SparseMatIterator_& it);
03783     _Tp& operator *() const;
03784 
03786     SparseMatIterator_& operator ++();
03788     SparseMatIterator_ operator ++(int);
03789 };
03790 
03792 
03817 class CV_EXPORTS_W KDTree
03818 {
03819 public:
03823     struct Node
03824     {
03825         Node() : idx(-1), left(-1), right(-1), boundary(0.f) {}
03826         Node(int _idx, int _left, int _right, float _boundary)
03827             : idx(_idx), left(_left), right(_right), boundary(_boundary) {}
03829         int idx;
03831         int left, right;
03833         float boundary;
03834     };
03835 
03837     CV_WRAP KDTree();
03839     CV_WRAP KDTree(InputArray points, bool copyAndReorderPoints=false);
03841     CV_WRAP KDTree(InputArray points, InputArray _labels,
03842                    bool copyAndReorderPoints=false);
03844     CV_WRAP void build(InputArray points, bool copyAndReorderPoints=false);
03846     CV_WRAP void build(InputArray points, InputArray labels,
03847                        bool copyAndReorderPoints=false);
03849     CV_WRAP int findNearest(InputArray vec, int K, int Emax,
03850                             OutputArray neighborsIdx,
03851                             OutputArray neighbors=noArray(),
03852                             OutputArray dist=noArray(),
03853                             OutputArray labels=noArray()) const;
03855     CV_WRAP void findOrthoRange(InputArray minBounds,
03856                                 InputArray maxBounds,
03857                                 OutputArray neighborsIdx,
03858                                 OutputArray neighbors=noArray(),
03859                                 OutputArray labels=noArray()) const;
03861     CV_WRAP void getPoints(InputArray idx, OutputArray pts,
03862                            OutputArray labels=noArray()) const;
03864     const float* getPoint(int ptidx, int* label=0) const;
03866     CV_WRAP int dims() const;
03867 
03868     vector<Node> nodes; 
03869     CV_PROP Mat points; 
03870     CV_PROP vector<int> labels; 
03871     CV_PROP int maxDepth; 
03872     CV_PROP_RW int normType; 
03873 };
03874 
03876 
03877 class CV_EXPORTS FileNode;
03878 
03976 class CV_EXPORTS_W FileStorage
03977 {
03978 public:
03980     enum
03981     {
03982         READ=0, 
03983         WRITE=1, 
03984         APPEND=2, 
03985         MEMORY=4,
03986         FORMAT_MASK=(7<<3),
03987         FORMAT_AUTO=0,
03988         FORMAT_XML=(1<<3),
03989         FORMAT_YAML=(2<<3)
03990     };
03991     enum
03992     {
03993         UNDEFINED=0,
03994         VALUE_EXPECTED=1,
03995         NAME_EXPECTED=2,
03996         INSIDE_MAP=4
03997     };
03999     CV_WRAP FileStorage();
04001     CV_WRAP FileStorage(const string& source, int flags, const string& encoding=string());
04003     FileStorage(CvFileStorage* fs);
04005     virtual ~FileStorage();
04006 
04008     CV_WRAP virtual bool open(const string& filename, int flags, const string& encoding=string());
04010     CV_WRAP virtual bool isOpened() const;
04012     CV_WRAP virtual void release();
04014     CV_WRAP string releaseAndGetString();
04015 
04017     CV_WRAP FileNode getFirstTopLevelNode() const;
04019     CV_WRAP FileNode root(int streamidx=0) const;
04021     FileNode operator[](const string& nodename) const;
04023     CV_WRAP FileNode operator[](const char* nodename) const;
04024 
04026     CvFileStorage* operator *() { return fs; }
04028     const CvFileStorage* operator *() const { return fs; }
04030     void writeRaw( const string& fmt, const uchar* vec, size_t len );
04032     void writeObj( const string& name, const void* obj );
04033 
04035     static string getDefaultObjectName(const string& filename);
04036 
04037     Ptr<CvFileStorage> fs; 
04038     string elname; 
04039     vector<char> structs; 
04040     int state; 
04041 };
04042 
04043 class CV_EXPORTS FileNodeIterator;
04044 
04055 class CV_EXPORTS_W_SIMPLE FileNode
04056 {
04057 public:
04059     enum
04060     {
04061         NONE=0, 
04062         INT=1, 
04063         REAL=2, 
04064         FLOAT=REAL, 
04065         STR=3, 
04066         STRING=STR, 
04067         REF=4, 
04068         SEQ=5, 
04069         MAP=6, 
04070         TYPE_MASK=7,
04071         FLOW=8, 
04072         USER=16, 
04073         EMPTY=32, 
04074         NAMED=64 
04075     };
04077     CV_WRAP FileNode();
04079     FileNode(const CvFileStorage* fs, const CvFileNode* node);
04081     FileNode(const FileNode& node);
04083     FileNode operator[](const string& nodename) const;
04085     CV_WRAP FileNode operator[](const char* nodename) const;
04087     CV_WRAP FileNode operator[](int i) const;
04089     CV_WRAP int type() const;
04090 
04092     CV_WRAP bool empty() const;
04094     CV_WRAP bool isNone() const;
04096     CV_WRAP bool isSeq() const;
04098     CV_WRAP bool isMap() const;
04100     CV_WRAP bool isInt() const;
04102     CV_WRAP bool isReal() const;
04104     CV_WRAP bool isString() const;
04106     CV_WRAP bool isNamed() const;
04108     CV_WRAP string name() const;
04110     CV_WRAP size_t size() const;
04112     operator int() const;
04114     operator float() const;
04116     operator double() const;
04118     operator string() const;
04119 
04121     CvFileNode* operator *();
04123     const CvFileNode* operator* () const;
04124 
04126     FileNodeIterator begin() const;
04128     FileNodeIterator end() const;
04129 
04131     void readRaw( const string& fmt, uchar* vec, size_t len ) const;
04133     void* readObj() const;
04134 
04135     // do not use wrapper pointer classes for better efficiency
04136     const CvFileStorage* fs;
04137     const CvFileNode* node;
04138 };
04139 
04140 
04146 class CV_EXPORTS FileNodeIterator
04147 {
04148 public:
04150     FileNodeIterator();
04152     FileNodeIterator(const CvFileStorage* fs, const CvFileNode* node, size_t ofs=0);
04154     FileNodeIterator(const FileNodeIterator& it);
04156     FileNode operator *() const;
04158     FileNode operator ->() const;
04159 
04161     FileNodeIterator& operator ++ ();
04163     FileNodeIterator operator ++ (int);
04165     FileNodeIterator& operator -- ();
04167     FileNodeIterator operator -- (int);
04169     FileNodeIterator& operator += (int ofs);
04171     FileNodeIterator& operator -= (int ofs);
04172 
04174     FileNodeIterator& readRaw( const string& fmt, uchar* vec,
04175                                size_t maxCount=(size_t)INT_MAX );
04176 
04177     const CvFileStorage* fs;
04178     const CvFileNode* container;
04179     CvSeqReader reader;
04180     size_t remaining;
04181 };
04182 
04184 
04185 template<typename _Tp> class SeqIterator;
04186 
04187 typedef Ptr<CvMemStorage> MemStorage;
04188 
04199 template<typename _Tp> class CV_EXPORTS Seq
04200 {
04201 public:
04202     typedef SeqIterator<_Tp> iterator;
04203     typedef SeqIterator<_Tp> const_iterator;
04204 
04206     Seq();
04208     Seq(const CvSeq* seq);
04210     Seq(MemStorage& storage, int headerSize = sizeof(CvSeq));
04212     _Tp& operator [](int idx);
04214     const _Tp& operator[](int idx) const;
04216     SeqIterator<_Tp> begin() const;
04218     SeqIterator<_Tp> end() const;
04220     size_t size() const;
04222     int type() const;
04224     int depth() const;
04226     int channels() const;
04228     size_t elemSize() const;
04230     size_t index(const _Tp& elem) const;
04232     void push_back(const _Tp& elem);
04234     void push_front(const _Tp& elem);
04236     void push_back(const _Tp* elems, size_t count);
04238     void push_front(const _Tp* elems, size_t count);
04240     void insert(int idx, const _Tp& elem);
04242     void insert(int idx, const _Tp* elems, size_t count);
04244     void remove(int idx);
04246     void remove(const Range& r);
04247 
04249     _Tp& front();
04251     const _Tp& front() const;
04253     _Tp& back();
04255     const _Tp& back() const;
04257     bool empty() const;
04258 
04260     void clear();
04262     void pop_front();
04264     void pop_back();
04266     void pop_front(_Tp* elems, size_t count);
04268     void pop_back(_Tp* elems, size_t count);
04269 
04271     void copyTo(vector<_Tp>& vec, const Range& range=Range::all()) const;
04273     operator vector<_Tp>() const;
04274 
04275     CvSeq* seq;
04276 };
04277 
04278 
04282 template<typename _Tp> class CV_EXPORTS SeqIterator : public CvSeqReader
04283 {
04284 public:
04286     SeqIterator();
04288     SeqIterator(const Seq<_Tp>& seq, bool seekEnd=false);
04290     void seek(size_t pos);
04292     size_t tell() const;
04294     _Tp& operator *();
04296     const _Tp& operator *() const;
04298     SeqIterator& operator ++();
04300     SeqIterator operator ++(int) const;
04302     SeqIterator& operator --();
04304     SeqIterator operator --(int) const;
04305 
04307     SeqIterator& operator +=(int);
04309     SeqIterator& operator -=(int);
04310 
04311     // this is index of the current element module seq->total*2
04312     // (to distinguish between 0 and seq->total)
04313     int index;
04314 };
04315 
04316 
04317 class CV_EXPORTS Algorithm;
04318 class CV_EXPORTS AlgorithmInfo;
04319 struct CV_EXPORTS AlgorithmInfoData;
04320 
04321 template<typename _Tp> struct ParamType {};
04322 
04326 class CV_EXPORTS_W Algorithm
04327 {
04328 public:
04329     Algorithm();
04330     virtual ~Algorithm();
04331     string name() const;
04332 
04333     template<typename _Tp> typename ParamType<_Tp>::member_type get(const string& name) const;
04334     template<typename _Tp> typename ParamType<_Tp>::member_type get(const char* name) const;
04335 
04336     CV_WRAP int getInt(const string& name) const;
04337     CV_WRAP double getDouble(const string& name) const;
04338     CV_WRAP bool getBool(const string& name) const;
04339     CV_WRAP string getString(const string& name) const;
04340     CV_WRAP Mat getMat(const string& name) const;
04341     CV_WRAP vector<Mat> getMatVector(const string& name) const;
04342     CV_WRAP Ptr<Algorithm> getAlgorithm(const string& name) const;
04343 
04344     void set(const string& name, int value);
04345     void set(const string& name, double value);
04346     void set(const string& name, bool value);
04347     void set(const string& name, const string& value);
04348     void set(const string& name, const Mat& value);
04349     void set(const string& name, const vector<Mat>& value);
04350     void set(const string& name, const Ptr<Algorithm>& value);
04351     template<typename _Tp> void set(const string& name, const Ptr<_Tp>& value);
04352 
04353     CV_WRAP void setInt(const string& name, int value);
04354     CV_WRAP void setDouble(const string& name, double value);
04355     CV_WRAP void setBool(const string& name, bool value);
04356     CV_WRAP void setString(const string& name, const string& value);
04357     CV_WRAP void setMat(const string& name, const Mat& value);
04358     CV_WRAP void setMatVector(const string& name, const vector<Mat>& value);
04359     CV_WRAP void setAlgorithm(const string& name, const Ptr<Algorithm>& value);
04360     template<typename _Tp> void setAlgorithm(const string& name, const Ptr<_Tp>& value);
04361 
04362     void set(const char* name, int value);
04363     void set(const char* name, double value);
04364     void set(const char* name, bool value);
04365     void set(const char* name, const string& value);
04366     void set(const char* name, const Mat& value);
04367     void set(const char* name, const vector<Mat>& value);
04368     void set(const char* name, const Ptr<Algorithm>& value);
04369     template<typename _Tp> void set(const char* name, const Ptr<_Tp>& value);
04370 
04371     void setInt(const char* name, int value);
04372     void setDouble(const char* name, double value);
04373     void setBool(const char* name, bool value);
04374     void setString(const char* name, const string& value);
04375     void setMat(const char* name, const Mat& value);
04376     void setMatVector(const char* name, const vector<Mat>& value);
04377     void setAlgorithm(const char* name, const Ptr<Algorithm>& value);
04378     template<typename _Tp> void setAlgorithm(const char* name, const Ptr<_Tp>& value);
04379 
04380     CV_WRAP string paramHelp(const string& name) const;
04381     int paramType(const char* name) const;
04382     CV_WRAP int paramType(const string& name) const;
04383     CV_WRAP void getParams(CV_OUT vector<string>& names) const;
04384 
04385 
04386     virtual void write(FileStorage& fs) const;
04387     virtual void read(const FileNode& fn);
04388 
04389     typedef Algorithm* (*Constructor)(void);
04390     typedef int (Algorithm::*Getter)() const;
04391     typedef void (Algorithm::*Setter)(int);
04392 
04393     CV_WRAP static void getList(CV_OUT vector<string>& algorithms);
04394     CV_WRAP static Ptr<Algorithm> _create(const string& name);
04395     template<typename _Tp> static Ptr<_Tp> create(const string& name);
04396 
04397     virtual AlgorithmInfo* info() const /* TODO: make it = 0;*/ { return 0; }
04398 };
04399 
04400 
04401 class CV_EXPORTS AlgorithmInfo
04402 {
04403 public:
04404     friend class Algorithm;
04405     AlgorithmInfo(const string& name, Algorithm::Constructor create);
04406     ~AlgorithmInfo();
04407     void get(const Algorithm* algo, const char* name, int argType, void* value) const;
04408     void addParam_(Algorithm& algo, const char* name, int argType,
04409                    void* value, bool readOnly,
04410                    Algorithm::Getter getter, Algorithm::Setter setter,
04411                    const string& help=string());
04412     string paramHelp(const char* name) const;
04413     int paramType(const char* name) const;
04414     void getParams(vector<string>& names) const;
04415 
04416     void write(const Algorithm* algo, FileStorage& fs) const;
04417     void read(Algorithm* algo, const FileNode& fn) const;
04418     string name() const;
04419 
04420     void addParam(Algorithm& algo, const char* name,
04421                   int& value, bool readOnly=false,
04422                   int (Algorithm::*getter)()=0,
04423                   void (Algorithm::*setter)(int)=0,
04424                   const string& help=string());
04425     void addParam(Algorithm& algo, const char* name,
04426                   short& value, bool readOnly=false,
04427                   int (Algorithm::*getter)()=0,
04428                   void (Algorithm::*setter)(int)=0,
04429                   const string& help=string());
04430     void addParam(Algorithm& algo, const char* name,
04431                   bool& value, bool readOnly=false,
04432                   int (Algorithm::*getter)()=0,
04433                   void (Algorithm::*setter)(int)=0,
04434                   const string& help=string());
04435     void addParam(Algorithm& algo, const char* name,
04436                   double& value, bool readOnly=false,
04437                   double (Algorithm::*getter)()=0,
04438                   void (Algorithm::*setter)(double)=0,
04439                   const string& help=string());
04440     void addParam(Algorithm& algo, const char* name,
04441                   string& value, bool readOnly=false,
04442                   string (Algorithm::*getter)()=0,
04443                   void (Algorithm::*setter)(const string&)=0,
04444                   const string& help=string());
04445     void addParam(Algorithm& algo, const char* name,
04446                   Mat& value, bool readOnly=false,
04447                   Mat (Algorithm::*getter)()=0,
04448                   void (Algorithm::*setter)(const Mat&)=0,
04449                   const string& help=string());
04450     void addParam(Algorithm& algo, const char* name,
04451                   vector<Mat>& value, bool readOnly=false,
04452                   vector<Mat> (Algorithm::*getter)()=0,
04453                   void (Algorithm::*setter)(const vector<Mat>&)=0,
04454                   const string& help=string());
04455     void addParam(Algorithm& algo, const char* name,
04456                   Ptr<Algorithm>& value, bool readOnly=false,
04457                   Ptr<Algorithm> (Algorithm::*getter)()=0,
04458                   void (Algorithm::*setter)(const Ptr<Algorithm>&)=0,
04459                   const string& help=string());
04460     template<typename _Tp, typename _Base> void addParam(Algorithm& algo, const char* name,
04461                   Ptr<_Tp>& value, bool readOnly=false,
04462                   Ptr<_Tp> (Algorithm::*getter)()=0,
04463                   void (Algorithm::*setter)(const Ptr<_Tp>&)=0,
04464                   const string& help=string());
04465     template<typename _Tp> void addParam(Algorithm& algo, const char* name,
04466                   Ptr<_Tp>& value, bool readOnly=false,
04467                   Ptr<_Tp> (Algorithm::*getter)()=0,
04468                   void (Algorithm::*setter)(const Ptr<_Tp>&)=0,
04469                   const string& help=string());
04470 protected:
04471     AlgorithmInfoData* data;
04472     void set(Algorithm* algo, const char* name, int argType,
04473               const void* value, bool force=false) const;
04474 };
04475 
04476 
04477 struct CV_EXPORTS Param
04478 {
04479     enum { INT=0, BOOLEAN=1, REAL=2, STRING=3, MAT=4, MAT_VECTOR=5, ALGORITHM=6, FLOAT=7, UNSIGNED_INT=8, UINT64=9, SHORT=10 };
04480 
04481     Param();
04482     Param(int _type, bool _readonly, int _offset,
04483           Algorithm::Getter _getter=0,
04484           Algorithm::Setter _setter=0,
04485           const string& _help=string());
04486     int type;
04487     int offset;
04488     bool readonly;
04489     Algorithm::Getter getter;
04490     Algorithm::Setter setter;
04491     string help;
04492 };
04493 
04494 template<> struct ParamType<bool>
04495 {
04496     typedef bool const_param_type;
04497     typedef bool member_type;
04498 
04499     enum { type = Param::BOOLEAN };
04500 };
04501 
04502 template<> struct ParamType<int>
04503 {
04504     typedef int const_param_type;
04505     typedef int member_type;
04506 
04507     enum { type = Param::INT };
04508 };
04509 
04510 template<> struct ParamType<short>
04511 {
04512     typedef int const_param_type;
04513     typedef int member_type;
04514 
04515     enum { type = Param::SHORT };
04516 };
04517 
04518 template<> struct ParamType<double>
04519 {
04520     typedef double const_param_type;
04521     typedef double member_type;
04522 
04523     enum { type = Param::REAL };
04524 };
04525 
04526 template<> struct ParamType<string>
04527 {
04528     typedef const string& const_param_type;
04529     typedef string member_type;
04530 
04531     enum { type = Param::STRING };
04532 };
04533 
04534 template<> struct ParamType<Mat>
04535 {
04536     typedef const Mat& const_param_type;
04537     typedef Mat member_type;
04538 
04539     enum { type = Param::MAT };
04540 };
04541 
04542 template<> struct ParamType<vector<Mat> >
04543 {
04544     typedef const vector<Mat>& const_param_type;
04545     typedef vector<Mat> member_type;
04546 
04547     enum { type = Param::MAT_VECTOR };
04548 };
04549 
04550 template<> struct ParamType<Algorithm>
04551 {
04552     typedef const Ptr<Algorithm>& const_param_type;
04553     typedef Ptr<Algorithm> member_type;
04554 
04555     enum { type = Param::ALGORITHM };
04556 };
04557 
04558 template<> struct ParamType<float>
04559 {
04560     typedef float const_param_type;
04561     typedef float member_type;
04562 
04563     enum { type = Param::FLOAT };
04564 };
04565 
04566 template<> struct ParamType<unsigned>
04567 {
04568     typedef unsigned const_param_type;
04569     typedef unsigned member_type;
04570 
04571     enum { type = Param::UNSIGNED_INT };
04572 };
04573 
04574 template<> struct ParamType<uint64>
04575 {
04576     typedef uint64 const_param_type;
04577     typedef uint64 member_type;
04578 
04579     enum { type = Param::UINT64 };
04580 };
04581 
04582 
04624 class CV_EXPORTS CommandLineParser
04625 {
04626     public:
04627 
04629       CommandLineParser(int argc, const char* const argv[], const char* key_map);
04630 
04632     template<typename _Tp>
04633     _Tp get(const std::string& name, bool space_delete=true)
04634     {
04635         if (!has(name))
04636         {
04637             return _Tp();
04638         }
04639         std::string str = getString(name);
04640         return analyzeValue<_Tp>(str, space_delete);
04641     }
04642 
04644     void printParams();
04645 
04646     protected:
04647     std::map<std::string, std::vector<std::string> > data;
04648     std::string getString(const std::string& name);
04649 
04650     bool has(const std::string& keys);
04651 
04652     template<typename _Tp>
04653     _Tp analyzeValue(const std::string& str, bool space_delete=false);
04654 
04655     template<typename _Tp>
04656     static _Tp getData(const std::string& str)
04657     {
04658         _Tp res;
04659         std::stringstream s1(str);
04660         s1 >> res;
04661         return res;
04662     }
04663 
04664     template<typename _Tp>
04665      _Tp fromStringNumber(const std::string& str);//the default conversion function for numbers
04666 
04667     };
04668 
04669 template<> CV_EXPORTS
04670 bool CommandLineParser::get<bool>(const std::string& name, bool space_delete);
04671 
04672 template<> CV_EXPORTS
04673 std::string CommandLineParser::analyzeValue<std::string>(const std::string& str, bool space_delete);
04674 
04675 template<> CV_EXPORTS
04676 int CommandLineParser::analyzeValue<int>(const std::string& str, bool space_delete);
04677 
04678 template<> CV_EXPORTS
04679 unsigned int CommandLineParser::analyzeValue<unsigned int>(const std::string& str, bool space_delete);
04680 
04681 template<> CV_EXPORTS
04682 uint64 CommandLineParser::analyzeValue<uint64>(const std::string& str, bool space_delete);
04683 
04684 template<> CV_EXPORTS
04685 float CommandLineParser::analyzeValue<float>(const std::string& str, bool space_delete);
04686 
04687 template<> CV_EXPORTS
04688 double CommandLineParser::analyzeValue<double>(const std::string& str, bool space_delete);
04689 
04690 
04692 
04693 // a base body class
04694 class CV_EXPORTS ParallelLoopBody
04695 {
04696 public:
04697     virtual ~ParallelLoopBody();
04698     virtual void operator() (const Range& range) const = 0;
04699 };
04700 
04701 CV_EXPORTS void parallel_for_(const Range& range, const ParallelLoopBody& body, double nstripes=-1.);
04702 
04704 
04705 class CV_EXPORTS Mutex
04706 {
04707 public:
04708     Mutex();
04709     ~Mutex();
04710     Mutex(const Mutex& m);
04711     Mutex& operator = (const Mutex& m);
04712 
04713     void lock();
04714     bool trylock();
04715     void unlock();
04716 
04717     struct Impl;
04718 protected:
04719     Impl* impl;
04720 };
04721 
04722 class CV_EXPORTS AutoLock
04723 {
04724 public:
04725     AutoLock(Mutex& m) : mutex(&m) { mutex->lock(); }
04726     ~AutoLock() { mutex->unlock(); }
04727 protected:
04728     Mutex* mutex;
04729 };
04730 
04731 }
04732 
04733 #endif // __cplusplus
04734 
04735 #include "opencv2/core/operations.hpp"
04736 #include "opencv2/core/mat.hpp"
04737 
04738 #endif /*__OPENCV_CORE_HPP__*/