Cinder

  • Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

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 #endif // SKIP_INCLUDES
00065 
00069 namespace cv {
00070 
00071 #undef abs
00072 #undef min
00073 #undef max
00074 #undef Complex
00075 
00076 using std::vector;
00077 using std::string;
00078 using std::ptrdiff_t;
00079     
00080 template<typename _Tp> class CV_EXPORTS Size_;
00081 template<typename _Tp> class CV_EXPORTS Point_;
00082 template<typename _Tp> class CV_EXPORTS Rect_;
00083 template<typename _Tp, int cn> class CV_EXPORTS Vec;
00084 template<typename _Tp, int m, int n> class CV_EXPORTS Matx;
00085     
00086 typedef std::string String;
00087 typedef std::basic_string<wchar_t> WString;
00088 
00089 class Mat;
00090 class SparseMat;
00091 typedef Mat MatND;
00092 
00093 class CV_EXPORTS MatExpr;
00094 class CV_EXPORTS MatOp_Base;
00095 class CV_EXPORTS MatArg;
00096 class CV_EXPORTS MatConstIterator;
00097 
00098 template<typename _Tp> class CV_EXPORTS Mat_;
00099 template<typename _Tp> class CV_EXPORTS MatIterator_;
00100 template<typename _Tp> class CV_EXPORTS MatConstIterator_;
00101 template<typename _Tp> class CV_EXPORTS MatCommaInitializer_;
00102     
00103 CV_EXPORTS string fromUtf16(const WString& str);
00104 CV_EXPORTS WString toUtf16(const string& str);
00105 
00106 CV_EXPORTS string format( const char* fmt, ... );
00107 CV_EXPORTS string tempfile( const char* suffix CV_DEFAULT(0));
00108     
00109 // matrix decomposition types
00110 enum { DECOMP_LU=0, DECOMP_SVD=1, DECOMP_EIG=2, DECOMP_CHOLESKY=3, DECOMP_QR=4, DECOMP_NORMAL=16 };
00111 enum { NORM_INF=1, NORM_L1=2, NORM_L2=4, NORM_TYPE_MASK=7, NORM_RELATIVE=8, NORM_MINMAX=32};
00112 enum { CMP_EQ=0, CMP_GT=1, CMP_GE=2, CMP_LT=3, CMP_LE=4, CMP_NE=5 };
00113 enum { GEMM_1_T=1, GEMM_2_T=2, GEMM_3_T=4 };
00114 enum { DFT_INVERSE=1, DFT_SCALE=2, DFT_ROWS=4, DFT_COMPLEX_OUTPUT=16, DFT_REAL_OUTPUT=32,
00115     DCT_INVERSE = DFT_INVERSE, DCT_ROWS=DFT_ROWS };
00116 
00117     
00122 class CV_EXPORTS Exception : public std::exception
00123 {
00124 public:
00128     Exception();
00133     Exception(int _code, const string& _err, const string& _func, const string& _file, int _line);
00134     virtual ~Exception() throw();
00135 
00139     virtual const char *what() const throw();
00140     void formatMessage();
00141     
00142     string msg; 
00143 
00144     int code; 
00145     string err; 
00146     string func; 
00147     string file; 
00148     int line; 
00149 };
00150 
00151 
00153  
00161 CV_EXPORTS void error( const Exception& exc );
00162 
00164 
00171 CV_EXPORTS bool setBreakOnError(bool flag);
00172     
00173 typedef int (CV_CDECL *ErrorCallback)( int status, const char* func_name,
00174                                        const char* err_msg, const char* file_name,
00175                                        int line, void* userdata );
00176 
00178 
00188 CV_EXPORTS ErrorCallback redirectError( ErrorCallback errCallback,
00189                                         void* userdata=0, void** prevUserdata=0);
00190     
00191 #ifdef __GNUC__
00192 #define CV_Error( code, msg ) cv::error( cv::Exception(code, msg, __func__, __FILE__, __LINE__) )
00193 #define CV_Error_( code, args ) cv::error( cv::Exception(code, cv::format args, __func__, __FILE__, __LINE__) )
00194 #define CV_Assert( expr ) if((expr)) ; else cv::error( cv::Exception(CV_StsAssert, #expr, __func__, __FILE__, __LINE__) )
00195 #else
00196 #define CV_Error( code, msg ) cv::error( cv::Exception(code, msg, "", __FILE__, __LINE__) )
00197 #define CV_Error_( code, args ) cv::error( cv::Exception(code, cv::format args, "", __FILE__, __LINE__) )
00198 #define CV_Assert( expr ) if((expr)) ; else cv::error( cv::Exception(CV_StsAssert, #expr, "", __FILE__, __LINE__) )
00199 #endif
00200     
00201 #ifdef _DEBUG
00202 #define CV_DbgAssert(expr) CV_Assert(expr)
00203 #else
00204 #define CV_DbgAssert(expr)
00205 #endif
00206 
00207 CV_EXPORTS void setNumThreads(int nthreads);
00208 CV_EXPORTS int getNumThreads();
00209 CV_EXPORTS int getThreadNum();
00210 
00212 
00219 CV_EXPORTS int64 getTickCount();
00220 
00233 CV_EXPORTS_W double getTickFrequency();
00234 
00243 CV_EXPORTS int64 getCPUTickCount();
00244 
00264 CV_EXPORTS_W bool checkHardwareSupport(int feature);
00265 
00276 CV_EXPORTS void* fastMalloc(size_t bufSize);
00277 
00284 CV_EXPORTS void fastFree(void* ptr);
00285 
00286 template<typename _Tp> static inline _Tp* allocate(size_t n)
00287 {
00288     return new _Tp[n];
00289 }
00290 
00291 template<typename _Tp> static inline void deallocate(_Tp* ptr, size_t)
00292 {
00293     delete[] ptr;
00294 }
00295 
00302 template<typename _Tp> static inline _Tp* alignPtr(_Tp* ptr, int n=(int)sizeof(_Tp))
00303 {
00304     return (_Tp*)(((size_t)ptr + n-1) & -n);
00305 }
00306 
00312 static inline size_t alignSize(size_t sz, int n)
00313 {
00314     return (sz + n-1) & -n;
00315 }
00316 
00326 CV_EXPORTS_W void setUseOptimized(bool onoff);
00327 
00333 CV_EXPORTS_W bool useOptimized();
00334 
00338 template<typename _Tp> class CV_EXPORTS Allocator
00339 {
00340 public: 
00341     typedef _Tp value_type;
00342     typedef value_type* pointer;
00343     typedef const value_type* const_pointer;
00344     typedef value_type& reference;
00345     typedef const value_type& const_reference;
00346     typedef size_t size_type;
00347     typedef ptrdiff_t difference_type;
00348     template<typename U> class rebind { typedef Allocator<U> other; };
00349 
00350     explicit Allocator() {}
00351     ~Allocator() {}
00352     explicit Allocator(Allocator const&) {}
00353     template<typename U>
00354     explicit Allocator(Allocator<U> const&) {}
00355 
00356     // address
00357     pointer address(reference r) { return &r; }
00358     const_pointer address(const_reference r) { return &r; }
00359 
00360     pointer allocate(size_type count, const void* =0)
00361     { return reinterpret_cast<pointer>(fastMalloc(count * sizeof (_Tp))); }
00362 
00363     void deallocate(pointer p, size_type) {fastFree(p); }
00364 
00365     size_type max_size() const
00366     { return max(static_cast<_Tp>(-1)/sizeof(_Tp), 1); }
00367 
00368     void construct(pointer p, const _Tp& v) { new(static_cast<void*>(p)) _Tp(v); }
00369     void destroy(pointer p) { p->~_Tp(); }
00370 };
00371 
00373 
00380 template<typename _Tp> class CV_EXPORTS DataDepth {};
00381 
00382 template<> class DataDepth<bool> { public: enum { value = CV_8U, fmt=(int)'u' }; };
00383 template<> class DataDepth<uchar> { public: enum { value = CV_8U, fmt=(int)'u' }; };
00384 template<> class DataDepth<schar> { public: enum { value = CV_8S, fmt=(int)'c' }; };
00385 template<> class DataDepth<char> { public: enum { value = CV_8S, fmt=(int)'c' }; };
00386 template<> class DataDepth<ushort> { public: enum { value = CV_16U, fmt=(int)'w' }; };
00387 template<> class DataDepth<short> { public: enum { value = CV_16S, fmt=(int)'s' }; };
00388 template<> class DataDepth<int> { public: enum { value = CV_32S, fmt=(int)'i' }; };
00389 // this is temporary solution to support 32-bit unsigned integers
00390 template<> class DataDepth<unsigned> { public: enum { value = CV_32S, fmt=(int)'i' }; };
00391 template<> class DataDepth<float> { public: enum { value = CV_32F, fmt=(int)'f' }; };
00392 template<> class DataDepth<double> { public: enum { value = CV_64F, fmt=(int)'d' }; };
00393 template<typename _Tp> class DataDepth<_Tp*> { public: enum { value = CV_USRTYPE1, fmt=(int)'r' }; };
00394 
00395 
00397     
00414 struct CV_EXPORTS Matx_AddOp {};
00415 struct CV_EXPORTS Matx_SubOp {};
00416 struct CV_EXPORTS Matx_ScaleOp {};
00417 struct CV_EXPORTS Matx_MulOp {};
00418 struct CV_EXPORTS Matx_MatMulOp {};
00419 struct CV_EXPORTS Matx_TOp {};
00420     
00421 template<typename _Tp, int m, int n> class CV_EXPORTS Matx
00422 {
00423 public:
00424     typedef _Tp value_type;
00425     typedef Matx<_Tp, MIN(m, n), 1> diag_type;
00426     typedef Matx<_Tp, m, n> mat_type;
00427     enum { depth = DataDepth<_Tp>::value, rows = m, cols = n, channels = rows*cols,
00428            type = CV_MAKETYPE(depth, channels) };
00429     
00431     Matx();
00432     
00433     Matx(_Tp v0); 
00434     Matx(_Tp v0, _Tp v1); 
00435     Matx(_Tp v0, _Tp v1, _Tp v2); 
00436     Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3); 
00437     Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4); 
00438     Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5); 
00439     Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6); 
00440     Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7); 
00441     Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8); 
00442     Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8, _Tp v9); 
00443     Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3,
00444          _Tp v4, _Tp v5, _Tp v6, _Tp v7,
00445          _Tp v8, _Tp v9, _Tp v10, _Tp v11); 
00446     Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3,
00447          _Tp v4, _Tp v5, _Tp v6, _Tp v7,
00448          _Tp v8, _Tp v9, _Tp v10, _Tp v11,
00449          _Tp v12, _Tp v13, _Tp v14, _Tp v15); 
00450     explicit Matx(const _Tp* vals); 
00451     
00452     static Matx all(_Tp alpha);
00453     static Matx zeros();
00454     static Matx ones();
00455     static Matx eye();
00456     static Matx diag(const diag_type& d);
00457     static Matx randu(_Tp a, _Tp b);
00458     static Matx randn(_Tp a, _Tp b);
00459     
00461     _Tp dot(const Matx<_Tp, m, n>& v) const;
00462     
00464     double ddot(const Matx<_Tp, m, n>& v) const;
00465 
00467     template<typename T2> operator Matx<T2, m, n>() const;
00468     
00470     template<int m1, int n1> Matx<_Tp, m1, n1> reshape() const;
00471     
00473     template<int m1, int n1> Matx<_Tp, m1, n1> get_minor(int i, int j) const;
00474     
00476     Matx<_Tp, 1, n> row(int i) const;
00477     
00479     Matx<_Tp, m, 1> col(int i) const;
00480     
00482     Matx<_Tp, MIN(m,n), 1> diag() const;
00483     
00485     Matx<_Tp, n, m> t() const;
00486     
00488     Matx<_Tp, n, m> inv(int method=DECOMP_LU) const;
00489     
00491     template<int l> Matx<_Tp, n, l> solve(const Matx<_Tp, m, l>& rhs, int flags=DECOMP_LU) const;
00492     Matx<_Tp, n, 1> solve(const Matx<_Tp, m, 1>& rhs, int method) const;
00493     
00495     Matx<_Tp, m, n> mul(const Matx<_Tp, m, n>& a) const;
00496     
00498     const _Tp& operator ()(int i, int j) const;
00499     _Tp& operator ()(int i, int j);
00500     
00502     const _Tp& operator ()(int i) const;
00503     _Tp& operator ()(int i);
00504     
00505     Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_AddOp);
00506     Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_SubOp);
00507     template<typename _T2> Matx(const Matx<_Tp, m, n>& a, _T2 alpha, Matx_ScaleOp);
00508     Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_MulOp);
00509     template<int l> Matx(const Matx<_Tp, m, l>& a, const Matx<_Tp, l, n>& b, Matx_MatMulOp);
00510     Matx(const Matx<_Tp, n, m>& a, Matx_TOp);
00511 
00512     _Tp val[m*n]; //< matrix elements
00513 };
00514 
00515     
00516 typedef Matx<float, 1, 2> Matx12f;
00517 typedef Matx<double, 1, 2> Matx12d;
00518 typedef Matx<float, 1, 3> Matx13f;
00519 typedef Matx<double, 1, 3> Matx13d;
00520 typedef Matx<float, 1, 4> Matx14f;
00521 typedef Matx<double, 1, 4> Matx14d;
00522 typedef Matx<float, 1, 6> Matx16f;
00523 typedef Matx<double, 1, 6> Matx16d;
00524     
00525 typedef Matx<float, 2, 1> Matx21f;
00526 typedef Matx<double, 2, 1> Matx21d;
00527 typedef Matx<float, 3, 1> Matx31f;
00528 typedef Matx<double, 3, 1> Matx31d;
00529 typedef Matx<float, 4, 1> Matx41f;
00530 typedef Matx<double, 4, 1> Matx41d;
00531 typedef Matx<float, 6, 1> Matx61f;
00532 typedef Matx<double, 6, 1> Matx61d;
00533 
00534 typedef Matx<float, 2, 2> Matx22f;
00535 typedef Matx<double, 2, 2> Matx22d;
00536 typedef Matx<float, 2, 3> Matx23f;
00537 typedef Matx<double, 2, 3> Matx23d;
00538 typedef Matx<float, 3, 2> Matx32f;
00539 typedef Matx<double, 3, 2> Matx32d;
00540     
00541 typedef Matx<float, 3, 3> Matx33f;
00542 typedef Matx<double, 3, 3> Matx33d;
00543     
00544 typedef Matx<float, 3, 4> Matx34f;
00545 typedef Matx<double, 3, 4> Matx34d;
00546 typedef Matx<float, 4, 3> Matx43f;
00547 typedef Matx<double, 4, 3> Matx43d;
00548     
00549 typedef Matx<float, 4, 4> Matx44f;
00550 typedef Matx<double, 4, 4> Matx44d;
00551 typedef Matx<float, 6, 6> Matx66f;
00552 typedef Matx<double, 6, 6> Matx66d;    
00553 
00554 
00570 template<typename _Tp, int cn> class CV_EXPORTS Vec : public Matx<_Tp, cn, 1>
00571 {
00572 public:
00573     typedef _Tp value_type;
00574     enum { depth = DataDepth<_Tp>::value, channels = cn, type = CV_MAKETYPE(depth, channels) };
00575     
00577     Vec();
00578 
00579     Vec(_Tp v0); 
00580     Vec(_Tp v0, _Tp v1); 
00581     Vec(_Tp v0, _Tp v1, _Tp v2); 
00582     Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3); 
00583     Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4); 
00584     Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5); 
00585     Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6); 
00586     Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7); 
00587     Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8); 
00588     Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8, _Tp v9); 
00589     explicit Vec(const _Tp* values);
00590 
00591     Vec(const Vec<_Tp, cn>& v);
00592     static Vec all(_Tp alpha);
00593 
00595     Vec mul(const Vec<_Tp, cn>& v) const;
00596     
00602     Vec cross(const Vec& v) const;
00604     template<typename T2> operator Vec<T2, cn>() const;
00606     operator CvScalar() const;
00607     
00609     const _Tp& operator [](int i) const;
00610     _Tp& operator[](int i);
00611     const _Tp& operator ()(int i) const;
00612     _Tp& operator ()(int i);
00613 };
00614 
00615 
00616 /* \typedef
00617 
00618    Shorter aliases for the most popular specializations of Vec<T,n>
00619 */
00620 typedef Vec<uchar, 2> Vec2b;
00621 typedef Vec<uchar, 3> Vec3b;
00622 typedef Vec<uchar, 4> Vec4b;
00623 
00624 typedef Vec<short, 2> Vec2s;
00625 typedef Vec<short, 3> Vec3s;
00626 typedef Vec<short, 4> Vec4s;
00627 
00628 typedef Vec<ushort, 2> Vec2w;
00629 typedef Vec<ushort, 3> Vec3w;
00630 typedef Vec<ushort, 4> Vec4w;    
00631     
00632 typedef Vec<int, 2> Vec2i;
00633 typedef Vec<int, 3> Vec3i;
00634 typedef Vec<int, 4> Vec4i;
00635 typedef Vec<int, 6> Vec6i;
00636 typedef Vec<int, 8> Vec8i;
00637 
00638 typedef Vec<float, 2> Vec2f;
00639 typedef Vec<float, 3> Vec3f;
00640 typedef Vec<float, 4> Vec4f;
00641 typedef Vec<float, 6> Vec6f;
00642 
00643 typedef Vec<double, 2> Vec2d;
00644 typedef Vec<double, 3> Vec3d;
00645 typedef Vec<double, 4> Vec4d;
00646 typedef Vec<double, 6> Vec6d;
00647 
00648 
00650 
00658 template<typename _Tp> class CV_EXPORTS Complex
00659 {
00660 public:
00661 
00663     Complex();
00664     Complex( _Tp _re, _Tp _im=0 );
00665     Complex( const std::complex<_Tp>& c );
00666 
00668     template<typename T2> operator Complex<T2>() const;
00670     Complex conj() const;
00672     operator std::complex<_Tp>() const;
00673 
00674     _Tp re, im; //< the real and the imaginary parts
00675 };
00676 
00677 
00681 typedef Complex<float> Complexf;
00682 typedef Complex<double> Complexd;
00683 
00684 
00686 
00694 template<typename _Tp> class CV_EXPORTS Point_
00695 {
00696 public:
00697     typedef _Tp value_type;
00698     
00699     // various constructors
00700     Point_();
00701     Point_(_Tp _x, _Tp _y);
00702     Point_(const Point_& pt);
00703     Point_(const CvPoint& pt);
00704     Point_(const CvPoint2D32f& pt);
00705     Point_(const Size_<_Tp>& sz);
00706     Point_(const Vec<_Tp, 2>& v);
00707 
00708     Point_& operator = (const Point_& pt);
00710     template<typename _Tp2> operator Point_<_Tp2>() const;
00711 
00713     operator CvPoint() const;
00714     operator CvPoint2D32f() const;
00715     operator Vec<_Tp, 2>() const;
00716 
00718     _Tp dot(const Point_& pt) const;
00720     double ddot(const Point_& pt) const;
00722     bool inside(const Rect_<_Tp>& r) const;
00723     
00724     _Tp x, y; //< the point coordinates
00725 };
00726 
00735 template<typename _Tp> class CV_EXPORTS Point3_
00736 {
00737 public:
00738     typedef _Tp value_type;
00739     
00740     // various constructors
00741     Point3_();
00742     Point3_(_Tp _x, _Tp _y, _Tp _z);
00743     Point3_(const Point3_& pt);
00744     explicit Point3_(const Point_<_Tp>& pt);
00745     Point3_(const CvPoint3D32f& pt);
00746     Point3_(const Vec<_Tp, 3>& v);
00747 
00748     Point3_& operator = (const Point3_& pt);
00750     template<typename _Tp2> operator Point3_<_Tp2>() const;
00752     operator CvPoint3D32f() const;
00754     operator Vec<_Tp, 3>() const;
00755 
00757     _Tp dot(const Point3_& pt) const;
00759     double ddot(const Point3_& pt) const;
00761     Point3_ cross(const Point3_& pt) const;
00762     
00763     _Tp x, y, z; //< the point coordinates
00764 };
00765 
00767 
00774 template<typename _Tp> class CV_EXPORTS Size_
00775 {
00776 public:
00777     typedef _Tp value_type;
00778     
00780     Size_();
00781     Size_(_Tp _width, _Tp _height);
00782     Size_(const Size_& sz);
00783     Size_(const CvSize& sz);
00784     Size_(const CvSize2D32f& sz);
00785     Size_(const Point_<_Tp>& pt);
00786 
00787     Size_& operator = (const Size_& sz);
00789     _Tp area() const;
00790 
00792     template<typename _Tp2> operator Size_<_Tp2>() const;
00793     
00795     operator CvSize() const;
00796     operator CvSize2D32f() const;
00797 
00798     _Tp width, height; // the width and the height
00799 };
00800 
00802 
00809 template<typename _Tp> class CV_EXPORTS Rect_
00810 {
00811 public:
00812     typedef _Tp value_type;
00813     
00815     Rect_();
00816     Rect_(_Tp _x, _Tp _y, _Tp _width, _Tp _height);
00817     Rect_(const Rect_& r);
00818     Rect_(const CvRect& r);
00819     Rect_(const Point_<_Tp>& org, const Size_<_Tp>& sz);
00820     Rect_(const Point_<_Tp>& pt1, const Point_<_Tp>& pt2);
00821 
00822     Rect_& operator = ( const Rect_& r );
00824     Point_<_Tp> tl() const;
00826     Point_<_Tp> br() const;
00827     
00829     Size_<_Tp> size() const;
00831     _Tp area() const;
00832 
00834     template<typename _Tp2> operator Rect_<_Tp2>() const;
00836     operator CvRect() const;
00837 
00839     bool contains(const Point_<_Tp>& pt) const;
00840 
00841     _Tp x, y, width, height; //< the top-left corner, as well as width and height of the rectangle
00842 };
00843 
00844 
00850 typedef Point_<int> Point2i;
00851 typedef Point2i Point;
00852 typedef Size_<int> Size2i;
00853 typedef Size2i Size;
00854 typedef Rect_<int> Rect;
00855 typedef Point_<float> Point2f;
00856 typedef Point_<double> Point2d;
00857 typedef Size_<float> Size2f;
00858 typedef Point3_<int> Point3i;
00859 typedef Point3_<float> Point3f;
00860 typedef Point3_<double> Point3d;
00861 
00862 
00870 class CV_EXPORTS RotatedRect
00871 {
00872 public:
00874     RotatedRect();
00875     RotatedRect(const Point2f& _center, const Size2f& _size, float _angle);
00876     RotatedRect(const CvBox2D& box);
00877 
00879     void points(Point2f pts[]) const;
00881     Rect boundingRect() const;
00883     operator CvBox2D() const;
00884     
00885     Point2f center; //< the rectangle mass center
00886     Size2f size;    //< width and height of the rectangle
00887     float angle;    //< the rotation angle. When the angle is 0, 90, 180, 270 etc., the rectangle becomes an up-right rectangle. 
00888 };
00889 
00891 
00898 template<typename _Tp> class CV_EXPORTS Scalar_ : public Vec<_Tp, 4>
00899 {
00900 public:
00902     Scalar_();
00903     Scalar_(_Tp v0, _Tp v1, _Tp v2=0, _Tp v3=0);
00904     Scalar_(const CvScalar& s);
00905     Scalar_(_Tp v0);
00906 
00908     static Scalar_<_Tp> all(_Tp v0);
00910     operator CvScalar() const;
00911 
00913     template<typename T2> operator Scalar_<T2>() const;
00914 
00916     Scalar_<_Tp> mul(const Scalar_<_Tp>& t, double scale=1 ) const;
00917     
00918     // returns (v0, -v1, -v2, -v3)
00919     Scalar_<_Tp> conj() const;
00920     
00921     // returns true iff v1 == v2 == v3 == 0
00922     bool isReal() const;
00923 };
00924 
00925 typedef Scalar_<double> Scalar;
00926 
00927 CV_EXPORTS void scalarToRawData(const Scalar& s, void* buf, int type, int unroll_to=0);
00928 
00930 
00936 class CV_EXPORTS Range
00937 {
00938 public:
00939     Range();
00940     Range(int _start, int _end);
00941     Range(const CvSlice& slice);
00942     int size() const;
00943     bool empty() const;
00944     static Range all();
00945     operator CvSlice() const;
00946 
00947     int start, end;
00948 };
00949 
00951 
00963 template<typename _Tp> class DataType
00964 {
00965 public:
00966     typedef _Tp value_type;
00967     typedef value_type work_type;
00968     typedef value_type channel_type;
00969     typedef value_type vec_type;
00970     
00971     enum { generic_type = 1, depth = -1, channels = 1, fmt=0,
00972         type = CV_MAKETYPE(depth, channels) };
00973 };
00974 
00975 template<> class DataType<bool>
00976 {
00977 public:
00978     typedef bool value_type;
00979     typedef int work_type;
00980     typedef value_type channel_type;
00981     typedef value_type vec_type;
00982     enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 1,
00983            fmt=DataDepth<channel_type>::fmt,
00984            type = CV_MAKETYPE(depth, channels) };
00985 };
00986 
00987 template<> class DataType<uchar>
00988 {
00989 public:
00990     typedef uchar value_type;
00991     typedef int work_type;
00992     typedef value_type channel_type;
00993     typedef value_type vec_type;
00994     enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 1,
00995            fmt=DataDepth<channel_type>::fmt,
00996            type = CV_MAKETYPE(depth, channels) };
00997 };
00998 
00999 template<> class DataType<schar>
01000 {
01001 public:
01002     typedef schar value_type;
01003     typedef int work_type;
01004     typedef value_type channel_type;
01005     typedef value_type vec_type;
01006     enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 1,
01007            fmt=DataDepth<channel_type>::fmt,
01008            type = CV_MAKETYPE(depth, channels) };
01009 };
01010 
01011 template<> class DataType<char>
01012 {
01013 public:
01014     typedef schar value_type;
01015     typedef int work_type;
01016     typedef value_type channel_type;
01017     typedef value_type vec_type;
01018     enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 1,
01019            fmt=DataDepth<channel_type>::fmt,
01020            type = CV_MAKETYPE(depth, channels) };
01021 };
01022 
01023 template<> class DataType<ushort>
01024 {
01025 public:
01026     typedef ushort value_type;
01027     typedef int work_type;
01028     typedef value_type channel_type;
01029     typedef value_type vec_type;
01030     enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 1,
01031            fmt=DataDepth<channel_type>::fmt,
01032            type = CV_MAKETYPE(depth, channels) };
01033 };
01034 
01035 template<> class DataType<short>
01036 {
01037 public:
01038     typedef short value_type;
01039     typedef int work_type;
01040     typedef value_type channel_type;
01041     typedef value_type vec_type;
01042     enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 1,
01043            fmt=DataDepth<channel_type>::fmt,
01044            type = CV_MAKETYPE(depth, channels) };
01045 };
01046 
01047 template<> class DataType<int>
01048 {
01049 public:
01050     typedef int value_type;
01051     typedef value_type work_type;
01052     typedef value_type channel_type;
01053     typedef value_type vec_type;
01054     enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 1,
01055            fmt=DataDepth<channel_type>::fmt,
01056            type = CV_MAKETYPE(depth, channels) };
01057 };
01058 
01059 template<> class DataType<float>
01060 {
01061 public:
01062     typedef float value_type;
01063     typedef value_type work_type;
01064     typedef value_type channel_type;
01065     typedef value_type vec_type;
01066     enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 1,
01067            fmt=DataDepth<channel_type>::fmt,
01068            type = CV_MAKETYPE(depth, channels) };
01069 };
01070 
01071 template<> class DataType<double>
01072 {
01073 public:
01074     typedef double value_type;
01075     typedef value_type work_type;
01076     typedef value_type channel_type;
01077     typedef value_type vec_type;
01078     enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 1,
01079            fmt=DataDepth<channel_type>::fmt,
01080            type = CV_MAKETYPE(depth, channels) };
01081 };
01082 
01083 template<typename _Tp, int cn> class DataType<Vec<_Tp, cn> >
01084 {
01085 public:
01086     typedef Vec<_Tp, cn> value_type;
01087     typedef Vec<typename DataType<_Tp>::work_type, cn> work_type;
01088     typedef _Tp channel_type;
01089     typedef value_type vec_type;
01090     enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = cn,
01091            fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt,
01092            type = CV_MAKETYPE(depth, channels) };
01093 };
01094 
01095 template<typename _Tp> class DataType<std::complex<_Tp> >
01096 {
01097 public:
01098     typedef std::complex<_Tp> value_type;
01099     typedef value_type work_type;
01100     typedef _Tp channel_type;
01101     enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 2,
01102            fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt,
01103            type = CV_MAKETYPE(depth, channels) };
01104     typedef Vec<channel_type, channels> vec_type;
01105 };
01106 
01107 template<typename _Tp> class DataType<Complex<_Tp> >
01108 {
01109 public:
01110     typedef Complex<_Tp> value_type;
01111     typedef value_type work_type;
01112     typedef _Tp channel_type;
01113     enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 2,
01114            fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt,
01115            type = CV_MAKETYPE(depth, channels) };
01116     typedef Vec<channel_type, channels> vec_type;
01117 };
01118 
01119 template<typename _Tp> class DataType<Point_<_Tp> >
01120 {
01121 public:
01122     typedef Point_<_Tp> value_type;
01123     typedef Point_<typename DataType<_Tp>::work_type> work_type;
01124     typedef _Tp channel_type;
01125     enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 2,
01126            fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt,
01127            type = CV_MAKETYPE(depth, channels) };
01128     typedef Vec<channel_type, channels> vec_type;
01129 };
01130 
01131 template<typename _Tp> class DataType<Point3_<_Tp> >
01132 {
01133 public:
01134     typedef Point3_<_Tp> value_type;
01135     typedef Point3_<typename DataType<_Tp>::work_type> work_type;
01136     typedef _Tp channel_type;
01137     enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 3,
01138            fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt,
01139            type = CV_MAKETYPE(depth, channels) };
01140     typedef Vec<channel_type, channels> vec_type;
01141 };
01142 
01143 template<typename _Tp> class DataType<Size_<_Tp> >
01144 {
01145 public:
01146     typedef Size_<_Tp> value_type;
01147     typedef Size_<typename DataType<_Tp>::work_type> work_type;
01148     typedef _Tp channel_type;
01149     enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 2,
01150            fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt,
01151            type = CV_MAKETYPE(depth, channels) };
01152     typedef Vec<channel_type, channels> vec_type;
01153 };
01154 
01155 template<typename _Tp> class DataType<Rect_<_Tp> >
01156 {
01157 public:
01158     typedef Rect_<_Tp> value_type;
01159     typedef Rect_<typename DataType<_Tp>::work_type> work_type;
01160     typedef _Tp channel_type;
01161     enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 4,
01162            fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt,
01163            type = CV_MAKETYPE(depth, channels) };
01164     typedef Vec<channel_type, channels> vec_type;
01165 };
01166 
01167 template<typename _Tp> class DataType<Scalar_<_Tp> >
01168 {
01169 public:
01170     typedef Scalar_<_Tp> value_type;
01171     typedef Scalar_<typename DataType<_Tp>::work_type> work_type;
01172     typedef _Tp channel_type;
01173     enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 4,
01174            fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt,
01175            type = CV_MAKETYPE(depth, channels) };
01176     typedef Vec<channel_type, channels> vec_type;
01177 };
01178 
01179 template<> class DataType<Range>
01180 {
01181 public:
01182     typedef Range value_type;
01183     typedef value_type work_type;
01184     typedef int channel_type;
01185     enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 2,
01186            fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt,
01187            type = CV_MAKETYPE(depth, channels) };
01188     typedef Vec<channel_type, channels> vec_type;
01189 };
01190 
01191     
01193 
01215 template<typename _Tp> class CV_EXPORTS Ptr
01216 {
01217 public:
01219     Ptr();
01221     Ptr(_Tp* _obj);
01223     ~Ptr();
01225     Ptr(const Ptr& ptr);
01227     Ptr& operator = (const Ptr& ptr);
01229     void addref();
01231     void release();
01233     void delete_obj();
01235     bool empty() const;
01236 
01237     
01239     _Tp* operator -> ();
01240     const _Tp* operator -> () const;
01241 
01242     operator _Tp* ();
01243     operator const _Tp*() const;
01244     
01245 protected:
01246     _Tp* obj; //< the object pointer.
01247     int* refcount; //< the associated reference counter
01248 };
01249 
01250     
01252     
01256 class CV_EXPORTS _InputArray
01257 {
01258 public:
01259     enum { KIND_SHIFT=16, NONE=0<<KIND_SHIFT, MAT=1<<KIND_SHIFT,
01260         MATX=2<<KIND_SHIFT, STD_VECTOR=3<<KIND_SHIFT,
01261         STD_VECTOR_VECTOR=4<<KIND_SHIFT,
01262         STD_VECTOR_MAT=5<<KIND_SHIFT, EXPR=6<<KIND_SHIFT };
01263     _InputArray();
01264     _InputArray(const Mat& m);
01265     _InputArray(const MatExpr& expr);
01266     template<typename _Tp> _InputArray(const vector<_Tp>& vec);
01267     template<typename _Tp> _InputArray(const vector<vector<_Tp> >& vec);
01268     _InputArray(const vector<Mat>& vec);
01269     template<typename _Tp, int m, int n> _InputArray(const Matx<_Tp, m, n>& matx);
01270     _InputArray(const double& val);
01271     virtual Mat getMat(int i=-1) const;
01272     virtual void getMatVector(vector<Mat>& mv) const;
01273     virtual int kind() const;
01274     virtual Size size(int i=-1) const;
01275     virtual size_t total(int i=-1) const;
01276     virtual int type(int i=-1) const;
01277     virtual int depth(int i=-1) const;
01278     virtual int channels(int i=-1) const;
01279     virtual bool empty() const;
01280 
01281     int flags;
01282     void* obj;
01283     Size sz;
01284 };
01285 
01286 
01287 enum
01288 {
01289     DEPTH_MASK_8U = 1 << CV_8U,
01290     DEPTH_MASK_8S = 1 << CV_8S,
01291     DEPTH_MASK_16U = 1 << CV_16U,
01292     DEPTH_MASK_16S = 1 << CV_16S,
01293     DEPTH_MASK_32S = 1 << CV_32S,
01294     DEPTH_MASK_32F = 1 << CV_32F,
01295     DEPTH_MASK_64F = 1 << CV_64F,
01296     DEPTH_MASK_ALL = (DEPTH_MASK_64F<<1)-1,
01297     DEPTH_MASK_ALL_BUT_8S = DEPTH_MASK_ALL & ~DEPTH_MASK_8S,
01298     DEPTH_MASK_FLT = DEPTH_MASK_32F + DEPTH_MASK_64F
01299 };
01300 
01301 
01305 class CV_EXPORTS _OutputArray : public _InputArray
01306 {
01307 public:
01308     _OutputArray();
01309     _OutputArray(Mat& m);
01310     template<typename _Tp> _OutputArray(vector<_Tp>& vec);
01311     template<typename _Tp> _OutputArray(vector<vector<_Tp> >& vec);
01312     _OutputArray(vector<Mat>& vec);
01313     template<typename _Tp, int m, int n> _OutputArray(Matx<_Tp, m, n>& matx);
01314     virtual bool fixedSize() const;
01315     virtual bool fixedType() const;
01316     virtual bool needed() const;
01317     virtual Mat& getMatRef(int i=-1) const;
01318     virtual void create(Size sz, int type, int i=-1, bool allocateVector=false, int fixedDepthMask=0) const;
01319     virtual void create(int rows, int cols, int type, int i=-1, bool allowTransposed=false, int fixedDepthMask=0) const;
01320     virtual void create(int dims, const int* size, int type, int i=-1, bool allowTransposed=false, int fixedDepthMask=0) const;
01321     virtual void release() const;
01322     virtual void clear() const;
01323 };
01324 
01325 typedef const _InputArray& InputArray;
01326 typedef InputArray InputArrayOfArrays;
01327 typedef const _OutputArray& OutputArray;
01328 typedef OutputArray OutputArrayOfArrays;
01329 typedef OutputArray InputOutputArray;
01330 
01331 CV_EXPORTS OutputArray noArray();
01332 
01334 
01335 enum { MAGIC_MASK=0xFFFF0000, TYPE_MASK=0x00000FFF, DEPTH_MASK=7 };
01336 
01337 static inline size_t getElemSize(int type) { return CV_ELEM_SIZE(type); }
01338 
01343 class CV_EXPORTS MatAllocator
01344 {
01345 public:
01346     MatAllocator() {}
01347     virtual ~MatAllocator() {}
01348     virtual void allocate(int dims, const int* sizes, int type, int*& refcount,
01349                           uchar*& datastart, uchar*& data, size_t* step) = 0;
01350     virtual void deallocate(int* refcount, uchar* datastart, uchar* data) = 0;
01351 };
01352     
01565 class CV_EXPORTS Mat
01566 {
01567 public:
01569     Mat();
01571     // (_type is CV_8UC1, CV_64FC3, CV_32SC(12) etc.)
01572     Mat(int _rows, int _cols, int _type);
01573     Mat(Size _size, int _type);
01575     Mat(int _rows, int _cols, int _type, const Scalar& _s);
01576     Mat(Size _size, int _type, const Scalar& _s);
01577     
01579     Mat(int _ndims, const int* _sizes, int _type);
01580     Mat(int _ndims, const int* _sizes, int _type, const Scalar& _s);
01581     
01583     Mat(const Mat& m);
01585     Mat(int _rows, int _cols, int _type, void* _data, size_t _step=AUTO_STEP);
01586     Mat(Size _size, int _type, void* _data, size_t _step=AUTO_STEP);
01587     Mat(int _ndims, const int* _sizes, int _type, void* _data, const size_t* _steps=0);
01588     
01590     Mat(const Mat& m, const Range& rowRange, const Range& colRange=Range::all());
01591     Mat(const Mat& m, const Rect& roi);
01592     Mat(const Mat& m, const Range* ranges);
01594     Mat(const CvMat* m, bool copyData=false);
01596     Mat(const CvMatND* m, bool copyData=false);
01598     Mat(const IplImage* img, bool copyData=false);
01600     template<typename _Tp> explicit Mat(const vector<_Tp>& vec, bool copyData=false);
01602     template<typename _Tp, int n> explicit Mat(const Vec<_Tp, n>& vec,
01603                                                bool copyData=true);
01605     template<typename _Tp, int m, int n> explicit Mat(const Matx<_Tp, m, n>& mtx,
01606                                                       bool copyData=true);
01608     template<typename _Tp> explicit Mat(const Point_<_Tp>& pt, bool copyData=true);
01610     template<typename _Tp> explicit Mat(const Point3_<_Tp>& pt, bool copyData=true);
01612     template<typename _Tp> explicit Mat(const MatCommaInitializer_<_Tp>& commaInitializer);
01614     ~Mat();
01616     Mat& operator = (const Mat& m);
01617     Mat& operator = (const MatExpr& expr);
01618 
01620     Mat row(int y) const;
01622     Mat col(int x) const;
01624     Mat rowRange(int startrow, int endrow) const;
01625     Mat rowRange(const Range& r) const;
01627     Mat colRange(int startcol, int endcol) const;
01628     Mat colRange(const Range& r) const;
01630     // (d=0 - the main diagonal,
01631     //  >0 - a diagonal from the lower half,
01632     //  <0 - a diagonal from the upper half)
01633     Mat diag(int d=0) const;
01635     static Mat diag(const Mat& d);
01636 
01638     Mat clone() const;
01640     // It calls m.create(this->size(), this->type()).
01641     void copyTo( OutputArray m ) const;
01643     void copyTo( OutputArray m, InputArray mask ) const;
01645     void convertTo( OutputArray m, int rtype, double alpha=1, double beta=0 ) const;
01646 
01647     void assignTo( Mat& m, int type=-1 ) const;
01648 
01650     Mat& operator = (const Scalar& s);
01652     Mat& setTo(InputArray value, InputArray mask=noArray());
01654     // number of channels and/or different number of rows. see cvReshape.
01655     Mat reshape(int _cn, int _rows=0) const;
01656     Mat reshape(int _cn, int _newndims, const int* _newsz) const;
01657 
01659     MatExpr t() const;
01661     MatExpr inv(int method=DECOMP_LU) const;
01663     MatExpr mul(InputArray m, double scale=1) const;
01664     
01666     Mat cross(InputArray m) const;
01668     double dot(InputArray m) const;
01669 
01671     static MatExpr zeros(int rows, int cols, int type);
01672     static MatExpr zeros(Size size, int type);
01673     static MatExpr zeros(int ndims, const int* sz, int type);
01674     static MatExpr ones(int rows, int cols, int type);
01675     static MatExpr ones(Size size, int type);
01676     static MatExpr ones(int ndims, const int* sz, int type);
01677     static MatExpr eye(int rows, int cols, int type);
01678     static MatExpr eye(Size size, int type);
01679 
01681     // previous data is unreferenced if needed.
01682     void create(int _rows, int _cols, int _type);
01683     void create(Size _size, int _type);
01684     void create(int _ndims, const int* _sizes, int _type);
01685     
01687     void addref();
01689     // deallocates the data when reference counter reaches 0.
01690     void release();
01691     
01693     void deallocate();
01695     void copySize(const Mat& m);
01696     
01698     void reserve(size_t sz);
01700     void resize(size_t sz);
01702     void resize(size_t sz, const Scalar& s);
01704     void push_back_(const void* elem);
01706     template<typename _Tp> void push_back(const _Tp& elem);
01707     template<typename _Tp> void push_back(const Mat_<_Tp>& elem);
01708     void push_back(const Mat& m);
01710     void pop_back(size_t nelems=1);
01711     
01713     void locateROI( Size& wholeSize, Point& ofs ) const;
01715     Mat& adjustROI( int dtop, int dbottom, int dleft, int dright );
01717     // (this is a generalized form of row, rowRange etc.)
01718     Mat operator()( Range rowRange, Range colRange ) const;
01719     Mat operator()( const Rect& roi ) const;
01720     Mat operator()( const Range* ranges ) const;
01721 
01723     operator CvMat() const;
01725     operator CvMatND() const;
01727     operator IplImage() const;
01728     
01729     template<typename _Tp> operator vector<_Tp>() const;
01730     template<typename _Tp, int n> operator Vec<_Tp, n>() const;
01731     template<typename _Tp, int m, int n> operator Matx<_Tp, m, n>() const;
01732     
01734     // (i.e. when there are no gaps between successive rows).
01735     // similar to CV_IS_MAT_CONT(cvmat->type)
01736     bool isContinuous() const;
01737     
01739     bool isSubmatrix() const;
01740     
01742     // similar to CV_ELEM_SIZE(cvmat->type)
01743     size_t elemSize() const;
01745     size_t elemSize1() const;
01747     int type() const;
01749     int depth() const;
01751     int channels() const;
01753     size_t step1(int i=0) const;
01755     bool empty() const;
01757     size_t total() const;
01758     
01760     int checkVector(int elemChannels, int depth=-1, bool requireContinuous=true) const;
01761 
01763     uchar* ptr(int i0=0);
01764     const uchar* ptr(int i0=0) const;
01765     
01767     uchar* ptr(int i0, int i1);
01768     const uchar* ptr(int i0, int i1) const;
01769     
01771     uchar* ptr(int i0, int i1, int i2);
01772     const uchar* ptr(int i0, int i1, int i2) const;
01773     
01775     uchar* ptr(const int* idx);
01777     const uchar* ptr(const int* idx) const;
01778     
01779     template<int n> uchar* ptr(const Vec<int, n>& idx);
01780     template<int n> const uchar* ptr(const Vec<int, n>& idx) const;
01781 
01783     template<typename _Tp> _Tp* ptr(int i0=0);
01784     template<typename _Tp> const _Tp* ptr(int i0=0) const;
01785     
01786     template<typename _Tp> _Tp* ptr(int i0, int i1);
01787     template<typename _Tp> const _Tp* ptr(int i0, int i1) const;
01788     
01789     template<typename _Tp> _Tp* ptr(int i0, int i1, int i2);
01790     template<typename _Tp> const _Tp* ptr(int i0, int i1, int i2) const;
01791     
01792     template<typename _Tp> _Tp* ptr(const int* idx);
01793     template<typename _Tp> const _Tp* ptr(const int* idx) const;
01794     
01795     template<typename _Tp, int n> _Tp* ptr(const Vec<int, n>& idx);
01796     template<typename _Tp, int n> const _Tp* ptr(const Vec<int, n>& idx) const;
01797     
01799     template<typename _Tp> _Tp& at(int i0=0);
01800     template<typename _Tp> const _Tp& at(int i0=0) const;
01801     
01802     template<typename _Tp> _Tp& at(int i0, int i1);
01803     template<typename _Tp> const _Tp& at(int i0, int i1) const;
01804     
01805     template<typename _Tp> _Tp& at(int i0, int i1, int i2);
01806     template<typename _Tp> const _Tp& at(int i0, int i1, int i2) const;
01807     
01808     template<typename _Tp> _Tp& at(const int* idx);
01809     template<typename _Tp> const _Tp& at(const int* idx) const;
01810     
01811     template<typename _Tp, int n> _Tp& at(const Vec<int, n>& idx);
01812     template<typename _Tp, int n> const _Tp& at(const Vec<int, n>& idx) const;
01813     
01815     template<typename _Tp> _Tp& at(Point pt);
01816     template<typename _Tp> const _Tp& at(Point pt) const;
01817     
01819     // the iterators take care of skipping gaps in the end of rows (if any)
01820     template<typename _Tp> MatIterator_<_Tp> begin();
01821     template<typename _Tp> MatIterator_<_Tp> end();
01822     template<typename _Tp> MatConstIterator_<_Tp> begin() const;
01823     template<typename _Tp> MatConstIterator_<_Tp> end() const;
01824 
01825     enum { MAGIC_VAL=0x42FF0000, AUTO_STEP=0, CONTINUOUS_FLAG=CV_MAT_CONT_FLAG, SUBMATRIX_FLAG=CV_SUBMAT_FLAG };
01826 
01833     int flags;
01835     int dims;
01837     int rows, cols;
01839     uchar* data;
01840 
01842     // when matrix points to user-allocated data, the pointer is NULL
01843     int* refcount;
01844     
01846     uchar* datastart;
01847     uchar* dataend;
01848     uchar* datalimit;
01849     
01851     MatAllocator* allocator;
01852     
01853     struct CV_EXPORTS MSize
01854     {
01855         MSize(int* _p);
01856         Size operator()() const;
01857         const int& operator[](int i) const;
01858         int& operator[](int i);
01859         operator const int*() const;
01860         bool operator == (const MSize& sz) const;
01861         bool operator != (const MSize& sz) const;
01862         
01863         int* p;
01864     };
01865     
01866     struct CV_EXPORTS MStep
01867     {
01868         MStep();
01869         MStep(size_t s);
01870         const size_t& operator[](int i) const;
01871         size_t& operator[](int i);
01872         operator size_t() const;
01873         MStep& operator = (size_t s);
01874         
01875         size_t* p;
01876         size_t buf[2];
01877     protected:
01878         MStep& operator = (const MStep&);
01879     };
01880     
01881     MSize size;
01882     MStep step;
01883 };
01884 
01885 
01891 class CV_EXPORTS RNG
01892 {
01893 public:
01894     enum { UNIFORM=0, NORMAL=1 };
01895 
01896     RNG();
01897     RNG(uint64 _state);
01899     unsigned next();
01900 
01901     operator uchar();
01902     operator schar();
01903     operator ushort();
01904     operator short();
01905     operator unsigned();
01907     unsigned operator()(unsigned N);
01908     unsigned operator ()();
01909     operator int();
01910     operator float();
01911     operator double();
01913     int uniform(int a, int b);
01915     float uniform(float a, float b);
01917     double uniform(double a, double b);
01918     void fill( InputOutputArray mat, int distType, InputArray a, InputArray b );
01920     double gaussian(double sigma);
01921 
01922     uint64 state;
01923 };
01924 
01925 
01929 class CV_EXPORTS TermCriteria
01930 {
01931 public:
01932     enum
01933     {
01934         COUNT=1, 
01935         MAX_ITER=COUNT, 
01936         EPS=2 
01937     };
01938 
01940     TermCriteria();
01942     TermCriteria(int _type, int _maxCount, double _epsilon);
01944     TermCriteria(const CvTermCriteria& criteria);
01946     operator CvTermCriteria() const;
01947     
01948     int type; 
01949     int maxCount; // the maximum number of iterations/elements
01950     double epsilon; // the desired accuracy
01951 };
01952 
01953     
01955 CV_EXPORTS void swap(Mat& a, Mat& b);
01956     
01958 CV_EXPORTS Mat cvarrToMat(const CvArr* arr, bool copyData=false,
01959                           bool allowND=true, int coiMode=0);
01961 CV_EXPORTS void extractImageCOI(const CvArr* arr, OutputArray coiimg, int coi=-1);
01963 CV_EXPORTS void insertImageCOI(InputArray coiimg, CvArr* arr, int coi=-1);  
01964 
01966 CV_EXPORTS_W void add(InputArray src1, InputArray src2, OutputArray dst,
01967                       InputArray mask=noArray(), int dtype=-1);
01969 CV_EXPORTS_W void subtract(InputArray src1, InputArray src2, OutputArray dst,
01970                            InputArray mask=noArray(), int dtype=-1);
01971 
01973 CV_EXPORTS_W void multiply(InputArray src1, InputArray src2,
01974                            OutputArray dst, double scale=1, int dtype=-1);
01975     
01977 CV_EXPORTS_W void divide(InputArray src1, InputArray src2, OutputArray dst,
01978                          double scale=1, int dtype=-1);
01979     
01981 CV_EXPORTS_W void divide(double scale, InputArray src2,
01982                          OutputArray dst, int dtype=-1);
01983 
01985 CV_EXPORTS_W void scaleAdd(InputArray src1, double alpha, InputArray src2, OutputArray dst);
01986     
01988 CV_EXPORTS_W void addWeighted(InputArray src1, double alpha, InputArray src2,
01989                               double beta, double gamma, OutputArray dst, int dtype=-1);
01990 
01992 CV_EXPORTS_W void convertScaleAbs(InputArray src, OutputArray dst,
01993                                   double alpha=1, double beta=0);
01995 CV_EXPORTS_W void LUT(InputArray src, InputArray lut, OutputArray dst,
01996                       int interpolation=0);
01997 
01999 CV_EXPORTS_AS(sumElems) Scalar sum(InputArray src); 
02001 CV_EXPORTS_W int countNonZero( InputArray src );
02003 CV_EXPORTS_W Scalar mean(InputArray src, InputArray mask=noArray());
02005 CV_EXPORTS_W void meanStdDev(InputArray src, OutputArray mean, OutputArray stddev,
02006                              InputArray mask=noArray());
02008 CV_EXPORTS_W double norm(InputArray src1, int normType=NORM_L2, InputArray mask=noArray());
02010 CV_EXPORTS_W double norm(InputArray src1, InputArray src2,
02011                          int normType=NORM_L2, InputArray mask=noArray());
02013 CV_EXPORTS_W void normalize( InputArray src, OutputArray dst, double alpha=1, double beta=0,
02014                              int norm_type=NORM_L2, int dtype=-1, InputArray mask=noArray());
02015 
02017 CV_EXPORTS_W void minMaxLoc(InputArray src, CV_OUT double* minVal,
02018                            CV_OUT double* maxVal=0, CV_OUT Point* minLoc=0,
02019                            CV_OUT Point* maxLoc=0, InputArray mask=noArray());
02020 CV_EXPORTS void minMaxIdx(InputArray src, double* minVal, double* maxVal,
02021                           int* minIdx=0, int* maxIdx=0, InputArray mask=noArray());
02022     
02024 CV_EXPORTS_W void reduce(InputArray src, OutputArray dst, int dim, int rtype, int dtype=-1);
02025 
02027 CV_EXPORTS void merge(const Mat* mv, size_t count, OutputArray dst);
02029 CV_EXPORTS_W void merge(const vector<Mat>& mv, OutputArray dst);
02030     
02032 CV_EXPORTS void split(const Mat& src, Mat* mvbegin);
02034 CV_EXPORTS_W void split(const Mat& m, vector<Mat>& mv);
02035     
02037 CV_EXPORTS void mixChannels(const Mat* src, size_t nsrcs, Mat* dst, size_t ndsts,
02038                             const int* fromTo, size_t npairs);
02039 CV_EXPORTS void mixChannels(const vector<Mat>& src, vector<Mat>& dst,
02040                             const int* fromTo, size_t npairs);
02041 
02043 CV_EXPORTS_W void extractChannel(InputArray src, OutputArray dst, int coi);
02044 
02046 CV_EXPORTS_W void insertChannel(InputArray src, InputOutputArray dst, int coi);
02047     
02049 CV_EXPORTS_W void flip(InputArray src, OutputArray dst, int flipCode);
02050 
02052 CV_EXPORTS_W void repeat(InputArray src, int ny, int nx, OutputArray dst);
02053 CV_EXPORTS Mat repeat(const Mat& src, int ny, int nx);
02054         
02055 CV_EXPORTS void hconcat(const Mat* src, size_t nsrc, OutputArray dst);
02056 CV_EXPORTS void hconcat(InputArray src1, InputArray src2, OutputArray dst);
02057 CV_EXPORTS_W void hconcat(InputArray src, OutputArray dst);
02058 
02059 CV_EXPORTS void vconcat(const Mat* src, size_t nsrc, OutputArray dst);
02060 CV_EXPORTS void vconcat(InputArray src1, InputArray src2, OutputArray dst);
02061 CV_EXPORTS_W void vconcat(InputArray src, OutputArray dst);
02062     
02064 CV_EXPORTS_W void bitwise_and(InputArray src1, InputArray src2,
02065                               OutputArray dst, InputArray mask=noArray());
02067 CV_EXPORTS_W void bitwise_or(InputArray src1, InputArray src2,
02068                              OutputArray dst, InputArray mask=noArray());
02070 CV_EXPORTS_W void bitwise_xor(InputArray src1, InputArray src2,
02071                               OutputArray dst, InputArray mask=noArray());
02073 CV_EXPORTS_W void bitwise_not(InputArray src, OutputArray dst,
02074                               InputArray mask=noArray());
02076 CV_EXPORTS_W void absdiff(InputArray src1, InputArray src2, OutputArray dst);
02078 CV_EXPORTS_W void inRange(InputArray src, InputArray lowerb,
02079                           InputArray upperb, OutputArray dst);    
02081 CV_EXPORTS_W void compare(InputArray src1, InputArray src2, OutputArray dst, int cmpop);
02083 CV_EXPORTS_W void min(InputArray src1, InputArray src2, OutputArray dst);
02085 CV_EXPORTS_W void max(InputArray src1, InputArray src2, OutputArray dst);
02086 
02088 CV_EXPORTS void min(const Mat& src1, const Mat& src2, Mat& dst);
02090 CV_EXPORTS void min(const Mat& src1, double src2, Mat& dst);
02092 CV_EXPORTS void max(const Mat& src1, const Mat& src2, Mat& dst);
02094 CV_EXPORTS void max(const Mat& src1, double src2, Mat& dst);    
02095     
02097 CV_EXPORTS_W void sqrt(InputArray src, OutputArray dst);
02099 CV_EXPORTS_W void pow(InputArray src, double power, OutputArray dst);
02101 CV_EXPORTS_W void exp(InputArray src, OutputArray dst);
02103 CV_EXPORTS_W void log(InputArray src, OutputArray dst);
02105 CV_EXPORTS_W float cubeRoot(float val);
02107 CV_EXPORTS_W float fastAtan2(float y, float x);
02109 CV_EXPORTS_W void polarToCart(InputArray magnitude, InputArray angle,
02110                               OutputArray x, OutputArray y, bool angleInDegrees=false);
02112 CV_EXPORTS_W void cartToPolar(InputArray x, InputArray y,
02113                               OutputArray magnitude, OutputArray angle,
02114                               bool angleInDegrees=false);
02116 CV_EXPORTS_W void phase(InputArray x, InputArray y, OutputArray angle,
02117                         bool angleInDegrees=false);
02119 CV_EXPORTS_W void magnitude(InputArray x, InputArray y, OutputArray magnitude);
02121 CV_EXPORTS_W bool checkRange(InputArray a, bool quiet=true, CV_OUT Point* pt=0,
02122                             double minVal=-DBL_MAX, double maxVal=DBL_MAX);
02124 CV_EXPORTS_W void gemm(InputArray src1, InputArray src2, double alpha,
02125                        InputArray src3, double gamma, OutputArray dst, int flags=0);
02127 CV_EXPORTS_W void mulTransposed( InputArray src, OutputArray dst, bool aTa,
02128                                  InputArray delta=noArray(),
02129                                  double scale=1, int dtype=-1 );
02131 CV_EXPORTS_W void transpose(InputArray src, OutputArray dst);
02133 CV_EXPORTS_W void transform(InputArray src, OutputArray dst, InputArray m );
02135 CV_EXPORTS_W void perspectiveTransform(InputArray src, OutputArray dst, InputArray m );
02136 
02138 CV_EXPORTS_W void completeSymm(InputOutputArray mtx, bool lowerToUpper=false);
02140 CV_EXPORTS_W void setIdentity(InputOutputArray mtx, const Scalar& s=Scalar(1));
02142 CV_EXPORTS_W double determinant(InputArray mtx);
02144 CV_EXPORTS_W Scalar trace(InputArray mtx);
02146 CV_EXPORTS_W double invert(InputArray src, OutputArray dst, int flags=DECOMP_LU);
02148 CV_EXPORTS_W bool solve(InputArray src1, InputArray src2,
02149                         OutputArray dst, int flags=DECOMP_LU);
02151 CV_EXPORTS_W void sort(InputArray src, OutputArray dst, int flags);
02153 CV_EXPORTS_W void sortIdx(InputArray src, OutputArray dst, int flags);
02155 CV_EXPORTS_W int solveCubic(InputArray coeffs, OutputArray roots);
02157 CV_EXPORTS_W double solvePoly(InputArray coeffs, OutputArray roots, int maxIters=300);
02159 CV_EXPORTS bool eigen(InputArray src, OutputArray eigenvalues, int lowindex=-1,
02160                       int highindex=-1);
02162 CV_EXPORTS bool eigen(InputArray src, OutputArray eigenvalues,
02163                       OutputArray eigenvectors,
02164                       int lowindex=-1, int highindex=-1);
02166 CV_EXPORTS void calcCovarMatrix( const Mat* samples, int nsamples, Mat& covar, Mat& mean,
02167                                  int flags, int ctype=CV_64F);
02169 CV_EXPORTS_W void calcCovarMatrix( InputArray samples, OutputArray covar,
02170                                    OutputArray mean, int flags, int ctype=CV_64F);
02171 
02226 class CV_EXPORTS PCA
02227 {
02228 public:
02230     PCA();
02232     PCA(InputArray data, InputArray mean, int flags, int maxComponents=0);
02234     PCA& operator()(InputArray data, InputArray mean, int flags, int maxComponents=0);
02236     Mat project(InputArray vec) const;
02238     void project(InputArray vec, OutputArray result) const;
02240     Mat backProject(InputArray vec) const;
02242     void backProject(InputArray vec, OutputArray result) const;
02243 
02244     Mat eigenvectors; 
02245     Mat eigenvalues; 
02246     Mat mean; 
02247 };
02248 
02262 class CV_EXPORTS SVD
02263 {
02264 public:
02265     enum { MODIFY_A=1, NO_UV=2, FULL_UV=4 };
02267     SVD();
02269     SVD( InputArray src, int flags=0 );
02271     SVD& operator ()( InputArray src, int flags=0 );
02272 
02274     static void compute( InputArray src, OutputArray w,
02275                          OutputArray u, OutputArray vt, int flags=0 );
02277     static void compute( InputArray src, OutputArray w, int flags=0 );
02279     static void backSubst( InputArray w, InputArray u,
02280                            InputArray vt, InputArray rhs,
02281                            OutputArray dst );
02282     
02283     template<typename _Tp, int m, int n, int nm> static void compute( const Matx<_Tp, m, n>& a,
02284         Matx<_Tp, nm, 1>& w, Matx<_Tp, m, nm>& u, Matx<_Tp, n, nm>& vt );
02285     template<typename _Tp, int m, int n, int nm> static void compute( const Matx<_Tp, m, n>& a,
02286         Matx<_Tp, nm, 1>& w );
02287     template<typename _Tp, int m, int n, int nm, int nb> static void backSubst( const Matx<_Tp, nm, 1>& w,
02288         const Matx<_Tp, m, nm>& u, const Matx<_Tp, n, nm>& vt, const Matx<_Tp, m, nb>& rhs, Matx<_Tp, n, nb>& dst );
02289     
02291     static void solveZ( InputArray src, OutputArray dst );
02293     void backSubst( InputArray rhs, OutputArray dst ) const;
02294 
02295     Mat u, w, vt;
02296 };
02297 
02299 CV_EXPORTS_W double Mahalanobis(InputArray v1, InputArray v2, InputArray icovar);
02301 CV_EXPORTS double Mahalonobis(InputArray v1, InputArray v2, InputArray icovar);
02302 
02304 CV_EXPORTS_W void dft(InputArray src, OutputArray dst, int flags=0, int nonzeroRows=0);
02306 CV_EXPORTS_W void idft(InputArray src, OutputArray dst, int flags=0, int nonzeroRows=0);
02308 CV_EXPORTS_W void dct(InputArray src, OutputArray dst, int flags=0);
02310 CV_EXPORTS_W void idct(InputArray src, OutputArray dst, int flags=0);
02312 CV_EXPORTS_W void mulSpectrums(InputArray a, InputArray b, OutputArray c,
02313                                int flags, bool conjB=false);
02315 CV_EXPORTS_W int getOptimalDFTSize(int vecsize);
02316 
02320 enum
02321 {
02322     KMEANS_RANDOM_CENTERS=0, // Chooses random centers for k-Means initialization
02323     KMEANS_PP_CENTERS=2,     // Uses k-Means++ algorithm for initialization
02324     KMEANS_USE_INITIAL_LABELS=1 // Uses the user-provided labels for K-Means initialization
02325 };
02327 CV_EXPORTS_W double kmeans( InputArray data, int K, CV_OUT InputOutputArray bestLabels,
02328                             TermCriteria criteria, int attempts,
02329                             int flags, OutputArray centers=noArray() );
02330 
02332 CV_EXPORTS RNG& theRNG();
02333 
02335 template<typename _Tp> static inline _Tp randu() { return (_Tp)theRNG(); }
02336 
02338 CV_EXPORTS_W void randu(InputOutputArray dst, InputArray low, InputArray high);
02339     
02341 CV_EXPORTS_W void randn(InputOutputArray dst, InputArray mean, InputArray stddev);
02342 
02344 CV_EXPORTS void randShuffle(InputOutputArray dst, double iterFactor=1., RNG* rng=0);
02345 
02347 CV_EXPORTS_W void line(Mat& img, Point pt1, Point pt2, const Scalar& color,
02348                      int thickness=1, int lineType=8, int shift=0);
02349 
02351 CV_EXPORTS_W void rectangle(Mat& img, Point pt1, Point pt2,
02352                           const Scalar& color, int thickness=1,
02353                           int lineType=8, int shift=0);
02354     
02356 CV_EXPORTS void rectangle(Mat& img, Rect rec,
02357                           const Scalar& color, int thickness=1,
02358                           int lineType=8, int shift=0);
02359 
02361 CV_EXPORTS_W void circle(Mat& img, Point center, int radius,
02362                        const Scalar& color, int thickness=1,
02363                        int lineType=8, int shift=0);
02364 
02366 CV_EXPORTS_W void ellipse(Mat& img, Point center, Size axes,
02367                         double angle, double startAngle, double endAngle,
02368                         const Scalar& color, int thickness=1,
02369                         int lineType=8, int shift=0);
02370 
02372 CV_EXPORTS_W void ellipse(Mat& img, const RotatedRect& box, const Scalar& color,
02373                         int thickness=1, int lineType=8);
02374 
02376 CV_EXPORTS void fillConvexPoly(Mat& img, const Point* pts, int npts,
02377                                const Scalar& color, int lineType=8,
02378                                int shift=0);
02379 
02381 CV_EXPORTS void fillPoly(Mat& img, const Point** pts,
02382                          const int* npts, int ncontours,
02383                          const Scalar& color, int lineType=8, int shift=0,
02384                          Point offset=Point() );
02385 
02387 CV_EXPORTS void polylines(Mat& img, const Point** pts, const int* npts,
02388                           int ncontours, bool isClosed, const Scalar& color,
02389                           int thickness=1, int lineType=8, int shift=0 );
02390 
02392 CV_EXPORTS bool clipLine(Size imgSize, CV_IN_OUT Point& pt1, CV_IN_OUT Point& pt2);
02393 
02395 CV_EXPORTS_W bool clipLine(Rect imgRect, CV_IN_OUT Point& pt1, CV_IN_OUT Point& pt2);
02396 
02403 class CV_EXPORTS LineIterator
02404 {
02405 public:
02407     LineIterator( const Mat& img, Point pt1, Point pt2,
02408                   int connectivity=8, bool leftToRight=false );
02410     uchar* operator *();
02412     LineIterator& operator ++();
02414     LineIterator operator ++(int);
02416     Point pos() const;
02417 
02418     uchar* ptr;
02419     const uchar* ptr0;
02420     int step, elemSize;
02421     int err, count;
02422     int minusDelta, plusDelta;
02423     int minusStep, plusStep;
02424 };
02425 
02427 CV_EXPORTS_W void ellipse2Poly( Point center, Size axes, int angle,
02428                                 int arcStart, int arcEnd, int delta,
02429                                 CV_OUT vector<Point>& pts );
02430 
02431 enum
02432 {
02433     FONT_HERSHEY_SIMPLEX = 0,
02434     FONT_HERSHEY_PLAIN = 1,
02435     FONT_HERSHEY_DUPLEX = 2,
02436     FONT_HERSHEY_COMPLEX = 3,
02437     FONT_HERSHEY_TRIPLEX = 4,
02438     FONT_HERSHEY_COMPLEX_SMALL = 5,
02439     FONT_HERSHEY_SCRIPT_SIMPLEX = 6,
02440     FONT_HERSHEY_SCRIPT_COMPLEX = 7,
02441     FONT_ITALIC = 16
02442 };
02443 
02445 CV_EXPORTS_W void putText( Mat& img, const string& text, Point org,
02446                          int fontFace, double fontScale, Scalar color,
02447                          int thickness=1, int linetype=8,
02448                          bool bottomLeftOrigin=false );
02449 
02451 CV_EXPORTS_W Size getTextSize(const string& text, int fontFace,
02452                             double fontScale, int thickness,
02453                             CV_OUT int* baseLine);
02454 
02456 
02502 template<typename _Tp> class CV_EXPORTS Mat_ : public Mat
02503 {
02504 public:
02505     typedef _Tp value_type;
02506     typedef typename DataType<_Tp>::channel_type channel_type;
02507     typedef MatIterator_<_Tp> iterator;
02508     typedef MatConstIterator_<_Tp> const_iterator;
02509     
02511     Mat_();
02513     Mat_(int _rows, int _cols);
02515     Mat_(int _rows, int _cols, const _Tp& value);
02517     explicit Mat_(Size _size);
02519     Mat_(Size _size, const _Tp& value);
02521     Mat_(int _ndims, const int* _sizes);
02523     Mat_(int _ndims, const int* _sizes, const _Tp& value);
02525     Mat_(const Mat& m);
02527     Mat_(const Mat_& m);
02529     Mat_(int _rows, int _cols, _Tp* _data, size_t _step=AUTO_STEP);
02531     Mat_(int _ndims, const int* _sizes, _Tp* _data, const size_t* _steps=0);
02533     Mat_(const Mat_& m, const Range& rowRange, const Range& colRange=Range::all());
02535     Mat_(const Mat_& m, const Rect& roi);
02537     Mat_(const Mat_& m, const Range* ranges);
02539     explicit Mat_(const MatExpr& e);
02541     explicit Mat_(const vector<_Tp>& vec, bool copyData=false);
02542     template<int n> explicit Mat_(const Vec<typename DataType<_Tp>::channel_type, n>& vec, bool copyData=true);
02543     template<int m, int n> explicit Mat_(const Matx<typename DataType<_Tp>::channel_type, m, n>& mtx, bool copyData=true);
02544     explicit Mat_(const Point_<typename DataType<_Tp>::channel_type>& pt, bool copyData=true);
02545     explicit Mat_(const Point3_<typename DataType<_Tp>::channel_type>& pt, bool copyData=true);
02546     explicit Mat_(const MatCommaInitializer_<_Tp>& commaInitializer);
02547 
02548     Mat_& operator = (const Mat& m);
02549     Mat_& operator = (const Mat_& m);
02551     Mat_& operator = (const _Tp& s);
02553     Mat_& operator = (const MatExpr& e);
02554 
02556     iterator begin();
02557     iterator end();
02558     const_iterator begin() const;
02559     const_iterator end() const;
02560 
02562     void create(int _rows, int _cols);
02564     void create(Size _size);
02566     void create(int _ndims, const int* _sizes);
02568     Mat_ cross(const Mat_& m) const;
02570     template<typename T2> operator Mat_<T2>() const;
02572     Mat_ row(int y) const;
02573     Mat_ col(int x) const;
02574     Mat_ diag(int d=0) const;
02575     Mat_ clone() const;
02576 
02578     size_t elemSize() const;
02579     size_t elemSize1() const;
02580     int type() const;
02581     int depth() const;
02582     int channels() const;
02583     size_t step1(int i=0) const;
02585     size_t stepT(int i=0) const;
02586 
02588     static MatExpr zeros(int rows, int cols);
02589     static MatExpr zeros(Size size);
02590     static MatExpr zeros(int _ndims, const int* _sizes);
02591     static MatExpr ones(int rows, int cols);
02592     static MatExpr ones(Size size);
02593     static MatExpr ones(int _ndims, const int* _sizes);
02594     static MatExpr eye(int rows, int cols);
02595     static MatExpr eye(Size size);
02596 
02598     Mat_ reshape(int _rows) const;
02599     Mat_& adjustROI( int dtop, int dbottom, int dleft, int dright );
02600     Mat_ operator()( const Range& rowRange, const Range& colRange ) const;
02601     Mat_ operator()( const Rect& roi ) const;
02602     Mat_ operator()( const Range* ranges ) const;
02603 
02605     _Tp* operator [](int y);
02606     const _Tp* operator [](int y) const;
02607 
02609     _Tp& operator ()(const int* idx);
02611     const _Tp& operator ()(const int* idx) const;
02612     
02614     template<int n> _Tp& operator ()(const Vec<int, n>& idx);
02616     template<int n> const _Tp& operator ()(const Vec<int, n>& idx) const;
02617     
02619     _Tp& operator ()(int idx0);
02621     const _Tp& operator ()(int idx0) const;
02623     _Tp& operator ()(int idx0, int idx1);
02625     const _Tp& operator ()(int idx0, int idx1) const;
02627     _Tp& operator ()(int idx0, int idx1, int idx2);
02629     const _Tp& operator ()(int idx0, int idx1, int idx2) const;
02630     
02631     _Tp& operator ()(Point pt);
02632     const _Tp& operator ()(Point pt) const;
02633 
02635     operator vector<_Tp>() const;
02637     template<int n> operator Vec<typename DataType<_Tp>::channel_type, n>() const;
02639     template<int m, int n> operator Matx<typename DataType<_Tp>::channel_type, m, n>() const;
02640 };
02641 
02642 typedef Mat_<uchar> Mat1b;
02643 typedef Mat_<Vec2b> Mat2b;
02644 typedef Mat_<Vec3b> Mat3b;
02645 typedef Mat_<Vec4b> Mat4b;
02646 
02647 typedef Mat_<short> Mat1s;
02648 typedef Mat_<Vec2s> Mat2s;
02649 typedef Mat_<Vec3s> Mat3s;
02650 typedef Mat_<Vec4s> Mat4s;
02651 
02652 typedef Mat_<ushort> Mat1w;
02653 typedef Mat_<Vec2w> Mat2w;
02654 typedef Mat_<Vec3w> Mat3w;
02655 typedef Mat_<Vec4w> Mat4w;
02656 
02657 typedef Mat_<int>   Mat1i;
02658 typedef Mat_<Vec2i> Mat2i;
02659 typedef Mat_<Vec3i> Mat3i;
02660 typedef Mat_<Vec4i> Mat4i;
02661 
02662 typedef Mat_<float> Mat1f;
02663 typedef Mat_<Vec2f> Mat2f;
02664 typedef Mat_<Vec3f> Mat3f;
02665 typedef Mat_<Vec4f> Mat4f;
02666 
02667 typedef Mat_<double> Mat1d;
02668 typedef Mat_<Vec2d> Mat2d;
02669 typedef Mat_<Vec3d> Mat3d;
02670 typedef Mat_<Vec4d> Mat4d;
02671 
02673 
02674 class CV_EXPORTS MatConstIterator
02675 {
02676 public:
02677     typedef uchar* value_type;
02678     typedef ptrdiff_t difference_type;
02679     typedef const uchar** pointer;
02680     typedef uchar* reference;
02681     typedef std::random_access_iterator_tag iterator_category;
02682     
02684     MatConstIterator();
02686     MatConstIterator(const Mat* _m);
02688     MatConstIterator(const Mat* _m, int _row, int _col=0);
02690     MatConstIterator(const Mat* _m, Point _pt);
02692     MatConstIterator(const Mat* _m, const int* _idx);
02694     MatConstIterator(const MatConstIterator& it);
02695     
02697     MatConstIterator& operator = (const MatConstIterator& it);
02699     uchar* operator *() const;
02701     uchar* operator [](ptrdiff_t i) const;
02702     
02704     MatConstIterator& operator += (ptrdiff_t ofs);
02706     MatConstIterator& operator -= (ptrdiff_t ofs);
02708     MatConstIterator& operator --();
02710     MatConstIterator operator --(int);
02712     MatConstIterator& operator ++();
02714     MatConstIterator operator ++(int);
02716     Point pos() const;
02718     void pos(int* _idx) const;
02719     ptrdiff_t lpos() const;
02720     void seek(ptrdiff_t ofs, bool relative=false);
02721     void seek(const int* _idx, bool relative=false);
02722     
02723     const Mat* m;
02724     size_t elemSize;
02725     uchar* ptr;
02726     uchar* sliceStart;
02727     uchar* sliceEnd;
02728 };
02729     
02734 template<typename _Tp>
02735 class CV_EXPORTS MatConstIterator_ : public MatConstIterator
02736 {
02737 public:
02738     typedef _Tp value_type;
02739     typedef ptrdiff_t difference_type;
02740     typedef const _Tp* pointer;
02741     typedef const _Tp& reference;
02742     typedef std::random_access_iterator_tag iterator_category;
02743 
02745     MatConstIterator_();
02747     MatConstIterator_(const Mat_<_Tp>* _m);
02749     MatConstIterator_(const Mat_<_Tp>* _m, int _row, int _col=0);
02751     MatConstIterator_(const Mat_<_Tp>* _m, Point _pt);
02753     MatConstIterator_(const Mat_<_Tp>* _m, const int* _idx);
02755     MatConstIterator_(const MatConstIterator_& it);
02756 
02758     MatConstIterator_& operator = (const MatConstIterator_& it);
02760     _Tp operator *() const;
02762     _Tp operator [](ptrdiff_t i) const;
02763     
02765     MatConstIterator_& operator += (ptrdiff_t ofs);
02767     MatConstIterator_& operator -= (ptrdiff_t ofs);
02769     MatConstIterator_& operator --();
02771     MatConstIterator_ operator --(int);
02773     MatConstIterator_& operator ++();
02775     MatConstIterator_ operator ++(int);
02777     Point pos() const;
02778 };
02779 
02780 
02785 template<typename _Tp>
02786 class CV_EXPORTS MatIterator_ : public MatConstIterator_<_Tp>
02787 {
02788 public:
02789     typedef _Tp* pointer;
02790     typedef _Tp& reference;
02791     typedef std::random_access_iterator_tag iterator_category;
02792 
02794     MatIterator_();
02796     MatIterator_(Mat_<_Tp>* _m);
02798     MatIterator_(Mat_<_Tp>* _m, int _row, int _col=0);
02800     MatIterator_(const Mat_<_Tp>* _m, Point _pt);
02802     MatIterator_(const Mat_<_Tp>* _m, const int* _idx);
02804     MatIterator_(const MatIterator_& it);
02806     MatIterator_& operator = (const MatIterator_<_Tp>& it );
02807 
02809     _Tp& operator *() const;
02811     _Tp& operator [](ptrdiff_t i) const;
02812 
02814     MatIterator_& operator += (ptrdiff_t ofs);
02816     MatIterator_& operator -= (ptrdiff_t ofs);
02818     MatIterator_& operator --();
02820     MatIterator_ operator --(int);
02822     MatIterator_& operator ++();
02824     MatIterator_ operator ++(int);
02825 };
02826 
02827 template<typename _Tp> class CV_EXPORTS MatOp_Iter_;
02828 
02842 template<typename _Tp> class CV_EXPORTS MatCommaInitializer_
02843 {
02844 public:
02846     MatCommaInitializer_(Mat_<_Tp>* _m);
02848     template<typename T2> MatCommaInitializer_<_Tp>& operator , (T2 v);
02850     Mat_<_Tp> operator *() const;
02851     operator Mat_<_Tp>() const;
02852 protected:
02853     MatIterator_<_Tp> it;
02854 };
02855 
02856 
02857 template<typename _Tp, int m, int n> class CV_EXPORTS MatxCommaInitializer
02858 {
02859 public:
02860     MatxCommaInitializer(Matx<_Tp, m, n>* _mtx);
02861     template<typename T2> MatxCommaInitializer<_Tp, m, n>& operator , (T2 val);
02862     Matx<_Tp, m, n> operator *() const;
02863 
02864     Matx<_Tp, m, n>* dst;
02865     int idx;
02866 };
02867 
02868 template<typename _Tp, int m> class CV_EXPORTS VecCommaInitializer : public MatxCommaInitializer<_Tp, m, 1>
02869 {
02870 public:
02871     VecCommaInitializer(Vec<_Tp, m>* _vec);
02872     template<typename T2> VecCommaInitializer<_Tp, m>& operator , (T2 val);
02873     Vec<_Tp, m> operator *() const;
02874 };
02875         
02903 template<typename _Tp, size_t fixed_size=4096/sizeof(_Tp)+8> class CV_EXPORTS AutoBuffer
02904 {
02905 public:
02906     typedef _Tp value_type;
02907     enum { buffer_padding = (int)((16 + sizeof(_Tp) - 1)/sizeof(_Tp)) };
02908 
02910     AutoBuffer();
02912     AutoBuffer(size_t _size);
02914     ~AutoBuffer();
02915 
02917     void allocate(size_t _size);
02919     void deallocate();
02921     operator _Tp* ();
02923     operator const _Tp* () const;
02924 
02925 protected:
02927     _Tp* ptr;
02929     size_t size;
02931     _Tp buf[fixed_size+buffer_padding];
02932 };
02933 
02935 
02986 class CV_EXPORTS NAryMatIterator
02987 {
02988 public:
02990     NAryMatIterator();
02992     NAryMatIterator(const Mat** arrays, uchar** ptrs, int narrays=-1);
02994     NAryMatIterator(const Mat** arrays, Mat* planes, int narrays=-1);
02996     void init(const Mat** arrays, Mat* planes, uchar** ptrs, int narrays=-1);
02997 
02999     NAryMatIterator& operator ++();
03001     NAryMatIterator operator ++(int);
03002 
03004     const Mat** arrays;
03006     Mat* planes;
03008     uchar** ptrs;
03010     int narrays;
03012     size_t nplanes;
03014     size_t size;
03015 protected:
03016     int iterdepth;
03017     size_t idx;
03018 };
03019     
03020 //typedef NAryMatIterator NAryMatNDIterator;
03021 
03022 typedef void (*ConvertData)(const void* from, void* to, int cn);
03023 typedef void (*ConvertScaleData)(const void* from, void* to, int cn, double alpha, double beta);
03024 
03026 CV_EXPORTS ConvertData getConvertElem(int fromType, int toType);
03028 CV_EXPORTS ConvertScaleData getConvertScaleElem(int fromType, int toType);
03029 
03030     
03032 
03033 class SparseMatIterator;
03034 class SparseMatConstIterator;
03035 template<typename _Tp> class SparseMatIterator_;
03036 template<typename _Tp> class SparseMatConstIterator_;
03037 
03123 class CV_EXPORTS SparseMat
03124 {
03125 public:
03126     typedef SparseMatIterator iterator;
03127     typedef SparseMatConstIterator const_iterator;
03128 
03130     struct CV_EXPORTS Hdr
03131     {
03132         Hdr(int _dims, const int* _sizes, int _type);
03133         void clear();
03134         int refcount;
03135         int dims;
03136         int valueOffset;
03137         size_t nodeSize;
03138         size_t nodeCount;
03139         size_t freeList;
03140         vector<uchar> pool;
03141         vector<size_t> hashtab;
03142         int size[CV_MAX_DIM];
03143     };
03144 
03146     struct CV_EXPORTS Node
03147     {
03149         size_t hashval;
03151         size_t next;
03153         int idx[CV_MAX_DIM];
03154     };
03155 
03157     SparseMat();
03159     SparseMat(int dims, const int* _sizes, int _type);
03161     SparseMat(const SparseMat& m);
03163 
03168     explicit SparseMat(const Mat& m);
03170     SparseMat(const CvSparseMat* m);
03172     ~SparseMat();
03173     
03175     SparseMat& operator = (const SparseMat& m);
03177     SparseMat& operator = (const Mat& m);
03178 
03180     SparseMat clone() const;
03181     
03183     void copyTo( SparseMat& m ) const;
03185     void copyTo( Mat& m ) const;
03187     void convertTo( SparseMat& m, int rtype, double alpha=1 ) const;
03189 
03194     void convertTo( Mat& m, int rtype, double alpha=1, double beta=0 ) const;
03195 
03196     // not used now
03197     void assignTo( SparseMat& m, int type=-1 ) const;
03198 
03200 
03205     void create(int dims, const int* _sizes, int _type);
03207     void clear();
03209     void addref();
03210     // decrements the header reference counter. When the counter reaches 0, the header and all the underlying data are deallocated.
03211     void release();
03212 
03214     operator CvSparseMat*() const;
03216     size_t elemSize() const;
03218     size_t elemSize1() const;
03219     
03221     int type() const;
03223     int depth() const;
03225     int channels() const;
03226     
03228     const int* size() const;
03230     int size(int i) const;
03232     int dims() const;
03234     size_t nzcount() const;
03235     
03237     size_t hash(int i0) const;
03239     size_t hash(int i0, int i1) const;
03241     size_t hash(int i0, int i1, int i2) const;
03243     size_t hash(const int* idx) const;
03244     
03246 
03259 
03260     uchar* ptr(int i0, bool createMissing, size_t* hashval=0);
03262     uchar* ptr(int i0, int i1, bool createMissing, size_t* hashval=0);
03264     uchar* ptr(int i0, int i1, int i2, bool createMissing, size_t* hashval=0);
03266     uchar* ptr(const int* idx, bool createMissing, size_t* hashval=0);
03268 
03270 
03277 
03278     template<typename _Tp> _Tp& ref(int i0, size_t* hashval=0);   
03280     template<typename _Tp> _Tp& ref(int i0, int i1, size_t* hashval=0);   
03282     template<typename _Tp> _Tp& ref(int i0, int i1, int i2, size_t* hashval=0);
03284     template<typename _Tp> _Tp& ref(const int* idx, size_t* hashval=0);
03286     
03288 
03299 
03300     template<typename _Tp> _Tp value(int i0, size_t* hashval=0) const;
03302     template<typename _Tp> _Tp value(int i0, int i1, size_t* hashval=0) const;
03304     template<typename _Tp> _Tp value(int i0, int i1, int i2, size_t* hashval=0) const;
03306     template<typename _Tp> _Tp value(const int* idx, size_t* hashval=0) const;
03308     
03310 
03317 
03318     template<typename _Tp> const _Tp* find(int i0, size_t* hashval=0) const;
03320     template<typename _Tp> const _Tp* find(int i0, int i1, size_t* hashval=0) const;
03322     template<typename _Tp> const _Tp* find(int i0, int i1, int i2, size_t* hashval=0) const;
03324     template<typename _Tp> const _Tp* find(const int* idx, size_t* hashval=0) const;
03325 
03327     void erase(int i0, int i1, size_t* hashval=0);
03329     void erase(int i0, int i1, int i2, size_t* hashval=0);
03331     void erase(const int* idx, size_t* hashval=0);
03332 
03334 
03337 
03338     SparseMatIterator begin();
03340     template<typename _Tp> SparseMatIterator_<_Tp> begin();
03342     SparseMatConstIterator begin() const;
03344     template<typename _Tp> SparseMatConstIterator_<_Tp> begin() const;
03346 
03349 
03350     SparseMatIterator end();
03352     SparseMatConstIterator end() const;
03354     template<typename _Tp> SparseMatIterator_<_Tp> end();
03356     template<typename _Tp> SparseMatConstIterator_<_Tp> end() const;
03357 
03359     template<typename _Tp> _Tp& value(Node* n);
03361     template<typename _Tp> const _Tp& value(const Node* n) const;
03362     
03364     Node* node(size_t nidx);
03365     const Node* node(size_t nidx) const;
03366 
03367     uchar* newNode(const int* idx, size_t hashval);
03368     void removeNode(size_t hidx, size_t nidx, size_t previdx);
03369     void resizeHashTab(size_t newsize);
03370 
03371     enum { MAGIC_VAL=0x42FD0000, MAX_DIM=CV_MAX_DIM, HASH_SCALE=0x5bd1e995, HASH_BIT=0x80000000 };
03372 
03373     int flags;
03374     Hdr* hdr;
03375 };
03376 
03378 CV_EXPORTS void minMaxLoc(const SparseMat& a, double* minVal,
03379                           double* maxVal, int* minIdx=0, int* maxIdx=0);
03381 CV_EXPORTS double norm( const SparseMat& src, int normType );
03383 CV_EXPORTS void normalize( const SparseMat& src, SparseMat& dst, double alpha, int normType );
03384 
03397 class CV_EXPORTS SparseMatConstIterator
03398 {
03399 public:
03401     SparseMatConstIterator();
03403     SparseMatConstIterator(const SparseMat* _m);
03405     SparseMatConstIterator(const SparseMatConstIterator& it);
03406 
03408     SparseMatConstIterator& operator = (const SparseMatConstIterator& it);
03409 
03411     template<typename _Tp> const _Tp& value() const;
03413     const SparseMat::Node* node() const;
03414     
03416     SparseMatConstIterator& operator --();
03418     SparseMatConstIterator operator --(int);
03420     SparseMatConstIterator& operator ++();
03422     SparseMatConstIterator operator ++(int);
03423     
03425     void seekEnd();
03426 
03427     const SparseMat* m;
03428     size_t hashidx;
03429     uchar* ptr;
03430 };
03431 
03438 class CV_EXPORTS SparseMatIterator : public SparseMatConstIterator
03439 {
03440 public:
03442     SparseMatIterator();
03444     SparseMatIterator(SparseMat* _m);
03446     SparseMatIterator(SparseMat* _m, const int* idx);
03448     SparseMatIterator(const SparseMatIterator& it);
03449 
03451     SparseMatIterator& operator = (const SparseMatIterator& it);
03453     template<typename _Tp> _Tp& value() const;
03455     SparseMat::Node* node() const;
03456     
03458     SparseMatIterator& operator ++();
03460     SparseMatIterator operator ++(int);
03461 };
03462 
03476 template<typename _Tp> class CV_EXPORTS SparseMat_ : public SparseMat
03477 {
03478 public:
03479     typedef SparseMatIterator_<_Tp> iterator;
03480     typedef SparseMatConstIterator_<_Tp> const_iterator;
03481 
03483     SparseMat_();
03485     SparseMat_(int dims, const int* _sizes);
03487     SparseMat_(const SparseMat& m);
03489     SparseMat_(const SparseMat_& m);
03491     SparseMat_(const Mat& m);
03493     SparseMat_(const CvSparseMat* m);
03495     SparseMat_& operator = (const SparseMat& m);
03497     SparseMat_& operator = (const SparseMat_& m);
03499     SparseMat_& operator = (const Mat& m);
03500 
03502     SparseMat_ clone() const;
03504     void create(int dims, const int* _sizes);
03506     operator CvSparseMat*() const;
03507 
03509     int type() const;
03511     int depth() const;
03513     int channels() const;
03514     
03516     _Tp& ref(int i0, size_t* hashval=0);
03518     _Tp& ref(int i0, int i1, size_t* hashval=0);
03520     _Tp& ref(int i0, int i1, int i2, size_t* hashval=0);
03522     _Tp& ref(const int* idx, size_t* hashval=0);
03523     
03525     _Tp operator()(int i0, size_t* hashval=0) const;
03527     _Tp operator()(int i0, int i1, size_t* hashval=0) const;
03529     _Tp operator()(int i0, int i1, int i2, size_t* hashval=0) const;
03531     _Tp operator()(const int* idx, size_t* hashval=0) const;
03532 
03534     SparseMatIterator_<_Tp> begin();
03536     SparseMatConstIterator_<_Tp> begin() const;
03538     SparseMatIterator_<_Tp> end();
03540     SparseMatConstIterator_<_Tp> end() const;
03541 };
03542 
03543 
03550 template<typename _Tp> class CV_EXPORTS SparseMatConstIterator_ : public SparseMatConstIterator
03551 {
03552 public:
03553     typedef std::forward_iterator_tag iterator_category;
03554     
03556     SparseMatConstIterator_();
03558     SparseMatConstIterator_(const SparseMat_<_Tp>* _m);
03560     SparseMatConstIterator_(const SparseMatConstIterator_& it);
03561 
03563     SparseMatConstIterator_& operator = (const SparseMatConstIterator_& it);
03565     const _Tp& operator *() const;
03566     
03568     SparseMatConstIterator_& operator ++();
03570     SparseMatConstIterator_ operator ++(int);
03571 };
03572 
03579 template<typename _Tp> class CV_EXPORTS SparseMatIterator_ : public SparseMatConstIterator_<_Tp>
03580 {
03581 public:
03582     typedef std::forward_iterator_tag iterator_category;
03583     
03585     SparseMatIterator_();
03587     SparseMatIterator_(SparseMat_<_Tp>* _m);
03589     SparseMatIterator_(const SparseMatIterator_& it);
03590 
03592     SparseMatIterator_& operator = (const SparseMatIterator_& it);
03594     _Tp& operator *() const;
03595     
03597     SparseMatIterator_& operator ++();
03599     SparseMatIterator_ operator ++(int);
03600 };
03601 
03603 
03628 class CV_EXPORTS_W KDTree
03629 {
03630 public:
03634     struct Node
03635     {
03636         Node() : idx(-1), left(-1), right(-1), boundary(0.f) {}
03637         Node(int _idx, int _left, int _right, float _boundary)
03638             : idx(_idx), left(_left), right(_right), boundary(_boundary) {}
03640         int idx;
03642         int left, right;
03644         float boundary;
03645     };
03646 
03648     CV_WRAP KDTree();
03650     CV_WRAP KDTree(InputArray points, bool copyAndReorderPoints=false);
03652     CV_WRAP KDTree(InputArray points, InputArray _labels,
03653                    bool copyAndReorderPoints=false);
03655     CV_WRAP void build(InputArray points, bool copyAndReorderPoints=false);
03657     CV_WRAP void build(InputArray points, InputArray labels,
03658                        bool copyAndReorderPoints=false);
03660     CV_WRAP int findNearest(InputArray vec, int K, int Emax,
03661                             OutputArray neighborsIdx,
03662                             OutputArray neighbors=noArray(),
03663                             OutputArray dist=noArray(),
03664                             OutputArray labels=noArray()) const;
03666     CV_WRAP void findOrthoRange(InputArray minBounds,
03667                                 InputArray maxBounds,
03668                                 OutputArray neighborsIdx,
03669                                 OutputArray neighbors=noArray(),
03670                                 OutputArray labels=noArray()) const;
03672     CV_WRAP void getPoints(InputArray idx, OutputArray pts,
03673                            OutputArray labels=noArray()) const;
03675     const float* getPoint(int ptidx, int* label=0) const;
03677     CV_WRAP int dims() const;
03678 
03679     vector<Node> nodes; 
03680     CV_PROP Mat points; 
03681     CV_PROP vector<int> labels; 
03682     CV_PROP int maxDepth; 
03683     CV_PROP_RW int normType; 
03684 };
03685 
03687 
03688 class CV_EXPORTS FileNode;
03689 
03787 class CV_EXPORTS_W FileStorage
03788 {
03789 public:
03791     enum
03792     {
03793         READ=0, 
03794         WRITE=1, 
03795         APPEND=2 
03796     };
03797     enum
03798     {
03799         UNDEFINED=0, 
03800         VALUE_EXPECTED=1,
03801         NAME_EXPECTED=2,
03802         INSIDE_MAP=4
03803     };
03805     CV_WRAP FileStorage();
03807     CV_WRAP FileStorage(const string& filename, int flags, const string& encoding=string());
03809     FileStorage(CvFileStorage* fs);
03811     virtual ~FileStorage();
03812 
03814     CV_WRAP virtual bool open(const string& filename, int flags, const string& encoding=string());
03816     CV_WRAP virtual bool isOpened() const;
03818     CV_WRAP virtual void release();
03819 
03821     CV_WRAP FileNode getFirstTopLevelNode() const;
03823     CV_WRAP FileNode root(int streamidx=0) const;
03825     FileNode operator[](const string& nodename) const;
03827     CV_WRAP FileNode operator[](const char* nodename) const;
03828 
03830     CvFileStorage* operator *() { return fs; }
03832     const CvFileStorage* operator *() const { return fs; }
03834     void writeRaw( const string& fmt, const uchar* vec, size_t len );
03836     void writeObj( const string& name, const void* obj );
03837 
03839     static string getDefaultObjectName(const string& filename);
03840 
03841     Ptr<CvFileStorage> fs; 
03842     string elname; 
03843     vector<char> structs; 
03844     int state; 
03845 };
03846 
03847 class CV_EXPORTS FileNodeIterator;
03848 
03859 class CV_EXPORTS_W_SIMPLE FileNode
03860 {
03861 public:
03863     enum
03864     {
03865         NONE=0, 
03866         INT=1, 
03867         REAL=2, 
03868         FLOAT=REAL, 
03869         STR=3, 
03870         STRING=STR, 
03871         REF=4, 
03872         SEQ=5, 
03873         MAP=6, 
03874         TYPE_MASK=7,
03875         FLOW=8, 
03876         USER=16, 
03877         EMPTY=32, 
03878         NAMED=64 
03879     };
03881     CV_WRAP FileNode();
03883     FileNode(const CvFileStorage* fs, const CvFileNode* node);
03885     FileNode(const FileNode& node);
03887     FileNode operator[](const string& nodename) const;
03889     CV_WRAP FileNode operator[](const char* nodename) const;
03891     CV_WRAP FileNode operator[](int i) const;
03893     CV_WRAP int type() const;
03894 
03896     CV_WRAP bool empty() const;
03898     CV_WRAP bool isNone() const;
03900     CV_WRAP bool isSeq() const;
03902     CV_WRAP bool isMap() const;
03904     CV_WRAP bool isInt() const;
03906     CV_WRAP bool isReal() const;
03908     CV_WRAP bool isString() const;
03910     CV_WRAP bool isNamed() const;
03912     CV_WRAP string name() const;
03914     CV_WRAP size_t size() const;
03916     operator int() const;
03918     operator float() const;
03920     operator double() const;
03922     operator string() const;
03923     
03925     CvFileNode* operator *();
03927     const CvFileNode* operator* () const;
03928 
03930     FileNodeIterator begin() const;
03932     FileNodeIterator end() const;
03933 
03935     void readRaw( const string& fmt, uchar* vec, size_t len ) const;
03937     void* readObj() const;
03938 
03939     // do not use wrapper pointer classes for better efficiency
03940     const CvFileStorage* fs;
03941     const CvFileNode* node;
03942 };
03943 
03944 
03950 class CV_EXPORTS FileNodeIterator
03951 {
03952 public:
03954     FileNodeIterator();
03956     FileNodeIterator(const CvFileStorage* fs, const CvFileNode* node, size_t ofs=0);
03958     FileNodeIterator(const FileNodeIterator& it);
03960     FileNode operator *() const;
03962     FileNode operator ->() const;
03963 
03965     FileNodeIterator& operator ++ ();
03967     FileNodeIterator operator ++ (int);
03969     FileNodeIterator& operator -- ();
03971     FileNodeIterator operator -- (int);
03973     FileNodeIterator& operator += (int);
03975     FileNodeIterator& operator -= (int);
03976 
03978     FileNodeIterator& readRaw( const string& fmt, uchar* vec,
03979                                size_t maxCount=(size_t)INT_MAX );
03980     
03981     const CvFileStorage* fs;
03982     const CvFileNode* container;
03983     CvSeqReader reader;
03984     size_t remaining;
03985 };
03986 
03988 
03989 template<typename _Tp> class SeqIterator;
03990 
03991 typedef Ptr<CvMemStorage> MemStorage;
03992 
04003 template<typename _Tp> class CV_EXPORTS Seq
04004 {
04005 public:
04006     typedef SeqIterator<_Tp> iterator;
04007     typedef SeqIterator<_Tp> const_iterator;
04008     
04010     Seq();
04012     Seq(const CvSeq* seq);
04014     Seq(MemStorage& storage, int headerSize = sizeof(CvSeq));
04016     _Tp& operator [](int idx);
04018     const _Tp& operator[](int idx) const;
04020     SeqIterator<_Tp> begin() const;
04022     SeqIterator<_Tp> end() const;
04024     size_t size() const;
04026     int type() const;
04028     int depth() const;
04030     int channels() const;
04032     size_t elemSize() const;
04034     size_t index(const _Tp& elem) const;
04036     void push_back(const _Tp& elem);
04038     void push_front(const _Tp& elem);
04040     void push_back(const _Tp* elems, size_t count);
04042     void push_front(const _Tp* elems, size_t count);
04044     void insert(int idx, const _Tp& elem);
04046     void insert(int idx, const _Tp* elems, size_t count);
04048     void remove(int idx);
04050     void remove(const Range& r);
04051     
04053     _Tp& front();
04055     const _Tp& front() const;
04057     _Tp& back();
04059     const _Tp& back() const;
04061     bool empty() const;
04062 
04064     void clear();
04066     void pop_front();
04068     void pop_back();
04070     void pop_front(_Tp* elems, size_t count);
04072     void pop_back(_Tp* elems, size_t count);
04073 
04075     void copyTo(vector<_Tp>& vec, const Range& range=Range::all()) const;
04077     operator vector<_Tp>() const;
04078     
04079     CvSeq* seq;
04080 };
04081 
04082     
04086 template<typename _Tp> class CV_EXPORTS SeqIterator : public CvSeqReader
04087 {
04088 public:
04090     SeqIterator();
04092     SeqIterator(const Seq<_Tp>& seq, bool seekEnd=false);
04094     void seek(size_t pos);
04096     size_t tell() const;
04098     _Tp& operator *();
04100     const _Tp& operator *() const;
04102     SeqIterator& operator ++();
04104     SeqIterator operator ++(int) const;
04106     SeqIterator& operator --();
04108     SeqIterator operator --(int) const;
04109 
04111     SeqIterator& operator +=(int);
04113     SeqIterator& operator -=(int);
04114 
04115     // this is index of the current element module seq->total*2
04116     // (to distinguish between 0 and seq->total)
04117     int index;
04118 };
04119 
04120 
04121 #if 0
04122 class CV_EXPORTS AlgorithmImpl;
04123 
04127 class CV_EXPORTS Algorithm
04128 {
04129 public:
04130     virtual ~Algorithm();
04131     virtual string name() const;
04132     
04133     template<typename _Tp> _Tp get(int paramId) const;
04134     template<typename _Tp> bool set(int paramId, const _Tp& value);
04135     string paramName(int paramId) const;
04136     string paramHelp(int paramId) const;
04137     int paramType(int paramId) const;
04138     int findParam(const string& name) const;
04139     template<typename _Tp> _Tp paramDefaultValue(int paramId) const;
04140     template<typename _Tp> bool paramRange(int paramId, _Tp& minVal, _Tp& maxVal) const;
04141     
04142     virtual void getParams(vector<int>& ids) const;
04143     virtual void write(vector<uchar>& buf) const;
04144     virtual bool read(const vector<uchar>& buf);
04145     
04146     typedef Algorithm* (*Constructor)(void);
04147     static void add(const string& name, Constructor create);
04148     static void getList(vector<string>& algorithms);
04149     static Ptr<Algorithm> create(const string& name);
04150     
04151 protected:
04152     template<typename _Tp> void addParam(int propId, _Tp& value, bool readOnly, const string& name,
04153                                          const string& help=string(), const _Tp& defaultValue=_Tp(),
04154                                          _Tp (Algorithm::*getter)()=0, bool (Algorithm::*setter)(const _Tp&)=0);
04155     template<typename _Tp> void setParamRange(int propId, const _Tp& minVal, const _Tp& maxVal);
04156     
04157     bool set_(int paramId, int argType, const void* value);
04158     void get_(int paramId, int argType, void* value);
04159     void paramDefaultValue_(int paramId, int argType, void* value);
04160     void paramRange_(int paramId, int argType, void* minval, void* maxval);
04161     void addParam_(int propId, int argType, void* value, bool readOnly, const string& name,
04162                   const string& help, const void* defaultValue, void* getter, void* setter);
04163     void setParamRange_(int propId, int argType, const void* minVal, const void* maxVal);
04164     
04165     Ptr<AlgorithmImpl> impl;
04166 };
04167 #endif
04168 
04187 class CV_EXPORTS CommandLineParser
04188 {
04189     public:
04190 
04192         CommandLineParser(int argc, const char* argv[]);
04193 
04195         template<typename _Tp>
04196         _Tp get(const std::string& name, const _Tp& default_value = _Tp())
04197         {
04198             std::string str = getString(name);
04199             if (!has(name))
04200                 return default_value;
04201             return analyzeValue<_Tp>(str);
04202         }
04203 
04204     protected:
04205         std::map<std::string, std::string > data;
04206         std::string getString(const std::string& name) const;
04207 
04208         bool has(const std::string& keys) const;
04209 
04210         template<typename _Tp>
04211         static _Tp getData(const std::string& str)
04212         {
04213             _Tp res;
04214             std::stringstream s1(str);
04215             s1 >> res;
04216             return res;
04217         }
04218 
04219         template<typename _Tp>
04220         _Tp fromStringNumber(const std::string& str);//the default conversion function for numbers
04221 
04222         template<typename _Tp>
04223         _Tp analyzeValue(const std::string& str);
04224     };
04225     template<> CV_EXPORTS
04226     bool CommandLineParser::get<bool>(const std::string& name, const bool& default_value);
04227 
04228     template<> CV_EXPORTS
04229     std::string CommandLineParser::analyzeValue<std::string>(const std::string& str);
04230 
04231     template<> CV_EXPORTS
04232     int CommandLineParser::analyzeValue<int>(const std::string& str);
04233 
04234     template<> CV_EXPORTS
04235     unsigned CommandLineParser::analyzeValue<unsigned int>(const std::string& str);
04236 
04237     template<> CV_EXPORTS
04238     float CommandLineParser::analyzeValue<float>(const std::string& str);
04239 
04240     template<> CV_EXPORTS
04241     double CommandLineParser::analyzeValue<double>(const std::string& str);
04242 
04243 }
04244 
04245 #endif // __cplusplus
04246 
04247 #include "opencv2/core/operations.hpp"
04248 #include "opencv2/core/mat.hpp"
04249 
04250 #endif /*__OPENCV_CORE_HPP__*/