- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

# /usr/ports/pobj/OpenCV-2.2.0/OpenCV-2.2.0/modules/core/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, 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 <complex>
    00059 #include <map>
    00060 #include <new>
    00061 #include <string>
    00062 #include <vector>
    00063 #endif // SKIP_INCLUDES
    00064
    00068 namespace cv {
    00069
    00070 #undef abs
    00071 #undef min
    00072 #undef max
    00073 #undef Complex
    00074
    00075 using std::vector;
    00076 using std::string;
    00077
    00078 template<typename _Tp> class CV_EXPORTS Size_;
    00079 template<typename _Tp> class CV_EXPORTS Point_;
    00080 template<typename _Tp> class CV_EXPORTS Rect_;
    00081 template<typename _Tp, int cn> class CV_EXPORTS Vec;
    00082 template<typename _Tp, int m, int n> class CV_EXPORTS Matx;
    00083
    00084 typedef std::string String;
    00085 typedef std::basic_string<wchar_t> WString;
    00086
    00087 class Mat;
    00088 class SparseMat;
    00089 typedef Mat MatND;
    00090
    00091 class CV_EXPORTS MatExpr;
    00092 class CV_EXPORTS MatOp_Base;
    00093 class CV_EXPORTS MatArg;
    00094 class CV_EXPORTS MatConstIterator;
    00095
    00096 template<typename _Tp> class CV_EXPORTS Mat_;
    00097 template<typename _Tp> class CV_EXPORTS MatIterator_;
    00098 template<typename _Tp> class CV_EXPORTS MatConstIterator_;
    00099 template<typename _Tp> class CV_EXPORTS MatCommaInitializer_;
    00100
    00101 CV_EXPORTS string fromUtf16(const WString& str);
    00102 CV_EXPORTS WString toUtf16(const string& str);
    00103
    00104 CV_EXPORTS string format( const char* fmt, ... );
    00105
    00106
    00107 // matrix decomposition types
    00108 enum { DECOMP_LU=0, DECOMP_SVD=1, DECOMP_EIG=2, DECOMP_CHOLESKY=3, DECOMP_QR=4, DECOMP_NORMAL=16 };
    00109 enum { NORM_INF=1, NORM_L1=2, NORM_L2=4, NORM_TYPE_MASK=7, NORM_RELATIVE=8, NORM_MINMAX=32};
    00110 enum { CMP_EQ=0, CMP_GT=1, CMP_GE=2, CMP_LT=3, CMP_LE=4, CMP_NE=5 };
    00111 enum { GEMM_1_T=1, GEMM_2_T=2, GEMM_3_T=4 };
    00112 enum { DFT_INVERSE=1, DFT_SCALE=2, DFT_ROWS=4, DFT_COMPLEX_OUTPUT=16, DFT_REAL_OUTPUT=32,
    00113     DCT_INVERSE = DFT_INVERSE, DCT_ROWS=DFT_ROWS };
    00114
    00115
    00120 class CV_EXPORTS Exception : public std::exception
    00121 {
    00122 public:
    00126     Exception() { code = 0; line = 0; }
    00131         Exception(int _code, const string& _err, const string& _func, const string& _file, int _line)
    00132                 : code(_code), err(_err), func(_func), file(_file), line(_line)
    00133     { formatMessage(); }
    00134
    00135         virtual ~Exception() throw() {}
    00136
    00140         virtual const char *what() const throw() { return msg.c_str(); }
    00141
    00142     void formatMessage()
    00143     {
    00144         if( func.size() > 0 )
    00145             msg = format("%s:%d: error: (%d) %s in function %s\n", file.c_str(), line, code, err.c_str(), func.c_str());
    00146         else
    00147             msg = format("%s:%d: error: (%d) %s\n", file.c_str(), line, code, err.c_str());
    00148     }
    00149
    00150         string msg;
    00151
    00152         int code;
    00153         string err;
    00154         string func;
    00155         string file;
    00156         int line;
    00157 };
    00158
    00159
    00161
    00169 CV_EXPORTS void error( const Exception& exc );
    00170
    00172
    00179 CV_EXPORTS bool setBreakOnError(bool flag);
    00180
    00181 typedef int (CV_CDECL *ErrorCallback)( int status, const char* func_name,
    00182                                        const char* err_msg, const char* file_name,
    00183                                        int line, void* userdata );
    00184
    00186
    00196 CV_EXPORTS ErrorCallback redirectError( ErrorCallback errCallback,
    00197                                         void* userdata=0, void** prevUserdata=0);
    00198
    00199 #ifdef __GNUC__
    00200 #define CV_Error( code, msg ) cv::error( cv::Exception(code, msg, __func__, __FILE__, __LINE__) )
    00201 #define CV_Error_( code, args ) cv::error( cv::Exception(code, cv::format args, __func__, __FILE__, __LINE__) )
    00202 #define CV_Assert( expr ) if((expr)) ; else cv::error( cv::Exception(CV_StsAssert, #expr, __func__, __FILE__, __LINE__) )
    00203 #else
    00204 #define CV_Error( code, msg ) cv::error( cv::Exception(code, msg, "", __FILE__, __LINE__) )
    00205 #define CV_Error_( code, args ) cv::error( cv::Exception(code, cv::format args, "", __FILE__, __LINE__) )
    00206 #define CV_Assert( expr ) if((expr)) ; else cv::error( cv::Exception(CV_StsAssert, #expr, "", __FILE__, __LINE__) )
    00207 #endif
    00208
    00209 #ifdef _DEBUG
    00210 #define CV_DbgAssert(expr) CV_Assert(expr)
    00211 #else
    00212 #define CV_DbgAssert(expr)
    00213 #endif
    00214
    00215 CV_EXPORTS void setNumThreads(int nthreads);
    00216 CV_EXPORTS int getNumThreads();
    00217 CV_EXPORTS int getThreadNum();
    00218
    00220
    00227 CV_EXPORTS int64 getTickCount();
    00228
    00241 CV_EXPORTS_W double getTickFrequency();
    00242
    00251 CV_EXPORTS int64 getCPUTickCount();
    00252
    00271 CV_EXPORTS_W bool checkHardwareSupport(int feature);
    00272
    00283 CV_EXPORTS void* fastMalloc(size_t bufSize);
    00284
    00291 CV_EXPORTS void fastFree(void* ptr);
    00292
    00293 template<typename _Tp> static inline _Tp* allocate(size_t n)
    00294 {
    00295     return new _Tp[n];
    00296 }
    00297
    00298 template<typename _Tp> static inline void deallocate(_Tp* ptr, size_t)
    00299 {
    00300     delete[] ptr;
    00301 }
    00302
    00309 template<typename _Tp> static inline _Tp* alignPtr(_Tp* ptr, int n=(int)sizeof(_Tp))
    00310 {
    00311     return (_Tp*)(((size_t)ptr + n-1) & -n);
    00312 }
    00313
    00319 static inline size_t alignSize(size_t sz, int n)
    00320 {
    00321     return (sz + n-1) & -n;
    00322 }
    00323
    00333 CV_EXPORTS_W void setUseOptimized(bool onoff);
    00334
    00340 CV_EXPORTS_W bool useOptimized();
    00341
    00345 template<typename _Tp> class CV_EXPORTS Allocator
    00346 {
    00347 public:
    00348     typedef _Tp value_type;
    00349     typedef value_type* pointer;
    00350     typedef const value_type* const_pointer;
    00351     typedef value_type& reference;
    00352     typedef const value_type& const_reference;
    00353     typedef size_t size_type;
    00354     typedef ptrdiff_t difference_type;
    00355     template<typename U> class rebind { typedef Allocator<U> other; };
    00356
    00357     explicit Allocator() {}
    00358     ~Allocator() {}
    00359     explicit Allocator(Allocator const&) {}
    00360     template<typename U>
    00361     explicit Allocator(Allocator<U> const&) {}
    00362
    00363     // address
    00364     pointer address(reference r) { return &r; }
    00365     const_pointer address(const_reference r) { return &r; }
    00366
    00367     pointer allocate(size_type count, const void* =0)
    00368     { return reinterpret_cast<pointer>(fastMalloc(count * sizeof (_Tp))); }
    00369
    00370     void deallocate(pointer p, size_type) {fastFree(p); }
    00371
    00372     size_type max_size() const
    00373     { return max(static_cast<_Tp>(-1)/sizeof(_Tp), 1); }
    00374
    00375     void construct(pointer p, const _Tp& v) { new(static_cast<void*>(p)) _Tp(v); }
    00376     void destroy(pointer p) { p->~_Tp(); }
    00377 };
    00378
    00380
    00387 template<typename _Tp> class CV_EXPORTS DataDepth {};
    00388
    00389 template<> class DataDepth<bool> { public: enum { value = CV_8U, fmt=(int)'u' }; };
    00390 template<> class DataDepth<uchar> { public: enum { value = CV_8U, fmt=(int)'u' }; };
    00391 template<> class DataDepth<schar> { public: enum { value = CV_8S, fmt=(int)'c' }; };
    00392 template<> class DataDepth<char> { public: enum { value = CV_8S, fmt=(int)'c' }; };
    00393 template<> class DataDepth<ushort> { public: enum { value = CV_16U, fmt=(int)'w' }; };
    00394 template<> class DataDepth<short> { public: enum { value = CV_16S, fmt=(int)'s' }; };
    00395 template<> class DataDepth<int> { public: enum { value = CV_32S, fmt=(int)'i' }; };
    00396 // this is temporary solution to support 32-bit unsigned integers
    00397 template<> class DataDepth<unsigned> { public: enum { value = CV_32S, fmt=(int)'i' }; };
    00398 template<> class DataDepth<float> { public: enum { value = CV_32F, fmt=(int)'f' }; };
    00399 template<> class DataDepth<double> { public: enum { value = CV_64F, fmt=(int)'d' }; };
    00400 template<typename _Tp> class DataDepth<_Tp*> { public: enum { value = CV_USRTYPE1, fmt=(int)'r' }; };
    00401
    00402
    00404
    00421 struct CV_EXPORTS Matx_AddOp {};
    00422 struct CV_EXPORTS Matx_SubOp {};
    00423 struct CV_EXPORTS Matx_ScaleOp {};
    00424 struct CV_EXPORTS Matx_MulOp {};
    00425 struct CV_EXPORTS Matx_MatMulOp {};
    00426 struct CV_EXPORTS Matx_TOp {};
    00427
    00428 template<typename _Tp, int m, int n> class CV_EXPORTS Matx
    00429 {
    00430 public:
    00431     typedef _Tp value_type;
    00432     typedef Matx<_Tp, MIN(m, n), 1> diag_type;
    00433     typedef Matx<_Tp, m, n> mat_type;
    00434     enum { depth = DataDepth<_Tp>::value, rows = m, cols = n, channels = rows*cols,
    00435            type = CV_MAKETYPE(depth, channels) };
    00436
    00438     Matx();
    00439
    00440     Matx(_Tp v0);
    00441     Matx(_Tp v0, _Tp v1);
    00442     Matx(_Tp v0, _Tp v1, _Tp v2);
    00443     Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3);
    00444     Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4);
    00445     Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5);
    00446     Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6);
    00447     Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7);
    00448     Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8);
    00449     Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8, _Tp v9);
    00450     Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3,
    00451          _Tp v4, _Tp v5, _Tp v6, _Tp v7,
    00452          _Tp v8, _Tp v9, _Tp v10, _Tp v11);
    00453     Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3,
    00454          _Tp v4, _Tp v5, _Tp v6, _Tp v7,
    00455          _Tp v8, _Tp v9, _Tp v10, _Tp v11,
    00456          _Tp v12, _Tp v13, _Tp v14, _Tp v15);
    00457     explicit Matx(const _Tp* vals);
    00458
    00459     static Matx all(_Tp alpha);
    00460     static Matx zeros();
    00461     static Matx ones();
    00462     static Matx eye();
    00463     static Matx diag(const diag_type& d);
    00464     static Matx randu(_Tp a, _Tp b);
    00465     static Matx randn(_Tp a, _Tp b);
    00466
    00468     _Tp dot(const Matx<_Tp, m, n>& v) const;
    00469
    00471     double ddot(const Matx<_Tp, m, n>& v) const;
    00472
    00474     template<typename T2> operator Matx<T2, m, n>() const;
    00475
    00477     template<int m1, int n1> Matx<_Tp, m1, n1> reshape() const;
    00478
    00480     template<int m1, int n1> Matx<_Tp, m1, n1> get_minor(int i, int j) const;
    00481
    00483     Matx<_Tp, 1, n> row(int i) const;
    00484
    00486     Matx<_Tp, m, 1> col(int i) const;
    00487
    00489     Matx<_Tp, MIN(m,n), 1> diag() const;
    00490
    00492     Matx<_Tp, n, m> t() const;
    00493
    00495     Matx<_Tp, n, m> inv(int method=DECOMP_LU) const;
    00496
    00498     template<int l> Matx<_Tp, n, l> solve(const Matx<_Tp, m, l>& rhs, int flags=DECOMP_LU) const;
    00499     Matx<_Tp, n, 1> solve(const Matx<_Tp, m, 1>& rhs, int method) const;
    00500
    00502     Matx<_Tp, m, n> mul(const Matx<_Tp, m, n>& a) const;
    00503
    00505     const _Tp& operator ()(int i, int j) const;
    00506     _Tp& operator ()(int i, int j);
    00507
    00509     const _Tp& operator ()(int i) const;
    00510     _Tp& operator ()(int i);
    00511
    00512     Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_AddOp);
    00513     Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_SubOp);
    00514     template<typename _T2> Matx(const Matx<_Tp, m, n>& a, _T2 alpha, Matx_ScaleOp);
    00515     Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_MulOp);
    00516     template<int l> Matx(const Matx<_Tp, m, l>& a, const Matx<_Tp, l, n>& b, Matx_MatMulOp);
    00517     Matx(const Matx<_Tp, n, m>& a, Matx_TOp);
    00518
    00519     _Tp val[m*n]; //< matrix elements
    00520 };
    00521
    00522
    00523 typedef Matx<float, 1, 2> Matx12f;
    00524 typedef Matx<double, 1, 2> Matx12d;
    00525 typedef Matx<float, 1, 3> Matx13f;
    00526 typedef Matx<double, 1, 3> Matx13d;
    00527 typedef Matx<float, 1, 4> Matx14f;
    00528 typedef Matx<double, 1, 4> Matx14d;
    00529 typedef Matx<float, 1, 6> Matx16f;
    00530 typedef Matx<double, 1, 6> Matx16d;
    00531
    00532 typedef Matx<float, 2, 1> Matx21f;
    00533 typedef Matx<double, 2, 1> Matx21d;
    00534 typedef Matx<float, 3, 1> Matx31f;
    00535 typedef Matx<double, 3, 1> Matx31d;
    00536 typedef Matx<float, 4, 1> Matx41f;
    00537 typedef Matx<double, 4, 1> Matx41d;
    00538 typedef Matx<float, 6, 1> Matx61f;
    00539 typedef Matx<double, 6, 1> Matx61d;
    00540
    00541 typedef Matx<float, 2, 2> Matx22f;
    00542 typedef Matx<double, 2, 2> Matx22d;
    00543 typedef Matx<float, 2, 3> Matx23f;
    00544 typedef Matx<double, 2, 3> Matx23d;
    00545 typedef Matx<float, 3, 2> Matx32f;
    00546 typedef Matx<double, 3, 2> Matx32d;
    00547
    00548 typedef Matx<float, 3, 3> Matx33f;
    00549 typedef Matx<double, 3, 3> Matx33d;
    00550
    00551 typedef Matx<float, 3, 4> Matx34f;
    00552 typedef Matx<double, 3, 4> Matx34d;
    00553 typedef Matx<float, 4, 3> Matx43f;
    00554 typedef Matx<double, 4, 3> Matx43d;
    00555
    00556 typedef Matx<float, 4, 4> Matx44f;
    00557 typedef Matx<double, 4, 4> Matx44d;
    00558 typedef Matx<float, 6, 6> Matx66f;
    00559 typedef Matx<double, 6, 6> Matx66d;
    00560
    00561
    00577 template<typename _Tp, int cn> class CV_EXPORTS Vec : public Matx<_Tp, cn, 1>
    00578 {
    00579 public:
    00580     typedef _Tp value_type;
    00581     enum { depth = DataDepth<_Tp>::value, channels = cn, type = CV_MAKETYPE(depth, channels) };
    00582
    00584     Vec();
    00585
    00586     Vec(_Tp v0);
    00587     Vec(_Tp v0, _Tp v1);
    00588     Vec(_Tp v0, _Tp v1, _Tp v2);
    00589     Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3);
    00590     Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4);
    00591     Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5);
    00592     Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6);
    00593     Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7);
    00594     Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8);
    00595     Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8, _Tp v9);
    00596     explicit Vec(const _Tp* values);
    00597
    00598     Vec(const Vec<_Tp, cn>& v);
    00599     static Vec all(_Tp alpha);
    00600
    00602     Vec mul(const Vec<_Tp, cn>& v) const;
    00603
    00609     Vec cross(const Vec& v) const;
    00611     template<typename T2> operator Vec<T2, cn>() const;
    00613     operator CvScalar() const;
    00614
    00616     const _Tp& operator [](int i) const;
    00617     _Tp& operator[](int i);
    00618     const _Tp& operator ()(int i) const;
    00619     _Tp& operator ()(int i);
    00620 };
    00621
    00622
    00623 /* \typedef
    00624
    00625    Shorter aliases for the most popular specializations of Vec<T,n>
    00626 */
    00627 typedef Vec<uchar, 2> Vec2b;
    00628 typedef Vec<uchar, 3> Vec3b;
    00629 typedef Vec<uchar, 4> Vec4b;
    00630
    00631 typedef Vec<short, 2> Vec2s;
    00632 typedef Vec<short, 3> Vec3s;
    00633 typedef Vec<short, 4> Vec4s;
    00634
    00635 typedef Vec<ushort, 2> Vec2w;
    00636 typedef Vec<ushort, 3> Vec3w;
    00637 typedef Vec<ushort, 4> Vec4w;
    00638
    00639 typedef Vec<int, 2> Vec2i;
    00640 typedef Vec<int, 3> Vec3i;
    00641 typedef Vec<int, 4> Vec4i;
    00642
    00643 typedef Vec<float, 2> Vec2f;
    00644 typedef Vec<float, 3> Vec3f;
    00645 typedef Vec<float, 4> Vec4f;
    00646 typedef Vec<float, 6> Vec6f;
    00647
    00648 typedef Vec<double, 2> Vec2d;
    00649 typedef Vec<double, 3> Vec3d;
    00650 typedef Vec<double, 4> Vec4d;
    00651 typedef Vec<double, 6> Vec6d;
    00652
    00653
    00655
    00663 template<typename _Tp> class CV_EXPORTS Complex
    00664 {
    00665 public:
    00666
    00668     Complex();
    00669     Complex( _Tp _re, _Tp _im=0 );
    00670     Complex( const std::complex<_Tp>& c );
    00671
    00673     template<typename T2> operator Complex<T2>() const;
    00675     Complex conj() const;
    00677     operator std::complex<_Tp>() const;
    00678
    00679     _Tp re, im; //< the real and the imaginary parts
    00680 };
    00681
    00682
    00686 typedef Complex<float> Complexf;
    00687 typedef Complex<double> Complexd;
    00688
    00689
    00691
    00699 template<typename _Tp> class CV_EXPORTS Point_
    00700 {
    00701 public:
    00702     typedef _Tp value_type;
    00703
    00704     // various constructors
    00705     Point_();
    00706     Point_(_Tp _x, _Tp _y);
    00707     Point_(const Point_& pt);
    00708     Point_(const CvPoint& pt);
    00709     Point_(const CvPoint2D32f& pt);
    00710     Point_(const Size_<_Tp>& sz);
    00711     Point_(const Vec<_Tp, 2>& v);
    00712
    00713     Point_& operator = (const Point_& pt);
    00715     template<typename _Tp2> operator Point_<_Tp2>() const;
    00716
    00718     operator CvPoint() const;
    00719     operator CvPoint2D32f() const;
    00720     operator Vec<_Tp, 2>() const;
    00721
    00723     _Tp dot(const Point_& pt) const;
    00725     double ddot(const Point_& pt) const;
    00727     bool inside(const Rect_<_Tp>& r) const;
    00728
    00729     _Tp x, y; //< the point coordinates
    00730 };
    00731
    00740 template<typename _Tp> class CV_EXPORTS Point3_
    00741 {
    00742 public:
    00743     typedef _Tp value_type;
    00744
    00745     // various constructors
    00746     Point3_();
    00747     Point3_(_Tp _x, _Tp _y, _Tp _z);
    00748     Point3_(const Point3_& pt);
    00749         explicit Point3_(const Point_<_Tp>& pt);
    00750     Point3_(const CvPoint3D32f& pt);
    00751     Point3_(const Vec<_Tp, 3>& v);
    00752
    00753     Point3_& operator = (const Point3_& pt);
    00755     template<typename _Tp2> operator Point3_<_Tp2>() const;
    00757     operator CvPoint3D32f() const;
    00759     operator Vec<_Tp, 3>() const;
    00760
    00762     _Tp dot(const Point3_& pt) const;
    00764     double ddot(const Point3_& pt) const;
    00766     Point3_ cross(const Point3_& pt) const;
    00767
    00768     _Tp x, y, z; //< the point coordinates
    00769 };
    00770
    00772
    00779 template<typename _Tp> class CV_EXPORTS Size_
    00780 {
    00781 public:
    00782     typedef _Tp value_type;
    00783
    00785     Size_();
    00786     Size_(_Tp _width, _Tp _height);
    00787     Size_(const Size_& sz);
    00788     Size_(const CvSize& sz);
    00789     Size_(const CvSize2D32f& sz);
    00790     Size_(const Point_<_Tp>& pt);
    00791
    00792     Size_& operator = (const Size_& sz);
    00794     _Tp area() const;
    00795
    00797     template<typename _Tp2> operator Size_<_Tp2>() const;
    00798
    00800     operator CvSize() const;
    00801     operator CvSize2D32f() const;
    00802
    00803     _Tp width, height; // the width and the height
    00804 };
    00805
    00807
    00814 template<typename _Tp> class CV_EXPORTS Rect_
    00815 {
    00816 public:
    00817     typedef _Tp value_type;
    00818
    00820     Rect_();
    00821     Rect_(_Tp _x, _Tp _y, _Tp _width, _Tp _height);
    00822     Rect_(const Rect_& r);
    00823     Rect_(const CvRect& r);
    00824     Rect_(const Point_<_Tp>& org, const Size_<_Tp>& sz);
    00825     Rect_(const Point_<_Tp>& pt1, const Point_<_Tp>& pt2);
    00826
    00827     Rect_& operator = ( const Rect_& r );
    00829     Point_<_Tp> tl() const;
    00831     Point_<_Tp> br() const;
    00832
    00834     Size_<_Tp> size() const;
    00836     _Tp area() const;
    00837
    00839     template<typename _Tp2> operator Rect_<_Tp2>() const;
    00841     operator CvRect() const;
    00842
    00844     bool contains(const Point_<_Tp>& pt) const;
    00845
    00846     _Tp x, y, width, height; //< the top-left corner, as well as width and height of the rectangle
    00847 };
    00848
    00849
    00855 typedef Point_<int> Point2i;
    00856 typedef Point2i Point;
    00857 typedef Size_<int> Size2i;
    00858 typedef Size2i Size;
    00859 typedef Rect_<int> Rect;
    00860 typedef Point_<float> Point2f;
    00861 typedef Point_<double> Point2d;
    00862 typedef Size_<float> Size2f;
    00863 typedef Point3_<int> Point3i;
    00864 typedef Point3_<float> Point3f;
    00865 typedef Point3_<double> Point3d;
    00866
    00867
    00875 class CV_EXPORTS RotatedRect
    00876 {
    00877 public:
    00879     RotatedRect();
    00880     RotatedRect(const Point2f& _center, const Size2f& _size, float _angle);
    00881     RotatedRect(const CvBox2D& box);
    00882
    00884     void points(Point2f pts[]) const;
    00886     Rect boundingRect() const;
    00888     operator CvBox2D() const;
    00889
    00890     Point2f center; //< the rectangle mass center
    00891     Size2f size;    //< width and height of the rectangle
    00892     float angle;    //< the rotation angle. When the angle is 0, 90, 180, 270 etc., the rectangle becomes an up-right rectangle.
    00893 };
    00894
    00896
    00903 template<typename _Tp> class CV_EXPORTS Scalar_ : public Vec<_Tp, 4>
    00904 {
    00905 public:
    00907     Scalar_();
    00908     Scalar_(_Tp v0, _Tp v1, _Tp v2=0, _Tp v3=0);
    00909     Scalar_(const CvScalar& s);
    00910     Scalar_(_Tp v0);
    00911
    00913     static Scalar_<_Tp> all(_Tp v0);
    00915     operator CvScalar() const;
    00916
    00918     template<typename T2> operator Scalar_<T2>() const;
    00919
    00921     Scalar_<_Tp> mul(const Scalar_<_Tp>& t, double scale=1 ) const;
    00922
    00923     // returns (v0, -v1, -v2, -v3)
    00924     Scalar_<_Tp> conj() const;
    00925
    00926     // returns true iff v1 == v2 == v3 == 0
    00927     bool isReal() const;
    00928 };
    00929
    00930 typedef Scalar_<double> Scalar;
    00931
    00932 CV_EXPORTS void scalarToRawData(const Scalar& s, void* buf, int type, int unroll_to=0);
    00933
    00935
    00941 class CV_EXPORTS Range
    00942 {
    00943 public:
    00944     Range();
    00945     Range(int _start, int _end);
    00946     Range(const CvSlice& slice);
    00947     int size() const;
    00948     bool empty() const;
    00949     static Range all();
    00950     operator CvSlice() const;
    00951
    00952     int start, end;
    00953 };
    00954
    00956
    00968 template<typename _Tp> class DataType
    00969 {
    00970 public:
    00971     typedef _Tp value_type;
    00972     typedef value_type work_type;
    00973     typedef value_type channel_type;
    00974     typedef value_type vec_type;
    00975
    00976     enum { generic_type = 1, depth = DataDepth<channel_type>::value, channels = 1,
    00977         fmt=DataDepth<channel_type>::fmt,
    00978         type = CV_MAKETYPE(depth, channels) };
    00979 };
    00980
    00981 template<> class DataType<bool>
    00982 {
    00983 public:
    00984     typedef bool value_type;
    00985     typedef int work_type;
    00986     typedef value_type channel_type;
    00987     typedef value_type vec_type;
    00988     enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 1,
    00989            fmt=DataDepth<channel_type>::fmt,
    00990            type = CV_MAKETYPE(depth, channels) };
    00991 };
    00992
    00993 template<> class DataType<uchar>
    00994 {
    00995 public:
    00996     typedef uchar value_type;
    00997     typedef int work_type;
    00998     typedef value_type channel_type;
    00999     typedef value_type vec_type;
    01000     enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 1,
    01001            fmt=DataDepth<channel_type>::fmt,
    01002            type = CV_MAKETYPE(depth, channels) };
    01003 };
    01004
    01005 template<> class DataType<schar>
    01006 {
    01007 public:
    01008     typedef schar value_type;
    01009     typedef int work_type;
    01010     typedef value_type channel_type;
    01011     typedef value_type vec_type;
    01012     enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 1,
    01013            fmt=DataDepth<channel_type>::fmt,
    01014            type = CV_MAKETYPE(depth, channels) };
    01015 };
    01016
    01017 template<> class DataType<char>
    01018 {
    01019 public:
    01020     typedef schar value_type;
    01021     typedef int work_type;
    01022     typedef value_type channel_type;
    01023     typedef value_type vec_type;
    01024     enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 1,
    01025            fmt=DataDepth<channel_type>::fmt,
    01026            type = CV_MAKETYPE(depth, channels) };
    01027 };
    01028
    01029 template<> class DataType<ushort>
    01030 {
    01031 public:
    01032     typedef ushort value_type;
    01033     typedef int work_type;
    01034     typedef value_type channel_type;
    01035     typedef value_type vec_type;
    01036     enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 1,
    01037            fmt=DataDepth<channel_type>::fmt,
    01038            type = CV_MAKETYPE(depth, channels) };
    01039 };
    01040
    01041 template<> class DataType<short>
    01042 {
    01043 public:
    01044     typedef short value_type;
    01045     typedef int work_type;
    01046     typedef value_type channel_type;
    01047     typedef value_type vec_type;
    01048     enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 1,
    01049            fmt=DataDepth<channel_type>::fmt,
    01050            type = CV_MAKETYPE(depth, channels) };
    01051 };
    01052
    01053 template<> class DataType<int>
    01054 {
    01055 public:
    01056     typedef int value_type;
    01057     typedef value_type work_type;
    01058     typedef value_type channel_type;
    01059     typedef value_type vec_type;
    01060     enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 1,
    01061            fmt=DataDepth<channel_type>::fmt,
    01062            type = CV_MAKETYPE(depth, channels) };
    01063 };
    01064
    01065 template<> class DataType<float>
    01066 {
    01067 public:
    01068     typedef float value_type;
    01069     typedef value_type work_type;
    01070     typedef value_type channel_type;
    01071     typedef value_type vec_type;
    01072     enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 1,
    01073            fmt=DataDepth<channel_type>::fmt,
    01074            type = CV_MAKETYPE(depth, channels) };
    01075 };
    01076
    01077 template<> class DataType<double>
    01078 {
    01079 public:
    01080     typedef double value_type;
    01081     typedef value_type work_type;
    01082     typedef value_type channel_type;
    01083     typedef value_type vec_type;
    01084     enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 1,
    01085            fmt=DataDepth<channel_type>::fmt,
    01086            type = CV_MAKETYPE(depth, channels) };
    01087 };
    01088
    01089 template<typename _Tp, int cn> class DataType<Vec<_Tp, cn> >
    01090 {
    01091 public:
    01092     typedef Vec<_Tp, cn> value_type;
    01093     typedef Vec<typename DataType<_Tp>::work_type, cn> work_type;
    01094     typedef _Tp channel_type;
    01095     typedef value_type vec_type;
    01096     enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = cn,
    01097            fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt,
    01098            type = CV_MAKETYPE(depth, channels) };
    01099 };
    01100
    01101 template<typename _Tp> class DataType<std::complex<_Tp> >
    01102 {
    01103 public:
    01104     typedef std::complex<_Tp> value_type;
    01105     typedef value_type work_type;
    01106     typedef _Tp channel_type;
    01107     enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 2,
    01108            fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt,
    01109            type = CV_MAKETYPE(depth, channels) };
    01110     typedef Vec<channel_type, channels> vec_type;
    01111 };
    01112
    01113 template<typename _Tp> class DataType<Complex<_Tp> >
    01114 {
    01115 public:
    01116     typedef Complex<_Tp> value_type;
    01117     typedef value_type work_type;
    01118     typedef _Tp channel_type;
    01119     enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 2,
    01120            fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt,
    01121            type = CV_MAKETYPE(depth, channels) };
    01122     typedef Vec<channel_type, channels> vec_type;
    01123 };
    01124
    01125 template<typename _Tp> class DataType<Point_<_Tp> >
    01126 {
    01127 public:
    01128     typedef Point_<_Tp> value_type;
    01129     typedef Point_<typename DataType<_Tp>::work_type> work_type;
    01130     typedef _Tp channel_type;
    01131     enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 2,
    01132            fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt,
    01133            type = CV_MAKETYPE(depth, channels) };
    01134     typedef Vec<channel_type, channels> vec_type;
    01135 };
    01136
    01137 template<typename _Tp> class DataType<Point3_<_Tp> >
    01138 {
    01139 public:
    01140     typedef Point3_<_Tp> value_type;
    01141     typedef Point3_<typename DataType<_Tp>::work_type> work_type;
    01142     typedef _Tp channel_type;
    01143     enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 3,
    01144            fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt,
    01145            type = CV_MAKETYPE(depth, channels) };
    01146     typedef Vec<channel_type, channels> vec_type;
    01147 };
    01148
    01149 template<typename _Tp> class DataType<Size_<_Tp> >
    01150 {
    01151 public:
    01152     typedef Size_<_Tp> value_type;
    01153     typedef Size_<typename DataType<_Tp>::work_type> work_type;
    01154     typedef _Tp channel_type;
    01155     enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 2,
    01156            fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt,
    01157            type = CV_MAKETYPE(depth, channels) };
    01158     typedef Vec<channel_type, channels> vec_type;
    01159 };
    01160
    01161 template<typename _Tp> class DataType<Rect_<_Tp> >
    01162 {
    01163 public:
    01164     typedef Rect_<_Tp> value_type;
    01165     typedef Rect_<typename DataType<_Tp>::work_type> work_type;
    01166     typedef _Tp channel_type;
    01167     enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 4,
    01168            fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt,
    01169            type = CV_MAKETYPE(depth, channels) };
    01170     typedef Vec<channel_type, channels> vec_type;
    01171 };
    01172
    01173 template<typename _Tp> class DataType<Scalar_<_Tp> >
    01174 {
    01175 public:
    01176     typedef Scalar_<_Tp> value_type;
    01177     typedef Scalar_<typename DataType<_Tp>::work_type> work_type;
    01178     typedef _Tp channel_type;
    01179     enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 4,
    01180            fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt,
    01181            type = CV_MAKETYPE(depth, channels) };
    01182     typedef Vec<channel_type, channels> vec_type;
    01183 };
    01184
    01185 template<> class DataType<Range>
    01186 {
    01187 public:
    01188     typedef Range value_type;
    01189     typedef value_type work_type;
    01190     typedef int channel_type;
    01191     enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 2,
    01192            fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt,
    01193            type = CV_MAKETYPE(depth, channels) };
    01194     typedef Vec<channel_type, channels> vec_type;
    01195 };
    01196
    01197
    01199
    01221 template<typename _Tp> class CV_EXPORTS Ptr
    01222 {
    01223 public:
    01225     Ptr();
    01227     Ptr(_Tp* _obj);
    01229     ~Ptr();
    01231     Ptr(const Ptr& ptr);
    01233     Ptr& operator = (const Ptr& ptr);
    01235     void addref();
    01237     void release();
    01239     void delete_obj();
    01241     bool empty() const;
    01242
    01243
    01245     _Tp* operator -> ();
    01246     const _Tp* operator -> () const;
    01247
    01248     operator _Tp* ();
    01249     operator const _Tp*() const;
    01250
    01251 protected:
    01252     _Tp* obj; //< the object pointer.
    01253     int* refcount; //< the associated                         bbbbbbbbbbbbbbbbbb reference counter
    01254 };
    01255
    01257
    01258 enum { MAGIC_MASK=0xFFFF0000, TYPE_MASK=0x00000FFF, DEPTH_MASK=7 };
    01259
    01260 static inline size_t getElemSize(int type) { return CV_ELEM_SIZE(type); }
    01261
    01266 class CV_EXPORTS MatAllocator
    01267 {
    01268 public:
    01269     MatAllocator() {}
    01270     virtual ~MatAllocator() {}
    01271     virtual void allocate(int dims, const int* sizes, int type, int*& refcount,
    01272                           uchar*& datastart, uchar*& data, size_t* step) = 0;
    01273     virtual void deallocate(int* refcount, uchar* datastart, uchar* data) = 0;
    01274 };
    01275
    01488 class CV_EXPORTS Mat
    01489 {
    01490 public:
    01492     Mat();
    01494     // (_type is CV_8UC1, CV_64FC3, CV_32SC(12) etc.)
    01495     Mat(int _rows, int _cols, int _type);
    01496     Mat(Size _size, int _type);
    01498     Mat(int _rows, int _cols, int _type, const Scalar& _s);
    01499     Mat(Size _size, int _type, const Scalar& _s);
    01500
    01502     Mat(int _ndims, const int* _sizes, int _type);
    01503     Mat(int _ndims, const int* _sizes, int _type, const Scalar& _s);
    01504
    01506     Mat(const Mat& m);
    01508     Mat(int _rows, int _cols, int _type, void* _data, size_t _step=AUTO_STEP);
    01509     Mat(Size _size, int _type, void* _data, size_t _step=AUTO_STEP);
    01510     Mat(int _ndims, const int* _sizes, int _type, void* _data, const size_t* _steps=0);
    01511
    01513     Mat(const Mat& m, const Range& rowRange, const Range& colRange=Range::all());
    01514     Mat(const Mat& m, const Rect& roi);
    01515     Mat(const Mat& m, const Range* ranges);
    01517     Mat(const CvMat* m, bool copyData=false);
    01519     Mat(const CvMatND* m, bool copyData=false);
    01521     Mat(const IplImage* img, bool copyData=false);
    01523     template<typename _Tp> explicit Mat(const vector<_Tp>& vec, bool copyData=false);
    01525     template<typename _Tp, int n> explicit Mat(const Vec<_Tp, n>& vec,
    01526                                                bool copyData=true);
    01528     template<typename _Tp, int m, int n> explicit Mat(const Matx<_Tp, m, n>& mtx,
    01529                                                       bool copyData=true);
    01531     template<typename _Tp> explicit Mat(const Point_<_Tp>& pt, bool copyData=true);
    01533     template<typename _Tp> explicit Mat(const Point3_<_Tp>& pt, bool copyData=true);
    01535     template<typename _Tp> explicit Mat(const MatCommaInitializer_<_Tp>& commaInitializer);
    01537     ~Mat();
    01539     Mat& operator = (const Mat& m);
    01540     Mat& operator = (const MatExpr& expr);
    01541
    01543     Mat row(int y) const;
    01545     Mat col(int x) const;
    01547     Mat rowRange(int startrow, int endrow) const;
    01548     Mat rowRange(const Range& r) const;
    01550     Mat colRange(int startcol, int endcol) const;
    01551     Mat colRange(const Range& r) const;
    01553     // (d=0 - the main diagonal,
    01554     //  >0 - a diagonal from the lower half,
    01555     //  <0 - a diagonal from the upper half)
    01556     Mat diag(int d=0) const;
    01558     static Mat diag(const Mat& d);
    01559
    01561     Mat clone() const;
    01563     // It calls m.create(this->size(), this->type()).
    01564     void copyTo( Mat& m ) const;
    01565     template<typename _Tp> void copyTo( vector<_Tp>& v ) const;
    01567     void copyTo( Mat& m, const Mat& mask ) const;
    01569     void convertTo( Mat& m, int rtype, double alpha=1, double beta=0 ) const;
    01570
    01571     void assignTo( Mat& m, int type=-1 ) const;
    01572
    01574     Mat& operator = (const Scalar& s);
    01576     Mat& setTo(const Scalar& s, const Mat& mask=Mat());
    01578     // number of channels and/or different number of rows. see cvReshape.
    01579     Mat reshape(int _cn, int _rows=0) const;
    01580     Mat reshape(int _cn, int _newndims, const int* _newsz) const;
    01581
    01583     MatExpr t() const;
    01585     MatExpr inv(int method=DECOMP_LU) const;
    01587     MatExpr mul(const Mat& m, double scale=1) const;
    01588     MatExpr mul(const MatExpr& m, double scale=1) const;
    01589
    01591     Mat cross(const Mat& m) const;
    01593     double dot(const Mat& m) const;
    01594
    01596     static MatExpr zeros(int rows, int cols, int type);
    01597     static MatExpr zeros(Size size, int type);
    01598     static MatExpr zeros(int ndims, const int* sz, int type);
    01599     static MatExpr ones(int rows, int cols, int type);
    01600     static MatExpr ones(Size size, int type);
    01601     static MatExpr ones(int ndims, const int* sz, int type);
    01602     static MatExpr eye(int rows, int cols, int type);
    01603     static MatExpr eye(Size size, int type);
    01604
    01606     // previous data is unreferenced if needed.
    01607     void create(int _rows, int _cols, int _type);
    01608     void create(Size _size, int _type);
    01609     void create(int _ndims, const int* _sizes, int _type);
    01610
    01612     void addref();
    01614     // deallocates the data when reference counter reaches 0.
    01615     void release();
    01616
    01618     void deallocate();
    01620     void copySize(const Mat& m);
    01621
    01623     void reserve(size_t sz);
    01625     void resize(size_t sz);
    01627     void resize(size_t sz, const Scalar& s);
    01629     void push_back_(const void* elem);
    01631     template<typename _Tp> void push_back(const _Tp& elem);
    01632     template<typename _Tp> void push_back(const Mat_<_Tp>& elem);
    01633     void push_back(const Mat& m);
    01635     void pop_back(size_t nelems=1);
    01636
    01638     void locateROI( Size& wholeSize, Point& ofs ) const;
    01640     Mat& adjustROI( int dtop, int dbottom, int dleft, int dright );
    01642     // (this is a generalized form of row, rowRange etc.)
    01643     Mat operator()( Range rowRange, Range colRange ) const;
    01644     Mat operator()( const Rect& roi ) const;
    01645     Mat operator()( const Range* ranges ) const;
    01646
    01648     operator CvMat() const;
    01650     operator CvMatND() const;
    01652     operator IplImage() const;
    01653
    01654     template<typename _Tp> operator vector<_Tp>() const;
    01655     template<typename _Tp, int n> operator Vec<_Tp, n>() const;
    01656     template<typename _Tp, int m, int n> operator Matx<_Tp, m, n>() const;
    01657
    01659     // (i.e. when there are no gaps between successive rows).
    01660     // similar to CV_IS_MAT_CONT(cvmat->type)
    01661     bool isContinuous() const;
    01662
    01664     bool isSubmatrix() const;
    01665
    01667     // similar to CV_ELEM_SIZE(cvmat->type)
    01668     size_t elemSize() const;
    01670     size_t elemSize1() const;
    01672     int type() const;
    01674     int depth() const;
    01676     int channels() const;
    01678     size_t step1(int i=0) const;
    01680     bool empty() const;
    01682     size_t total() const;
    01683
    01685     int checkVector(int elemChannels, int depth=-1, bool requireContinuous=true) const;
    01686
    01688     uchar* ptr(int i0=0);
    01689     const uchar* ptr(int i0=0) const;
    01690
    01692     uchar* ptr(int i0, int i1);
    01693     const uchar* ptr(int i0, int i1) const;
    01694
    01696     uchar* ptr(int i0, int i1, int i2);
    01697     const uchar* ptr(int i0, int i1, int i2) const;
    01698
    01700     uchar* ptr(const int* idx);
    01702     const uchar* ptr(const int* idx) const;
    01703
    01704     template<int n> uchar* ptr(const Vec<int, n>& idx);
    01705     template<int n> const uchar* ptr(const Vec<int, n>& idx) const;
    01706
    01708     template<typename _Tp> _Tp* ptr(int i0=0);
    01709     template<typename _Tp> const _Tp* ptr(int i0=0) const;
    01710
    01711     template<typename _Tp> _Tp* ptr(int i0, int i1);
    01712     template<typename _Tp> const _Tp* ptr(int i0, int i1) const;
    01713
    01714     template<typename _Tp> _Tp* ptr(int i0, int i1, int i2);
    01715     template<typename _Tp> const _Tp* ptr(int i0, int i1, int i2) const;
    01716
    01717     template<typename _Tp> _Tp* ptr(const int* idx);
    01718     template<typename _Tp> const _Tp* ptr(const int* idx) const;
    01719
    01720     template<typename _Tp, int n> _Tp* ptr(const Vec<int, n>& idx);
    01721     template<typename _Tp, int n> const _Tp* ptr(const Vec<int, n>& idx) const;
    01722
    01724     template<typename _Tp> _Tp& at(int i0=0);
    01725     template<typename _Tp> const _Tp& at(int i0=0) const;
    01726
    01727     template<typename _Tp> _Tp& at(int i0, int i1);
    01728     template<typename _Tp> const _Tp& at(int i0, int i1) const;
    01729
    01730     template<typename _Tp> _Tp& at(int i0, int i1, int i2);
    01731     template<typename _Tp> const _Tp& at(int i0, int i1, int i2) const;
    01732
    01733     template<typename _Tp> _Tp& at(const int* idx);
    01734     template<typename _Tp> const _Tp& at(const int* idx) const;
    01735
    01736     template<typename _Tp, int n> _Tp& at(const Vec<int, n>& idx);
    01737     template<typename _Tp, int n> const _Tp& at(const Vec<int, n>& idx) const;
    01738
    01740     template<typename _Tp> _Tp& at(Point pt);
    01741     template<typename _Tp> const _Tp& at(Point pt) const;
    01742
    01744     // the iterators take care of skipping gaps in the end of rows (if any)
    01745     template<typename _Tp> MatIterator_<_Tp> begin();
    01746     template<typename _Tp> MatIterator_<_Tp> end();
    01747     template<typename _Tp> MatConstIterator_<_Tp> begin() const;
    01748     template<typename _Tp> MatConstIterator_<_Tp> end() const;
    01749
    01750     enum { MAGIC_VAL=0x42FF0000, AUTO_STEP=0, CONTINUOUS_FLAG=CV_MAT_CONT_FLAG, SUBMATRIX_FLAG=CV_SUBMAT_FLAG };
    01751
    01758     int flags;
    01760     int dims;
    01762     int rows, cols;
    01764     uchar* data;
    01765
    01767     // when matrix points to user-allocated data, the pointer is NULL
    01768     int* refcount;
    01769
    01771     uchar* datastart;
    01772     uchar* dataend;
    01773     uchar* datalimit;
    01774
    01776     MatAllocator* allocator;
    01777
    01778     struct CV_EXPORTS MSize
    01779     {
    01780         MSize(int* _p);
    01781         Size operator()() const;
    01782         int operator[](int i) const;
    01783         int& operator[](int i);
    01784         operator const int*() const;
    01785         bool operator == (const MSize& sz) const;
    01786         bool operator != (const MSize& sz) const;
    01787
    01788         int* p;
    01789     };
    01790
    01791     struct CV_EXPORTS MStep
    01792     {
    01793         MStep();
    01794         MStep(size_t s);
    01795         size_t operator[](int i) const;
    01796         size_t& operator[](int i);
    01797         operator size_t() const;
    01798         MStep& operator = (size_t s);
    01799
    01800         size_t* p;
    01801         size_t buf[2];
    01802     protected:
    01803         MStep& operator = (const MStep&);
    01804     };
    01805
    01806     MSize size;
    01807     MStep step;
    01808 };
    01809
    01810
    01816 class CV_EXPORTS RNG
    01817 {
    01818 public:
    01819     enum { A=4164903690U, UNIFORM=0, NORMAL=1 };
    01820
    01821     RNG();
    01822     RNG(uint64 _state);
    01824     unsigned next();
    01825
    01826     operator uchar();
    01827     operator schar();
    01828     operator ushort();
    01829     operator short();
    01830     operator unsigned();
    01832         unsigned operator()(unsigned N);
    01833         unsigned operator ()();
    01834     operator int();
    01835     operator float();
    01836     operator double();
    01838     int uniform(int a, int b);
    01840     float uniform(float a, float b);
    01842     double uniform(double a, double b);
    01843     void fill( Mat& mat, int distType, const Scalar& a, const Scalar& b );
    01845         double gaussian(double sigma);
    01846
    01847     uint64 state;
    01848 };
    01849
    01850
    01851
    01852
    01856 class CV_EXPORTS TermCriteria
    01857 {
    01858 public:
    01859     enum
    01860     {
    01861         COUNT=1,
    01862         MAX_ITER=COUNT,
    01863         EPS=2
    01864     };
    01865
    01867     TermCriteria();
    01869     TermCriteria(int _type, int _maxCount, double _epsilon);
    01871     TermCriteria(const CvTermCriteria& criteria);
    01873     operator CvTermCriteria() const;
    01874
    01875     int type;
    01876     int maxCount; // the maximum number of iterations/elements
    01877     double epsilon; // the desired accuracy
    01878 };
    01879
    01881 CV_EXPORTS void swap(Mat& a, Mat& b);
    01882
    01884 CV_EXPORTS Mat cvarrToMat(const CvArr* arr, bool copyData=false,
    01885                           bool allowND=true, int coiMode=0);
    01887 CV_EXPORTS void extractImageCOI(const CvArr* arr, CV_OUT Mat& coiimg, int coi=-1);
    01889 CV_EXPORTS void insertImageCOI(const Mat& coiimg, CvArr* arr, int coi=-1);
    01890
    01892 CV_EXPORTS_W void add(const Mat& src1, const Mat& src2, CV_OUT Mat& dst, const Mat& mask CV_WRAP_DEFAULT(Mat()));
    01894 CV_EXPORTS_W void subtract(const Mat& src1, const Mat& src2, CV_OUT Mat& dst, const Mat& mask CV_WRAP_DEFAULT(Mat()));
    01896 CV_EXPORTS void add(const Mat& src1, const Mat& src2, CV_OUT Mat& dst);
    01898 CV_EXPORTS void subtract(const Mat& src1, const Mat& src2, CV_OUT Mat& dst);
    01900 CV_EXPORTS_W void add(const Mat& src1, const Scalar& src2, CV_OUT Mat& dst, const Mat& mask=Mat());
    01902 CV_EXPORTS_W void subtract(const Mat& src1, const Scalar& src2, CV_OUT Mat& dst, const Mat& mask=Mat());
    01904 CV_EXPORTS_W void subtract(const Scalar& src1, const Mat& src2, CV_OUT Mat& dst, const Mat& mask=Mat());
    01905
    01907 CV_EXPORTS_W void multiply(const Mat& src1, const Mat& src2, CV_OUT Mat& dst, double scale=1);
    01909 CV_EXPORTS_W void divide(const Mat& src1, const Mat& src2, CV_OUT Mat& dst, double scale=1);
    01911 CV_EXPORTS_W void divide(double scale, const Mat& src2, CV_OUT Mat& dst);
    01912
    01914 CV_EXPORTS_W void scaleAdd(const Mat& src1, double alpha, const Mat& src2, CV_OUT Mat& dst);
    01916 CV_EXPORTS_W void addWeighted(const Mat& src1, double alpha, const Mat& src2,
    01917                             double beta, double gamma, CV_OUT Mat& dst);
    01919 CV_EXPORTS_W void convertScaleAbs(const Mat& src, CV_OUT Mat& dst, double alpha=1, double beta=0);
    01921 CV_EXPORTS_W void LUT(const Mat& src, const Mat& lut, CV_OUT Mat& dst);
    01922
    01924 CV_EXPORTS_W Scalar sum(const Mat& src);
    01926 CV_EXPORTS_W int countNonZero( const Mat& src );
    01927
    01929 CV_EXPORTS Scalar mean(const Mat& src);
    01931 CV_EXPORTS_W Scalar mean(const Mat& src, const Mat& mask CV_WRAP_DEFAULT(Mat()));
    01933 CV_EXPORTS_W void meanStdDev(const Mat& src, CV_OUT Scalar& mean, CV_OUT Scalar& stddev, const Mat& mask=Mat());
    01935 CV_EXPORTS double norm(const Mat& src1, int normType=NORM_L2);
    01937 CV_EXPORTS double norm(const Mat& src1, const Mat& src2, int normType=NORM_L2);
    01939 CV_EXPORTS_W double norm(const Mat& src1, int normType, const Mat& mask CV_WRAP_DEFAULT(Mat()));
    01941 CV_EXPORTS_W double norm(const Mat& src1, const Mat& src2,
    01942                        int normType, const Mat& mask CV_WRAP_DEFAULT(Mat()));
    01944 CV_EXPORTS_W void normalize( const Mat& src, CV_OUT Mat& dst, double alpha=1, double beta=0,
    01945                            int norm_type=NORM_L2, int rtype=-1, const Mat& mask=Mat());
    01946
    01948 CV_EXPORTS_W void minMaxLoc(const Mat& src, CV_OUT double* minVal,
    01949                           CV_OUT double* maxVal=0, CV_OUT Point* minLoc=0,
    01950                           CV_OUT Point* maxLoc=0, const Mat& mask=Mat());
    01951 CV_EXPORTS void minMaxIdx(const Mat& src, double* minVal, double* maxVal,
    01952                           int* minIdx=0, int* maxIdx=0, const Mat& mask=Mat());
    01953
    01955 CV_EXPORTS_W void reduce(const Mat& src, CV_OUT Mat& dst, int dim, int rtype, int dtype=-1);
    01957 CV_EXPORTS void merge(const Mat* mv, size_t count, CV_OUT Mat& dst);
    01959 CV_EXPORTS_W void merge(const vector<Mat>& mv, Mat& dst);
    01960
    01962 CV_EXPORTS void split(const Mat& src, Mat* mvbegin);
    01964 CV_EXPORTS_W void split(const Mat& m, vector<Mat>& mv);
    01965
    01967 CV_EXPORTS void mixChannels(const Mat* src, size_t nsrcs, Mat* dst, size_t ndsts,
    01968                             const int* fromTo, size_t npairs);
    01969 CV_EXPORTS void mixChannels(const vector<Mat>& src, vector<Mat>& dst,
    01970                             const int* fromTo, int npairs);
    01971
    01973 CV_EXPORTS_W void flip(const Mat& src, CV_OUT Mat& dst, int flipCode);
    01974
    01976 CV_EXPORTS_W void repeat(const Mat& src, int ny, int nx, CV_OUT Mat& dst);
    01977 CV_EXPORTS Mat repeat(const Mat& src, int ny, int nx);
    01978
    01979 CV_EXPORTS void hconcat(const Mat* src, size_t nsrc, Mat& dst);
    01980 CV_EXPORTS void hconcat(const Mat& src1, const Mat& src2, Mat& dst);
    01981 CV_EXPORTS_W void hconcat(const vector<Mat>& src, CV_OUT Mat& dst);
    01982
    01983 CV_EXPORTS void vconcat(const Mat* src, size_t nsrc, Mat& dst);
    01984 CV_EXPORTS void vconcat(const Mat& src1, const Mat& src2, Mat& dst);
    01985 CV_EXPORTS_W void vconcat(const vector<Mat>& src, CV_OUT Mat& dst);
    01986
    01988 CV_EXPORTS_W void bitwise_and(const Mat& src1, const Mat& src2, CV_OUT Mat& dst, const Mat& mask=Mat());
    01990 CV_EXPORTS_W void bitwise_or(const Mat& src1, const Mat& src2, CV_OUT Mat& dst, const Mat& mask=Mat());
    01992 CV_EXPORTS_W void bitwise_xor(const Mat& src1, const Mat& src2, CV_OUT Mat& dst, const Mat& mask=Mat());
    01994 CV_EXPORTS_W void bitwise_and(const Mat& src1, const Scalar& src2, CV_OUT Mat& dst, const Mat& mask=Mat());
    01996 CV_EXPORTS_W void bitwise_or(const Mat& src1, const Scalar& src2, CV_OUT Mat& dst, const Mat& mask=Mat());
    01998 CV_EXPORTS_W void bitwise_xor(const Mat& src1, const Scalar& src2, CV_OUT Mat& dst, const Mat& mask=Mat());
    02000 CV_EXPORTS_W void bitwise_not(const Mat& src, CV_OUT Mat& dst);
    02002 CV_EXPORTS_W void absdiff(const Mat& src1, const Mat& src2, CV_OUT Mat& dst);
    02004 CV_EXPORTS_W void absdiff(const Mat& src1, const Scalar& src2, CV_OUT Mat& dst);
    02006 CV_EXPORTS_W void inRange(const Mat& src, const Mat& lowerb,
    02007                         const Mat& upperb, CV_OUT Mat& dst);
    02009 CV_EXPORTS_W void inRange(const Mat& src, const Scalar& lowerb,
    02010                         const Scalar& upperb, CV_OUT Mat& dst);
    02012 CV_EXPORTS_W void compare(const Mat& src1, const Mat& src2, CV_OUT Mat& dst, int cmpop);
    02014 CV_EXPORTS_W void compare(const Mat& src1, double s, CV_OUT Mat& dst, int cmpop);
    02016 CV_EXPORTS_W void min(const Mat& src1, const Mat& src2, CV_OUT Mat& dst);
    02018 CV_EXPORTS_W void min(const Mat& src1, double src2, CV_OUT Mat& dst);
    02020 CV_EXPORTS_W void max(const Mat& src1, const Mat& src2, CV_OUT Mat& dst);
    02022 CV_EXPORTS_W void max(const Mat& src1, double src2, CV_OUT Mat& dst);
    02023
    02025 CV_EXPORTS_W void sqrt(const Mat& src, CV_OUT Mat& dst);
    02027 CV_EXPORTS_W void pow(const Mat& src, double power, CV_OUT Mat& dst);
    02029 CV_EXPORTS_W void exp(const Mat& src, CV_OUT Mat& dst);
    02031 CV_EXPORTS_W void log(const Mat& src, CV_OUT Mat& dst);
    02033 CV_EXPORTS_W float cubeRoot(float val);
    02035 CV_EXPORTS_W float fastAtan2(float y, float x);
    02037 CV_EXPORTS_W void polarToCart(const Mat& magnitude, const Mat& angle,
    02038                             CV_OUT Mat& x, CV_OUT Mat& y, bool angleInDegrees=false);
    02040 CV_EXPORTS_W void cartToPolar(const Mat& x, const Mat& y,
    02041                             CV_OUT Mat& magnitude, CV_OUT Mat& angle,
    02042                             bool angleInDegrees=false);
    02044 CV_EXPORTS_W void phase(const Mat& x, const Mat& y, CV_OUT Mat& angle,
    02045                         bool angleInDegrees=false);
    02047 CV_EXPORTS_W void magnitude(const Mat& x, const Mat& y, CV_OUT Mat& magnitude);
    02049 CV_EXPORTS_W bool checkRange(const Mat& a, bool quiet=true, CV_OUT Point* pt=0,
    02050                             double minVal=-DBL_MAX, double maxVal=DBL_MAX);
    02052 CV_EXPORTS_W void gemm(const Mat& src1, const Mat& src2, double alpha,
    02053                        const Mat& src3, double gamma, CV_OUT Mat& dst, int flags=0);
    02055 CV_EXPORTS_W void mulTransposed( const Mat& src, CV_OUT Mat& dst, bool aTa,
    02056                                  const Mat& delta=Mat(),
    02057                                  double scale=1, int rtype=-1 );
    02059 CV_EXPORTS_W void transpose(const Mat& src, CV_OUT Mat& dst);
    02061 CV_EXPORTS_W void transform(const Mat& src, CV_OUT Mat& dst, const Mat& m );
    02063 CV_EXPORTS_W void perspectiveTransform(const Mat& src, CV_OUT Mat& dst, const Mat& m );
    02064
    02066 CV_EXPORTS_W void completeSymm(Mat& mtx, bool lowerToUpper=false);
    02068 CV_EXPORTS_W void setIdentity(Mat& mtx, const Scalar& s=Scalar(1));
    02070 CV_EXPORTS_W double determinant(const Mat& mtx);
    02072 CV_EXPORTS_W Scalar trace(const Mat& mtx);
    02074 CV_EXPORTS_W double invert(const Mat& src, CV_OUT Mat& dst, int flags=DECOMP_LU);
    02076 CV_EXPORTS_W bool solve(const Mat& src1, const Mat& src2, CV_OUT Mat& dst, int flags=DECOMP_LU);
    02078 CV_EXPORTS_W void sort(const Mat& src, CV_OUT Mat& dst, int flags);
    02080 CV_EXPORTS_W void sortIdx(const Mat& src, CV_OUT Mat& dst, int flags);
    02082 CV_EXPORTS_W int solveCubic(const Mat& coeffs, CV_OUT Mat& roots);
    02084 CV_EXPORTS_W double solvePoly(const Mat& coeffs, CV_OUT Mat& roots, int maxIters=300);
    02086 CV_EXPORTS bool eigen(const Mat& src, CV_OUT Mat& eigenvalues, int lowindex=-1,
    02087                       int highindex=-1);
    02089 CV_EXPORTS bool eigen(const Mat& src, CV_OUT Mat& eigenvalues, CV_OUT Mat& eigenvectors,
    02090                       int lowindex=-1, int highindex=-1);
    02092 CV_EXPORTS void calcCovarMatrix( const Mat* samples, int nsamples, Mat& covar, Mat& mean,
    02093                                  int flags, int ctype=CV_64F);
    02095 CV_EXPORTS_W void calcCovarMatrix( const Mat& samples, CV_OUT Mat& covar, CV_OUT Mat& mean,
    02096                                  int flags, int ctype=CV_64F);
    02097
    02152 class CV_EXPORTS PCA
    02153 {
    02154 public:
    02156     PCA();
    02158     PCA(const Mat& data, const Mat& mean, int flags, int maxComponents=0);
    02160     PCA& operator()(const Mat& data, const Mat& mean, int flags, int maxComponents=0);
    02162     Mat project(const Mat& vec) const;
    02164     void project(const Mat& vec, CV_OUT Mat& result) const;
    02166     Mat backProject(const Mat& vec) const;
    02168     void backProject(const Mat& vec, CV_OUT Mat& result) const;
    02169
    02170     Mat eigenvectors;
    02171     Mat eigenvalues;
    02172     Mat mean;
    02173 };
    02174
    02188 class CV_EXPORTS SVD
    02189 {
    02190 public:
    02191     enum { MODIFY_A=1, NO_UV=2, FULL_UV=4 };
    02193     SVD();
    02195     SVD( const Mat& src, int flags=0 );
    02197     SVD& operator ()( const Mat& src, int flags=0 );
    02198
    02200     static void compute( const Mat& src, CV_OUT Mat& w, CV_OUT Mat& u, CV_OUT Mat& vt, int flags=0 );
    02202     static void compute( const Mat& src, CV_OUT Mat& w, int flags=0 );
    02204     static void backSubst( const Mat& w, const Mat& u, const Mat& vt,
    02205                            const Mat& rhs, CV_OUT Mat& dst );
    02206
    02207     template<typename _Tp, int m, int n, int nm> static void compute( const Matx<_Tp, m, n>& a,
    02208         Matx<_Tp, nm, 1>& w, Matx<_Tp, m, nm>& u, Matx<_Tp, n, nm>& vt );
    02209     template<typename _Tp, int m, int n, int nm> static void compute( const Matx<_Tp, m, n>& a,
    02210         Matx<_Tp, nm, 1>& w );
    02211     template<typename _Tp, int m, int n, int nm, int nb> static void backSubst( const Matx<_Tp, nm, 1>& w,
    02212         const Matx<_Tp, m, nm>& u, const Matx<_Tp, n, nm>& vt, const Matx<_Tp, m, nb>& rhs, Matx<_Tp, n, nb>& dst );
    02213
    02215     static void solveZ( const Mat& src, CV_OUT Mat& dst );
    02217     void backSubst( const Mat& rhs, CV_OUT Mat& dst ) const;
    02218
    02219     Mat u, w, vt;
    02220 };
    02221
    02223 CV_EXPORTS_W double Mahalanobis(const Mat& v1, const Mat& v2, const Mat& icovar);
    02225 CV_EXPORTS double Mahalonobis(const Mat& v1, const Mat& v2, const Mat& icovar);
    02226
    02228 CV_EXPORTS_W void dft(const Mat& src, CV_OUT Mat& dst, int flags=0, int nonzeroRows=0);
    02230 CV_EXPORTS_W void idft(const Mat& src, CV_OUT Mat& dst, int flags=0, int nonzeroRows=0);
    02232 CV_EXPORTS_W void dct(const Mat& src, CV_OUT Mat& dst, int flags=0);
    02234 CV_EXPORTS_W void idct(const Mat& src, CV_OUT Mat& dst, int flags=0);
    02236 CV_EXPORTS_W void mulSpectrums(const Mat& a, const Mat& b, CV_OUT Mat& c,
    02237                              int flags, bool conjB=false);
    02239 CV_EXPORTS_W int getOptimalDFTSize(int vecsize);
    02240
    02244 enum
    02245 {
    02246     KMEANS_RANDOM_CENTERS=0, // Chooses random centers for k-Means initialization
    02247     KMEANS_PP_CENTERS=2,     // Uses k-Means++ algorithm for initialization
    02248     KMEANS_USE_INITIAL_LABELS=1 // Uses the user-provided labels for K-Means initialization
    02249 };
    02251 CV_EXPORTS_W double kmeans( const Mat& data, int K, CV_OUT Mat& bestLabels,
    02252                           TermCriteria criteria, int attempts,
    02253                           int flags, CV_OUT Mat* centers=0 );
    02254
    02256 CV_EXPORTS RNG& theRNG();
    02257
    02259 template<typename _Tp> static inline _Tp randu() { return (_Tp)theRNG(); }
    02260
    02262 CV_EXPORTS_W void randu(CV_OUT Mat& dst, const Scalar& low, const Scalar& high);
    02263
    02265 CV_EXPORTS_W void randn(CV_OUT Mat& dst, const Scalar& mean, const Scalar& stddev);
    02266
    02268 CV_EXPORTS void randShuffle(Mat& dst, double iterFactor=1., RNG* rng=0);
    02269
    02271 CV_EXPORTS_W void line(Mat& img, Point pt1, Point pt2, const Scalar& color,
    02272                      int thickness=1, int lineType=8, int shift=0);
    02273
    02275 CV_EXPORTS_W void rectangle(Mat& img, Point pt1, Point pt2,
    02276                           const Scalar& color, int thickness=1,
    02277                           int lineType=8, int shift=0);
    02278
    02280 CV_EXPORTS void rectangle(Mat& img, Rect rec,
    02281                           const Scalar& color, int thickness=1,
    02282                           int lineType=8, int shift=0);
    02283
    02285 CV_EXPORTS_W void circle(Mat& img, Point center, int radius,
    02286                        const Scalar& color, int thickness=1,
    02287                        int lineType=8, int shift=0);
    02288
    02290 CV_EXPORTS_W void ellipse(Mat& img, Point center, Size axes,
    02291                         double angle, double startAngle, double endAngle,
    02292                         const Scalar& color, int thickness=1,
    02293                         int lineType=8, int shift=0);
    02294
    02296 CV_EXPORTS_W void ellipse(Mat& img, const RotatedRect& box, const Scalar& color,
    02297                         int thickness=1, int lineType=8);
    02298
    02300 CV_EXPORTS void fillConvexPoly(Mat& img, const Point* pts, int npts,
    02301                                const Scalar& color, int lineType=8,
    02302                                int shift=0);
    02303
    02305 CV_EXPORTS void fillPoly(Mat& img, const Point** pts,
    02306                          const int* npts, int ncontours,
    02307                          const Scalar& color, int lineType=8, int shift=0,
    02308                          Point offset=Point() );
    02309
    02311 CV_EXPORTS void polylines(Mat& img, const Point** pts, const int* npts,
    02312                           int ncontours, bool isClosed, const Scalar& color,
    02313                           int thickness=1, int lineType=8, int shift=0 );
    02314
    02316 CV_EXPORTS bool clipLine(Size imgSize, CV_IN_OUT Point& pt1, CV_IN_OUT Point& pt2);
    02317
    02319 CV_EXPORTS_W bool clipLine(Rect imgRect, CV_IN_OUT Point& pt1, CV_IN_OUT Point& pt2);
    02320
    02327 class CV_EXPORTS LineIterator
    02328 {
    02329 public:
    02331     LineIterator( const Mat& img, Point pt1, Point pt2,
    02332                   int connectivity=8, bool leftToRight=false );
    02334     uchar* operator *();
    02336     LineIterator& operator ++();
    02338     LineIterator operator ++(int);
    02340     Point pos() const;
    02341
    02342     uchar* ptr;
    02343     const uchar* ptr0;
    02344     int step, elemSize;
    02345     int err, count;
    02346     int minusDelta, plusDelta;
    02347     int minusStep, plusStep;
    02348 };
    02349
    02351 CV_EXPORTS_W void ellipse2Poly( Point center, Size axes, int angle,
    02352                               int arcStart, int arcEnd, int delta,
    02353                               CV_OUT vector<Point>& pts );
    02354
    02355 enum
    02356 {
    02357     FONT_HERSHEY_SIMPLEX = 0,
    02358     FONT_HERSHEY_PLAIN = 1,
    02359     FONT_HERSHEY_DUPLEX = 2,
    02360     FONT_HERSHEY_COMPLEX = 3,
    02361     FONT_HERSHEY_TRIPLEX = 4,
    02362     FONT_HERSHEY_COMPLEX_SMALL = 5,
    02363     FONT_HERSHEY_SCRIPT_SIMPLEX = 6,
    02364     FONT_HERSHEY_SCRIPT_COMPLEX = 7,
    02365     FONT_ITALIC = 16
    02366 };
    02367
    02369 CV_EXPORTS_W void putText( Mat& img, const string& text, Point org,
    02370                          int fontFace, double fontScale, Scalar color,
    02371                          int thickness=1, int linetype=8,
    02372                          bool bottomLeftOrigin=false );
    02373
    02375 CV_EXPORTS_W Size getTextSize(const string& text, int fontFace,
    02376                             double fontScale, int thickness,
    02377                             CV_OUT int* baseLine);
    02378
    02380
    02426 template<typename _Tp> class CV_EXPORTS Mat_ : public Mat
    02427 {
    02428 public:
    02429     typedef _Tp value_type;
    02430     typedef typename DataType<_Tp>::channel_type channel_type;
    02431     typedef MatIterator_<_Tp> iterator;
    02432     typedef MatConstIterator_<_Tp> const_iterator;
    02433
    02435     Mat_();
    02437     Mat_(int _rows, int _cols);
    02439     Mat_(int _rows, int _cols, const _Tp& value);
    02441     explicit Mat_(Size _size);
    02443     Mat_(Size _size, const _Tp& value);
    02445     Mat_(int _ndims, const int* _sizes);
    02447     Mat_(int _ndims, const int* _sizes, const _Tp& value);
    02449     Mat_(const Mat& m);
    02451     Mat_(const Mat_& m);
    02453     Mat_(int _rows, int _cols, _Tp* _data, size_t _step=AUTO_STEP);
    02455     Mat_(int _ndims, const int* _sizes, _Tp* _data, const size_t* _steps=0);
    02457     Mat_(const Mat_& m, const Range& rowRange, const Range& colRange=Range::all());
    02459     Mat_(const Mat_& m, const Rect& roi);
    02461     Mat_(const Mat_& m, const Range* ranges);
    02463     explicit Mat_(const vector<_Tp>& vec, bool copyData=false);
    02464     template<int n> explicit Mat_(const Vec<typename DataType<_Tp>::channel_type, n>& vec, bool copyData=true);
    02465     template<int m, int n> explicit Mat_(const Matx<typename DataType<_Tp>::channel_type, m, n>& mtx, bool copyData=true);
    02466     explicit Mat_(const Point_<typename DataType<_Tp>::channel_type>& pt, bool copyData=true);
    02467     explicit Mat_(const Point3_<typename DataType<_Tp>::channel_type>& pt, bool copyData=true);
    02468     explicit Mat_(const MatCommaInitializer_<_Tp>& commaInitializer);
    02469
    02470     Mat_& operator = (const Mat& m);
    02471     Mat_& operator = (const Mat_& m);
    02473     Mat_& operator = (const _Tp& s);
    02474
    02476     iterator begin();
    02477     iterator end();
    02478     const_iterator begin() const;
    02479     const_iterator end() const;
    02480
    02482     void create(int _rows, int _cols);
    02484     void create(Size _size);
    02486     void create(int _ndims, const int* _sizes);
    02488     Mat_ cross(const Mat_& m) const;
    02490     Mat_& operator = (const MatExpr& expr);
    02492     template<typename T2> operator Mat_<T2>() const;
    02494     Mat_ row(int y) const;
    02495     Mat_ col(int x) const;
    02496     Mat_ diag(int d=0) const;
    02497     Mat_ clone() const;
    02498
    02500     size_t elemSize() const;
    02501     size_t elemSize1() const;
    02502     int type() const;
    02503     int depth() const;
    02504     int channels() const;
    02505     size_t step1(int i=0) const;
    02507     size_t stepT(int i=0) const;
    02508
    02510     static MatExpr zeros(int rows, int cols);
    02511     static MatExpr zeros(Size size);
    02512     static MatExpr zeros(int _ndims, const int* _sizes);
    02513     static MatExpr ones(int rows, int cols);
    02514     static MatExpr ones(Size size);
    02515     static MatExpr ones(int _ndims, const int* _sizes);
    02516     static MatExpr eye(int rows, int cols);
    02517     static MatExpr eye(Size size);
    02518
    02520     Mat_ reshape(int _rows) const;
    02521     Mat_& adjustROI( int dtop, int dbottom, int dleft, int dright );
    02522     Mat_ operator()( const Range& rowRange, const Range& colRange ) const;
    02523     Mat_ operator()( const Rect& roi ) const;
    02524     Mat_ operator()( const Range* ranges ) const;
    02525
    02527     _Tp* operator [](int y);
    02528     const _Tp* operator [](int y) const;
    02529
    02531     _Tp& operator ()(const int* idx);
    02533     const _Tp& operator ()(const int* idx) const;
    02534
    02536     template<int n> _Tp& operator ()(const Vec<int, n>& idx);
    02538     template<int n> const _Tp& operator ()(const Vec<int, n>& idx) const;
    02539
    02541     _Tp& operator ()(int idx0);
    02543     const _Tp& operator ()(int idx0) const;
    02545     _Tp& operator ()(int idx0, int idx1);
    02547     const _Tp& operator ()(int idx0, int idx1) const;
    02549     _Tp& operator ()(int idx0, int idx1, int idx2);
    02551     const _Tp& operator ()(int idx0, int idx1, int idx2) const;
    02552
    02553     _Tp& operator ()(Point pt);
    02554     const _Tp& operator ()(Point pt) const;
    02555
    02557     operator vector<_Tp>() const;
    02559     template<int n> operator Vec<typename DataType<_Tp>::channel_type, n>() const;
    02561     template<int m, int n> operator Matx<typename DataType<_Tp>::channel_type, m, n>() const;
    02562 };
    02563
    02564 typedef Mat_<uchar> Mat1b;
    02565 typedef Mat_<Vec2b> Mat2b;
    02566 typedef Mat_<Vec3b> Mat3b;
    02567 typedef Mat_<Vec4b> Mat4b;
    02568
    02569 typedef Mat_<short> Mat1s;
    02570 typedef Mat_<Vec2s> Mat2s;
    02571 typedef Mat_<Vec3s> Mat3s;
    02572 typedef Mat_<Vec4s> Mat4s;
    02573
    02574 typedef Mat_<ushort> Mat1w;
    02575 typedef Mat_<Vec2w> Mat2w;
    02576 typedef Mat_<Vec3w> Mat3w;
    02577 typedef Mat_<Vec4w> Mat4w;
    02578
    02579 typedef Mat_<int>   Mat1i;
    02580 typedef Mat_<Vec2i> Mat2i;
    02581 typedef Mat_<Vec3i> Mat3i;
    02582 typedef Mat_<Vec4i> Mat4i;
    02583
    02584 typedef Mat_<float> Mat1f;
    02585 typedef Mat_<Vec2f> Mat2f;
    02586 typedef Mat_<Vec3f> Mat3f;
    02587 typedef Mat_<Vec4f> Mat4f;
    02588
    02589 typedef Mat_<double> Mat1d;
    02590 typedef Mat_<Vec2d> Mat2d;
    02591 typedef Mat_<Vec3d> Mat3d;
    02592 typedef Mat_<Vec4d> Mat4d;
    02593
    02595
    02596 class CV_EXPORTS MatConstIterator
    02597 {
    02598 public:
    02599     typedef uchar* value_type;
    02600     typedef ptrdiff_t difference_type;
    02601     typedef const uchar** pointer;
    02602     typedef uchar* reference;
    02603     typedef std::random_access_iterator_tag iterator_category;
    02604
    02606     MatConstIterator();
    02608     MatConstIterator(const Mat* _m);
    02610     MatConstIterator(const Mat* _m, int _row, int _col=0);
    02612     MatConstIterator(const Mat* _m, Point _pt);
    02614     MatConstIterator(const Mat* _m, const int* _idx);
    02616     MatConstIterator(const MatConstIterator& it);
    02617
    02619     MatConstIterator& operator = (const MatConstIterator& it);
    02621     uchar* operator *() const;
    02623     uchar* operator [](ptrdiff_t i) const;
    02624
    02626     MatConstIterator& operator += (ptrdiff_t ofs);
    02628     MatConstIterator& operator -= (ptrdiff_t ofs);
    02630     MatConstIterator& operator --();
    02632     MatConstIterator operator --(int);
    02634     MatConstIterator& operator ++();
    02636     MatConstIterator operator ++(int);
    02638     Point pos() const;
    02640     void pos(int* _idx) const;
    02641     ptrdiff_t lpos() const;
    02642     void seek(ptrdiff_t ofs, bool relative=false);
    02643     void seek(const int* _idx, bool relative=false);
    02644
    02645     const Mat* m;
    02646     size_t elemSize;
    02647     uchar* ptr;
    02648     uchar* sliceStart;
    02649     uchar* sliceEnd;
    02650 };
    02651
    02656 template<typename _Tp>
    02657 class CV_EXPORTS MatConstIterator_ : public MatConstIterator
    02658 {
    02659 public:
    02660     typedef _Tp value_type;
    02661     typedef ptrdiff_t difference_type;
    02662     typedef const _Tp* pointer;
    02663     typedef const _Tp& reference;
    02664     typedef std::random_access_iterator_tag iterator_category;
    02665
    02667     MatConstIterator_();
    02669     MatConstIterator_(const Mat_<_Tp>* _m);
    02671     MatConstIterator_(const Mat_<_Tp>* _m, int _row, int _col=0);
    02673     MatConstIterator_(const Mat_<_Tp>* _m, Point _pt);
    02675     MatConstIterator_(const Mat_<_Tp>* _m, const int* _idx);
    02677     MatConstIterator_(const MatConstIterator_& it);
    02678
    02680     MatConstIterator_& operator = (const MatConstIterator_& it);
    02682     _Tp operator *() const;
    02684     _Tp operator [](ptrdiff_t i) const;
    02685
    02687     MatConstIterator_& operator += (ptrdiff_t ofs);
    02689     MatConstIterator_& operator -= (ptrdiff_t ofs);
    02691     MatConstIterator_& operator --();
    02693     MatConstIterator_ operator --(int);
    02695     MatConstIterator_& operator ++();
    02697     MatConstIterator_ operator ++(int);
    02699     Point pos() const;
    02700 };
    02701
    02702
    02707 template<typename _Tp>
    02708 class CV_EXPORTS MatIterator_ : public MatConstIterator_<_Tp>
    02709 {
    02710 public:
    02711     typedef _Tp* pointer;
    02712     typedef _Tp& reference;
    02713     typedef std::random_access_iterator_tag iterator_category;
    02714
    02716     MatIterator_();
    02718     MatIterator_(Mat_<_Tp>* _m);
    02720     MatIterator_(Mat_<_Tp>* _m, int _row, int _col=0);
    02722     MatIterator_(const Mat_<_Tp>* _m, Point _pt);
    02724     MatIterator_(const Mat_<_Tp>* _m, const int* _idx);
    02726     MatIterator_(const MatIterator_& it);
    02728     MatIterator_& operator = (const MatIterator_<_Tp>& it );
    02729
    02731     _Tp& operator *() const;
    02733     _Tp& operator [](ptrdiff_t i) const;
    02734
    02736     MatIterator_& operator += (ptrdiff_t ofs);
    02738     MatIterator_& operator -= (ptrdiff_t ofs);
    02740     MatIterator_& operator --();
    02742     MatIterator_ operator --(int);
    02744     MatIterator_& operator ++();
    02746     MatIterator_ operator ++(int);
    02747 };
    02748
    02749 template<typename _Tp> class CV_EXPORTS MatOp_Iter_;
    02750
    02764 template<typename _Tp> class CV_EXPORTS MatCommaInitializer_
    02765 {
    02766 public:
    02768     MatCommaInitializer_(Mat_<_Tp>* _m);
    02770     template<typename T2> MatCommaInitializer_<_Tp>& operator , (T2 v);
    02772     Mat_<_Tp> operator *() const;
    02773     operator Mat_<_Tp>() const;
    02774 protected:
    02775     MatIterator_<_Tp> it;
    02776 };
    02777
    02778
    02779 template<typename _Tp, int m, int n> class CV_EXPORTS MatxCommaInitializer
    02780 {
    02781 public:
    02782     MatxCommaInitializer(Matx<_Tp, m, n>* _mtx);
    02783     template<typename T2> MatxCommaInitializer<_Tp, m, n>& operator , (T2 val);
    02784     Matx<_Tp, m, n> operator *() const;
    02785
    02786     Matx<_Tp, m, n>* dst;
    02787     int idx;
    02788 };
    02789
    02790 template<typename _Tp, int m> class CV_EXPORTS VecCommaInitializer : public MatxCommaInitializer<_Tp, m, 1>
    02791 {
    02792 public:
    02793     VecCommaInitializer(Vec<_Tp, m>* _vec);
    02794     template<typename T2> VecCommaInitializer<_Tp, m>& operator , (T2 val);
    02795     Vec<_Tp, m> operator *() const;
    02796 };
    02797
    02825 template<typename _Tp, size_t fixed_size=4096/sizeof(_Tp)+8> class CV_EXPORTS AutoBuffer
    02826 {
    02827 public:
    02828     typedef _Tp value_type;
    02829
    02831     AutoBuffer();
    02833     AutoBuffer(size_t _size);
    02835     ~AutoBuffer();
    02836
    02838     void allocate(size_t _size);
    02840     void deallocate();
    02842     operator _Tp* ();
    02844     operator const _Tp* () const;
    02845
    02846 protected:
    02848     _Tp* ptr;
    02850     size_t size;
    02852     _Tp buf[fixed_size];
    02853 };
    02854
    02856
    02907 class CV_EXPORTS NAryMatIterator
    02908 {
    02909 public:
    02911     NAryMatIterator();
    02913     NAryMatIterator(const Mat** arrays, Mat* planes, int narrays=-1);
    02915     void init(const Mat** arrays, Mat* planes, int narrays=-1);
    02916
    02918     NAryMatIterator& operator ++();
    02920     NAryMatIterator operator ++(int);
    02921
    02923     const Mat** arrays;
    02925     Mat* planes;
    02927     int narrays;
    02929     int nplanes;
    02930 protected:
    02931     int iterdepth, idx;
    02932 };
    02933
    02934 //typedef NAryMatIterator NAryMatNDIterator;
    02935
    02936 typedef void (*ConvertData)(const void* from, void* to, int cn);
    02937 typedef void (*ConvertScaleData)(const void* from, void* to, int cn, double alpha, double beta);
    02938
    02940 CV_EXPORTS ConvertData getConvertElem(int fromType, int toType);
    02942 CV_EXPORTS ConvertScaleData getConvertScaleElem(int fromType, int toType);
    02943
    02944
    02946
    02947 class SparseMatIterator;
    02948 class SparseMatConstIterator;
    02949 template<typename _Tp> class SparseMatIterator_;
    02950 template<typename _Tp> class SparseMatConstIterator_;
    02951
    03037 class CV_EXPORTS SparseMat
    03038 {
    03039 public:
    03040     typedef SparseMatIterator iterator;
    03041     typedef SparseMatConstIterator const_iterator;
    03042
    03044     struct CV_EXPORTS Hdr
    03045     {
    03046         Hdr(int _dims, const int* _sizes, int _type);
    03047         void clear();
    03048         int refcount;
    03049         int dims;
    03050         int valueOffset;
    03051         size_t nodeSize;
    03052         size_t nodeCount;
    03053         size_t freeList;
    03054         vector<uchar> pool;
    03055         vector<size_t> hashtab;
    03056         int size[CV_MAX_DIM];
    03057     };
    03058
    03060     struct CV_EXPORTS Node
    03061     {
    03063         size_t hashval;
    03065         size_t next;
    03067         int idx[CV_MAX_DIM];
    03068     };
    03069
    03071     SparseMat();
    03073     SparseMat(int dims, const int* _sizes, int _type);
    03075     SparseMat(const SparseMat& m);
    03077
    03082     SparseMat(const Mat& m);
    03084     SparseMat(const CvSparseMat* m);
    03086     ~SparseMat();
    03087
    03089     SparseMat& operator = (const SparseMat& m);
    03091     SparseMat& operator = (const Mat& m);
    03092
    03094     SparseMat clone() const;
    03095
    03097     void copyTo( SparseMat& m ) const;
    03099     void copyTo( Mat& m ) const;
    03101     void convertTo( SparseMat& m, int rtype, double alpha=1 ) const;
    03103
    03108     void convertTo( Mat& m, int rtype, double alpha=1, double beta=0 ) const;
    03109
    03110     // not used now
    03111     void assignTo( SparseMat& m, int type=-1 ) const;
    03112
    03114
    03119     void create(int dims, const int* _sizes, int _type);
    03121     void clear();
    03123     void addref();
    03124     // decrements the header reference counter. When the counter reaches 0, the header and all the underlying data are deallocated.
    03125     void release();
    03126
    03128     operator CvSparseMat*() const;
    03130     size_t elemSize() const;
    03132     size_t elemSize1() const;
    03133
    03135     int type() const;
    03137     int depth() const;
    03139     int channels() const;
    03140
    03142     const int* size() const;
    03144     int size(int i) const;
    03146     int dims() const;
    03148     size_t nzcount() const;
    03149
    03151     size_t hash(int i0) const;
    03153     size_t hash(int i0, int i1) const;
    03155     size_t hash(int i0, int i1, int i2) const;
    03157     size_t hash(const int* idx) const;
    03158
    03160
    03173
    03174     uchar* ptr(int i0, bool createMissing, size_t* hashval=0);
    03176     uchar* ptr(int i0, int i1, bool createMissing, size_t* hashval=0);
    03178     uchar* ptr(int i0, int i1, int i2, bool createMissing, size_t* hashval=0);
    03180     uchar* ptr(const int* idx, bool createMissing, size_t* hashval=0);
    03182
    03184
    03191
    03192     template<typename _Tp> _Tp& ref(int i0, size_t* hashval=0);
    03194     template<typename _Tp> _Tp& ref(int i0, int i1, size_t* hashval=0);
    03196     template<typename _Tp> _Tp& ref(int i0, int i1, int i2, size_t* hashval=0);
    03198     template<typename _Tp> _Tp& ref(const int* idx, size_t* hashval=0);
    03200
    03202
    03213
    03214     template<typename _Tp> _Tp value(int i0, size_t* hashval=0) const;
    03216     template<typename _Tp> _Tp value(int i0, int i1, size_t* hashval=0) const;
    03218     template<typename _Tp> _Tp value(int i0, int i1, int i2, size_t* hashval=0) const;
    03220     template<typename _Tp> _Tp value(const int* idx, size_t* hashval=0) const;
    03222
    03224
    03231
    03232     template<typename _Tp> const _Tp* find(int i0, size_t* hashval=0) const;
    03234     template<typename _Tp> const _Tp* find(int i0, int i1, size_t* hashval=0) const;
    03236     template<typename _Tp> const _Tp* find(int i0, int i1, int i2, size_t* hashval=0) const;
    03238     template<typename _Tp> const _Tp* find(const int* idx, size_t* hashval=0) const;
    03239
    03241     void erase(int i0, int i1, size_t* hashval=0);
    03243     void erase(int i0, int i1, int i2, size_t* hashval=0);
    03245     void erase(const int* idx, size_t* hashval=0);
    03246
    03248
    03251
    03252     SparseMatIterator begin();
    03254     template<typename _Tp> SparseMatIterator_<_Tp> begin();
    03256     SparseMatConstIterator begin() const;
    03258     template<typename _Tp> SparseMatConstIterator_<_Tp> begin() const;
    03260
    03263
    03264     SparseMatIterator end();
    03266     SparseMatConstIterator end() const;
    03268     template<typename _Tp> SparseMatIterator_<_Tp> end();
    03270     template<typename _Tp> SparseMatConstIterator_<_Tp> end() const;
    03271
    03273     template<typename _Tp> _Tp& value(Node* n);
    03275     template<typename _Tp> const _Tp& value(const Node* n) const;
    03276
    03278     Node* node(size_t nidx);
    03279     const Node* node(size_t nidx) const;
    03280
    03281     uchar* newNode(const int* idx, size_t hashval);
    03282     void removeNode(size_t hidx, size_t nidx, size_t previdx);
    03283     void resizeHashTab(size_t newsize);
    03284
    03285     enum { MAGIC_VAL=0x42FD0000, MAX_DIM=CV_MAX_DIM, HASH_SCALE=0x5bd1e995, HASH_BIT=0x80000000 };
    03286
    03287     int flags;
    03288     Hdr* hdr;
    03289 };
    03290
    03292 CV_EXPORTS void minMaxLoc(const SparseMat& a, double* minVal,
    03293                           double* maxVal, int* minIdx=0, int* maxIdx=0);
    03295 CV_EXPORTS double norm( const SparseMat& src, int normType );
    03297 CV_EXPORTS void normalize( const SparseMat& src, SparseMat& dst, double alpha, int normType );
    03298
    03311 class CV_EXPORTS SparseMatConstIterator
    03312 {
    03313 public:
    03315     SparseMatConstIterator();
    03317     SparseMatConstIterator(const SparseMat* _m);
    03319     SparseMatConstIterator(const SparseMatConstIterator& it);
    03320
    03322     SparseMatConstIterator& operator = (const SparseMatConstIterator& it);
    03323
    03325     template<typename _Tp> const _Tp& value() const;
    03327     const SparseMat::Node* node() const;
    03328
    03330     SparseMatConstIterator& operator --();
    03332     SparseMatConstIterator operator --(int);
    03334     SparseMatConstIterator& operator ++();
    03336     SparseMatConstIterator operator ++(int);
    03337
    03339     void seekEnd();
    03340
    03341     const SparseMat* m;
    03342     size_t hashidx;
    03343     uchar* ptr;
    03344 };
    03345
    03352 class CV_EXPORTS SparseMatIterator : public SparseMatConstIterator
    03353 {
    03354 public:
    03356     SparseMatIterator();
    03358     SparseMatIterator(SparseMat* _m);
    03360     SparseMatIterator(SparseMat* _m, const int* idx);
    03362     SparseMatIterator(const SparseMatIterator& it);
    03363
    03365     SparseMatIterator& operator = (const SparseMatIterator& it);
    03367     template<typename _Tp> _Tp& value() const;
    03369     SparseMat::Node* node() const;
    03370
    03372     SparseMatIterator& operator ++();
    03374     SparseMatIterator operator ++(int);
    03375 };
    03376
    03390 template<typename _Tp> class CV_EXPORTS SparseMat_ : public SparseMat
    03391 {
    03392 public:
    03393     typedef SparseMatIterator_<_Tp> iterator;
    03394     typedef SparseMatConstIterator_<_Tp> const_iterator;
    03395
    03397     SparseMat_();
    03399     SparseMat_(int dims, const int* _sizes);
    03401     SparseMat_(const SparseMat& m);
    03403     SparseMat_(const SparseMat_& m);
    03405     SparseMat_(const Mat& m);
    03407     SparseMat_(const CvSparseMat* m);
    03409     SparseMat_& operator = (const SparseMat& m);
    03411     SparseMat_& operator = (const SparseMat_& m);
    03413     SparseMat_& operator = (const Mat& m);
    03414
    03416     SparseMat_ clone() const;
    03418     void create(int dims, const int* _sizes);
    03420     operator CvSparseMat*() const;
    03421
    03423     int type() const;
    03425     int depth() const;
    03427     int channels() const;
    03428
    03430     _Tp& ref(int i0, size_t* hashval=0);
    03432     _Tp& ref(int i0, int i1, size_t* hashval=0);
    03434     _Tp& ref(int i0, int i1, int i2, size_t* hashval=0);
    03436     _Tp& ref(const int* idx, size_t* hashval=0);
    03437
    03439     _Tp operator()(int i0, size_t* hashval=0) const;
    03441     _Tp operator()(int i0, int i1, size_t* hashval=0) const;
    03443     _Tp operator()(int i0, int i1, int i2, size_t* hashval=0) const;
    03445     _Tp operator()(const int* idx, size_t* hashval=0) const;
    03446
    03448     SparseMatIterator_<_Tp> begin();
    03450     SparseMatConstIterator_<_Tp> begin() const;
    03452     SparseMatIterator_<_Tp> end();
    03454     SparseMatConstIterator_<_Tp> end() const;
    03455 };
    03456
    03457
    03464 template<typename _Tp> class CV_EXPORTS SparseMatConstIterator_ : public SparseMatConstIterator
    03465 {
    03466 public:
    03467     typedef std::forward_iterator_tag iterator_category;
    03468
    03470     SparseMatConstIterator_();
    03472     SparseMatConstIterator_(const SparseMat_<_Tp>* _m);
    03474     SparseMatConstIterator_(const SparseMatConstIterator_& it);
    03475
    03477     SparseMatConstIterator_& operator = (const SparseMatConstIterator_& it);
    03479     const _Tp& operator *() const;
    03480
    03482     SparseMatConstIterator_& operator ++();
    03484     SparseMatConstIterator_ operator ++(int);
    03485 };
    03486
    03493 template<typename _Tp> class CV_EXPORTS SparseMatIterator_ : public SparseMatConstIterator_<_Tp>
    03494 {
    03495 public:
    03496     typedef std::forward_iterator_tag iterator_category;
    03497
    03499     SparseMatIterator_();
    03501     SparseMatIterator_(SparseMat_<_Tp>* _m);
    03503     SparseMatIterator_(const SparseMatIterator_& it);
    03504
    03506     SparseMatIterator_& operator = (const SparseMatIterator_& it);
    03508     _Tp& operator *() const;
    03509
    03511     SparseMatIterator_& operator ++();
    03513     SparseMatIterator_ operator ++(int);
    03514 };
    03515
    03517
    03542 class CV_EXPORTS_W KDTree
    03543 {
    03544 public:
    03548     struct Node
    03549     {
    03550         Node() : idx(-1), left(-1), right(-1), boundary(0.f) {}
    03551         Node(int _idx, int _left, int _right, float _boundary)
    03552             : idx(_idx), left(_left), right(_right), boundary(_boundary) {}
    03554         int idx;
    03556         int left, right;
    03558         float boundary;
    03559     };
    03560
    03562     CV_WRAP KDTree();
    03564     CV_WRAP KDTree(const Mat& _points, bool copyAndReorderPoints=false);
    03566     CV_WRAP KDTree(const Mat& _points, const Mat& _labels, bool copyAndReorderPoints=false);
    03568     CV_WRAP void build(const Mat& _points, bool copyAndReorderPoints=false);
    03570     CV_WRAP void build(const Mat& _points, const Mat& _labels, bool copyAndReorderPoints=false);
    03572     int findNearest(const float* vec,
    03573                     int K, int Emax, int* neighborsIdx,
    03574                     Mat* neighbors=0, float* dist=0, int* labels=0) const;
    03576     int findNearest(const float* vec, int K, int Emax,
    03577                     vector<int>* neighborsIdx,
    03578                     Mat* neighbors=0,
    03579                     vector<float>* dist=0,
    03580                     vector<int>* labels=0) const;
    03581     CV_WRAP int findNearest(const vector<float>& vec, int K, int Emax,
    03582                     CV_OUT vector<int>* neighborsIdx,
    03583                     CV_OUT Mat* neighbors=0,
    03584                     CV_OUT vector<float>* dist=0,
    03585                     CV_OUT vector<int>* labels=0) const;
    03587     void findOrthoRange(const float* minBounds, const float* maxBounds,
    03588                         vector<int>* neighborsIdx, Mat* neighbors=0,
    03589                         vector<int>* labels=0) const;
    03590     CV_WRAP void findOrthoRange(const vector<float>& minBounds, const vector<float>& maxBounds,
    03591                                 CV_OUT vector<int>* neighborsIdx, CV_OUT Mat* neighbors=0,
    03592                                 CV_OUT vector<int>* labels=0) const;
    03594     void getPoints(const int* idx, size_t nidx, Mat& pts, vector<int>* labels=0) const;
    03596     CV_WRAP void getPoints(const vector<int>& idxs, Mat& pts, CV_OUT vector<int>* labels=0) const;
    03598     const float* getPoint(int ptidx, int* label=0) const;
    03600     CV_WRAP int dims() const;
    03601
    03602     vector<Node> nodes;
    03603     CV_PROP Mat points;
    03604     CV_PROP vector<int> labels;
    03605     CV_PROP int maxDepth;
    03606     CV_PROP_RW int normType;
    03607 };
    03608
    03610
    03611 class CV_EXPORTS FileNode;
    03612
    03710 class CV_EXPORTS_W FileStorage
    03711 {
    03712 public:
    03714     enum
    03715     {
    03716         READ=0,
    03717         WRITE=1,
    03718         APPEND=2
    03719     };
    03720     enum
    03721     {
    03722         UNDEFINED=0,
    03723         VALUE_EXPECTED=1,
    03724         NAME_EXPECTED=2,
    03725         INSIDE_MAP=4
    03726     };
    03728     CV_WRAP FileStorage();
    03730     CV_WRAP FileStorage(const string& filename, int flags);
    03732     FileStorage(CvFileStorage* fs);
    03734     virtual ~FileStorage();
    03735
    03737     CV_WRAP virtual bool open(const string& filename, int flags);
    03739     CV_WRAP virtual bool isOpened() const;
    03741     CV_WRAP virtual void release();
    03742
    03744     CV_WRAP FileNode getFirstTopLevelNode() const;
    03746     CV_WRAP FileNode root(int streamidx=0) const;
    03748     FileNode operator[](const string& nodename) const;
    03750     CV_WRAP FileNode operator[](const char* nodename) const;
    03751
    03753     CvFileStorage* operator *() { return fs; }
    03755     const CvFileStorage* operator *() const { return fs; }
    03757     void writeRaw( const string& fmt, const uchar* vec, size_t len );
    03759     void writeObj( const string& name, const void* obj );
    03760
    03762     static string getDefaultObjectName(const string& filename);
    03763
    03764     Ptr<CvFileStorage> fs;
    03765     string elname;
    03766     vector<char> structs;
    03767     int state;
    03768 };
    03769
    03770 class CV_EXPORTS FileNodeIterator;
    03771
    03782 class CV_EXPORTS_W_SIMPLE FileNode
    03783 {
    03784 public:
    03786     enum
    03787     {
    03788         NONE=0,
    03789         INT=1,
    03790         REAL=2,
    03791         FLOAT=REAL,
    03792         STR=3,
    03793         STRING=STR,
    03794         REF=4,
    03795         SEQ=5,
    03796         MAP=6,
    03797         TYPE_MASK=7,
    03798         FLOW=8,
    03799         USER=16,
    03800         EMPTY=32,
    03801         NAMED=64
    03802     };
    03804     CV_WRAP FileNode();
    03806     FileNode(const CvFileStorage* fs, const CvFileNode* node);
    03808     FileNode(const FileNode& node);
    03810     FileNode operator[](const string& nodename) const;
    03812     CV_WRAP FileNode operator[](const char* nodename) const;
    03814     CV_WRAP FileNode operator[](int i) const;
    03816     CV_WRAP int type() const;
    03817
    03819     CV_WRAP bool empty() const;
    03821     CV_WRAP bool isNone() const;
    03823     CV_WRAP bool isSeq() const;
    03825     CV_WRAP bool isMap() const;
    03827     CV_WRAP bool isInt() const;
    03829     CV_WRAP bool isReal() const;
    03831     CV_WRAP bool isString() const;
    03833     CV_WRAP bool isNamed() const;
    03835     CV_WRAP string name() const;
    03837     CV_WRAP size_t size() const;
    03839     operator int() const;
    03841     operator float() const;
    03843     operator double() const;
    03845     operator string() const;
    03846
    03848     CvFileNode* operator *();
    03850     const CvFileNode* operator* () const;
    03851
    03853     FileNodeIterator begin() const;
    03855     FileNodeIterator end() const;
    03856
    03858     void readRaw( const string& fmt, uchar* vec, size_t len ) const;
    03860     void* readObj() const;
    03861
    03862     // do not use wrapper pointer classes for better efficiency
    03863     const CvFileStorage* fs;
    03864     const CvFileNode* node;
    03865 };
    03866
    03867
    03873 class CV_EXPORTS FileNodeIterator
    03874 {
    03875 public:
    03877     FileNodeIterator();
    03879     FileNodeIterator(const CvFileStorage* fs, const CvFileNode* node, size_t ofs=0);
    03881     FileNodeIterator(const FileNodeIterator& it);
    03883     FileNode operator *() const;
    03885     FileNode operator ->() const;
    03886
    03888     FileNodeIterator& operator ++ ();
    03890     FileNodeIterator operator ++ (int);
    03892     FileNodeIterator& operator -- ();
    03894     FileNodeIterator operator -- (int);
    03896     FileNodeIterator& operator += (int);
    03898     FileNodeIterator& operator -= (int);
    03899
    03901     FileNodeIterator& readRaw( const string& fmt, uchar* vec,
    03902                                size_t maxCount=(size_t)INT_MAX );
    03903
    03904     const CvFileStorage* fs;
    03905     const CvFileNode* container;
    03906     CvSeqReader reader;
    03907     size_t remaining;
    03908 };
    03909
    03911
    03912 template<typename _Tp> class SeqIterator;
    03913
    03914 typedef Ptr<CvMemStorage> MemStorage;
    03915
    03926 template<typename _Tp> class CV_EXPORTS Seq
    03927 {
    03928 public:
    03929     typedef SeqIterator<_Tp> iterator;
    03930     typedef SeqIterator<_Tp> const_iterator;
    03931
    03933     Seq();
    03935     Seq(const CvSeq* seq);
    03937     Seq(MemStorage& storage, int headerSize = sizeof(CvSeq));
    03939     _Tp& operator [](int idx);
    03941     const _Tp& operator[](int idx) const;
    03943     SeqIterator<_Tp> begin() const;
    03945     SeqIterator<_Tp> end() const;
    03947     size_t size() const;
    03949     int type() const;
    03951     int depth() const;
    03953     int channels() const;
    03955     size_t elemSize() const;
    03957     size_t index(const _Tp& elem) const;
    03959     void push_back(const _Tp& elem);
    03961     void push_front(const _Tp& elem);
    03963     void push_back(const _Tp* elems, size_t count);
    03965     void push_front(const _Tp* elems, size_t count);
    03967     void insert(int idx, const _Tp& elem);
    03969     void insert(int idx, const _Tp* elems, size_t count);
    03971     void remove(int idx);
    03973     void remove(const Range& r);
    03974
    03976     _Tp& front();
    03978     const _Tp& front() const;
    03980     _Tp& back();
    03982     const _Tp& back() const;
    03984     bool empty() const;
    03985
    03987     void clear();
    03989     void pop_front();
    03991     void pop_back();
    03993     void pop_front(_Tp* elems, size_t count);
    03995     void pop_back(_Tp* elems, size_t count);
    03996
    03998     void copyTo(vector<_Tp>& vec, const Range& range=Range::all()) const;
    04000     operator vector<_Tp>() const;
    04001
    04002     CvSeq* seq;
    04003 };
    04004
    04005
    04009 template<typename _Tp> class CV_EXPORTS SeqIterator : public CvSeqReader
    04010 {
    04011 public:
    04013     SeqIterator();
    04015     SeqIterator(const Seq<_Tp>& seq, bool seekEnd=false);
    04017     void seek(size_t pos);
    04019     size_t tell() const;
    04021     _Tp& operator *();
    04023     const _Tp& operator *() const;
    04025     SeqIterator& operator ++();
    04027     SeqIterator operator ++(int) const;
    04029     SeqIterator& operator --();
    04031     SeqIterator operator --(int) const;
    04032
    04034     SeqIterator& operator +=(int);
    04036     SeqIterator& operator -=(int);
    04037
    04038     // this is index of the current element module seq->total*2
    04039     // (to distinguish between 0 and seq->total)
    04040     int index;
    04041 };
    04042
    04043 }
    04044
    04045 #endif // __cplusplus
    04046
    04047 #include "opencv2/core/operations.hpp"
    04048 #include "opencv2/core/mat.hpp"
    04049
    04050 #endif /*__OPENCV_CORE_HPP__*/

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines