opencv  2.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
core.hpp
Go to the documentation of this file.
1 
4 /*M///////////////////////////////////////////////////////////////////////////////////////
5 //
6 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
7 //
8 // By downloading, copying, installing or using the software you agree to this license.
9 // If you do not agree to this license, do not download, install,
10 // copy or use the software.
11 //
12 //
13 // License Agreement
14 // For Open Source Computer Vision Library
15 //
16 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
17 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
18 // Third party copyrights are property of their respective owners.
19 //
20 // Redistribution and use in source and binary forms, with or without modification,
21 // are permitted provided that the following conditions are met:
22 //
23 // * Redistribution's of source code must retain the above copyright notice,
24 // this list of conditions and the following disclaimer.
25 //
26 // * Redistribution's in binary form must reproduce the above copyright notice,
27 // this list of conditions and the following disclaimer in the documentation
28 // and/or other materials provided with the distribution.
29 //
30 // * The name of the copyright holders may not be used to endorse or promote products
31 // derived from this software without specific prior written permission.
32 //
33 // This software is provided by the copyright holders and contributors "as is" and
34 // any express or implied warranties, including, but not limited to, the implied
35 // warranties of merchantability and fitness for a particular purpose are disclaimed.
36 // In no event shall the Intel Corporation or contributors be liable for any direct,
37 // indirect, incidental, special, exemplary, or consequential damages
38 // (including, but not limited to, procurement of substitute goods or services;
39 // loss of use, data, or profits; or business interruption) however caused
40 // and on any theory of liability, whether in contract, strict liability,
41 // or tort (including negligence or otherwise) arising in any way out of
42 // the use of this software, even if advised of the possibility of such damage.
43 //
44 //M*/
45 
46 #ifndef __OPENCV_CORE_HPP__
47 #define __OPENCV_CORE_HPP__
48 
49 #include "opencv2/core/types_c.h"
50 #include "opencv2/core/version.hpp"
51 
52 #ifdef __cplusplus
53 
54 #ifndef SKIP_INCLUDES
55 #include <limits.h>
56 #include <algorithm>
57 #include <cmath>
58 #include <complex>
59 #include <map>
60 #include <new>
61 #include <string>
62 #include <vector>
63 #endif // SKIP_INCLUDES
64 
68 namespace cv {
69 
70 #undef abs
71 #undef min
72 #undef max
73 #undef Complex
74 
75 using std::vector;
76 using std::string;
77 
78 template<typename _Tp> class CV_EXPORTS Size_;
79 template<typename _Tp> class CV_EXPORTS Point_;
80 template<typename _Tp> class CV_EXPORTS Rect_;
81 template<typename _Tp, int cn> class CV_EXPORTS Vec;
82 template<typename _Tp, int m, int n> class CV_EXPORTS Matx;
83 
84 typedef std::string String;
85 typedef std::basic_string<wchar_t> WString;
86 
87 class Mat;
88 class SparseMat;
89 typedef Mat MatND;
90 
91 class CV_EXPORTS MatExpr;
92 class CV_EXPORTS MatOp_Base;
93 class CV_EXPORTS MatArg;
95 
96 template<typename _Tp> class CV_EXPORTS Mat_;
97 template<typename _Tp> class CV_EXPORTS MatIterator_;
98 template<typename _Tp> class CV_EXPORTS MatConstIterator_;
99 template<typename _Tp> class CV_EXPORTS MatCommaInitializer_;
100 
101 CV_EXPORTS string fromUtf16(const WString& str);
102 CV_EXPORTS WString toUtf16(const string& str);
103 
104 CV_EXPORTS string format( const char* fmt, ... );
105 
106 
107 // matrix decomposition types
110 enum { CMP_EQ=0, CMP_GT=1, CMP_GE=2, CMP_LT=3, CMP_LE=4, CMP_NE=5 };
111 enum { GEMM_1_T=1, GEMM_2_T=2, GEMM_3_T=4 };
114 
115 
120 class CV_EXPORTS Exception : public std::exception
121 {
122 public:
126  Exception() { code = 0; line = 0; }
131  Exception(int _code, const string& _err, const string& _func, const string& _file, int _line)
132  : code(_code), err(_err), func(_func), file(_file), line(_line)
133  { formatMessage(); }
134 
135  virtual ~Exception() throw() {}
136 
140  virtual const char *what() const throw() { return msg.c_str(); }
141 
142  void formatMessage()
143  {
144  if( func.size() > 0 )
145  msg = format("%s:%d: error: (%d) %s in function %s\n", file.c_str(), line, code, err.c_str(), func.c_str());
146  else
147  msg = format("%s:%d: error: (%d) %s\n", file.c_str(), line, code, err.c_str());
148  }
149 
150  string msg;
151 
152  int code;
153  string err;
154  string func;
155  string file;
156  int line;
157 };
158 
159 
161 
169 CV_EXPORTS void error( const Exception& exc );
170 
172 
179 CV_EXPORTS bool setBreakOnError(bool flag);
180 
181 typedef int (CV_CDECL *ErrorCallback)( int status, const char* func_name,
182  const char* err_msg, const char* file_name,
183  int line, void* userdata );
184 
186 
197  void* userdata=0, void** prevUserdata=0);
198 
199 #ifdef __GNUC__
200 #define CV_Error( code, msg ) cv::error( cv::Exception(code, msg, __func__, __FILE__, __LINE__) )
201 #define CV_Error_( code, args ) cv::error( cv::Exception(code, cv::format args, __func__, __FILE__, __LINE__) )
202 #define CV_Assert( expr ) if((expr)) ; else cv::error( cv::Exception(CV_StsAssert, #expr, __func__, __FILE__, __LINE__) )
203 #else
204 #define CV_Error( code, msg ) cv::error( cv::Exception(code, msg, "", __FILE__, __LINE__) )
205 #define CV_Error_( code, args ) cv::error( cv::Exception(code, cv::format args, "", __FILE__, __LINE__) )
206 #define CV_Assert( expr ) if((expr)) ; else cv::error( cv::Exception(CV_StsAssert, #expr, "", __FILE__, __LINE__) )
207 #endif
208 
209 #ifdef _DEBUG
210 #define CV_DbgAssert(expr) CV_Assert(expr)
211 #else
212 #define CV_DbgAssert(expr)
213 #endif
214 
215 CV_EXPORTS void setNumThreads(int nthreads);
218 
220 
228 
242 
252 
271 CV_EXPORTS_W bool checkHardwareSupport(int feature);
272 
283 CV_EXPORTS void* fastMalloc(size_t bufSize);
284 
291 CV_EXPORTS void fastFree(void* ptr);
292 
293 template<typename _Tp> static inline _Tp* allocate(size_t n)
294 {
295  return new _Tp[n];
296 }
297 
298 template<typename _Tp> static inline void deallocate(_Tp* ptr, size_t)
299 {
300  delete[] ptr;
301 }
302 
309 template<typename _Tp> static inline _Tp* alignPtr(_Tp* ptr, int n=(int)sizeof(_Tp))
310 {
311  return (_Tp*)(((size_t)ptr + n-1) & -n);
312 }
313 
319 static inline size_t alignSize(size_t sz, int n)
320 {
321  return (sz + n-1) & -n;
322 }
323 
333 CV_EXPORTS_W void setUseOptimized(bool onoff);
334 
341 
345 template<typename _Tp> class CV_EXPORTS Allocator
346 {
347 public:
348  typedef _Tp value_type;
349  typedef value_type* pointer;
350  typedef const value_type* const_pointer;
352  typedef const value_type& const_reference;
353  typedef size_t size_type;
354  typedef ptrdiff_t difference_type;
355  template<typename U> class rebind { typedef Allocator<U> other; };
356 
357  explicit Allocator() {}
359  explicit Allocator(Allocator const&) {}
360  template<typename U>
361  explicit Allocator(Allocator<U> const&) {}
362 
363  // address
364  pointer address(reference r) { return &r; }
366 
367  pointer allocate(size_type count, const void* =0)
368  { return reinterpret_cast<pointer>(fastMalloc(count * sizeof (_Tp))); }
369 
371 
372  size_type max_size() const
373  { return max(static_cast<_Tp>(-1)/sizeof(_Tp), 1); }
374 
375  void construct(pointer p, const _Tp& v) { new(static_cast<void*>(p)) _Tp(v); }
376  void destroy(pointer p) { p->~_Tp(); }
377 };
378 
380 
387 template<typename _Tp> class CV_EXPORTS DataDepth {};
388 
389 template<> class DataDepth<bool> { public: enum { value = CV_8U, fmt=(int)'u' }; };
390 template<> class DataDepth<uchar> { public: enum { value = CV_8U, fmt=(int)'u' }; };
391 template<> class DataDepth<schar> { public: enum { value = CV_8S, fmt=(int)'c' }; };
392 template<> class DataDepth<char> { public: enum { value = CV_8S, fmt=(int)'c' }; };
393 template<> class DataDepth<ushort> { public: enum { value = CV_16U, fmt=(int)'w' }; };
394 template<> class DataDepth<short> { public: enum { value = CV_16S, fmt=(int)'s' }; };
395 template<> class DataDepth<int> { public: enum { value = CV_32S, fmt=(int)'i' }; };
396 // this is temporary solution to support 32-bit unsigned integers
397 template<> class DataDepth<unsigned> { public: enum { value = CV_32S, fmt=(int)'i' }; };
398 template<> class DataDepth<float> { public: enum { value = CV_32F, fmt=(int)'f' }; };
399 template<> class DataDepth<double> { public: enum { value = CV_64F, fmt=(int)'d' }; };
400 template<typename _Tp> class DataDepth<_Tp*> { public: enum { value = CV_USRTYPE1, fmt=(int)'r' }; };
401 
402 
404 
427 
428 template<typename _Tp, int m, int n> class CV_EXPORTS Matx
429 {
430 public:
431  typedef _Tp value_type;
434  enum { depth = DataDepth<_Tp>::value, rows = m, cols = n, channels = rows*cols,
435  type = CV_MAKETYPE(depth, channels) };
436 
438  Matx();
439 
440  Matx(_Tp v0);
441  Matx(_Tp v0, _Tp v1);
442  Matx(_Tp v0, _Tp v1, _Tp v2);
443  Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3);
444  Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4);
445  Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5);
446  Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6);
447  Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7);
448  Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8);
449  Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8, _Tp v9);
450  Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3,
451  _Tp v4, _Tp v5, _Tp v6, _Tp v7,
452  _Tp v8, _Tp v9, _Tp v10, _Tp v11);
453  Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3,
454  _Tp v4, _Tp v5, _Tp v6, _Tp v7,
455  _Tp v8, _Tp v9, _Tp v10, _Tp v11,
456  _Tp v12, _Tp v13, _Tp v14, _Tp v15);
457  explicit Matx(const _Tp* vals);
458 
459  static Matx all(_Tp alpha);
460  static Matx zeros();
461  static Matx ones();
462  static Matx eye();
463  static Matx diag(const diag_type& d);
464  static Matx randu(_Tp a, _Tp b);
465  static Matx randn(_Tp a, _Tp b);
466 
468  _Tp dot(const Matx<_Tp, m, n>& v) const;
469 
471  double ddot(const Matx<_Tp, m, n>& v) const;
472 
474  template<typename T2> operator Matx<T2, m, n>() const;
475 
477  template<int m1, int n1> Matx<_Tp, m1, n1> reshape() const;
478 
480  template<int m1, int n1> Matx<_Tp, m1, n1> get_minor(int i, int j) const;
481 
483  Matx<_Tp, 1, n> row(int i) const;
484 
486  Matx<_Tp, m, 1> col(int i) const;
487 
489  Matx<_Tp, MIN(m,n), 1> diag() const;
490 
492  Matx<_Tp, n, m> t() const;
493 
495  Matx<_Tp, n, m> inv(int method=DECOMP_LU) const;
496 
498  template<int l> Matx<_Tp, n, l> solve(const Matx<_Tp, m, l>& rhs, int flags=DECOMP_LU) const;
499  Matx<_Tp, n, 1> solve(const Matx<_Tp, m, 1>& rhs, int method) const;
500 
502  Matx<_Tp, m, n> mul(const Matx<_Tp, m, n>& a) const;
503 
505  const _Tp& operator ()(int i, int j) const;
506  _Tp& operator ()(int i, int j);
507 
509  const _Tp& operator ()(int i) const;
510  _Tp& operator ()(int i);
511 
512  Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_AddOp);
513  Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_SubOp);
514  template<typename _T2> Matx(const Matx<_Tp, m, n>& a, _T2 alpha, Matx_ScaleOp);
515  Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_MulOp);
516  template<int l> Matx(const Matx<_Tp, m, l>& a, const Matx<_Tp, l, n>& b, Matx_MatMulOp);
517  Matx(const Matx<_Tp, n, m>& a, Matx_TOp);
518 
519  _Tp val[m*n]; //< matrix elements
520 };
521 
522 
531 
540 
547 
550 
555 
560 
561 
577 template<typename _Tp, int cn> class CV_EXPORTS Vec : public Matx<_Tp, cn, 1>
578 {
579 public:
580  typedef _Tp value_type;
581  enum { depth = DataDepth<_Tp>::value, channels = cn, type = CV_MAKETYPE(depth, channels) };
582 
584  Vec();
585 
586  Vec(_Tp v0);
587  Vec(_Tp v0, _Tp v1);
588  Vec(_Tp v0, _Tp v1, _Tp v2);
589  Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3);
590  Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4);
591  Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5);
592  Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6);
593  Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7);
594  Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8);
595  Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8, _Tp v9);
596  explicit Vec(const _Tp* values);
597 
598  Vec(const Vec<_Tp, cn>& v);
599  static Vec all(_Tp alpha);
600 
602  Vec mul(const Vec<_Tp, cn>& v) const;
603 
609  Vec cross(const Vec& v) const;
611  template<typename T2> operator Vec<T2, cn>() const;
613  operator CvScalar() const;
614 
616  const _Tp& operator [](int i) const;
617  _Tp& operator[](int i);
618  const _Tp& operator ()(int i) const;
619  _Tp& operator ()(int i);
620 };
621 
622 
623 /* \typedef
624 
625  Shorter aliases for the most popular specializations of Vec<T,n>
626 */
630 
634 
638 
642 
647 
652 
653 
655 
663 template<typename _Tp> class CV_EXPORTS Complex
664 {
665 public:
666 
668  Complex();
669  Complex( _Tp _re, _Tp _im=0 );
670  Complex( const std::complex<_Tp>& c );
671 
673  template<typename T2> operator Complex<T2>() const;
675  Complex conj() const;
677  operator std::complex<_Tp>() const;
678 
679  _Tp re, im; //< the real and the imaginary parts
680 };
681 
682 
688 
689 
691 
699 template<typename _Tp> class CV_EXPORTS Point_
700 {
701 public:
702  typedef _Tp value_type;
703 
704  // various constructors
705  Point_();
706  Point_(_Tp _x, _Tp _y);
707  Point_(const Point_& pt);
708  Point_(const CvPoint& pt);
709  Point_(const CvPoint2D32f& pt);
710  Point_(const Size_<_Tp>& sz);
711  Point_(const Vec<_Tp, 2>& v);
712 
713  Point_& operator = (const Point_& pt);
715  template<typename _Tp2> operator Point_<_Tp2>() const;
716 
718  operator CvPoint() const;
719  operator CvPoint2D32f() const;
720  operator Vec<_Tp, 2>() const;
721 
723  _Tp dot(const Point_& pt) const;
725  double ddot(const Point_& pt) const;
727  bool inside(const Rect_<_Tp>& r) const;
728 
729  _Tp x, y; //< the point coordinates
730 };
731 
740 template<typename _Tp> class CV_EXPORTS Point3_
741 {
742 public:
743  typedef _Tp value_type;
744 
745  // various constructors
746  Point3_();
747  Point3_(_Tp _x, _Tp _y, _Tp _z);
748  Point3_(const Point3_& pt);
749  explicit Point3_(const Point_<_Tp>& pt);
750  Point3_(const CvPoint3D32f& pt);
751  Point3_(const Vec<_Tp, 3>& v);
752 
753  Point3_& operator = (const Point3_& pt);
755  template<typename _Tp2> operator Point3_<_Tp2>() const;
757  operator CvPoint3D32f() const;
759  operator Vec<_Tp, 3>() const;
760 
762  _Tp dot(const Point3_& pt) const;
764  double ddot(const Point3_& pt) const;
766  Point3_ cross(const Point3_& pt) const;
767 
768  _Tp x, y, z; //< the point coordinates
769 };
770 
772 
779 template<typename _Tp> class CV_EXPORTS Size_
780 {
781 public:
782  typedef _Tp value_type;
783 
785  Size_();
786  Size_(_Tp _width, _Tp _height);
787  Size_(const Size_& sz);
788  Size_(const CvSize& sz);
789  Size_(const CvSize2D32f& sz);
790  Size_(const Point_<_Tp>& pt);
791 
792  Size_& operator = (const Size_& sz);
794  _Tp area() const;
795 
797  template<typename _Tp2> operator Size_<_Tp2>() const;
798 
800  operator CvSize() const;
801  operator CvSize2D32f() const;
802 
803  _Tp width, height; // the width and the height
804 };
805 
807 
814 template<typename _Tp> class CV_EXPORTS Rect_
815 {
816 public:
817  typedef _Tp value_type;
818 
820  Rect_();
821  Rect_(_Tp _x, _Tp _y, _Tp _width, _Tp _height);
822  Rect_(const Rect_& r);
823  Rect_(const CvRect& r);
824  Rect_(const Point_<_Tp>& org, const Size_<_Tp>& sz);
825  Rect_(const Point_<_Tp>& pt1, const Point_<_Tp>& pt2);
826 
827  Rect_& operator = ( const Rect_& r );
829  Point_<_Tp> tl() const;
831  Point_<_Tp> br() const;
832 
834  Size_<_Tp> size() const;
836  _Tp area() const;
837 
839  template<typename _Tp2> operator Rect_<_Tp2>() const;
841  operator CvRect() const;
842 
844  bool contains(const Point_<_Tp>& pt) const;
845 
846  _Tp x, y, width, height; //< the top-left corner, as well as width and height of the rectangle
847 };
848 
849 
856 typedef Point2i Point;
858 typedef Size2i Size;
859 typedef Rect_<int> Rect;
866 
867 
876 {
877 public:
879  RotatedRect();
880  RotatedRect(const Point2f& _center, const Size2f& _size, float _angle);
881  RotatedRect(const CvBox2D& box);
882 
884  void points(Point2f pts[]) const;
886  Rect boundingRect() const;
888  operator CvBox2D() const;
889 
890  Point2f center; //< the rectangle mass center
891  Size2f size; //< width and height of the rectangle
892  float angle; //< the rotation angle. When the angle is 0, 90, 180, 270 etc., the rectangle becomes an up-right rectangle.
893 };
894 
896 
903 template<typename _Tp> class CV_EXPORTS Scalar_ : public Vec<_Tp, 4>
904 {
905 public:
907  Scalar_();
908  Scalar_(_Tp v0, _Tp v1, _Tp v2=0, _Tp v3=0);
909  Scalar_(const CvScalar& s);
910  Scalar_(_Tp v0);
911 
913  static Scalar_<_Tp> all(_Tp v0);
915  operator CvScalar() const;
916 
918  template<typename T2> operator Scalar_<T2>() const;
919 
921  Scalar_<_Tp> mul(const Scalar_<_Tp>& t, double scale=1 ) const;
922 
923  // returns (v0, -v1, -v2, -v3)
924  Scalar_<_Tp> conj() const;
925 
926  // returns true iff v1 == v2 == v3 == 0
927  bool isReal() const;
928 };
929 
931 
932 CV_EXPORTS void scalarToRawData(const Scalar& s, void* buf, int type, int unroll_to=0);
933 
935 
942 {
943 public:
944  Range();
945  Range(int _start, int _end);
946  Range(const CvSlice& slice);
947  int size() const;
948  bool empty() const;
949  static Range all();
950  operator CvSlice() const;
951 
952  int start, end;
953 };
954 
956 
968 template<typename _Tp> class DataType
969 {
970 public:
971  typedef _Tp value_type;
975 
976  enum { generic_type = 1, depth = DataDepth<channel_type>::value, channels = 1,
978  type = CV_MAKETYPE(depth, channels) };
979 };
980 
981 template<> class DataType<bool>
982 {
983 public:
984  typedef bool value_type;
985  typedef int work_type;
988  enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 1,
990  type = CV_MAKETYPE(depth, channels) };
991 };
992 
993 template<> class DataType<uchar>
994 {
995 public:
996  typedef uchar value_type;
997  typedef int work_type;
1000  enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 1,
1002  type = CV_MAKETYPE(depth, channels) };
1003 };
1004 
1005 template<> class DataType<schar>
1006 {
1007 public:
1009  typedef int work_type;
1012  enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 1,
1014  type = CV_MAKETYPE(depth, channels) };
1015 };
1016 
1017 template<> class DataType<char>
1018 {
1019 public:
1021  typedef int work_type;
1024  enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 1,
1026  type = CV_MAKETYPE(depth, channels) };
1027 };
1028 
1029 template<> class DataType<ushort>
1030 {
1031 public:
1033  typedef int work_type;
1036  enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 1,
1038  type = CV_MAKETYPE(depth, channels) };
1039 };
1040 
1041 template<> class DataType<short>
1042 {
1043 public:
1044  typedef short value_type;
1045  typedef int work_type;
1048  enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 1,
1050  type = CV_MAKETYPE(depth, channels) };
1051 };
1052 
1053 template<> class DataType<int>
1054 {
1055 public:
1056  typedef int value_type;
1060  enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 1,
1062  type = CV_MAKETYPE(depth, channels) };
1063 };
1064 
1065 template<> class DataType<float>
1066 {
1067 public:
1068  typedef float value_type;
1072  enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 1,
1074  type = CV_MAKETYPE(depth, channels) };
1075 };
1076 
1077 template<> class DataType<double>
1078 {
1079 public:
1080  typedef double value_type;
1084  enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 1,
1086  type = CV_MAKETYPE(depth, channels) };
1087 };
1088 
1089 template<typename _Tp, int cn> class DataType<Vec<_Tp, cn> >
1090 {
1091 public:
1094  typedef _Tp channel_type;
1096  enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = cn,
1097  fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt,
1098  type = CV_MAKETYPE(depth, channels) };
1099 };
1100 
1101 template<typename _Tp> class DataType<std::complex<_Tp> >
1102 {
1103 public:
1104  typedef std::complex<_Tp> value_type;
1106  typedef _Tp channel_type;
1107  enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 2,
1108  fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt,
1109  type = CV_MAKETYPE(depth, channels) };
1111 };
1112 
1113 template<typename _Tp> class DataType<Complex<_Tp> >
1114 {
1115 public:
1118  typedef _Tp channel_type;
1119  enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 2,
1120  fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt,
1121  type = CV_MAKETYPE(depth, channels) };
1123 };
1124 
1125 template<typename _Tp> class DataType<Point_<_Tp> >
1126 {
1127 public:
1130  typedef _Tp channel_type;
1131  enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 2,
1132  fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt,
1133  type = CV_MAKETYPE(depth, channels) };
1135 };
1136 
1137 template<typename _Tp> class DataType<Point3_<_Tp> >
1138 {
1139 public:
1142  typedef _Tp channel_type;
1143  enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 3,
1144  fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt,
1145  type = CV_MAKETYPE(depth, channels) };
1147 };
1148 
1149 template<typename _Tp> class DataType<Size_<_Tp> >
1150 {
1151 public:
1154  typedef _Tp channel_type;
1155  enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 2,
1156  fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt,
1157  type = CV_MAKETYPE(depth, channels) };
1159 };
1160 
1161 template<typename _Tp> class DataType<Rect_<_Tp> >
1162 {
1163 public:
1166  typedef _Tp channel_type;
1167  enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 4,
1168  fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt,
1169  type = CV_MAKETYPE(depth, channels) };
1171 };
1172 
1173 template<typename _Tp> class DataType<Scalar_<_Tp> >
1174 {
1175 public:
1178  typedef _Tp channel_type;
1179  enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 4,
1180  fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt,
1181  type = CV_MAKETYPE(depth, channels) };
1183 };
1184 
1185 template<> class DataType<Range>
1186 {
1187 public:
1190  typedef int channel_type;
1191  enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 2,
1192  fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt,
1193  type = CV_MAKETYPE(depth, channels) };
1195 };
1196 
1197 
1199 
1221 template<typename _Tp> class CV_EXPORTS Ptr
1222 {
1223 public:
1225  Ptr();
1227  Ptr(_Tp* _obj);
1229  ~Ptr();
1231  Ptr(const Ptr& ptr);
1233  Ptr& operator = (const Ptr& ptr);
1235  void addref();
1237  void release();
1239  void delete_obj();
1241  bool empty() const;
1242 
1243 
1245  _Tp* operator -> ();
1246  const _Tp* operator -> () const;
1247 
1248  operator _Tp* ();
1249  operator const _Tp*() const;
1250 
1251 protected:
1252  _Tp* obj; //< the object pointer.
1253  int* refcount; //< the associated bbbbbbbbbbbbbbbbbb reference counter
1254 };
1255 
1257 
1258 enum { MAGIC_MASK=0xFFFF0000, TYPE_MASK=0x00000FFF, DEPTH_MASK=7 };
1259 
1260 static inline size_t getElemSize(int type) { return CV_ELEM_SIZE(type); }
1261 
1267 {
1268 public:
1270  virtual ~MatAllocator() {}
1271  virtual void allocate(int dims, const int* sizes, int type, int*& refcount,
1272  uchar*& datastart, uchar*& data, size_t* step) = 0;
1273  virtual void deallocate(int* refcount, uchar* datastart, uchar* data) = 0;
1274 };
1275 
1489 {
1490 public:
1492  Mat();
1494  // (_type is CV_8UC1, CV_64FC3, CV_32SC(12) etc.)
1495  Mat(int _rows, int _cols, int _type);
1496  Mat(Size _size, int _type);
1498  Mat(int _rows, int _cols, int _type, const Scalar& _s);
1499  Mat(Size _size, int _type, const Scalar& _s);
1500 
1502  Mat(int _ndims, const int* _sizes, int _type);
1503  Mat(int _ndims, const int* _sizes, int _type, const Scalar& _s);
1504 
1506  Mat(const Mat& m);
1508  Mat(int _rows, int _cols, int _type, void* _data, size_t _step=AUTO_STEP);
1509  Mat(Size _size, int _type, void* _data, size_t _step=AUTO_STEP);
1510  Mat(int _ndims, const int* _sizes, int _type, void* _data, const size_t* _steps=0);
1511 
1513  Mat(const Mat& m, const Range& rowRange, const Range& colRange=Range::all());
1514  Mat(const Mat& m, const Rect& roi);
1515  Mat(const Mat& m, const Range* ranges);
1517  Mat(const CvMat* m, bool copyData=false);
1519  Mat(const CvMatND* m, bool copyData=false);
1521  Mat(const IplImage* img, bool copyData=false);
1523  template<typename _Tp> explicit Mat(const vector<_Tp>& vec, bool copyData=false);
1525  template<typename _Tp, int n> explicit Mat(const Vec<_Tp, n>& vec,
1526  bool copyData=true);
1528  template<typename _Tp, int m, int n> explicit Mat(const Matx<_Tp, m, n>& mtx,
1529  bool copyData=true);
1531  template<typename _Tp> explicit Mat(const Point_<_Tp>& pt, bool copyData=true);
1533  template<typename _Tp> explicit Mat(const Point3_<_Tp>& pt, bool copyData=true);
1535  template<typename _Tp> explicit Mat(const MatCommaInitializer_<_Tp>& commaInitializer);
1537  ~Mat();
1539  Mat& operator = (const Mat& m);
1540  Mat& operator = (const MatExpr& expr);
1541 
1543  Mat row(int y) const;
1545  Mat col(int x) const;
1547  Mat rowRange(int startrow, int endrow) const;
1548  Mat rowRange(const Range& r) const;
1550  Mat colRange(int startcol, int endcol) const;
1551  Mat colRange(const Range& r) const;
1553  // (d=0 - the main diagonal,
1554  // >0 - a diagonal from the lower half,
1555  // <0 - a diagonal from the upper half)
1556  Mat diag(int d=0) const;
1558  static Mat diag(const Mat& d);
1559 
1561  Mat clone() const;
1563  // It calls m.create(this->size(), this->type()).
1564  void copyTo( Mat& m ) const;
1565  template<typename _Tp> void copyTo( vector<_Tp>& v ) const;
1567  void copyTo( Mat& m, const Mat& mask ) const;
1569  void convertTo( Mat& m, int rtype, double alpha=1, double beta=0 ) const;
1570 
1571  void assignTo( Mat& m, int type=-1 ) const;
1572 
1574  Mat& operator = (const Scalar& s);
1576  Mat& setTo(const Scalar& s, const Mat& mask=Mat());
1578  // number of channels and/or different number of rows. see cvReshape.
1579  Mat reshape(int _cn, int _rows=0) const;
1580  Mat reshape(int _cn, int _newndims, const int* _newsz) const;
1581 
1583  MatExpr t() const;
1585  MatExpr inv(int method=DECOMP_LU) const;
1587  MatExpr mul(const Mat& m, double scale=1) const;
1588  MatExpr mul(const MatExpr& m, double scale=1) const;
1589 
1591  Mat cross(const Mat& m) const;
1593  double dot(const Mat& m) const;
1594 
1596  static MatExpr zeros(int rows, int cols, int type);
1597  static MatExpr zeros(Size size, int type);
1598  static MatExpr zeros(int ndims, const int* sz, int type);
1599  static MatExpr ones(int rows, int cols, int type);
1600  static MatExpr ones(Size size, int type);
1601  static MatExpr ones(int ndims, const int* sz, int type);
1602  static MatExpr eye(int rows, int cols, int type);
1603  static MatExpr eye(Size size, int type);
1604 
1606  // previous data is unreferenced if needed.
1607  void create(int _rows, int _cols, int _type);
1608  void create(Size _size, int _type);
1609  void create(int _ndims, const int* _sizes, int _type);
1610 
1612  void addref();
1614  // deallocates the data when reference counter reaches 0.
1615  void release();
1616 
1618  void deallocate();
1620  void copySize(const Mat& m);
1621 
1623  void reserve(size_t sz);
1625  void resize(size_t sz);
1627  void resize(size_t sz, const Scalar& s);
1629  void push_back_(const void* elem);
1631  template<typename _Tp> void push_back(const _Tp& elem);
1632  template<typename _Tp> void push_back(const Mat_<_Tp>& elem);
1633  void push_back(const Mat& m);
1635  void pop_back(size_t nelems=1);
1636 
1638  void locateROI( Size& wholeSize, Point& ofs ) const;
1640  Mat& adjustROI( int dtop, int dbottom, int dleft, int dright );
1642  // (this is a generalized form of row, rowRange etc.)
1643  Mat operator()( Range rowRange, Range colRange ) const;
1644  Mat operator()( const Rect& roi ) const;
1645  Mat operator()( const Range* ranges ) const;
1646 
1648  operator CvMat() const;
1650  operator CvMatND() const;
1652  operator IplImage() const;
1653 
1654  template<typename _Tp> operator vector<_Tp>() const;
1655  template<typename _Tp, int n> operator Vec<_Tp, n>() const;
1656  template<typename _Tp, int m, int n> operator Matx<_Tp, m, n>() const;
1657 
1659  // (i.e. when there are no gaps between successive rows).
1660  // similar to CV_IS_MAT_CONT(cvmat->type)
1661  bool isContinuous() const;
1662 
1664  bool isSubmatrix() const;
1665 
1667  // similar to CV_ELEM_SIZE(cvmat->type)
1668  size_t elemSize() const;
1670  size_t elemSize1() const;
1672  int type() const;
1674  int depth() const;
1676  int channels() const;
1678  size_t step1(int i=0) const;
1680  bool empty() const;
1682  size_t total() const;
1683 
1685  int checkVector(int elemChannels, int depth=-1, bool requireContinuous=true) const;
1686 
1688  uchar* ptr(int i0=0);
1689  const uchar* ptr(int i0=0) const;
1690 
1692  uchar* ptr(int i0, int i1);
1693  const uchar* ptr(int i0, int i1) const;
1694 
1696  uchar* ptr(int i0, int i1, int i2);
1697  const uchar* ptr(int i0, int i1, int i2) const;
1698 
1700  uchar* ptr(const int* idx);
1702  const uchar* ptr(const int* idx) const;
1703 
1704  template<int n> uchar* ptr(const Vec<int, n>& idx);
1705  template<int n> const uchar* ptr(const Vec<int, n>& idx) const;
1706 
1708  template<typename _Tp> _Tp* ptr(int i0=0);
1709  template<typename _Tp> const _Tp* ptr(int i0=0) const;
1710 
1711  template<typename _Tp> _Tp* ptr(int i0, int i1);
1712  template<typename _Tp> const _Tp* ptr(int i0, int i1) const;
1713 
1714  template<typename _Tp> _Tp* ptr(int i0, int i1, int i2);
1715  template<typename _Tp> const _Tp* ptr(int i0, int i1, int i2) const;
1716 
1717  template<typename _Tp> _Tp* ptr(const int* idx);
1718  template<typename _Tp> const _Tp* ptr(const int* idx) const;
1719 
1720  template<typename _Tp, int n> _Tp* ptr(const Vec<int, n>& idx);
1721  template<typename _Tp, int n> const _Tp* ptr(const Vec<int, n>& idx) const;
1722 
1724  template<typename _Tp> _Tp& at(int i0=0);
1725  template<typename _Tp> const _Tp& at(int i0=0) const;
1726 
1727  template<typename _Tp> _Tp& at(int i0, int i1);
1728  template<typename _Tp> const _Tp& at(int i0, int i1) const;
1729 
1730  template<typename _Tp> _Tp& at(int i0, int i1, int i2);
1731  template<typename _Tp> const _Tp& at(int i0, int i1, int i2) const;
1732 
1733  template<typename _Tp> _Tp& at(const int* idx);
1734  template<typename _Tp> const _Tp& at(const int* idx) const;
1735 
1736  template<typename _Tp, int n> _Tp& at(const Vec<int, n>& idx);
1737  template<typename _Tp, int n> const _Tp& at(const Vec<int, n>& idx) const;
1738 
1740  template<typename _Tp> _Tp& at(Point pt);
1741  template<typename _Tp> const _Tp& at(Point pt) const;
1742 
1744  // the iterators take care of skipping gaps in the end of rows (if any)
1745  template<typename _Tp> MatIterator_<_Tp> begin();
1746  template<typename _Tp> MatIterator_<_Tp> end();
1747  template<typename _Tp> MatConstIterator_<_Tp> begin() const;
1748  template<typename _Tp> MatConstIterator_<_Tp> end() const;
1749 
1750  enum { MAGIC_VAL=0x42FF0000, AUTO_STEP=0, CONTINUOUS_FLAG=CV_MAT_CONT_FLAG, SUBMATRIX_FLAG=CV_SUBMAT_FLAG };
1751 
1758  int flags;
1760  int dims;
1762  int rows, cols;
1765 
1767  // when matrix points to user-allocated data, the pointer is NULL
1768  int* refcount;
1769 
1774 
1777 
1779  {
1780  MSize(int* _p);
1781  Size operator()() const;
1782  int operator[](int i) const;
1783  int& operator[](int i);
1784  operator const int*() const;
1785  bool operator == (const MSize& sz) const;
1786  bool operator != (const MSize& sz) const;
1787 
1788  int* p;
1789  };
1790 
1792  {
1793  MStep();
1794  MStep(size_t s);
1795  size_t operator[](int i) const;
1796  size_t& operator[](int i);
1797  operator size_t() const;
1798  MStep& operator = (size_t s);
1799 
1800  size_t* p;
1801  size_t buf[2];
1802  protected:
1803  MStep& operator = (const MStep&);
1804  };
1805 
1808 };
1809 
1810 
1817 {
1818 public:
1819  enum { A=4164903690U, UNIFORM=0, NORMAL=1 };
1820 
1821  RNG();
1822  RNG(uint64 _state);
1824  unsigned next();
1825 
1826  operator uchar();
1827  operator schar();
1828  operator ushort();
1829  operator short();
1830  operator unsigned();
1832  unsigned operator()(unsigned N);
1833  unsigned operator ()();
1834  operator int();
1835  operator float();
1836  operator double();
1838  int uniform(int a, int b);
1840  float uniform(float a, float b);
1842  double uniform(double a, double b);
1843  void fill( Mat& mat, int distType, const Scalar& a, const Scalar& b );
1845  double gaussian(double sigma);
1846 
1848 };
1849 
1850 
1851 
1852 
1857 {
1858 public:
1859  enum
1860  {
1861  COUNT=1,
1862  MAX_ITER=COUNT,
1863  EPS=2
1864  };
1865 
1867  TermCriteria();
1869  TermCriteria(int _type, int _maxCount, double _epsilon);
1871  TermCriteria(const CvTermCriteria& criteria);
1873  operator CvTermCriteria() const;
1874 
1875  int type;
1876  int maxCount; // the maximum number of iterations/elements
1877  double epsilon; // the desired accuracy
1878 };
1879 
1881 CV_EXPORTS void swap(Mat& a, Mat& b);
1882 
1884 CV_EXPORTS Mat cvarrToMat(const CvArr* arr, bool copyData=false,
1885  bool allowND=true, int coiMode=0);
1887 CV_EXPORTS void extractImageCOI(const CvArr* arr, CV_OUT Mat& coiimg, int coi=-1);
1889 CV_EXPORTS void insertImageCOI(const Mat& coiimg, CvArr* arr, int coi=-1);
1890 
1892 CV_EXPORTS_W void add(const Mat& src1, const Mat& src2, CV_OUT Mat& dst, const Mat& mask CV_WRAP_DEFAULT(Mat()));
1894 CV_EXPORTS_W void subtract(const Mat& src1, const Mat& src2, CV_OUT Mat& dst, const Mat& mask CV_WRAP_DEFAULT(Mat()));
1896 CV_EXPORTS void add(const Mat& src1, const Mat& src2, CV_OUT Mat& dst);
1898 CV_EXPORTS void subtract(const Mat& src1, const Mat& src2, CV_OUT Mat& dst);
1900 CV_EXPORTS_W void add(const Mat& src1, const Scalar& src2, CV_OUT Mat& dst, const Mat& mask=Mat());
1902 CV_EXPORTS_W void subtract(const Mat& src1, const Scalar& src2, CV_OUT Mat& dst, const Mat& mask=Mat());
1904 CV_EXPORTS_W void subtract(const Scalar& src1, const Mat& src2, CV_OUT Mat& dst, const Mat& mask=Mat());
1905 
1907 CV_EXPORTS_W void multiply(const Mat& src1, const Mat& src2, CV_OUT Mat& dst, double scale=1);
1909 CV_EXPORTS_W void divide(const Mat& src1, const Mat& src2, CV_OUT Mat& dst, double scale=1);
1911 CV_EXPORTS_W void divide(double scale, const Mat& src2, CV_OUT Mat& dst);
1912 
1914 CV_EXPORTS_W void scaleAdd(const Mat& src1, double alpha, const Mat& src2, CV_OUT Mat& dst);
1916 CV_EXPORTS_W void addWeighted(const Mat& src1, double alpha, const Mat& src2,
1917  double beta, double gamma, CV_OUT Mat& dst);
1919 CV_EXPORTS_W void convertScaleAbs(const Mat& src, CV_OUT Mat& dst, double alpha=1, double beta=0);
1921 CV_EXPORTS_W void LUT(const Mat& src, const Mat& lut, CV_OUT Mat& dst);
1922 
1924 CV_EXPORTS_W Scalar sum(const Mat& src);
1926 CV_EXPORTS_W int countNonZero( const Mat& src );
1927 
1929 CV_EXPORTS Scalar mean(const Mat& src);
1931 CV_EXPORTS_W Scalar mean(const Mat& src, const Mat& mask CV_WRAP_DEFAULT(Mat()));
1933 CV_EXPORTS_W void meanStdDev(const Mat& src, CV_OUT Scalar& mean, CV_OUT Scalar& stddev, const Mat& mask=Mat());
1935 CV_EXPORTS double norm(const Mat& src1, int normType=NORM_L2);
1937 CV_EXPORTS double norm(const Mat& src1, const Mat& src2, int normType=NORM_L2);
1939 CV_EXPORTS_W double norm(const Mat& src1, int normType, const Mat& mask CV_WRAP_DEFAULT(Mat()));
1941 CV_EXPORTS_W double norm(const Mat& src1, const Mat& src2,
1942  int normType, const Mat& mask CV_WRAP_DEFAULT(Mat()));
1944 CV_EXPORTS_W void normalize( const Mat& src, CV_OUT Mat& dst, double alpha=1, double beta=0,
1945  int norm_type=NORM_L2, int rtype=-1, const Mat& mask=Mat());
1946 
1948 CV_EXPORTS_W void minMaxLoc(const Mat& src, CV_OUT double* minVal,
1949  CV_OUT double* maxVal=0, CV_OUT Point* minLoc=0,
1950  CV_OUT Point* maxLoc=0, const Mat& mask=Mat());
1951 CV_EXPORTS void minMaxIdx(const Mat& src, double* minVal, double* maxVal,
1952  int* minIdx=0, int* maxIdx=0, const Mat& mask=Mat());
1953 
1955 CV_EXPORTS_W void reduce(const Mat& src, CV_OUT Mat& dst, int dim, int rtype, int dtype=-1);
1957 CV_EXPORTS void merge(const Mat* mv, size_t count, CV_OUT Mat& dst);
1959 CV_EXPORTS_W void merge(const vector<Mat>& mv, Mat& dst);
1960 
1962 CV_EXPORTS void split(const Mat& src, Mat* mvbegin);
1964 CV_EXPORTS_W void split(const Mat& m, vector<Mat>& mv);
1965 
1967 CV_EXPORTS void mixChannels(const Mat* src, size_t nsrcs, Mat* dst, size_t ndsts,
1968  const int* fromTo, size_t npairs);
1969 CV_EXPORTS void mixChannels(const vector<Mat>& src, vector<Mat>& dst,
1970  const int* fromTo, int npairs);
1971 
1973 CV_EXPORTS_W void flip(const Mat& src, CV_OUT Mat& dst, int flipCode);
1974 
1976 CV_EXPORTS_W void repeat(const Mat& src, int ny, int nx, CV_OUT Mat& dst);
1977 CV_EXPORTS Mat repeat(const Mat& src, int ny, int nx);
1978 
1979 CV_EXPORTS void hconcat(const Mat* src, size_t nsrc, Mat& dst);
1980 CV_EXPORTS void hconcat(const Mat& src1, const Mat& src2, Mat& dst);
1981 CV_EXPORTS_W void hconcat(const vector<Mat>& src, CV_OUT Mat& dst);
1982 
1983 CV_EXPORTS void vconcat(const Mat* src, size_t nsrc, Mat& dst);
1984 CV_EXPORTS void vconcat(const Mat& src1, const Mat& src2, Mat& dst);
1985 CV_EXPORTS_W void vconcat(const vector<Mat>& src, CV_OUT Mat& dst);
1986 
1988 CV_EXPORTS_W void bitwise_and(const Mat& src1, const Mat& src2, CV_OUT Mat& dst, const Mat& mask=Mat());
1990 CV_EXPORTS_W void bitwise_or(const Mat& src1, const Mat& src2, CV_OUT Mat& dst, const Mat& mask=Mat());
1992 CV_EXPORTS_W void bitwise_xor(const Mat& src1, const Mat& src2, CV_OUT Mat& dst, const Mat& mask=Mat());
1994 CV_EXPORTS_W void bitwise_and(const Mat& src1, const Scalar& src2, CV_OUT Mat& dst, const Mat& mask=Mat());
1996 CV_EXPORTS_W void bitwise_or(const Mat& src1, const Scalar& src2, CV_OUT Mat& dst, const Mat& mask=Mat());
1998 CV_EXPORTS_W void bitwise_xor(const Mat& src1, const Scalar& src2, CV_OUT Mat& dst, const Mat& mask=Mat());
2000 CV_EXPORTS_W void bitwise_not(const Mat& src, CV_OUT Mat& dst);
2002 CV_EXPORTS_W void absdiff(const Mat& src1, const Mat& src2, CV_OUT Mat& dst);
2004 CV_EXPORTS_W void absdiff(const Mat& src1, const Scalar& src2, CV_OUT Mat& dst);
2006 CV_EXPORTS_W void inRange(const Mat& src, const Mat& lowerb,
2007  const Mat& upperb, CV_OUT Mat& dst);
2009 CV_EXPORTS_W void inRange(const Mat& src, const Scalar& lowerb,
2010  const Scalar& upperb, CV_OUT Mat& dst);
2012 CV_EXPORTS_W void compare(const Mat& src1, const Mat& src2, CV_OUT Mat& dst, int cmpop);
2014 CV_EXPORTS_W void compare(const Mat& src1, double s, CV_OUT Mat& dst, int cmpop);
2016 CV_EXPORTS_W void min(const Mat& src1, const Mat& src2, CV_OUT Mat& dst);
2018 CV_EXPORTS_W void min(const Mat& src1, double src2, CV_OUT Mat& dst);
2020 CV_EXPORTS_W void max(const Mat& src1, const Mat& src2, CV_OUT Mat& dst);
2022 CV_EXPORTS_W void max(const Mat& src1, double src2, CV_OUT Mat& dst);
2023 
2025 CV_EXPORTS_W void sqrt(const Mat& src, CV_OUT Mat& dst);
2027 CV_EXPORTS_W void pow(const Mat& src, double power, CV_OUT Mat& dst);
2029 CV_EXPORTS_W void exp(const Mat& src, CV_OUT Mat& dst);
2031 CV_EXPORTS_W void log(const Mat& src, CV_OUT Mat& dst);
2033 CV_EXPORTS_W float cubeRoot(float val);
2035 CV_EXPORTS_W float fastAtan2(float y, float x);
2037 CV_EXPORTS_W void polarToCart(const Mat& magnitude, const Mat& angle,
2038  CV_OUT Mat& x, CV_OUT Mat& y, bool angleInDegrees=false);
2040 CV_EXPORTS_W void cartToPolar(const Mat& x, const Mat& y,
2041  CV_OUT Mat& magnitude, CV_OUT Mat& angle,
2042  bool angleInDegrees=false);
2044 CV_EXPORTS_W void phase(const Mat& x, const Mat& y, CV_OUT Mat& angle,
2045  bool angleInDegrees=false);
2047 CV_EXPORTS_W void magnitude(const Mat& x, const Mat& y, CV_OUT Mat& magnitude);
2049 CV_EXPORTS_W bool checkRange(const Mat& a, bool quiet=true, CV_OUT Point* pt=0,
2050  double minVal=-DBL_MAX, double maxVal=DBL_MAX);
2052 CV_EXPORTS_W void gemm(const Mat& src1, const Mat& src2, double alpha,
2053  const Mat& src3, double gamma, CV_OUT Mat& dst, int flags=0);
2055 CV_EXPORTS_W void mulTransposed( const Mat& src, CV_OUT Mat& dst, bool aTa,
2056  const Mat& delta=Mat(),
2057  double scale=1, int rtype=-1 );
2059 CV_EXPORTS_W void transpose(const Mat& src, CV_OUT Mat& dst);
2061 CV_EXPORTS_W void transform(const Mat& src, CV_OUT Mat& dst, const Mat& m );
2063 CV_EXPORTS_W void perspectiveTransform(const Mat& src, CV_OUT Mat& dst, const Mat& m );
2064 
2066 CV_EXPORTS_W void completeSymm(Mat& mtx, bool lowerToUpper=false);
2068 CV_EXPORTS_W void setIdentity(Mat& mtx, const Scalar& s=Scalar(1));
2070 CV_EXPORTS_W double determinant(const Mat& mtx);
2072 CV_EXPORTS_W Scalar trace(const Mat& mtx);
2074 CV_EXPORTS_W double invert(const Mat& src, CV_OUT Mat& dst, int flags=DECOMP_LU);
2076 CV_EXPORTS_W bool solve(const Mat& src1, const Mat& src2, CV_OUT Mat& dst, int flags=DECOMP_LU);
2078 CV_EXPORTS_W void sort(const Mat& src, CV_OUT Mat& dst, int flags);
2080 CV_EXPORTS_W void sortIdx(const Mat& src, CV_OUT Mat& dst, int flags);
2082 CV_EXPORTS_W int solveCubic(const Mat& coeffs, CV_OUT Mat& roots);
2084 CV_EXPORTS_W double solvePoly(const Mat& coeffs, CV_OUT Mat& roots, int maxIters=300);
2086 CV_EXPORTS bool eigen(const Mat& src, CV_OUT Mat& eigenvalues, int lowindex=-1,
2087  int highindex=-1);
2089 CV_EXPORTS bool eigen(const Mat& src, CV_OUT Mat& eigenvalues, CV_OUT Mat& eigenvectors,
2090  int lowindex=-1, int highindex=-1);
2092 CV_EXPORTS void calcCovarMatrix( const Mat* samples, int nsamples, Mat& covar, Mat& mean,
2093  int flags, int ctype=CV_64F);
2095 CV_EXPORTS_W void calcCovarMatrix( const Mat& samples, CV_OUT Mat& covar, CV_OUT Mat& mean,
2096  int flags, int ctype=CV_64F);
2097 
2153 {
2154 public:
2156  PCA();
2158  PCA(const Mat& data, const Mat& mean, int flags, int maxComponents=0);
2160  PCA& operator()(const Mat& data, const Mat& mean, int flags, int maxComponents=0);
2162  Mat project(const Mat& vec) const;
2164  void project(const Mat& vec, CV_OUT Mat& result) const;
2166  Mat backProject(const Mat& vec) const;
2168  void backProject(const Mat& vec, CV_OUT Mat& result) const;
2169 
2173 };
2174 
2189 {
2190 public:
2191  enum { MODIFY_A=1, NO_UV=2, FULL_UV=4 };
2193  SVD();
2195  SVD( const Mat& src, int flags=0 );
2197  SVD& operator ()( const Mat& src, int flags=0 );
2198 
2200  static void compute( const Mat& src, CV_OUT Mat& w, CV_OUT Mat& u, CV_OUT Mat& vt, int flags=0 );
2202  static void compute( const Mat& src, CV_OUT Mat& w, int flags=0 );
2204  static void backSubst( const Mat& w, const Mat& u, const Mat& vt,
2205  const Mat& rhs, CV_OUT Mat& dst );
2206 
2207  template<typename _Tp, int m, int n, int nm> static void compute( const Matx<_Tp, m, n>& a,
2209  template<typename _Tp, int m, int n, int nm> static void compute( const Matx<_Tp, m, n>& a,
2210  Matx<_Tp, nm, 1>& w );
2211  template<typename _Tp, int m, int n, int nm, int nb> static void backSubst( const Matx<_Tp, nm, 1>& w,
2212  const Matx<_Tp, m, nm>& u, const Matx<_Tp, n, nm>& vt, const Matx<_Tp, m, nb>& rhs, Matx<_Tp, n, nb>& dst );
2213 
2215  static void solveZ( const Mat& src, CV_OUT Mat& dst );
2217  void backSubst( const Mat& rhs, CV_OUT Mat& dst ) const;
2218 
2219  Mat u, w, vt;
2220 };
2221 
2223 CV_EXPORTS_W double Mahalanobis(const Mat& v1, const Mat& v2, const Mat& icovar);
2225 CV_EXPORTS double Mahalonobis(const Mat& v1, const Mat& v2, const Mat& icovar);
2226 
2228 CV_EXPORTS_W void dft(const Mat& src, CV_OUT Mat& dst, int flags=0, int nonzeroRows=0);
2230 CV_EXPORTS_W void idft(const Mat& src, CV_OUT Mat& dst, int flags=0, int nonzeroRows=0);
2232 CV_EXPORTS_W void dct(const Mat& src, CV_OUT Mat& dst, int flags=0);
2234 CV_EXPORTS_W void idct(const Mat& src, CV_OUT Mat& dst, int flags=0);
2236 CV_EXPORTS_W void mulSpectrums(const Mat& a, const Mat& b, CV_OUT Mat& c,
2237  int flags, bool conjB=false);
2239 CV_EXPORTS_W int getOptimalDFTSize(int vecsize);
2240 
2244 enum
2245 {
2246  KMEANS_RANDOM_CENTERS=0, // Chooses random centers for k-Means initialization
2247  KMEANS_PP_CENTERS=2, // Uses k-Means++ algorithm for initialization
2248  KMEANS_USE_INITIAL_LABELS=1 // Uses the user-provided labels for K-Means initialization
2249 };
2251 CV_EXPORTS_W double kmeans( const Mat& data, int K, CV_OUT Mat& bestLabels,
2252  TermCriteria criteria, int attempts,
2253  int flags, CV_OUT Mat* centers=0 );
2254 
2256 CV_EXPORTS RNG& theRNG();
2257 
2259 template<typename _Tp> static inline _Tp randu() { return (_Tp)theRNG(); }
2260 
2262 CV_EXPORTS_W void randu(CV_OUT Mat& dst, const Scalar& low, const Scalar& high);
2263 
2265 CV_EXPORTS_W void randn(CV_OUT Mat& dst, const Scalar& mean, const Scalar& stddev);
2266 
2268 CV_EXPORTS void randShuffle(Mat& dst, double iterFactor=1., RNG* rng=0);
2269 
2271 CV_EXPORTS_W void line(Mat& img, Point pt1, Point pt2, const Scalar& color,
2272  int thickness=1, int lineType=8, int shift=0);
2273 
2275 CV_EXPORTS_W void rectangle(Mat& img, Point pt1, Point pt2,
2276  const Scalar& color, int thickness=1,
2277  int lineType=8, int shift=0);
2278 
2280 CV_EXPORTS void rectangle(Mat& img, Rect rec,
2281  const Scalar& color, int thickness=1,
2282  int lineType=8, int shift=0);
2283 
2285 CV_EXPORTS_W void circle(Mat& img, Point center, int radius,
2286  const Scalar& color, int thickness=1,
2287  int lineType=8, int shift=0);
2288 
2290 CV_EXPORTS_W void ellipse(Mat& img, Point center, Size axes,
2291  double angle, double startAngle, double endAngle,
2292  const Scalar& color, int thickness=1,
2293  int lineType=8, int shift=0);
2294 
2296 CV_EXPORTS_W void ellipse(Mat& img, const RotatedRect& box, const Scalar& color,
2297  int thickness=1, int lineType=8);
2298 
2300 CV_EXPORTS void fillConvexPoly(Mat& img, const Point* pts, int npts,
2301  const Scalar& color, int lineType=8,
2302  int shift=0);
2303 
2305 CV_EXPORTS void fillPoly(Mat& img, const Point** pts,
2306  const int* npts, int ncontours,
2307  const Scalar& color, int lineType=8, int shift=0,
2308  Point offset=Point() );
2309 
2311 CV_EXPORTS void polylines(Mat& img, const Point** pts, const int* npts,
2312  int ncontours, bool isClosed, const Scalar& color,
2313  int thickness=1, int lineType=8, int shift=0 );
2314 
2316 CV_EXPORTS bool clipLine(Size imgSize, CV_IN_OUT Point& pt1, CV_IN_OUT Point& pt2);
2317 
2319 CV_EXPORTS_W bool clipLine(Rect imgRect, CV_IN_OUT Point& pt1, CV_IN_OUT Point& pt2);
2320 
2328 {
2329 public:
2331  LineIterator( const Mat& img, Point pt1, Point pt2,
2332  int connectivity=8, bool leftToRight=false );
2334  uchar* operator *();
2336  LineIterator& operator ++();
2338  LineIterator operator ++(int);
2340  Point pos() const;
2341 
2343  const uchar* ptr0;
2344  int step, elemSize;
2345  int err, count;
2346  int minusDelta, plusDelta;
2347  int minusStep, plusStep;
2348 };
2349 
2351 CV_EXPORTS_W void ellipse2Poly( Point center, Size axes, int angle,
2352  int arcStart, int arcEnd, int delta,
2353  CV_OUT vector<Point>& pts );
2354 
2355 enum
2356 {
2366 };
2367 
2369 CV_EXPORTS_W void putText( Mat& img, const string& text, Point org,
2370  int fontFace, double fontScale, Scalar color,
2371  int thickness=1, int linetype=8,
2372  bool bottomLeftOrigin=false );
2373 
2375 CV_EXPORTS_W Size getTextSize(const string& text, int fontFace,
2376  double fontScale, int thickness,
2377  CV_OUT int* baseLine);
2378 
2380 
2426 template<typename _Tp> class CV_EXPORTS Mat_ : public Mat
2427 {
2428 public:
2429  typedef _Tp value_type;
2433 
2435  Mat_();
2437  Mat_(int _rows, int _cols);
2439  Mat_(int _rows, int _cols, const _Tp& value);
2441  explicit Mat_(Size _size);
2443  Mat_(Size _size, const _Tp& value);
2445  Mat_(int _ndims, const int* _sizes);
2447  Mat_(int _ndims, const int* _sizes, const _Tp& value);
2449  Mat_(const Mat& m);
2451  Mat_(const Mat_& m);
2453  Mat_(int _rows, int _cols, _Tp* _data, size_t _step=AUTO_STEP);
2455  Mat_(int _ndims, const int* _sizes, _Tp* _data, const size_t* _steps=0);
2457  Mat_(const Mat_& m, const Range& rowRange, const Range& colRange=Range::all());
2459  Mat_(const Mat_& m, const Rect& roi);
2461  Mat_(const Mat_& m, const Range* ranges);
2463  explicit Mat_(const vector<_Tp>& vec, bool copyData=false);
2464  template<int n> explicit Mat_(const Vec<typename DataType<_Tp>::channel_type, n>& vec, bool copyData=true);
2465  template<int m, int n> explicit Mat_(const Matx<typename DataType<_Tp>::channel_type, m, n>& mtx, bool copyData=true);
2466  explicit Mat_(const Point_<typename DataType<_Tp>::channel_type>& pt, bool copyData=true);
2467  explicit Mat_(const Point3_<typename DataType<_Tp>::channel_type>& pt, bool copyData=true);
2468  explicit Mat_(const MatCommaInitializer_<_Tp>& commaInitializer);
2469 
2470  Mat_& operator = (const Mat& m);
2471  Mat_& operator = (const Mat_& m);
2473  Mat_& operator = (const _Tp& s);
2474 
2476  iterator begin();
2477  iterator end();
2478  const_iterator begin() const;
2479  const_iterator end() const;
2480 
2482  void create(int _rows, int _cols);
2484  void create(Size _size);
2486  void create(int _ndims, const int* _sizes);
2488  Mat_ cross(const Mat_& m) const;
2490  Mat_& operator = (const MatExpr& expr);
2492  template<typename T2> operator Mat_<T2>() const;
2494  Mat_ row(int y) const;
2495  Mat_ col(int x) const;
2496  Mat_ diag(int d=0) const;
2497  Mat_ clone() const;
2498 
2500  size_t elemSize() const;
2501  size_t elemSize1() const;
2502  int type() const;
2503  int depth() const;
2504  int channels() const;
2505  size_t step1(int i=0) const;
2507  size_t stepT(int i=0) const;
2508 
2510  static MatExpr zeros(int rows, int cols);
2511  static MatExpr zeros(Size size);
2512  static MatExpr zeros(int _ndims, const int* _sizes);
2513  static MatExpr ones(int rows, int cols);
2514  static MatExpr ones(Size size);
2515  static MatExpr ones(int _ndims, const int* _sizes);
2516  static MatExpr eye(int rows, int cols);
2517  static MatExpr eye(Size size);
2518 
2520  Mat_ reshape(int _rows) const;
2521  Mat_& adjustROI( int dtop, int dbottom, int dleft, int dright );
2522  Mat_ operator()( const Range& rowRange, const Range& colRange ) const;
2523  Mat_ operator()( const Rect& roi ) const;
2524  Mat_ operator()( const Range* ranges ) const;
2525 
2527  _Tp* operator [](int y);
2528  const _Tp* operator [](int y) const;
2529 
2531  _Tp& operator ()(const int* idx);
2533  const _Tp& operator ()(const int* idx) const;
2534 
2536  template<int n> _Tp& operator ()(const Vec<int, n>& idx);
2538  template<int n> const _Tp& operator ()(const Vec<int, n>& idx) const;
2539 
2541  _Tp& operator ()(int idx0);
2543  const _Tp& operator ()(int idx0) const;
2545  _Tp& operator ()(int idx0, int idx1);
2547  const _Tp& operator ()(int idx0, int idx1) const;
2549  _Tp& operator ()(int idx0, int idx1, int idx2);
2551  const _Tp& operator ()(int idx0, int idx1, int idx2) const;
2552 
2553  _Tp& operator ()(Point pt);
2554  const _Tp& operator ()(Point pt) const;
2555 
2557  operator vector<_Tp>() const;
2559  template<int n> operator Vec<typename DataType<_Tp>::channel_type, n>() const;
2561  template<int m, int n> operator Matx<typename DataType<_Tp>::channel_type, m, n>() const;
2562 };
2563 
2568 
2573 
2578 
2583 
2588 
2593 
2595 
2597 {
2598 public:
2599  typedef uchar* value_type;
2600  typedef ptrdiff_t difference_type;
2601  typedef const uchar** pointer;
2602  typedef uchar* reference;
2603  typedef std::random_access_iterator_tag iterator_category;
2604 
2606  MatConstIterator();
2608  MatConstIterator(const Mat* _m);
2610  MatConstIterator(const Mat* _m, int _row, int _col=0);
2612  MatConstIterator(const Mat* _m, Point _pt);
2614  MatConstIterator(const Mat* _m, const int* _idx);
2617 
2619  MatConstIterator& operator = (const MatConstIterator& it);
2621  uchar* operator *() const;
2623  uchar* operator [](ptrdiff_t i) const;
2624 
2626  MatConstIterator& operator += (ptrdiff_t ofs);
2628  MatConstIterator& operator -= (ptrdiff_t ofs);
2630  MatConstIterator& operator --();
2632  MatConstIterator operator --(int);
2634  MatConstIterator& operator ++();
2636  MatConstIterator operator ++(int);
2638  Point pos() const;
2640  void pos(int* _idx) const;
2641  ptrdiff_t lpos() const;
2642  void seek(ptrdiff_t ofs, bool relative=false);
2643  void seek(const int* _idx, bool relative=false);
2644 
2645  const Mat* m;
2646  size_t elemSize;
2650 };
2651 
2656 template<typename _Tp>
2658 {
2659 public:
2660  typedef _Tp value_type;
2661  typedef ptrdiff_t difference_type;
2662  typedef const _Tp* pointer;
2663  typedef const _Tp& reference;
2664  typedef std::random_access_iterator_tag iterator_category;
2665 
2669  MatConstIterator_(const Mat_<_Tp>* _m);
2671  MatConstIterator_(const Mat_<_Tp>* _m, int _row, int _col=0);
2673  MatConstIterator_(const Mat_<_Tp>* _m, Point _pt);
2675  MatConstIterator_(const Mat_<_Tp>* _m, const int* _idx);
2678 
2680  MatConstIterator_& operator = (const MatConstIterator_& it);
2682  _Tp operator *() const;
2684  _Tp operator [](ptrdiff_t i) const;
2685 
2687  MatConstIterator_& operator += (ptrdiff_t ofs);
2689  MatConstIterator_& operator -= (ptrdiff_t ofs);
2691  MatConstIterator_& operator --();
2693  MatConstIterator_ operator --(int);
2695  MatConstIterator_& operator ++();
2697  MatConstIterator_ operator ++(int);
2699  Point pos() const;
2700 };
2701 
2702 
2707 template<typename _Tp>
2709 {
2710 public:
2711  typedef _Tp* pointer;
2712  typedef _Tp& reference;
2713  typedef std::random_access_iterator_tag iterator_category;
2714 
2716  MatIterator_();
2718  MatIterator_(Mat_<_Tp>* _m);
2720  MatIterator_(Mat_<_Tp>* _m, int _row, int _col=0);
2722  MatIterator_(const Mat_<_Tp>* _m, Point _pt);
2724  MatIterator_(const Mat_<_Tp>* _m, const int* _idx);
2726  MatIterator_(const MatIterator_& it);
2728  MatIterator_& operator = (const MatIterator_<_Tp>& it );
2729 
2731  _Tp& operator *() const;
2733  _Tp& operator [](ptrdiff_t i) const;
2734 
2736  MatIterator_& operator += (ptrdiff_t ofs);
2738  MatIterator_& operator -= (ptrdiff_t ofs);
2740  MatIterator_& operator --();
2742  MatIterator_ operator --(int);
2744  MatIterator_& operator ++();
2746  MatIterator_ operator ++(int);
2747 };
2748 
2749 template<typename _Tp> class CV_EXPORTS MatOp_Iter_;
2750 
2764 template<typename _Tp> class CV_EXPORTS MatCommaInitializer_
2765 {
2766 public:
2770  template<typename T2> MatCommaInitializer_<_Tp>& operator , (T2 v);
2772  Mat_<_Tp> operator *() const;
2773  operator Mat_<_Tp>() const;
2774 protected:
2776 };
2777 
2778 
2779 template<typename _Tp, int m, int n> class CV_EXPORTS MatxCommaInitializer
2780 {
2781 public:
2783  template<typename T2> MatxCommaInitializer<_Tp, m, n>& operator , (T2 val);
2784  Matx<_Tp, m, n> operator *() const;
2785 
2787  int idx;
2788 };
2789 
2790 template<typename _Tp, int m> class CV_EXPORTS VecCommaInitializer : public MatxCommaInitializer<_Tp, m, 1>
2791 {
2792 public:
2794  template<typename T2> VecCommaInitializer<_Tp, m>& operator , (T2 val);
2795  Vec<_Tp, m> operator *() const;
2796 };
2797 
2825 template<typename _Tp, size_t fixed_size=4096/sizeof(_Tp)+8> class CV_EXPORTS AutoBuffer
2826 {
2827 public:
2828  typedef _Tp value_type;
2829 
2831  AutoBuffer();
2833  AutoBuffer(size_t _size);
2835  ~AutoBuffer();
2836 
2838  void allocate(size_t _size);
2840  void deallocate();
2842  operator _Tp* ();
2844  operator const _Tp* () const;
2845 
2846 protected:
2848  _Tp* ptr;
2850  size_t size;
2852  _Tp buf[fixed_size];
2853 };
2854 
2856 
2908 {
2909 public:
2911  NAryMatIterator();
2913  NAryMatIterator(const Mat** arrays, Mat* planes, int narrays=-1);
2915  void init(const Mat** arrays, Mat* planes, int narrays=-1);
2916 
2918  NAryMatIterator& operator ++();
2920  NAryMatIterator operator ++(int);
2921 
2923  const Mat** arrays;
2927  int narrays;
2929  int nplanes;
2930 protected:
2931  int iterdepth, idx;
2932 };
2933 
2934 //typedef NAryMatIterator NAryMatNDIterator;
2935 
2936 typedef void (*ConvertData)(const void* from, void* to, int cn);
2937 typedef void (*ConvertScaleData)(const void* from, void* to, int cn, double alpha, double beta);
2938 
2940 CV_EXPORTS ConvertData getConvertElem(int fromType, int toType);
2942 CV_EXPORTS ConvertScaleData getConvertScaleElem(int fromType, int toType);
2943 
2944 
2946 
2947 class SparseMatIterator;
2949 template<typename _Tp> class SparseMatIterator_;
2950 template<typename _Tp> class SparseMatConstIterator_;
2951 
3038 {
3039 public:
3042 
3045  {
3046  Hdr(int _dims, const int* _sizes, int _type);
3047  void clear();
3049  int dims;
3051  size_t nodeSize;
3052  size_t nodeCount;
3053  size_t freeList;
3054  vector<uchar> pool;
3055  vector<size_t> hashtab;
3056  int size[CV_MAX_DIM];
3057  };
3058 
3061  {
3063  size_t hashval;
3065  size_t next;
3067  int idx[CV_MAX_DIM];
3068  };
3069 
3071  SparseMat();
3073  SparseMat(int dims, const int* _sizes, int _type);
3075  SparseMat(const SparseMat& m);
3077 
3082  SparseMat(const Mat& m);
3084  SparseMat(const CvSparseMat* m);
3086  ~SparseMat();
3087 
3089  SparseMat& operator = (const SparseMat& m);
3091  SparseMat& operator = (const Mat& m);
3092 
3094  SparseMat clone() const;
3095 
3097  void copyTo( SparseMat& m ) const;
3099  void copyTo( Mat& m ) const;
3101  void convertTo( SparseMat& m, int rtype, double alpha=1 ) const;
3103 
3108  void convertTo( Mat& m, int rtype, double alpha=1, double beta=0 ) const;
3109 
3110  // not used now
3111  void assignTo( SparseMat& m, int type=-1 ) const;
3112 
3114 
3119  void create(int dims, const int* _sizes, int _type);
3121  void clear();
3123  void addref();
3124  // decrements the header reference counter. When the counter reaches 0, the header and all the underlying data are deallocated.
3125  void release();
3126 
3128  operator CvSparseMat*() const;
3130  size_t elemSize() const;
3132  size_t elemSize1() const;
3133 
3135  int type() const;
3137  int depth() const;
3139  int channels() const;
3140 
3142  const int* size() const;
3144  int size(int i) const;
3146  int dims() const;
3148  size_t nzcount() const;
3149 
3151  size_t hash(int i0) const;
3153  size_t hash(int i0, int i1) const;
3155  size_t hash(int i0, int i1, int i2) const;
3157  size_t hash(const int* idx) const;
3158 
3160 
3173 
3174  uchar* ptr(int i0, bool createMissing, size_t* hashval=0);
3176  uchar* ptr(int i0, int i1, bool createMissing, size_t* hashval=0);
3178  uchar* ptr(int i0, int i1, int i2, bool createMissing, size_t* hashval=0);
3180  uchar* ptr(const int* idx, bool createMissing, size_t* hashval=0);
3182 
3184 
3191 
3192  template<typename _Tp> _Tp& ref(int i0, size_t* hashval=0);
3194  template<typename _Tp> _Tp& ref(int i0, int i1, size_t* hashval=0);
3196  template<typename _Tp> _Tp& ref(int i0, int i1, int i2, size_t* hashval=0);
3198  template<typename _Tp> _Tp& ref(const int* idx, size_t* hashval=0);
3200 
3202 
3213 
3214  template<typename _Tp> _Tp value(int i0, size_t* hashval=0) const;
3216  template<typename _Tp> _Tp value(int i0, int i1, size_t* hashval=0) const;
3218  template<typename _Tp> _Tp value(int i0, int i1, int i2, size_t* hashval=0) const;
3220  template<typename _Tp> _Tp value(const int* idx, size_t* hashval=0) const;
3222 
3224 
3231 
3232  template<typename _Tp> const _Tp* find(int i0, size_t* hashval=0) const;
3234  template<typename _Tp> const _Tp* find(int i0, int i1, size_t* hashval=0) const;
3236  template<typename _Tp> const _Tp* find(int i0, int i1, int i2, size_t* hashval=0) const;
3238  template<typename _Tp> const _Tp* find(const int* idx, size_t* hashval=0) const;
3239 
3241  void erase(int i0, int i1, size_t* hashval=0);
3243  void erase(int i0, int i1, int i2, size_t* hashval=0);
3245  void erase(const int* idx, size_t* hashval=0);
3246 
3248 
3251 
3252  SparseMatIterator begin();
3254  template<typename _Tp> SparseMatIterator_<_Tp> begin();
3256  SparseMatConstIterator begin() const;
3258  template<typename _Tp> SparseMatConstIterator_<_Tp> begin() const;
3260 
3263 
3264  SparseMatIterator end();
3266  SparseMatConstIterator end() const;
3268  template<typename _Tp> SparseMatIterator_<_Tp> end();
3270  template<typename _Tp> SparseMatConstIterator_<_Tp> end() const;
3271 
3273  template<typename _Tp> _Tp& value(Node* n);
3275  template<typename _Tp> const _Tp& value(const Node* n) const;
3276 
3278  Node* node(size_t nidx);
3279  const Node* node(size_t nidx) const;
3280 
3281  uchar* newNode(const int* idx, size_t hashval);
3282  void removeNode(size_t hidx, size_t nidx, size_t previdx);
3283  void resizeHashTab(size_t newsize);
3284 
3285  enum { MAGIC_VAL=0x42FD0000, MAX_DIM=CV_MAX_DIM, HASH_SCALE=0x5bd1e995, HASH_BIT=0x80000000 };
3286 
3287  int flags;
3289 };
3290 
3292 CV_EXPORTS void minMaxLoc(const SparseMat& a, double* minVal,
3293  double* maxVal, int* minIdx=0, int* maxIdx=0);
3295 CV_EXPORTS double norm( const SparseMat& src, int normType );
3297 CV_EXPORTS void normalize( const SparseMat& src, SparseMat& dst, double alpha, int normType );
3298 
3312 {
3313 public:
3317  SparseMatConstIterator(const SparseMat* _m);
3320 
3322  SparseMatConstIterator& operator = (const SparseMatConstIterator& it);
3323 
3325  template<typename _Tp> const _Tp& value() const;
3327  const SparseMat::Node* node() const;
3328 
3330  SparseMatConstIterator& operator --();
3332  SparseMatConstIterator operator --(int);
3334  SparseMatConstIterator& operator ++();
3336  SparseMatConstIterator operator ++(int);
3337 
3339  void seekEnd();
3340 
3341  const SparseMat* m;
3342  size_t hashidx;
3344 };
3345 
3353 {
3354 public:
3360  SparseMatIterator(SparseMat* _m, const int* idx);
3363 
3365  SparseMatIterator& operator = (const SparseMatIterator& it);
3367  template<typename _Tp> _Tp& value() const;
3369  SparseMat::Node* node() const;
3370 
3372  SparseMatIterator& operator ++();
3374  SparseMatIterator operator ++(int);
3375 };
3376 
3390 template<typename _Tp> class CV_EXPORTS SparseMat_ : public SparseMat
3391 {
3392 public:
3395 
3397  SparseMat_();
3399  SparseMat_(int dims, const int* _sizes);
3401  SparseMat_(const SparseMat& m);
3403  SparseMat_(const SparseMat_& m);
3405  SparseMat_(const Mat& m);
3407  SparseMat_(const CvSparseMat* m);
3409  SparseMat_& operator = (const SparseMat& m);
3411  SparseMat_& operator = (const SparseMat_& m);
3413  SparseMat_& operator = (const Mat& m);
3414 
3416  SparseMat_ clone() const;
3418  void create(int dims, const int* _sizes);
3420  operator CvSparseMat*() const;
3421 
3423  int type() const;
3425  int depth() const;
3427  int channels() const;
3428 
3430  _Tp& ref(int i0, size_t* hashval=0);
3432  _Tp& ref(int i0, int i1, size_t* hashval=0);
3434  _Tp& ref(int i0, int i1, int i2, size_t* hashval=0);
3436  _Tp& ref(const int* idx, size_t* hashval=0);
3437 
3439  _Tp operator()(int i0, size_t* hashval=0) const;
3441  _Tp operator()(int i0, int i1, size_t* hashval=0) const;
3443  _Tp operator()(int i0, int i1, int i2, size_t* hashval=0) const;
3445  _Tp operator()(const int* idx, size_t* hashval=0) const;
3446 
3448  SparseMatIterator_<_Tp> begin();
3450  SparseMatConstIterator_<_Tp> begin() const;
3454  SparseMatConstIterator_<_Tp> end() const;
3455 };
3456 
3457 
3464 template<typename _Tp> class CV_EXPORTS SparseMatConstIterator_ : public SparseMatConstIterator
3465 {
3466 public:
3467  typedef std::forward_iterator_tag iterator_category;
3468 
3475 
3477  SparseMatConstIterator_& operator = (const SparseMatConstIterator_& it);
3479  const _Tp& operator *() const;
3480 
3482  SparseMatConstIterator_& operator ++();
3484  SparseMatConstIterator_ operator ++(int);
3485 };
3486 
3493 template<typename _Tp> class CV_EXPORTS SparseMatIterator_ : public SparseMatConstIterator_<_Tp>
3494 {
3495 public:
3496  typedef std::forward_iterator_tag iterator_category;
3497 
3504 
3506  SparseMatIterator_& operator = (const SparseMatIterator_& it);
3508  _Tp& operator *() const;
3509 
3511  SparseMatIterator_& operator ++();
3513  SparseMatIterator_ operator ++(int);
3514 };
3515 
3517 
3543 {
3544 public:
3548  struct Node
3549  {
3550  Node() : idx(-1), left(-1), right(-1), boundary(0.f) {}
3551  Node(int _idx, int _left, int _right, float _boundary)
3552  : idx(_idx), left(_left), right(_right), boundary(_boundary) {}
3554  int idx;
3556  int left, right;
3558  float boundary;
3559  };
3560 
3562  CV_WRAP KDTree();
3564  CV_WRAP KDTree(const Mat& _points, bool copyAndReorderPoints=false);
3566  CV_WRAP KDTree(const Mat& _points, const Mat& _labels, bool copyAndReorderPoints=false);
3568  CV_WRAP void build(const Mat& _points, bool copyAndReorderPoints=false);
3570  CV_WRAP void build(const Mat& _points, const Mat& _labels, bool copyAndReorderPoints=false);
3572  int findNearest(const float* vec,
3573  int K, int Emax, int* neighborsIdx,
3574  Mat* neighbors=0, float* dist=0, int* labels=0) const;
3576  int findNearest(const float* vec, int K, int Emax,
3577  vector<int>* neighborsIdx,
3578  Mat* neighbors=0,
3579  vector<float>* dist=0,
3580  vector<int>* labels=0) const;
3581  CV_WRAP int findNearest(const vector<float>& vec, int K, int Emax,
3582  CV_OUT vector<int>* neighborsIdx,
3583  CV_OUT Mat* neighbors=0,
3584  CV_OUT vector<float>* dist=0,
3585  CV_OUT vector<int>* labels=0) const;
3587  void findOrthoRange(const float* minBounds, const float* maxBounds,
3588  vector<int>* neighborsIdx, Mat* neighbors=0,
3589  vector<int>* labels=0) const;
3590  CV_WRAP void findOrthoRange(const vector<float>& minBounds, const vector<float>& maxBounds,
3591  CV_OUT vector<int>* neighborsIdx, CV_OUT Mat* neighbors=0,
3592  CV_OUT vector<int>* labels=0) const;
3594  void getPoints(const int* idx, size_t nidx, Mat& pts, vector<int>* labels=0) const;
3596  CV_WRAP void getPoints(const vector<int>& idxs, Mat& pts, CV_OUT vector<int>* labels=0) const;
3598  const float* getPoint(int ptidx, int* label=0) const;
3600  CV_WRAP int dims() const;
3601 
3602  vector<Node> nodes;
3604  CV_PROP vector<int> labels;
3607 };
3608 
3610 
3611 class CV_EXPORTS FileNode;
3612 
3711 {
3712 public:
3714  enum
3715  {
3716  READ=0,
3717  WRITE=1,
3718  APPEND=2
3719  };
3720  enum
3721  {
3722  UNDEFINED=0,
3723  VALUE_EXPECTED=1,
3724  NAME_EXPECTED=2,
3725  INSIDE_MAP=4
3726  };
3728  CV_WRAP FileStorage();
3730  CV_WRAP FileStorage(const string& filename, int flags);
3734  virtual ~FileStorage();
3735 
3737  CV_WRAP virtual bool open(const string& filename, int flags);
3739  CV_WRAP virtual bool isOpened() const;
3741  CV_WRAP virtual void release();
3742 
3744  CV_WRAP FileNode getFirstTopLevelNode() const;
3746  CV_WRAP FileNode root(int streamidx=0) const;
3748  FileNode operator[](const string& nodename) const;
3750  CV_WRAP FileNode operator[](const char* nodename) const;
3751 
3753  CvFileStorage* operator *() { return fs; }
3755  const CvFileStorage* operator *() const { return fs; }
3757  void writeRaw( const string& fmt, const uchar* vec, size_t len );
3759  void writeObj( const string& name, const void* obj );
3760 
3762  static string getDefaultObjectName(const string& filename);
3763 
3765  string elname;
3766  vector<char> structs;
3767  int state;
3768 };
3769 
3771 
3782 class CV_EXPORTS_W_SIMPLE FileNode
3783 {
3784 public:
3786  enum
3787  {
3788  NONE=0,
3789  INT=1,
3790  REAL=2,
3791  FLOAT=REAL,
3792  STR=3,
3793  STRING=STR,
3794  REF=4,
3795  SEQ=5,
3796  MAP=6,
3798  FLOW=8,
3799  USER=16,
3800  EMPTY=32,
3801  NAMED=64
3802  };
3804  CV_WRAP FileNode();
3806  FileNode(const CvFileStorage* fs, const CvFileNode* node);
3808  FileNode(const FileNode& node);
3810  FileNode operator[](const string& nodename) const;
3812  CV_WRAP FileNode operator[](const char* nodename) const;
3814  CV_WRAP FileNode operator[](int i) const;
3816  CV_WRAP int type() const;
3817 
3819  CV_WRAP bool empty() const;
3821  CV_WRAP bool isNone() const;
3823  CV_WRAP bool isSeq() const;
3825  CV_WRAP bool isMap() const;
3827  CV_WRAP bool isInt() const;
3829  CV_WRAP bool isReal() const;
3831  CV_WRAP bool isString() const;
3833  CV_WRAP bool isNamed() const;
3835  CV_WRAP string name() const;
3837  CV_WRAP size_t size() const;
3839  operator int() const;
3841  operator float() const;
3843  operator double() const;
3845  operator string() const;
3846 
3850  const CvFileNode* operator* () const;
3851 
3853  FileNodeIterator begin() const;
3855  FileNodeIterator end() const;
3856 
3858  void readRaw( const string& fmt, uchar* vec, size_t len ) const;
3860  void* readObj() const;
3861 
3862  // do not use wrapper pointer classes for better efficiency
3865 };
3866 
3867 
3873 class CV_EXPORTS FileNodeIterator
3874 {
3875 public:
3877  FileNodeIterator();
3879  FileNodeIterator(const CvFileStorage* fs, const CvFileNode* node, size_t ofs=0);
3881  FileNodeIterator(const FileNodeIterator& it);
3883  FileNode operator *() const;
3885  FileNode operator ->() const;
3886 
3888  FileNodeIterator& operator ++ ();
3890  FileNodeIterator operator ++ (int);
3892  FileNodeIterator& operator -- ();
3894  FileNodeIterator operator -- (int);
3896  FileNodeIterator& operator += (int);
3898  FileNodeIterator& operator -= (int);
3899 
3901  FileNodeIterator& readRaw( const string& fmt, uchar* vec,
3902  size_t maxCount=(size_t)INT_MAX );
3903 
3907  size_t remaining;
3908 };
3909 
3911 
3912 template<typename _Tp> class SeqIterator;
3913 
3915 
3926 template<typename _Tp> class CV_EXPORTS Seq
3927 {
3928 public:
3931 
3933  Seq();
3935  Seq(const CvSeq* seq);
3937  Seq(MemStorage& storage, int headerSize = sizeof(CvSeq));
3939  _Tp& operator [](int idx);
3941  const _Tp& operator[](int idx) const;
3943  SeqIterator<_Tp> begin() const;
3945  SeqIterator<_Tp> end() const;
3947  size_t size() const;
3949  int type() const;
3951  int depth() const;
3953  int channels() const;
3955  size_t elemSize() const;
3957  size_t index(const _Tp& elem) const;
3959  void push_back(const _Tp& elem);
3961  void push_front(const _Tp& elem);
3963  void push_back(const _Tp* elems, size_t count);
3965  void push_front(const _Tp* elems, size_t count);
3967  void insert(int idx, const _Tp& elem);
3969  void insert(int idx, const _Tp* elems, size_t count);
3971  void remove(int idx);
3973  void remove(const Range& r);
3974 
3976  _Tp& front();
3978  const _Tp& front() const;
3980  _Tp& back();
3982  const _Tp& back() const;
3984  bool empty() const;
3985 
3987  void clear();
3989  void pop_front();
3991  void pop_back();
3993  void pop_front(_Tp* elems, size_t count);
3995  void pop_back(_Tp* elems, size_t count);
3996 
3998  void copyTo(vector<_Tp>& vec, const Range& range=Range::all()) const;
4000  operator vector<_Tp>() const;
4001 
4003 };
4004 
4005 
4009 template<typename _Tp> class CV_EXPORTS SeqIterator : public CvSeqReader
4010 {
4011 public:
4013  SeqIterator();
4015  SeqIterator(const Seq<_Tp>& seq, bool seekEnd=false);
4017  void seek(size_t pos);
4019  size_t tell() const;
4021  _Tp& operator *();
4023  const _Tp& operator *() const;
4025  SeqIterator& operator ++();
4027  SeqIterator operator ++(int) const;
4029  SeqIterator& operator --();
4031  SeqIterator operator --(int) const;
4032 
4034  SeqIterator& operator +=(int);
4036  SeqIterator& operator -=(int);
4037 
4038  // this is index of the current element module seq->total*2
4039  // (to distinguish between 0 and seq->total)
4040  int index;
4041 };
4042 
4043 }
4044 
4045 #endif // __cplusplus
4046 
4047 #include "opencv2/core/operations.hpp"
4048 #include "opencv2/core/mat.hpp"
4049 
4050 #endif /*__OPENCV_CORE_HPP__*/