00001 /*M/////////////////////////////////////////////////////////////////////////////////////// 00002 // 00003 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 00004 // 00005 // By downloading, copying, installing or using the software you agree to this license. 00006 // If you do not agree to this license, do not download, install, 00007 // copy or use the software. 00008 // 00009 // 00010 // License Agreement 00011 // For Open Source Computer Vision Library 00012 // 00013 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. 00014 // Copyright (C) 2009, Willow Garage Inc., all rights reserved. 00015 // Third party copyrights are property of their respective owners. 00016 // 00017 // Redistribution and use in source and binary forms, with or without modification, 00018 // are permitted provided that the following conditions are met: 00019 // 00020 // * Redistribution's of source code must retain the above copyright notice, 00021 // this list of conditions and the following disclaimer. 00022 // 00023 // * Redistribution's in binary form must reproduce the above copyright notice, 00024 // this list of conditions and the following disclaimer in the documentation 00025 // and/or other materials provided with the distribution. 00026 // 00027 // * The name of the copyright holders may not be used to endorse or promote products 00028 // derived from this software without specific prior written permission. 00029 // 00030 // This software is provided by the copyright holders and contributors "as is" and 00031 // any express or implied warranties, including, but not limited to, the implied 00032 // warranties of merchantability and fitness for a particular purpose are disclaimed. 00033 // In no event shall the Intel Corporation or contributors be liable for any direct, 00034 // indirect, incidental, special, exemplary, or consequential damages 00035 // (including, but not limited to, procurement of substitute goods or services; 00036 // loss of use, data, or profits; or business interruption) however caused 00037 // and on any theory of liability, whether in contract, strict liability, 00038 // or tort (including negligence or otherwise) arising in any way out of 00039 // the use of this software, even if advised of the possibility of such damage. 00040 // 00041 //M*/ 00042 00043 #ifndef __OPENCV_CORE_HPP__ 00044 #define __OPENCV_CORE_HPP__ 00045 00046 #include "cxmisc.h" 00047 00048 #ifdef __cplusplus 00049 00050 #ifndef SKIP_INCLUDES 00051 #include <algorithm> 00052 #include <cmath> 00053 #include <complex> 00054 #include <map> 00055 #include <new> 00056 #include <string> 00057 #include <vector> 00058 #endif // SKIP_INCLUDES 00059 00060 namespace cv { 00061 00062 #undef abs 00063 #undef min 00064 #undef max 00065 #undef Complex 00066 00067 using std::vector; 00068 using std::string; 00069 00070 template<typename _Tp> class CV_EXPORTS Size_; 00071 template<typename _Tp> class CV_EXPORTS Point_; 00072 template<typename _Tp> class CV_EXPORTS Rect_; 00073 00074 typedef std::string String; 00075 typedef std::basic_string<wchar_t> WString; 00076 00077 CV_EXPORTS string fromUtf16(const WString& str); 00078 CV_EXPORTS WString toUtf16(const string& str); 00079 00080 CV_EXPORTS string format( const char* fmt, ... ); 00081 00082 class CV_EXPORTS Exception : public std::exception 00083 { 00084 public: 00085 Exception() { code = 0; line = 0; } 00086 Exception(int _code, const string& _err, const string& _func, const string& _file, int _line) 00087 : code(_code), err(_err), func(_func), file(_file), line(_line) 00088 { formatMessage(); } 00089 00090 virtual ~Exception() throw() {} 00091 00092 virtual const char *what() const throw() { return msg.c_str(); } 00093 00094 void formatMessage() 00095 { 00096 if( func.size() > 0 ) 00097 msg = format("%s:%d: error: (%d) %s in function %s\n", file.c_str(), line, code, err.c_str(), func.c_str()); 00098 else 00099 msg = format("%s:%d: error: (%d) %s\n", file.c_str(), line, code, err.c_str()); 00100 } 00101 00102 string msg; 00103 00104 int code; 00105 string err; 00106 string func; 00107 string file; 00108 int line; 00109 }; 00110 00111 CV_EXPORTS void error( const Exception& exc ); 00112 CV_EXPORTS bool setBreakOnError(bool value); 00113 CV_EXPORTS CvErrorCallback redirectError( CvErrorCallback errCallback, 00114 void* userdata=0, void** prevUserdata=0); 00115 00116 #ifdef __GNUC__ 00117 #define CV_Error( code, msg ) cv::error( cv::Exception(code, msg, __func__, __FILE__, __LINE__) ) 00118 #define CV_Error_( code, args ) cv::error( cv::Exception(code, cv::format args, __func__, __FILE__, __LINE__) ) 00119 #define CV_Assert( expr ) { if(!(expr)) cv::error( cv::Exception(CV_StsAssert, #expr, __func__, __FILE__, __LINE__) ); } 00120 #else 00121 #define CV_Error( code, msg ) cv::error( cv::Exception(code, msg, "", __FILE__, __LINE__) ) 00122 #define CV_Error_( code, args ) cv::error( cv::Exception(code, cv::format args, "", __FILE__, __LINE__) ) 00123 #define CV_Assert( expr ) { if(!(expr)) cv::error( cv::Exception(CV_StsAssert, #expr, "", __FILE__, __LINE__) ); } 00124 #endif 00125 00126 #ifdef _DEBUG 00127 #define CV_DbgAssert(expr) CV_Assert(expr) 00128 #else 00129 #define CV_DbgAssert(expr) 00130 #endif 00131 00132 CV_EXPORTS void setNumThreads(int); 00133 CV_EXPORTS int getNumThreads(); 00134 CV_EXPORTS int getThreadNum(); 00135 00136 CV_EXPORTS int64 getTickCount(); 00137 CV_EXPORTS double getTickFrequency(); 00138 CV_EXPORTS int64 getCPUTickCount(); 00139 00140 CV_EXPORTS bool checkHardwareSupport(int feature); 00141 00142 CV_EXPORTS void* fastMalloc(size_t); 00143 CV_EXPORTS void fastFree(void* ptr); 00144 00145 template<typename _Tp> static inline _Tp* allocate(size_t n) 00146 { 00147 return new _Tp[n]; 00148 } 00149 00150 template<typename _Tp> static inline void deallocate(_Tp* ptr, size_t) 00151 { 00152 delete[] ptr; 00153 } 00154 00155 template<typename _Tp> static inline _Tp* alignPtr(_Tp* ptr, int n=(int)sizeof(_Tp)) 00156 { 00157 return (_Tp*)(((size_t)ptr + n-1) & -n); 00158 } 00159 00160 static inline size_t alignSize(size_t sz, int n) 00161 { 00162 return (sz + n-1) & -n; 00163 } 00164 00165 CV_EXPORTS void setUseOptimized(bool); 00166 CV_EXPORTS bool useOptimized(); 00167 00168 template<typename _Tp> class CV_EXPORTS Allocator 00169 { 00170 public: 00171 typedef _Tp value_type; 00172 typedef value_type* pointer; 00173 typedef const value_type* const_pointer; 00174 typedef value_type& reference; 00175 typedef const value_type& const_reference; 00176 typedef size_t size_type; 00177 typedef ptrdiff_t difference_type; 00178 template<typename U> class rebind { typedef Allocator<U> other; }; 00179 00180 explicit Allocator() {} 00181 ~Allocator() {} 00182 explicit Allocator(Allocator const&) {} 00183 template<typename U> 00184 explicit Allocator(Allocator<U> const&) {} 00185 00186 // address 00187 pointer address(reference r) { return &r; } 00188 const_pointer address(const_reference r) { return &r; } 00189 00190 pointer allocate(size_type count, const void* =0) 00191 { return reinterpret_cast<pointer>(fastMalloc(count * sizeof (_Tp))); } 00192 00193 void deallocate(pointer p, size_type) {fastFree(p); } 00194 00195 size_type max_size() const 00196 { return max(static_cast<_Tp>(-1)/sizeof(_Tp), 1); } 00197 00198 void construct(pointer p, const _Tp& v) { new(static_cast<void*>(p)) _Tp(v); } 00199 void destroy(pointer p) { p->~_Tp(); } 00200 }; 00201 00203 00204 template<typename _Tp> class CV_EXPORTS DataDepth { public: enum { value = -1, fmt=(int)'\0' }; }; 00205 00206 template<> class DataDepth<bool> { public: enum { value = CV_8U, fmt=(int)'u' }; }; 00207 template<> class DataDepth<uchar> { public: enum { value = CV_8U, fmt=(int)'u' }; }; 00208 template<> class DataDepth<schar> { public: enum { value = CV_8S, fmt=(int)'c' }; }; 00209 template<> class DataDepth<ushort> { public: enum { value = CV_16U, fmt=(int)'w' }; }; 00210 template<> class DataDepth<short> { public: enum { value = CV_16S, fmt=(int)'s' }; }; 00211 template<> class DataDepth<int> { public: enum { value = CV_32S, fmt=(int)'i' }; }; 00212 template<> class DataDepth<float> { public: enum { value = CV_32F, fmt=(int)'f' }; }; 00213 template<> class DataDepth<double> { public: enum { value = CV_64F, fmt=(int)'d' }; }; 00214 template<typename _Tp> class DataDepth<_Tp*> { public: enum { value = CV_USRTYPE1, fmt=(int)'r' }; }; 00215 00216 template<typename _Tp, int cn> class CV_EXPORTS Vec 00217 { 00218 public: 00219 typedef _Tp value_type; 00220 enum { depth = DataDepth<_Tp>::value, channels = cn, type = CV_MAKETYPE(depth, channels) }; 00221 00222 Vec(); 00223 Vec(_Tp v0); 00224 Vec(_Tp v0, _Tp v1); 00225 Vec(_Tp v0, _Tp v1, _Tp v2); 00226 Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3); 00227 Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4); 00228 Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5); 00229 Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6); 00230 Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7); 00231 Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8); 00232 Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8, _Tp v9); 00233 Vec(const Vec<_Tp, cn>& v); 00234 static Vec all(_Tp alpha); 00235 _Tp dot(const Vec& v) const; 00236 double ddot(const Vec& v) const; 00237 Vec cross(const Vec& v) const; 00238 template<typename T2> operator Vec<T2, cn>() const; 00239 operator CvScalar() const; 00240 _Tp operator [](int i) const; 00241 _Tp& operator[](int i); 00242 00243 _Tp val[cn]; 00244 }; 00245 00246 typedef Vec<uchar, 2> Vec2b; 00247 typedef Vec<uchar, 3> Vec3b; 00248 typedef Vec<uchar, 4> Vec4b; 00249 00250 typedef Vec<short, 2> Vec2s; 00251 typedef Vec<short, 3> Vec3s; 00252 typedef Vec<short, 4> Vec4s; 00253 00254 typedef Vec<ushort, 2> Vec2w; 00255 typedef Vec<ushort, 3> Vec3w; 00256 typedef Vec<ushort, 4> Vec4w; 00257 00258 typedef Vec<int, 2> Vec2i; 00259 typedef Vec<int, 3> Vec3i; 00260 typedef Vec<int, 4> Vec4i; 00261 00262 typedef Vec<float, 2> Vec2f; 00263 typedef Vec<float, 3> Vec3f; 00264 typedef Vec<float, 4> Vec4f; 00265 typedef Vec<float, 6> Vec6f; 00266 00267 typedef Vec<double, 2> Vec2d; 00268 typedef Vec<double, 3> Vec3d; 00269 typedef Vec<double, 4> Vec4d; 00270 typedef Vec<double, 6> Vec6d; 00271 00273 00274 template<typename _Tp> class CV_EXPORTS Complex 00275 { 00276 public: 00277 Complex(); 00278 Complex( _Tp _re, _Tp _im=0 ); 00279 Complex( const std::complex<_Tp>& c ); 00280 template<typename T2> operator Complex<T2>() const; 00281 Complex conj() const; 00282 operator std::complex<_Tp>() const; 00283 00284 _Tp re, im; 00285 }; 00286 00287 typedef Complex<float> Complexf; 00288 typedef Complex<double> Complexd; 00289 00291 00292 template<typename _Tp> class CV_EXPORTS Point_ 00293 { 00294 public: 00295 typedef _Tp value_type; 00296 00297 Point_(); 00298 Point_(_Tp _x, _Tp _y); 00299 Point_(const Point_& pt); 00300 Point_(const CvPoint& pt); 00301 Point_(const CvPoint2D32f& pt); 00302 Point_(const Size_<_Tp>& sz); 00303 Point_(const Vec<_Tp, 2>& v); 00304 Point_& operator = (const Point_& pt); 00305 template<typename _Tp2> operator Point_<_Tp2>() const; 00306 operator CvPoint() const; 00307 operator CvPoint2D32f() const; 00308 operator Vec<_Tp, 2>() const; 00309 00310 _Tp dot(const Point_& pt) const; 00311 double ddot(const Point_& pt) const; 00312 bool inside(const Rect_<_Tp>& r) const; 00313 00314 _Tp x, y; 00315 }; 00316 00317 template<typename _Tp> class CV_EXPORTS Point3_ 00318 { 00319 public: 00320 typedef _Tp value_type; 00321 00322 Point3_(); 00323 Point3_(_Tp _x, _Tp _y, _Tp _z); 00324 Point3_(const Point3_& pt); 00325 explicit Point3_(const Point_<_Tp>& pt); 00326 Point3_(const CvPoint3D32f& pt); 00327 Point3_(const Vec<_Tp, 3>& v); 00328 Point3_& operator = (const Point3_& pt); 00329 template<typename _Tp2> operator Point3_<_Tp2>() const; 00330 operator CvPoint3D32f() const; 00331 operator Vec<_Tp, 3>() const; 00332 00333 _Tp dot(const Point3_& pt) const; 00334 double ddot(const Point3_& pt) const; 00335 00336 _Tp x, y, z; 00337 }; 00338 00340 00341 template<typename _Tp> class CV_EXPORTS Size_ 00342 { 00343 public: 00344 typedef _Tp value_type; 00345 00346 Size_(); 00347 Size_(_Tp _width, _Tp _height); 00348 Size_(const Size_& sz); 00349 Size_(const CvSize& sz); 00350 Size_(const CvSize2D32f& sz); 00351 Size_(const Point_<_Tp>& pt); 00352 Size_& operator = (const Size_& sz); 00353 _Tp area() const; 00354 00355 template<typename _Tp2> operator Size_<_Tp2>() const; 00356 operator CvSize() const; 00357 operator CvSize2D32f() const; 00358 00359 _Tp width, height; 00360 }; 00361 00363 00364 template<typename _Tp> class CV_EXPORTS Rect_ 00365 { 00366 public: 00367 typedef _Tp value_type; 00368 00369 Rect_(); 00370 Rect_(_Tp _x, _Tp _y, _Tp _width, _Tp _height); 00371 Rect_(const Rect_& r); 00372 Rect_(const CvRect& r); 00373 Rect_(const Point_<_Tp>& org, const Size_<_Tp>& sz); 00374 Rect_(const Point_<_Tp>& pt1, const Point_<_Tp>& pt2); 00375 Rect_& operator = ( const Rect_& r ); 00376 Point_<_Tp> tl() const; 00377 Point_<_Tp> br() const; 00378 00379 Size_<_Tp> size() const; 00380 _Tp area() const; 00381 00382 template<typename _Tp2> operator Rect_<_Tp2>() const; 00383 operator CvRect() const; 00384 00385 bool contains(const Point_<_Tp>& pt) const; 00386 00387 _Tp x, y, width, height; 00388 }; 00389 00390 typedef Point_<int> Point2i; 00391 typedef Point2i Point; 00392 typedef Size_<int> Size2i; 00393 typedef Size2i Size; 00394 typedef Rect_<int> Rect; 00395 typedef Point_<float> Point2f; 00396 typedef Point_<double> Point2d; 00397 typedef Size_<float> Size2f; 00398 typedef Point3_<int> Point3i; 00399 typedef Point3_<float> Point3f; 00400 typedef Point3_<double> Point3d; 00401 00402 class CV_EXPORTS RotatedRect 00403 { 00404 public: 00405 RotatedRect(); 00406 RotatedRect(const Point2f& _center, const Size2f& _size, float _angle); 00407 RotatedRect(const CvBox2D& box); 00408 void points(Point2f pts[]) const; 00409 Rect boundingRect() const; 00410 operator CvBox2D() const; 00411 Point2f center; 00412 Size2f size; 00413 float angle; 00414 }; 00415 00417 00418 template<typename _Tp> class CV_EXPORTS Scalar_ : public Vec<_Tp, 4> 00419 { 00420 public: 00421 Scalar_(); 00422 Scalar_(_Tp v0, _Tp v1, _Tp v2=0, _Tp v3=0); 00423 Scalar_(const CvScalar& s); 00424 Scalar_(_Tp v0); 00425 static Scalar_<_Tp> all(_Tp v0); 00426 operator CvScalar() const; 00427 00428 template<typename T2> operator Scalar_<T2>() const; 00429 00430 Scalar_<_Tp> mul(const Scalar_<_Tp>& t, double scale=1 ) const; 00431 template<typename T2> void convertTo(T2* buf, int channels, int unroll_to=0) const; 00432 }; 00433 00434 typedef Scalar_<double> Scalar; 00435 00437 00438 class CV_EXPORTS Range 00439 { 00440 public: 00441 Range(); 00442 Range(int _start, int _end); 00443 Range(const CvSlice& slice); 00444 int size() const; 00445 bool empty() const; 00446 static Range all(); 00447 operator CvSlice() const; 00448 00449 int start, end; 00450 }; 00451 00453 00454 template<typename _Tp> class DataType 00455 { 00456 public: 00457 typedef _Tp value_type; 00458 typedef value_type work_type; 00459 typedef value_type channel_type; 00460 typedef value_type vec_type; 00461 enum { depth = DataDepth<channel_type>::value, channels = 1, 00462 fmt=DataDepth<channel_type>::fmt, 00463 type = CV_MAKETYPE(depth, channels) }; 00464 }; 00465 00466 template<> class DataType<bool> 00467 { 00468 public: 00469 typedef bool value_type; 00470 typedef int work_type; 00471 typedef value_type channel_type; 00472 typedef value_type vec_type; 00473 enum { depth = DataDepth<channel_type>::value, channels = 1, 00474 fmt=DataDepth<channel_type>::fmt, 00475 type = CV_MAKETYPE(depth, channels) }; 00476 }; 00477 00478 template<> class DataType<uchar> 00479 { 00480 public: 00481 typedef uchar value_type; 00482 typedef int work_type; 00483 typedef value_type channel_type; 00484 typedef value_type vec_type; 00485 enum { depth = DataDepth<channel_type>::value, channels = 1, 00486 fmt=DataDepth<channel_type>::fmt, 00487 type = CV_MAKETYPE(depth, channels) }; 00488 }; 00489 00490 template<> class DataType<schar> 00491 { 00492 public: 00493 typedef schar value_type; 00494 typedef int work_type; 00495 typedef value_type channel_type; 00496 typedef value_type vec_type; 00497 enum { depth = DataDepth<channel_type>::value, channels = 1, 00498 fmt=DataDepth<channel_type>::fmt, 00499 type = CV_MAKETYPE(depth, channels) }; 00500 }; 00501 00502 template<> class DataType<ushort> 00503 { 00504 public: 00505 typedef ushort value_type; 00506 typedef int work_type; 00507 typedef value_type channel_type; 00508 typedef value_type vec_type; 00509 enum { depth = DataDepth<channel_type>::value, channels = 1, 00510 fmt=DataDepth<channel_type>::fmt, 00511 type = CV_MAKETYPE(depth, channels) }; 00512 }; 00513 00514 template<> class DataType<short> 00515 { 00516 public: 00517 typedef short value_type; 00518 typedef int work_type; 00519 typedef value_type channel_type; 00520 typedef value_type vec_type; 00521 enum { depth = DataDepth<channel_type>::value, channels = 1, 00522 fmt=DataDepth<channel_type>::fmt, 00523 type = CV_MAKETYPE(depth, channels) }; 00524 }; 00525 00526 template<> class DataType<int> 00527 { 00528 public: 00529 typedef int value_type; 00530 typedef value_type work_type; 00531 typedef value_type channel_type; 00532 typedef value_type vec_type; 00533 enum { depth = DataDepth<channel_type>::value, channels = 1, 00534 fmt=DataDepth<channel_type>::fmt, 00535 type = CV_MAKETYPE(depth, channels) }; 00536 }; 00537 00538 template<> class DataType<float> 00539 { 00540 public: 00541 typedef float value_type; 00542 typedef value_type work_type; 00543 typedef value_type channel_type; 00544 typedef value_type vec_type; 00545 enum { depth = DataDepth<channel_type>::value, channels = 1, 00546 fmt=DataDepth<channel_type>::fmt, 00547 type = CV_MAKETYPE(depth, channels) }; 00548 }; 00549 00550 template<> class DataType<double> 00551 { 00552 public: 00553 typedef double value_type; 00554 typedef value_type work_type; 00555 typedef value_type channel_type; 00556 typedef value_type vec_type; 00557 enum { depth = DataDepth<channel_type>::value, channels = 1, 00558 fmt=DataDepth<channel_type>::fmt, 00559 type = CV_MAKETYPE(depth, channels) }; 00560 }; 00561 00562 template<typename _Tp, int cn> class DataType<Vec<_Tp, cn> > 00563 { 00564 public: 00565 typedef Vec<_Tp, cn> value_type; 00566 typedef Vec<typename DataType<_Tp>::work_type, cn> work_type; 00567 typedef _Tp channel_type; 00568 typedef value_type vec_type; 00569 enum { depth = DataDepth<channel_type>::value, channels = cn, 00570 fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt, 00571 type = CV_MAKETYPE(depth, channels) }; 00572 }; 00573 00574 template<typename _Tp> class DataType<std::complex<_Tp> > 00575 { 00576 public: 00577 typedef std::complex<_Tp> value_type; 00578 typedef value_type work_type; 00579 typedef _Tp channel_type; 00580 enum { depth = DataDepth<channel_type>::value, channels = 2, 00581 fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt, 00582 type = CV_MAKETYPE(depth, channels) }; 00583 typedef Vec<channel_type, channels> vec_type; 00584 }; 00585 00586 template<typename _Tp> class DataType<Complex<_Tp> > 00587 { 00588 public: 00589 typedef Complex<_Tp> value_type; 00590 typedef value_type work_type; 00591 typedef _Tp channel_type; 00592 enum { depth = DataDepth<channel_type>::value, channels = 2, 00593 fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt, 00594 type = CV_MAKETYPE(depth, channels) }; 00595 typedef Vec<channel_type, channels> vec_type; 00596 }; 00597 00598 template<typename _Tp> class DataType<Point_<_Tp> > 00599 { 00600 public: 00601 typedef Point_<_Tp> value_type; 00602 typedef Point_<typename DataType<_Tp>::work_type> work_type; 00603 typedef _Tp channel_type; 00604 enum { depth = DataDepth<channel_type>::value, channels = 2, 00605 fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt, 00606 type = CV_MAKETYPE(depth, channels) }; 00607 typedef Vec<channel_type, channels> vec_type; 00608 }; 00609 00610 template<typename _Tp> class DataType<Point3_<_Tp> > 00611 { 00612 public: 00613 typedef Point3_<_Tp> value_type; 00614 typedef Point3_<typename DataType<_Tp>::work_type> work_type; 00615 typedef _Tp channel_type; 00616 enum { depth = DataDepth<channel_type>::value, channels = 3, 00617 fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt, 00618 type = CV_MAKETYPE(depth, channels) }; 00619 typedef Vec<channel_type, channels> vec_type; 00620 }; 00621 00622 template<typename _Tp> class DataType<Size_<_Tp> > 00623 { 00624 public: 00625 typedef Size_<_Tp> value_type; 00626 typedef Size_<typename DataType<_Tp>::work_type> work_type; 00627 typedef _Tp channel_type; 00628 enum { depth = DataDepth<channel_type>::value, channels = 2, 00629 fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt, 00630 type = CV_MAKETYPE(depth, channels) }; 00631 typedef Vec<channel_type, channels> vec_type; 00632 }; 00633 00634 template<typename _Tp> class DataType<Rect_<_Tp> > 00635 { 00636 public: 00637 typedef Rect_<_Tp> value_type; 00638 typedef Rect_<typename DataType<_Tp>::work_type> work_type; 00639 typedef _Tp channel_type; 00640 enum { depth = DataDepth<channel_type>::value, channels = 4, 00641 fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt, 00642 type = CV_MAKETYPE(depth, channels) }; 00643 typedef Vec<channel_type, channels> vec_type; 00644 }; 00645 00646 template<typename _Tp> class DataType<Scalar_<_Tp> > 00647 { 00648 public: 00649 typedef Scalar_<_Tp> value_type; 00650 typedef Scalar_<typename DataType<_Tp>::work_type> work_type; 00651 typedef _Tp channel_type; 00652 enum { depth = DataDepth<channel_type>::value, channels = 4, 00653 fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt, 00654 type = CV_MAKETYPE(depth, channels) }; 00655 typedef Vec<channel_type, channels> vec_type; 00656 }; 00657 00658 template<> class DataType<Range> 00659 { 00660 public: 00661 typedef Range value_type; 00662 typedef value_type work_type; 00663 typedef int channel_type; 00664 enum { depth = DataDepth<channel_type>::value, channels = 2, 00665 fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt, 00666 type = CV_MAKETYPE(depth, channels) }; 00667 typedef Vec<channel_type, channels> vec_type; 00668 }; 00669 00670 00672 00673 template<typename _Tp> class CV_EXPORTS Ptr 00674 { 00675 public: 00676 Ptr(); 00677 Ptr(_Tp* _obj); 00678 ~Ptr(); 00679 Ptr(const Ptr& ptr); 00680 Ptr& operator = (const Ptr& ptr); 00681 void addref(); 00682 void release(); 00683 void delete_obj(); 00684 bool empty() const; 00685 00686 _Tp* operator -> (); 00687 const _Tp* operator -> () const; 00688 00689 operator _Tp* (); 00690 operator const _Tp*() const; 00691 protected: 00692 _Tp* obj; 00693 int* refcount; 00694 }; 00695 00697 00698 class Mat; 00699 class MatND; 00700 template<typename M> class CV_EXPORTS MatExpr_Base_; 00701 typedef MatExpr_Base_<Mat> MatExpr_Base; 00702 template<typename E, typename M> class MatExpr_; 00703 template<typename A1, typename M, typename Op> class MatExpr_Op1_; 00704 template<typename A1, typename A2, typename M, typename Op> class MatExpr_Op2_; 00705 template<typename A1, typename A2, typename A3, typename M, typename Op> class MatExpr_Op3_; 00706 template<typename A1, typename A2, typename A3, typename A4, 00707 typename M, typename Op> class MatExpr_Op4_; 00708 template<typename A1, typename A2, typename A3, typename A4, 00709 typename A5, typename M, typename Op> class MatExpr_Op5_; 00710 template<typename M> class CV_EXPORTS MatOp_DivRS_; 00711 template<typename M> class CV_EXPORTS MatOp_Inv_; 00712 template<typename M> class CV_EXPORTS MatOp_MulDiv_; 00713 template<typename M> class CV_EXPORTS MatOp_Repeat_; 00714 template<typename M> class CV_EXPORTS MatOp_Set_; 00715 template<typename M> class CV_EXPORTS MatOp_Scale_; 00716 template<typename M> class CV_EXPORTS MatOp_T_; 00717 00718 typedef MatExpr_<MatExpr_Op4_<Size, int, Scalar, 00719 int, Mat, MatOp_Set_<Mat> >, Mat> MatExpr_Initializer; 00720 00721 template<typename _Tp> class MatIterator_; 00722 template<typename _Tp> class MatConstIterator_; 00723 00724 enum { MAGIC_MASK=0xFFFF0000, TYPE_MASK=0x00000FFF, DEPTH_MASK=7 }; 00725 00726 static inline size_t getElemSize(int type) { return CV_ELEM_SIZE(type); } 00727 00728 // matrix decomposition types 00729 enum { DECOMP_LU=0, DECOMP_SVD=1, DECOMP_EIG=2, DECOMP_CHOLESKY=3, DECOMP_QR=4, DECOMP_NORMAL=16 }; 00730 enum { NORM_INF=1, NORM_L1=2, NORM_L2=4, NORM_TYPE_MASK=7, NORM_RELATIVE=8, NORM_MINMAX=32}; 00731 enum { CMP_EQ=0, CMP_GT=1, CMP_GE=2, CMP_LT=3, CMP_LE=4, CMP_NE=5 }; 00732 enum { GEMM_1_T=1, GEMM_2_T=2, GEMM_3_T=4 }; 00733 enum { DFT_INVERSE=1, DFT_SCALE=2, DFT_ROWS=4, DFT_COMPLEX_OUTPUT=16, DFT_REAL_OUTPUT=32, 00734 DCT_INVERSE = DFT_INVERSE, DCT_ROWS=DFT_ROWS }; 00735 00736 class CV_EXPORTS Mat 00737 { 00738 public: 00739 // constructors 00740 Mat(); 00741 // constructs matrix of the specified size and type 00742 // (_type is CV_8UC1, CV_64FC3, CV_32SC(12) etc.) 00743 Mat(int _rows, int _cols, int _type); 00744 Mat(Size _size, int _type); 00745 // constucts matrix and fills it with the specified value _s. 00746 Mat(int _rows, int _cols, int _type, const Scalar& _s); 00747 Mat(Size _size, int _type, const Scalar& _s); 00748 // copy constructor 00749 Mat(const Mat& m); 00750 // constructor for matrix headers pointing to user-allocated data 00751 Mat(int _rows, int _cols, int _type, void* _data, size_t _step=AUTO_STEP); 00752 Mat(Size _size, int _type, void* _data, size_t _step=AUTO_STEP); 00753 // creates a matrix header for a part of the bigger matrix 00754 Mat(const Mat& m, const Range& rowRange, const Range& colRange); 00755 Mat(const Mat& m, const Rect& roi); 00756 // converts old-style CvMat to the new matrix; the data is not copied by default 00757 Mat(const CvMat* m, bool copyData=false); 00758 // converts old-style IplImage to the new matrix; the data is not copied by default 00759 Mat(const IplImage* img, bool copyData=false); 00760 // builds matrix from std::vector with or without copying the data 00761 template<typename _Tp> explicit Mat(const vector<_Tp>& vec, bool copyData=false); 00762 // helper constructor to compile matrix expressions 00763 Mat(const MatExpr_Base& expr); 00764 // destructor - calls release() 00765 ~Mat(); 00766 // assignment operators 00767 Mat& operator = (const Mat& m); 00768 Mat& operator = (const MatExpr_Base& expr); 00769 00770 operator MatExpr_<Mat, Mat>() const; 00771 00772 // returns a new matrix header for the specified row 00773 Mat row(int y) const; 00774 // returns a new matrix header for the specified column 00775 Mat col(int x) const; 00776 // ... for the specified row span 00777 Mat rowRange(int startrow, int endrow) const; 00778 Mat rowRange(const Range& r) const; 00779 // ... for the specified column span 00780 Mat colRange(int startcol, int endcol) const; 00781 Mat colRange(const Range& r) const; 00782 // ... for the specified diagonal 00783 // (d=0 - the main diagonal, 00784 // >0 - a diagonal from the lower half, 00785 // <0 - a diagonal from the upper half) 00786 Mat diag(int d=0) const; 00787 // constructs a square diagonal matrix which main diagonal is vector "d" 00788 static Mat diag(const Mat& d); 00789 00790 // returns deep copy of the matrix, i.e. the data is copied 00791 Mat clone() const; 00792 // copies the matrix content to "m". 00793 // It calls m.create(this->size(), this->type()). 00794 void copyTo( Mat& m ) const; 00795 // copies those matrix elements to "m" that are marked with non-zero mask elements. 00796 void copyTo( Mat& m, const Mat& mask ) const; 00797 // converts matrix to another datatype with optional scalng. See cvConvertScale. 00798 void convertTo( Mat& m, int rtype, double alpha=1, double beta=0 ) const; 00799 00800 void assignTo( Mat& m, int type=-1 ) const; 00801 00802 // sets every matrix element to s 00803 Mat& operator = (const Scalar& s); 00804 // sets some of the matrix elements to s, according to the mask 00805 Mat& setTo(const Scalar& s, const Mat& mask=Mat()); 00806 // creates alternative matrix header for the same data, with different 00807 // number of channels and/or different number of rows. see cvReshape. 00808 Mat reshape(int _cn, int _rows=0) const; 00809 00810 // matrix transposition by means of matrix expressions 00811 MatExpr_<MatExpr_Op2_<Mat, double, Mat, MatOp_T_<Mat> >, Mat> 00812 t() const; 00813 // matrix inversion by means of matrix expressions 00814 MatExpr_<MatExpr_Op2_<Mat, int, Mat, MatOp_Inv_<Mat> >, Mat> 00815 inv(int method=DECOMP_LU) const; 00816 MatExpr_<MatExpr_Op4_<Mat, Mat, double, char, Mat, MatOp_MulDiv_<Mat> >, Mat> 00817 // per-element matrix multiplication by means of matrix expressions 00818 mul(const Mat& m, double scale=1) const; 00819 MatExpr_<MatExpr_Op4_<Mat, Mat, double, char, Mat, MatOp_MulDiv_<Mat> >, Mat> 00820 mul(const MatExpr_<MatExpr_Op2_<Mat, double, Mat, MatOp_Scale_<Mat> >, Mat>& m, double scale=1) const; 00821 MatExpr_<MatExpr_Op4_<Mat, Mat, double, char, Mat, MatOp_MulDiv_<Mat> >, Mat> 00822 mul(const MatExpr_<MatExpr_Op2_<Mat, double, Mat, MatOp_DivRS_<Mat> >, Mat>& m, double scale=1) const; 00823 00824 // computes cross-product of 2 3D vectors 00825 Mat cross(const Mat& m) const; 00826 // computes dot-product 00827 double dot(const Mat& m) const; 00828 00829 // Matlab-style matrix initialization 00830 static MatExpr_Initializer zeros(int rows, int cols, int type); 00831 static MatExpr_Initializer zeros(Size size, int type); 00832 static MatExpr_Initializer ones(int rows, int cols, int type); 00833 static MatExpr_Initializer ones(Size size, int type); 00834 static MatExpr_Initializer eye(int rows, int cols, int type); 00835 static MatExpr_Initializer eye(Size size, int type); 00836 00837 // allocates new matrix data unless the matrix already has specified size and type. 00838 // previous data is unreferenced if needed. 00839 void create(int _rows, int _cols, int _type); 00840 void create(Size _size, int _type); 00841 // increases the reference counter; use with care to avoid memleaks 00842 void addref(); 00843 // decreases reference counter; 00844 // deallocate the data when reference counter reaches 0. 00845 void release(); 00846 00847 // locates matrix header within a parent matrix. See below 00848 void locateROI( Size& wholeSize, Point& ofs ) const; 00849 // moves/resizes the current matrix ROI inside the parent matrix. 00850 Mat& adjustROI( int dtop, int dbottom, int dleft, int dright ); 00851 // extracts a rectangular sub-matrix 00852 // (this is a generalized form of row, rowRange etc.) 00853 Mat operator()( Range rowRange, Range colRange ) const; 00854 Mat operator()( const Rect& roi ) const; 00855 00856 // converts header to CvMat; no data is copied 00857 operator CvMat() const; 00858 // converts header to IplImage; no data is copied 00859 operator IplImage() const; 00860 00861 // returns true iff the matrix data is continuous 00862 // (i.e. when there are no gaps between successive rows). 00863 // similar to CV_IS_MAT_CONT(cvmat->type) 00864 bool isContinuous() const; 00865 // returns element size in bytes, 00866 // similar to CV_ELEM_SIZE(cvmat->type) 00867 size_t elemSize() const; 00868 // returns the size of element channel in bytes. 00869 size_t elemSize1() const; 00870 // returns element type, similar to CV_MAT_TYPE(cvmat->type) 00871 int type() const; 00872 // returns element type, similar to CV_MAT_DEPTH(cvmat->type) 00873 int depth() const; 00874 // returns element type, similar to CV_MAT_CN(cvmat->type) 00875 int channels() const; 00876 // returns step/elemSize1() 00877 size_t step1() const; 00878 // returns matrix size: 00879 // width == number of columns, height == number of rows 00880 Size size() const; 00881 // returns true if matrix data is NULL 00882 bool empty() const; 00883 00884 // returns pointer to y-th row 00885 uchar* ptr(int y=0); 00886 const uchar* ptr(int y=0) const; 00887 00888 // template version of the above method 00889 template<typename _Tp> _Tp* ptr(int y=0); 00890 template<typename _Tp> const _Tp* ptr(int y=0) const; 00891 00892 // template methods for read-write or read-only element access. 00893 // note that _Tp must match the actual matrix type - 00894 // the functions do not do any on-fly type conversion 00895 template<typename _Tp> _Tp& at(int y, int x); 00896 template<typename _Tp> _Tp& at(Point pt); 00897 template<typename _Tp> const _Tp& at(int y, int x) const; 00898 template<typename _Tp> const _Tp& at(Point pt) const; 00899 00900 // template methods for iteration over matrix elements. 00901 // the iterators take care of skipping gaps in the end of rows (if any) 00902 template<typename _Tp> MatIterator_<_Tp> begin(); 00903 template<typename _Tp> MatIterator_<_Tp> end(); 00904 template<typename _Tp> MatConstIterator_<_Tp> begin() const; 00905 template<typename _Tp> MatConstIterator_<_Tp> end() const; 00906 00907 enum { MAGIC_VAL=0x42FF0000, AUTO_STEP=0, CONTINUOUS_FLAG=CV_MAT_CONT_FLAG }; 00908 00909 // includes several bit-fields: 00910 // * the magic signature 00911 // * continuity flag 00912 // * depth 00913 // * number of channels 00914 int flags; 00915 // the number of rows and columns 00916 int rows, cols; 00917 // a distance between successive rows in bytes; includes the gap if any 00918 size_t step; 00919 // pointer to the data 00920 uchar* data; 00921 00922 // pointer to the reference counter; 00923 // when matrix points to user-allocated data, the pointer is NULL 00924 int* refcount; 00925 00926 // helper fields used in locateROI and adjustROI 00927 uchar* datastart; 00928 uchar* dataend; 00929 }; 00930 00931 00932 // Multiply-with-Carry RNG 00933 class CV_EXPORTS RNG 00934 { 00935 public: 00936 enum { A=4164903690U, UNIFORM=0, NORMAL=1 }; 00937 00938 RNG(); 00939 RNG(uint64 _state); 00940 unsigned next(); 00941 00942 operator uchar(); 00943 operator schar(); 00944 operator ushort(); 00945 operator short(); 00946 operator unsigned(); 00948 unsigned operator()(unsigned N); 00949 unsigned operator ()(); 00950 operator int(); 00951 operator float(); 00952 operator double(); 00953 int uniform(int a, int b); 00954 float uniform(float a, float b); 00955 double uniform(double a, double b); 00956 void fill( Mat& mat, int distType, const Scalar& a, const Scalar& b ); 00957 void fill( MatND& mat, int distType, const Scalar& a, const Scalar& b ); 00959 double gaussian(double sigma); 00960 00961 uint64 state; 00962 }; 00963 00964 class CV_EXPORTS TermCriteria 00965 { 00966 public: 00967 enum { COUNT=1, MAX_ITER=COUNT, EPS=2 }; 00968 00969 TermCriteria(); 00970 TermCriteria(int _type, int _maxCount, double _epsilon); 00971 TermCriteria(const CvTermCriteria& criteria); 00972 operator CvTermCriteria() const; 00973 00974 int type; 00975 int maxCount; 00976 double epsilon; 00977 }; 00978 00979 CV_EXPORTS void extractImageCOI(const CvArr* arr, Mat& coiimg, int coi=-1); 00980 CV_EXPORTS void insertImageCOI(const Mat& coiimg, CvArr* arr, int coi=-1); 00981 00982 CV_EXPORTS void add(const Mat& a, const Mat& b, Mat& c, const Mat& mask); 00983 CV_EXPORTS void subtract(const Mat& a, const Mat& b, Mat& c, const Mat& mask); 00984 CV_EXPORTS void add(const Mat& a, const Mat& b, Mat& c); 00985 CV_EXPORTS void subtract(const Mat& a, const Mat& b, Mat& c); 00986 CV_EXPORTS void add(const Mat& a, const Scalar& s, Mat& c, const Mat& mask=Mat()); 00987 CV_EXPORTS void subtract(const Mat& a, const Scalar& s, Mat& c, const Mat& mask=Mat()); 00988 00989 CV_EXPORTS void multiply(const Mat& a, const Mat& b, Mat& c, double scale=1); 00990 CV_EXPORTS void divide(const Mat& a, const Mat& b, Mat& c, double scale=1); 00991 CV_EXPORTS void divide(double scale, const Mat& b, Mat& c); 00992 00993 CV_EXPORTS void subtract(const Scalar& s, const Mat& a, Mat& c, const Mat& mask=Mat()); 00994 CV_EXPORTS void scaleAdd(const Mat& a, double alpha, const Mat& b, Mat& c); 00995 CV_EXPORTS void addWeighted(const Mat& a, double alpha, const Mat& b, 00996 double beta, double gamma, Mat& c); 00997 CV_EXPORTS void convertScaleAbs(const Mat& a, Mat& c, double alpha=1, double beta=0); 00998 CV_EXPORTS void LUT(const Mat& a, const Mat& lut, Mat& b); 00999 01000 CV_EXPORTS Scalar sum(const Mat& m); 01001 CV_EXPORTS int countNonZero( const Mat& m ); 01002 01003 CV_EXPORTS Scalar mean(const Mat& m); 01004 CV_EXPORTS Scalar mean(const Mat& m, const Mat& mask); 01005 CV_EXPORTS void meanStdDev(const Mat& m, Scalar& mean, Scalar& stddev, const Mat& mask=Mat()); 01006 CV_EXPORTS double norm(const Mat& a, int normType=NORM_L2); 01007 CV_EXPORTS double norm(const Mat& a, const Mat& b, int normType=NORM_L2); 01008 CV_EXPORTS double norm(const Mat& a, int normType, const Mat& mask); 01009 CV_EXPORTS double norm(const Mat& a, const Mat& b, 01010 int normType, const Mat& mask); 01011 CV_EXPORTS void normalize( const Mat& a, Mat& b, double alpha=1, double beta=0, 01012 int norm_type=NORM_L2, int rtype=-1, const Mat& mask=Mat()); 01013 01014 CV_EXPORTS void minMaxLoc(const Mat& a, double* minVal, 01015 double* maxVal=0, Point* minLoc=0, 01016 Point* maxLoc=0, const Mat& mask=Mat()); 01017 CV_EXPORTS void reduce(const Mat& m, Mat& dst, int dim, int rtype, int dtype=-1); 01018 CV_EXPORTS void merge(const Mat* mv, size_t count, Mat& dst); 01019 CV_EXPORTS void split(const Mat& m, Mat* mvbegin); 01020 01021 CV_EXPORTS void mixChannels(const Mat* src, int nsrcs, Mat* dst, int ndsts, 01022 const int* fromTo, size_t npairs); 01023 CV_EXPORTS void flip(const Mat& a, Mat& b, int flipCode); 01024 01025 CV_EXPORTS void repeat(const Mat& a, int ny, int nx, Mat& b); 01026 static inline Mat repeat(const Mat& src, int ny, int nx) 01027 { 01028 if( nx == 1 && ny == 1 ) return src; 01029 Mat dst; repeat(src, ny, nx, dst); return dst; 01030 } 01031 01032 CV_EXPORTS void bitwise_and(const Mat& a, const Mat& b, Mat& c, const Mat& mask=Mat()); 01033 CV_EXPORTS void bitwise_or(const Mat& a, const Mat& b, Mat& c, const Mat& mask=Mat()); 01034 CV_EXPORTS void bitwise_xor(const Mat& a, const Mat& b, Mat& c, const Mat& mask=Mat()); 01035 CV_EXPORTS void bitwise_and(const Mat& a, const Scalar& s, Mat& c, const Mat& mask=Mat()); 01036 CV_EXPORTS void bitwise_or(const Mat& a, const Scalar& s, Mat& c, const Mat& mask=Mat()); 01037 CV_EXPORTS void bitwise_xor(const Mat& a, const Scalar& s, Mat& c, const Mat& mask=Mat()); 01038 CV_EXPORTS void bitwise_not(const Mat& a, Mat& c); 01039 CV_EXPORTS void absdiff(const Mat& a, const Mat& b, Mat& c); 01040 CV_EXPORTS void absdiff(const Mat& a, const Scalar& s, Mat& c); 01041 CV_EXPORTS void inRange(const Mat& src, const Mat& lowerb, 01042 const Mat& upperb, Mat& dst); 01043 CV_EXPORTS void inRange(const Mat& src, const Scalar& lowerb, 01044 const Scalar& upperb, Mat& dst); 01045 CV_EXPORTS void compare(const Mat& a, const Mat& b, Mat& c, int cmpop); 01046 CV_EXPORTS void compare(const Mat& a, double s, Mat& c, int cmpop); 01047 CV_EXPORTS void min(const Mat& a, const Mat& b, Mat& c); 01048 CV_EXPORTS void min(const Mat& a, double alpha, Mat& c); 01049 CV_EXPORTS void max(const Mat& a, const Mat& b, Mat& c); 01050 CV_EXPORTS void max(const Mat& a, double alpha, Mat& c); 01051 01052 CV_EXPORTS void sqrt(const Mat& a, Mat& b); 01053 CV_EXPORTS void pow(const Mat& a, double power, Mat& b); 01054 CV_EXPORTS void exp(const Mat& a, Mat& b); 01055 CV_EXPORTS void log(const Mat& a, Mat& b); 01056 CV_EXPORTS float cubeRoot(float val); 01057 CV_EXPORTS float fastAtan2(float y, float x); 01058 CV_EXPORTS void polarToCart(const Mat& magnitude, const Mat& angle, 01059 Mat& x, Mat& y, bool angleInDegrees=false); 01060 CV_EXPORTS void cartToPolar(const Mat& x, const Mat& y, 01061 Mat& magnitude, Mat& angle, 01062 bool angleInDegrees=false); 01063 CV_EXPORTS void phase(const Mat& x, const Mat& y, Mat& angle, 01064 bool angleInDegrees=false); 01065 CV_EXPORTS void magnitude(const Mat& x, const Mat& y, Mat& magnitude); 01066 CV_EXPORTS bool checkRange(const Mat& a, bool quiet=true, Point* pt=0, 01067 double minVal=-DBL_MAX, double maxVal=DBL_MAX); 01068 01069 CV_EXPORTS void gemm(const Mat& a, const Mat& b, double alpha, 01070 const Mat& c, double gamma, Mat& d, int flags=0); 01071 CV_EXPORTS void mulTransposed( const Mat& a, Mat& c, bool aTa, 01072 const Mat& delta=Mat(), 01073 double scale=1, int rtype=-1 ); 01074 CV_EXPORTS void transpose(const Mat& a, Mat& b); 01075 CV_EXPORTS void transform(const Mat& src, Mat& dst, const Mat& m ); 01076 CV_EXPORTS void perspectiveTransform(const Mat& src, Mat& dst, const Mat& m ); 01077 01078 CV_EXPORTS void completeSymm(Mat& a, bool lowerToUpper=false); 01079 CV_EXPORTS void setIdentity(Mat& c, const Scalar& s=Scalar(1)); 01080 CV_EXPORTS double determinant(const Mat& m); 01081 CV_EXPORTS Scalar trace(const Mat& m); 01082 CV_EXPORTS double invert(const Mat& a, Mat& c, int flags=DECOMP_LU); 01083 CV_EXPORTS bool solve(const Mat& a, const Mat& b, Mat& x, int flags=DECOMP_LU); 01084 CV_EXPORTS void sort(const Mat& a, Mat& b, int flags); 01085 CV_EXPORTS void sortIdx(const Mat& a, Mat& b, int flags); 01086 CV_EXPORTS int solveCubic(const Mat& coeffs, Mat& roots); 01087 CV_EXPORTS double solvePoly(const Mat& coeffs, Mat& roots, int maxIters=300); 01088 CV_EXPORTS bool eigen(const Mat& a, Mat& eigenvalues, int lowindex=-1, 01089 int highindex=-1); 01090 CV_EXPORTS bool eigen(const Mat& a, Mat& eigenvalues, Mat& eigenvectors, 01091 int lowindex=-1, int highindex=-1); 01092 01093 CV_EXPORTS void calcCovarMatrix( const Mat* samples, int nsamples, 01094 Mat& covar, Mat& mean, 01095 int flags, int ctype=CV_64F); 01096 CV_EXPORTS void calcCovarMatrix( const Mat& samples, Mat& covar, Mat& mean, 01097 int flags, int ctype=CV_64F); 01098 01099 class CV_EXPORTS PCA 01100 { 01101 public: 01102 PCA(); 01103 PCA(const Mat& data, const Mat& mean, int flags, int maxComponents=0); 01104 PCA& operator()(const Mat& data, const Mat& mean, int flags, int maxComponents=0); 01105 Mat project(const Mat& vec) const; 01106 void project(const Mat& vec, Mat& result) const; 01107 Mat backProject(const Mat& vec) const; 01108 void backProject(const Mat& vec, Mat& result) const; 01109 01110 Mat eigenvectors; 01111 Mat eigenvalues; 01112 Mat mean; 01113 }; 01114 01115 class CV_EXPORTS SVD 01116 { 01117 public: 01118 enum { MODIFY_A=1, NO_UV=2, FULL_UV=4 }; 01119 SVD(); 01120 SVD( const Mat& m, int flags=0 ); 01121 SVD& operator ()( const Mat& m, int flags=0 ); 01122 01123 static void solveZ( const Mat& m, Mat& dst ); 01124 void backSubst( const Mat& rhs, Mat& dst ) const; 01125 01126 Mat u, w, vt; 01127 }; 01128 01129 CV_EXPORTS double Mahalanobis(const Mat& v1, const Mat& v2, const Mat& icovar); 01130 static inline double Mahalonobis(const Mat& v1, const Mat& v2, const Mat& icovar) 01131 { return Mahalanobis(v1, v2, icovar); } 01132 01133 CV_EXPORTS void dft(const Mat& src, Mat& dst, int flags=0, int nonzeroRows=0); 01134 CV_EXPORTS void idft(const Mat& src, Mat& dst, int flags=0, int nonzeroRows=0); 01135 CV_EXPORTS void dct(const Mat& src, Mat& dst, int flags=0); 01136 CV_EXPORTS void idct(const Mat& src, Mat& dst, int flags=0); 01137 CV_EXPORTS void mulSpectrums(const Mat& a, const Mat& b, Mat& c, 01138 int flags, bool conjB=false); 01139 CV_EXPORTS int getOptimalDFTSize(int vecsize); 01140 01141 enum { KMEANS_RANDOM_CENTERS=0, KMEANS_PP_CENTERS=2, KMEANS_USE_INITIAL_LABELS=1 }; 01142 CV_EXPORTS double kmeans( const Mat& data, int K, Mat& best_labels, 01143 TermCriteria criteria, int attempts, 01144 int flags, Mat* centers ); 01145 01146 CV_EXPORTS RNG& theRNG(); 01147 template<typename _Tp> static inline _Tp randu() { return (_Tp)theRNG(); } 01148 01149 static inline void randu(Mat& dst, const Scalar& low, const Scalar& high) 01150 { theRNG().fill(dst, RNG::UNIFORM, low, high); } 01151 static inline void randn(Mat& dst, const Scalar& mean, const Scalar& stddev) 01152 { theRNG().fill(dst, RNG::NORMAL, mean, stddev); } 01153 CV_EXPORTS void randShuffle(Mat& dst, double iterFactor=1., RNG* rng=0); 01154 01155 01156 CV_EXPORTS void line(Mat& img, Point pt1, Point pt2, const Scalar& color, 01157 int thickness=1, int lineType=8, int shift=0); 01158 01159 CV_EXPORTS void rectangle(Mat& img, Point pt1, Point pt2, 01160 const Scalar& color, int thickness=1, 01161 int lineType=8, int shift=0); 01162 01163 CV_EXPORTS void rectangle(Mat& img, Rect rec, 01164 const Scalar& color, int thickness=1, 01165 int lineType=8, int shift=0); 01166 01167 CV_EXPORTS void circle(Mat& img, Point center, int radius, 01168 const Scalar& color, int thickness=1, 01169 int lineType=8, int shift=0); 01170 01171 CV_EXPORTS void ellipse(Mat& img, Point center, Size axes, 01172 double angle, double startAngle, double endAngle, 01173 const Scalar& color, int thickness=1, 01174 int lineType=8, int shift=0); 01175 01176 CV_EXPORTS void ellipse(Mat& img, const RotatedRect& box, const Scalar& color, 01177 int thickness=1, int lineType=8); 01178 01179 CV_EXPORTS void fillConvexPoly(Mat& img, const Point* pts, int npts, 01180 const Scalar& color, int lineType=8, 01181 int shift=0); 01182 01183 CV_EXPORTS void fillPoly(Mat& img, const Point** pts, const int* npts, int ncontours, 01184 const Scalar& color, int lineType=8, int shift=0, 01185 Point offset=Point() ); 01186 01187 CV_EXPORTS void polylines(Mat& img, const Point** pts, const int* npts, int ncontours, bool isClosed, 01188 const Scalar& color, int thickness=1, int lineType=8, int shift=0 ); 01189 01190 CV_EXPORTS bool clipLine(Size imgSize, Point& pt1, Point& pt2); 01191 CV_EXPORTS bool clipLine(Rect img_rect, Point& pt1, Point& pt2); 01192 01193 class CV_EXPORTS LineIterator 01194 { 01195 public: 01196 LineIterator(const Mat& img, Point pt1, Point pt2, 01197 int connectivity=8, bool leftToRight=false); 01198 uchar* operator *(); 01199 LineIterator& operator ++(); 01200 LineIterator operator ++(int); 01201 01202 uchar* ptr; 01203 int err, count; 01204 int minusDelta, plusDelta; 01205 int minusStep, plusStep; 01206 }; 01207 01208 CV_EXPORTS void ellipse2Poly( Point center, Size axes, int angle, 01209 int arcStart, int arcEnd, int delta, vector<Point>& pts ); 01210 01211 enum 01212 { 01213 FONT_HERSHEY_SIMPLEX = 0, 01214 FONT_HERSHEY_PLAIN = 1, 01215 FONT_HERSHEY_DUPLEX = 2, 01216 FONT_HERSHEY_COMPLEX = 3, 01217 FONT_HERSHEY_TRIPLEX = 4, 01218 FONT_HERSHEY_COMPLEX_SMALL = 5, 01219 FONT_HERSHEY_SCRIPT_SIMPLEX = 6, 01220 FONT_HERSHEY_SCRIPT_COMPLEX = 7, 01221 FONT_ITALIC = 16 01222 }; 01223 01224 CV_EXPORTS void putText( Mat& img, const string& text, Point org, 01225 int fontFace, double fontScale, Scalar color, 01226 int thickness=1, int linetype=8, 01227 bool bottomLeftOrigin=false ); 01228 01229 CV_EXPORTS Size getTextSize(const string& text, int fontFace, 01230 double fontScale, int thickness, 01231 int* baseLine); 01232 01234 01235 template<typename _Tp> class CV_EXPORTS Mat_ : public Mat 01236 { 01237 public: 01238 typedef _Tp value_type; 01239 typedef typename DataType<_Tp>::channel_type channel_type; 01240 typedef MatIterator_<_Tp> iterator; 01241 typedef MatConstIterator_<_Tp> const_iterator; 01242 01243 Mat_(); 01244 // equivalent to Mat(_rows, _cols, DataType<_Tp>::type) 01245 Mat_(int _rows, int _cols); 01246 // other forms of the above constructor 01247 Mat_(int _rows, int _cols, const _Tp& value); 01248 explicit Mat_(Size _size); 01249 Mat_(Size _size, const _Tp& value); 01250 // copy/conversion contructor. If m is of different type, it's converted 01251 Mat_(const Mat& m); 01252 // copy constructor 01253 Mat_(const Mat_& m); 01254 // construct a matrix on top of user-allocated data. 01255 // step is in bytes(!!!), regardless of the type 01256 Mat_(int _rows, int _cols, _Tp* _data, size_t _step=AUTO_STEP); 01257 // minor selection 01258 Mat_(const Mat_& m, const Range& rowRange, const Range& colRange); 01259 Mat_(const Mat_& m, const Rect& roi); 01260 // to support complex matrix expressions 01261 Mat_(const MatExpr_Base& expr); 01262 // makes a matrix out of Vec or std::vector. The matrix will have a single column 01263 template<int n> explicit Mat_(const Vec<_Tp, n>& vec); 01264 explicit Mat_(const vector<_Tp>& vec, bool copyData=false); 01265 01266 Mat_& operator = (const Mat& m); 01267 Mat_& operator = (const Mat_& m); 01268 // set all the elements to s. 01269 Mat_& operator = (const _Tp& s); 01270 01271 // iterators; they are smart enough to skip gaps in the end of rows 01272 iterator begin(); 01273 iterator end(); 01274 const_iterator begin() const; 01275 const_iterator end() const; 01276 01277 // equivalent to Mat::create(_rows, _cols, DataType<_Tp>::type) 01278 void create(int _rows, int _cols); 01279 void create(Size _size); 01280 // cross-product 01281 Mat_ cross(const Mat_& m) const; 01282 // to support complex matrix expressions 01283 Mat_& operator = (const MatExpr_Base& expr); 01284 // data type conversion 01285 template<typename T2> operator Mat_<T2>() const; 01286 // overridden forms of Mat::row() etc. 01287 Mat_ row(int y) const; 01288 Mat_ col(int x) const; 01289 Mat_ diag(int d=0) const; 01290 Mat_ clone() const; 01291 01292 // transposition, inversion, per-element multiplication 01293 MatExpr_<MatExpr_Op2_<Mat, double, Mat, MatOp_T_<Mat> >, Mat> t() const; 01294 MatExpr_<MatExpr_Op2_<Mat, int, Mat, MatOp_Inv_<Mat> >, Mat> inv(int method=DECOMP_LU) const; 01295 01296 MatExpr_<MatExpr_Op4_<Mat, Mat, double, char, Mat, MatOp_MulDiv_<Mat> >, Mat> 01297 mul(const Mat_& m, double scale=1) const; 01298 MatExpr_<MatExpr_Op4_<Mat, Mat, double, char, Mat, MatOp_MulDiv_<Mat> >, Mat> 01299 mul(const MatExpr_<MatExpr_Op2_<Mat, double, Mat, 01300 MatOp_Scale_<Mat> >, Mat>& m, double scale=1) const; 01301 MatExpr_<MatExpr_Op4_<Mat, Mat, double, char, Mat, MatOp_MulDiv_<Mat> >, Mat> 01302 mul(const MatExpr_<MatExpr_Op2_<Mat, double, Mat, 01303 MatOp_DivRS_<Mat> >, Mat>& m, double scale=1) const; 01304 01305 // overridden forms of Mat::elemSize() etc. 01306 size_t elemSize() const; 01307 size_t elemSize1() const; 01308 int type() const; 01309 int depth() const; 01310 int channels() const; 01311 size_t step1() const; 01312 // returns step()/sizeof(_Tp) 01313 size_t stepT() const; 01314 01315 // overridden forms of Mat::zeros() etc. Data type is omitted, of course 01316 static MatExpr_Initializer zeros(int rows, int cols); 01317 static MatExpr_Initializer zeros(Size size); 01318 static MatExpr_Initializer ones(int rows, int cols); 01319 static MatExpr_Initializer ones(Size size); 01320 static MatExpr_Initializer eye(int rows, int cols); 01321 static MatExpr_Initializer eye(Size size); 01322 01323 // some more overriden methods 01324 Mat_ reshape(int _rows) const; 01325 Mat_& adjustROI( int dtop, int dbottom, int dleft, int dright ); 01326 Mat_ operator()( const Range& rowRange, const Range& colRange ) const; 01327 Mat_ operator()( const Rect& roi ) const; 01328 01329 // more convenient forms of row and element access operators 01330 _Tp* operator [](int y); 01331 const _Tp* operator [](int y) const; 01332 01333 _Tp& operator ()(int row, int col); 01334 const _Tp& operator ()(int row, int col) const; 01335 _Tp& operator ()(Point pt); 01336 const _Tp& operator ()(Point pt) const; 01337 01338 // to support matrix expressions 01339 operator MatExpr_<Mat, Mat>() const; 01340 01341 // conversion to vector. 01342 operator vector<_Tp>() const; 01343 }; 01344 01345 typedef Mat_<uchar> Mat1b; 01346 typedef Mat_<Vec2b> Mat2b; 01347 typedef Mat_<Vec3b> Mat3b; 01348 typedef Mat_<Vec4b> Mat4b; 01349 01350 typedef Mat_<short> Mat1s; 01351 typedef Mat_<Vec2s> Mat2s; 01352 typedef Mat_<Vec3s> Mat3s; 01353 typedef Mat_<Vec4s> Mat4s; 01354 01355 typedef Mat_<ushort> Mat1w; 01356 typedef Mat_<Vec2w> Mat2w; 01357 typedef Mat_<Vec3w> Mat3w; 01358 typedef Mat_<Vec4w> Mat4w; 01359 01360 typedef Mat_<int> Mat1i; 01361 typedef Mat_<Vec2i> Mat2i; 01362 typedef Mat_<Vec3i> Mat3i; 01363 typedef Mat_<Vec4i> Mat4i; 01364 01365 typedef Mat_<float> Mat1f; 01366 typedef Mat_<Vec2f> Mat2f; 01367 typedef Mat_<Vec3f> Mat3f; 01368 typedef Mat_<Vec4f> Mat4f; 01369 01370 typedef Mat_<double> Mat1d; 01371 typedef Mat_<Vec2d> Mat2d; 01372 typedef Mat_<Vec3d> Mat3d; 01373 typedef Mat_<Vec4d> Mat4d; 01374 01376 01377 template<typename _Tp> 01378 class CV_EXPORTS MatConstIterator_ 01379 { 01380 public: 01381 typedef _Tp value_type; 01382 typedef int difference_type; 01383 01384 MatConstIterator_(); 01385 MatConstIterator_(const Mat_<_Tp>* _m); 01386 MatConstIterator_(const Mat_<_Tp>* _m, int _row, int _col=0); 01387 MatConstIterator_(const Mat_<_Tp>* _m, Point _pt); 01388 MatConstIterator_(const MatConstIterator_& it); 01389 01390 MatConstIterator_& operator = (const MatConstIterator_& it ); 01391 _Tp operator *() const; 01392 _Tp operator [](int i) const; 01393 01394 MatConstIterator_& operator += (int ofs); 01395 MatConstIterator_& operator -= (int ofs); 01396 MatConstIterator_& operator --(); 01397 MatConstIterator_ operator --(int); 01398 MatConstIterator_& operator ++(); 01399 MatConstIterator_ operator ++(int); 01400 Point pos() const; 01401 01402 const Mat_<_Tp>* m; 01403 _Tp* ptr; 01404 _Tp* sliceEnd; 01405 }; 01406 01407 01408 template<typename _Tp> 01409 class CV_EXPORTS MatIterator_ : public MatConstIterator_<_Tp> 01410 { 01411 public: 01412 typedef _Tp* pointer; 01413 typedef _Tp& reference; 01414 typedef std::random_access_iterator_tag iterator_category; 01415 01416 MatIterator_(); 01417 MatIterator_(Mat_<_Tp>* _m); 01418 MatIterator_(Mat_<_Tp>* _m, int _row, int _col=0); 01419 MatIterator_(const Mat_<_Tp>* _m, Point _pt); 01420 MatIterator_(const MatIterator_& it); 01421 MatIterator_& operator = (const MatIterator_<_Tp>& it ); 01422 01423 _Tp& operator *() const; 01424 _Tp& operator [](int i) const; 01425 01426 MatIterator_& operator += (int ofs); 01427 MatIterator_& operator -= (int ofs); 01428 MatIterator_& operator --(); 01429 MatIterator_ operator --(int); 01430 MatIterator_& operator ++(); 01431 MatIterator_ operator ++(int); 01432 }; 01433 01434 template<typename _Tp> class CV_EXPORTS MatOp_Iter_; 01435 01436 template<typename _Tp> class CV_EXPORTS MatCommaInitializer_ : 01437 public MatExpr_<MatExpr_Op1_<MatIterator_<_Tp>, Mat_<_Tp>, MatOp_Iter_<_Tp> >, Mat_<_Tp> > 01438 { 01439 public: 01440 MatCommaInitializer_(Mat_<_Tp>* _m); 01441 template<typename T2> MatCommaInitializer_<_Tp>& operator , (T2 v); 01442 operator Mat_<_Tp>() const; 01443 Mat_<_Tp> operator *() const; 01444 void assignTo(Mat& m, int type=-1) const; 01445 }; 01446 01447 #if 0 01448 template<typename _Tp> class VectorCommaInitializer_ 01449 { 01450 public: 01451 VectorCommaInitializer_(vector<_Tp>* _vec); 01452 template<typename T2> VectorCommaInitializer_<_Tp>& operator , (T2 val); 01453 operator vector<_Tp>() const; 01454 vector<_Tp> operator *() const; 01455 01456 vector<_Tp>* vec; 01457 int idx; 01458 }; 01459 #endif 01460 01461 template<typename _Tp, size_t fixed_size=4096/sizeof(_Tp)+8> class CV_EXPORTS AutoBuffer 01462 { 01463 public: 01464 typedef _Tp value_type; 01465 01466 AutoBuffer(); 01467 AutoBuffer(size_t _size); 01468 ~AutoBuffer(); 01469 01470 void allocate(size_t _size); 01471 void deallocate(); 01472 operator _Tp* (); 01473 operator const _Tp* () const; 01474 01475 protected: 01476 _Tp* ptr; 01477 size_t size; 01478 _Tp buf[fixed_size]; 01479 }; 01480 01482 01483 class MatND; 01484 class SparseMat; 01485 01486 class CV_EXPORTS MatND 01487 { 01488 public: 01489 // default constructor 01490 MatND(); 01491 // constructs array with specific size and data type 01492 MatND(int _ndims, const int* _sizes, int _type); 01493 // constructs array and fills it with the specified value 01494 MatND(int _ndims, const int* _sizes, int _type, const Scalar& _s); 01495 // copy constructor. only the header is copied. 01496 MatND(const MatND& m); 01497 // sub-array selection. only the header is copied 01498 MatND(const MatND& m, const Range* ranges); 01499 // converts 2D matrix to ND matrix 01500 explicit MatND(const Mat& m); 01501 // converts old-style nd array to MatND; optionally, copies the data 01502 MatND(const CvMatND* m, bool copyData=false); 01503 ~MatND(); 01504 MatND& operator = (const MatND& m); 01505 01506 void assignTo( MatND& m, int type ) const; 01507 01508 // creates a complete copy of the matrix (all the data is copied) 01509 MatND clone() const; 01510 // sub-array selection; only the header is copied 01511 MatND operator()(const Range* ranges) const; 01512 01513 // copies the data to another matrix. 01514 // Calls m.create(this->size(), this->type()) prior to 01515 // copying the data 01516 void copyTo( MatND& m ) const; 01517 // copies only the selected elements to another matrix. 01518 void copyTo( MatND& m, const MatND& mask ) const; 01519 // converts data to the specified data type. 01520 // calls m.create(this->size(), rtype) prior to the conversion 01521 void convertTo( MatND& m, int rtype, double alpha=1, double beta=0 ) const; 01522 01523 // assigns "s" to each array element. 01524 MatND& operator = (const Scalar& s); 01525 // assigns "s" to the selected elements of array 01526 // (or to all the elements if mask==MatND()) 01527 MatND& setTo(const Scalar& s, const MatND& mask=MatND()); 01528 // modifies geometry of array without copying the data 01529 MatND reshape(int _newcn, int _newndims=0, const int* _newsz=0) const; 01530 01531 // allocates a new buffer for the data unless the current one already 01532 // has the specified size and type. 01533 void create(int _ndims, const int* _sizes, int _type); 01534 // manually increment reference counter (use with care !!!) 01535 void addref(); 01536 // decrements the reference counter. Dealloctes the data when 01537 // the reference counter reaches zero. 01538 void release(); 01539 01540 // converts the matrix to 2D Mat or to the old-style CvMatND. 01541 // In either case the data is not copied. 01542 operator Mat() const; 01543 operator CvMatND() const; 01544 // returns true if the array data is stored continuously 01545 bool isContinuous() const; 01546 // returns size of each element in bytes 01547 size_t elemSize() const; 01548 // returns size of each element channel in bytes 01549 size_t elemSize1() const; 01550 // returns OpenCV data type id (CV_8UC1, ... CV_64FC4,...) 01551 int type() const; 01552 // returns depth (CV_8U ... CV_64F) 01553 int depth() const; 01554 // returns the number of channels 01555 int channels() const; 01556 // step1() ~ step()/elemSize1() 01557 size_t step1(int i) const; 01558 01559 // return pointer to the element (versions for 1D, 2D, 3D and generic nD cases) 01560 uchar* ptr(int i0); 01561 const uchar* ptr(int i0) const; 01562 uchar* ptr(int i0, int i1); 01563 const uchar* ptr(int i0, int i1) const; 01564 uchar* ptr(int i0, int i1, int i2); 01565 const uchar* ptr(int i0, int i1, int i2) const; 01566 uchar* ptr(const int* idx); 01567 const uchar* ptr(const int* idx) const; 01568 01569 // convenient template methods for element access. 01570 // note that _Tp must match the actual matrix type - 01571 // the functions do not do any on-fly type conversion 01572 template<typename _Tp> _Tp& at(int i0); 01573 template<typename _Tp> const _Tp& at(int i0) const; 01574 template<typename _Tp> _Tp& at(int i0, int i1); 01575 template<typename _Tp> const _Tp& at(int i0, int i1) const; 01576 template<typename _Tp> _Tp& at(int i0, int i1, int i2); 01577 template<typename _Tp> const _Tp& at(int i0, int i1, int i2) const; 01578 template<typename _Tp> _Tp& at(const int* idx); 01579 template<typename _Tp> const _Tp& at(const int* idx) const; 01580 01581 enum { MAGIC_VAL=0x42FE0000, AUTO_STEP=-1, 01582 CONTINUOUS_FLAG=CV_MAT_CONT_FLAG, MAX_DIM=CV_MAX_DIM }; 01583 01584 // combines data type, continuity flag, signature (magic value) 01585 int flags; 01586 // the array dimensionality 01587 int dims; 01588 01589 // data reference counter 01590 int* refcount; 01591 // pointer to the data 01592 uchar* data; 01593 // and its actual beginning and end 01594 uchar* datastart; 01595 uchar* dataend; 01596 01597 // step and size for each dimension, MAX_DIM at max 01598 int size[MAX_DIM]; 01599 size_t step[MAX_DIM]; 01600 }; 01601 01602 class CV_EXPORTS NAryMatNDIterator 01603 { 01604 public: 01605 NAryMatNDIterator(); 01606 NAryMatNDIterator(const MatND* arrays, size_t count); 01607 NAryMatNDIterator(const MatND** arrays, size_t count); 01608 NAryMatNDIterator(const MatND& m1); 01609 NAryMatNDIterator(const MatND& m1, const MatND& m2); 01610 NAryMatNDIterator(const MatND& m1, const MatND& m2, const MatND& m3); 01611 NAryMatNDIterator(const MatND& m1, const MatND& m2, const MatND& m3, const MatND& m4); 01612 NAryMatNDIterator(const MatND& m1, const MatND& m2, const MatND& m3, 01613 const MatND& m4, const MatND& m5); 01614 NAryMatNDIterator(const MatND& m1, const MatND& m2, const MatND& m3, 01615 const MatND& m4, const MatND& m5, const MatND& m6); 01616 01617 void init(const MatND** arrays, size_t count); 01618 01619 NAryMatNDIterator& operator ++(); 01620 NAryMatNDIterator operator ++(int); 01621 01622 vector<MatND> arrays; 01623 vector<Mat> planes; 01624 01625 int nplanes; 01626 protected: 01627 int iterdepth, idx; 01628 }; 01629 01630 CV_EXPORTS void add(const MatND& a, const MatND& b, MatND& c, const MatND& mask); 01631 CV_EXPORTS void subtract(const MatND& a, const MatND& b, MatND& c, const MatND& mask); 01632 CV_EXPORTS void add(const MatND& a, const MatND& b, MatND& c); 01633 CV_EXPORTS void subtract(const MatND& a, const MatND& b, MatND& c); 01634 CV_EXPORTS void add(const MatND& a, const Scalar& s, MatND& c, const MatND& mask=MatND()); 01635 01636 CV_EXPORTS void multiply(const MatND& a, const MatND& b, MatND& c, double scale=1); 01637 CV_EXPORTS void divide(const MatND& a, const MatND& b, MatND& c, double scale=1); 01638 CV_EXPORTS void divide(double scale, const MatND& b, MatND& c); 01639 01640 CV_EXPORTS void subtract(const Scalar& s, const MatND& a, MatND& c, const MatND& mask=MatND()); 01641 CV_EXPORTS void scaleAdd(const MatND& a, double alpha, const MatND& b, MatND& c); 01642 CV_EXPORTS void addWeighted(const MatND& a, double alpha, const MatND& b, 01643 double beta, double gamma, MatND& c); 01644 01645 CV_EXPORTS Scalar sum(const MatND& m); 01646 CV_EXPORTS int countNonZero( const MatND& m ); 01647 01648 CV_EXPORTS Scalar mean(const MatND& m); 01649 CV_EXPORTS Scalar mean(const MatND& m, const MatND& mask); 01650 CV_EXPORTS void meanStdDev(const MatND& m, Scalar& mean, Scalar& stddev, const MatND& mask=MatND()); 01651 CV_EXPORTS double norm(const MatND& a, int normType=NORM_L2, const MatND& mask=MatND()); 01652 CV_EXPORTS double norm(const MatND& a, const MatND& b, 01653 int normType=NORM_L2, const MatND& mask=MatND()); 01654 CV_EXPORTS void normalize( const MatND& a, MatND& b, double alpha=1, double beta=0, 01655 int norm_type=NORM_L2, int rtype=-1, const MatND& mask=MatND()); 01656 01657 CV_EXPORTS void minMaxLoc(const MatND& a, double* minVal, 01658 double* maxVal, int* minIdx=0, int* maxIdx=0, 01659 const MatND& mask=MatND()); 01660 01661 CV_EXPORTS void merge(const MatND* mvbegin, size_t count, MatND& dst); 01662 CV_EXPORTS void split(const MatND& m, MatND* mv); 01663 CV_EXPORTS void mixChannels(const MatND* src, int nsrcs, MatND* dst, int ndsts, 01664 const int* fromTo, size_t npairs); 01665 01666 CV_EXPORTS void bitwise_and(const MatND& a, const MatND& b, MatND& c, const MatND& mask=MatND()); 01667 CV_EXPORTS void bitwise_or(const MatND& a, const MatND& b, MatND& c, const MatND& mask=MatND()); 01668 CV_EXPORTS void bitwise_xor(const MatND& a, const MatND& b, MatND& c, const MatND& mask=MatND()); 01669 CV_EXPORTS void bitwise_and(const MatND& a, const Scalar& s, MatND& c, const MatND& mask=MatND()); 01670 CV_EXPORTS void bitwise_or(const MatND& a, const Scalar& s, MatND& c, const MatND& mask=MatND()); 01671 CV_EXPORTS void bitwise_xor(const MatND& a, const Scalar& s, MatND& c, const MatND& mask=MatND()); 01672 CV_EXPORTS void bitwise_not(const MatND& a, MatND& c); 01673 CV_EXPORTS void absdiff(const MatND& a, const MatND& b, MatND& c); 01674 CV_EXPORTS void absdiff(const MatND& a, const Scalar& s, MatND& c); 01675 CV_EXPORTS void inRange(const MatND& src, const MatND& lowerb, 01676 const MatND& upperb, MatND& dst); 01677 CV_EXPORTS void inRange(const MatND& src, const Scalar& lowerb, 01678 const Scalar& upperb, MatND& dst); 01679 CV_EXPORTS void compare(const MatND& a, const MatND& b, MatND& c, int cmpop); 01680 CV_EXPORTS void compare(const MatND& a, double s, MatND& c, int cmpop); 01681 CV_EXPORTS void min(const MatND& a, const MatND& b, MatND& c); 01682 CV_EXPORTS void min(const MatND& a, double alpha, MatND& c); 01683 CV_EXPORTS void max(const MatND& a, const MatND& b, MatND& c); 01684 CV_EXPORTS void max(const MatND& a, double alpha, MatND& c); 01685 01686 CV_EXPORTS void sqrt(const MatND& a, MatND& b); 01687 CV_EXPORTS void pow(const MatND& a, double power, MatND& b); 01688 CV_EXPORTS void exp(const MatND& a, MatND& b); 01689 CV_EXPORTS void log(const MatND& a, MatND& b); 01690 CV_EXPORTS bool checkRange(const MatND& a, bool quiet=true, int* idx=0, 01691 double minVal=-DBL_MAX, double maxVal=DBL_MAX); 01692 01693 typedef void (*ConvertData)(const void* from, void* to, int cn); 01694 typedef void (*ConvertScaleData)(const void* from, void* to, int cn, double alpha, double beta); 01695 01696 CV_EXPORTS ConvertData getConvertElem(int fromType, int toType); 01697 CV_EXPORTS ConvertScaleData getConvertScaleElem(int fromType, int toType); 01698 01699 template<typename _Tp> class CV_EXPORTS MatND_ : public MatND 01700 { 01701 public: 01702 typedef _Tp value_type; 01703 typedef typename DataType<_Tp>::channel_type channel_type; 01704 01705 MatND_(); 01706 MatND_(int dims, const int* _sizes); 01707 MatND_(int dims, const int* _sizes, const _Tp& _s); 01708 MatND_(const MatND& m); 01709 MatND_(const MatND_& m); 01710 MatND_(const MatND_& m, const Range* ranges); 01711 MatND_(const CvMatND* m, bool copyData=false); 01712 MatND_& operator = (const MatND& m); 01713 MatND_& operator = (const MatND_& m); 01714 MatND_& operator = (const _Tp& s); 01715 01716 void create(int dims, const int* _sizes); 01717 template<typename T2> operator MatND_<T2>() const; 01718 MatND_ clone() const; 01719 MatND_ operator()(const Range* ranges) const; 01720 01721 size_t elemSize() const; 01722 size_t elemSize1() const; 01723 int type() const; 01724 int depth() const; 01725 int channels() const; 01726 size_t stepT(int i) const; 01727 size_t step1(int i) const; 01728 01729 _Tp& operator ()(const int* idx); 01730 const _Tp& operator ()(const int* idx) const; 01731 01732 _Tp& operator ()(int idx0); 01733 const _Tp& operator ()(int idx0) const; 01734 _Tp& operator ()(int idx0, int idx1); 01735 const _Tp& operator ()(int idx0, int idx1) const; 01736 _Tp& operator ()(int idx0, int idx1, int idx2); 01737 const _Tp& operator ()(int idx0, int idx1, int idx2) const; 01738 }; 01739 01741 01742 class SparseMatIterator; 01743 class SparseMatConstIterator; 01744 template<typename _Tp> class SparseMatIterator_; 01745 template<typename _Tp> class SparseMatConstIterator_; 01746 01747 class CV_EXPORTS SparseMat 01748 { 01749 public: 01750 typedef SparseMatIterator iterator; 01751 typedef SparseMatConstIterator const_iterator; 01752 01753 struct CV_EXPORTS Hdr 01754 { 01755 Hdr(int _dims, const int* _sizes, int _type); 01756 void clear(); 01757 int refcount; 01758 int dims; 01759 int valueOffset; 01760 size_t nodeSize; 01761 size_t nodeCount; 01762 size_t freeList; 01763 vector<uchar> pool; 01764 vector<size_t> hashtab; 01765 int size[CV_MAX_DIM]; 01766 }; 01767 01768 // sparse matrix node - element of a hash table 01769 struct CV_EXPORTS Node 01770 { 01771 size_t hashval; 01772 size_t next; 01773 int idx[CV_MAX_DIM]; 01774 }; 01775 01777 // default constructor 01778 SparseMat(); 01779 // creates matrix of the specified size and type 01780 SparseMat(int dims, const int* _sizes, int _type); 01781 // copy constructor 01782 SparseMat(const SparseMat& m); 01783 // converts dense 2d matrix to the sparse form, 01784 // if try1d is true and matrix is a single-column matrix (Nx1), 01785 // then the sparse matrix will be 1-dimensional. 01786 SparseMat(const Mat& m, bool try1d=false); 01787 // converts dense n-d matrix to the sparse form 01788 SparseMat(const MatND& m); 01789 // converts old-style sparse matrix to the new-style. 01790 // all the data is copied, so that "m" can be safely 01791 // deleted after the conversion 01792 SparseMat(const CvSparseMat* m); 01793 // destructor 01794 ~SparseMat(); 01795 01797 01798 // this is O(1) operation; no data is copied 01799 SparseMat& operator = (const SparseMat& m); 01800 // (equivalent to the corresponding constructor with try1d=false) 01801 SparseMat& operator = (const Mat& m); 01802 SparseMat& operator = (const MatND& m); 01803 01804 // creates full copy of the matrix 01805 SparseMat clone() const; 01806 01807 // copy all the data to the destination matrix. 01808 // the destination will be reallocated if needed. 01809 void copyTo( SparseMat& m ) const; 01810 // converts 1D or 2D sparse matrix to dense 2D matrix. 01811 // If the sparse matrix is 1D, then the result will 01812 // be a single-column matrix. 01813 void copyTo( Mat& m ) const; 01814 // converts arbitrary sparse matrix to dense matrix. 01815 // watch out the memory! 01816 void copyTo( MatND& m ) const; 01817 // multiplies all the matrix elements by the specified scalar 01818 void convertTo( SparseMat& m, int rtype, double alpha=1 ) const; 01819 // converts sparse matrix to dense matrix with optional type conversion and scaling. 01820 // When rtype=-1, the destination element type will be the same 01821 // as the sparse matrix element type. 01822 // Otherwise rtype will specify the depth and 01823 // the number of channels will remain the same is in the sparse matrix 01824 void convertTo( Mat& m, int rtype, double alpha=1, double beta=0 ) const; 01825 void convertTo( MatND& m, int rtype, double alpha=1, double beta=0 ) const; 01826 01827 // not used now 01828 void assignTo( SparseMat& m, int type=-1 ) const; 01829 01830 // reallocates sparse matrix. If it was already of the proper size and type, 01831 // it is simply cleared with clear(), otherwise, 01832 // the old matrix is released (using release()) and the new one is allocated. 01833 void create(int dims, const int* _sizes, int _type); 01834 // sets all the matrix elements to 0, which means clearing the hash table. 01835 void clear(); 01836 // manually increases reference counter to the header. 01837 void addref(); 01838 // decreses the header reference counter, when it reaches 0, 01839 // the header and all the underlying data are deallocated. 01840 void release(); 01841 01842 // converts sparse matrix to the old-style representation. 01843 // all the elements are copied. 01844 operator CvSparseMat*() const; 01845 // size of each element in bytes 01846 // (the matrix nodes will be bigger because of 01847 // element indices and other SparseMat::Node elements). 01848 size_t elemSize() const; 01849 // elemSize()/channels() 01850 size_t elemSize1() const; 01851 01852 // the same is in Mat and MatND 01853 int type() const; 01854 int depth() const; 01855 int channels() const; 01856 01857 // returns the array of sizes and 0 if the matrix is not allocated 01858 const int* size() const; 01859 // returns i-th size (or 0) 01860 int size(int i) const; 01861 // returns the matrix dimensionality 01862 int dims() const; 01863 // returns the number of non-zero elements 01864 size_t nzcount() const; 01865 01866 // compute element hash value from the element indices: 01867 // 1D case 01868 size_t hash(int i0) const; 01869 // 2D case 01870 size_t hash(int i0, int i1) const; 01871 // 3D case 01872 size_t hash(int i0, int i1, int i2) const; 01873 // n-D case 01874 size_t hash(const int* idx) const; 01875 01876 // low-level element-acccess functions, 01877 // special variants for 1D, 2D, 3D cases and the generic one for n-D case. 01878 // 01879 // return pointer to the matrix element. 01880 // if the element is there (it's non-zero), the pointer to it is returned 01881 // if it's not there and createMissing=false, NULL pointer is returned 01882 // if it's not there and createMissing=true, then the new element 01883 // is created and initialized with 0. Pointer to it is returned 01884 // If the optional hashval pointer is not NULL, the element hash value is 01885 // not computed, but *hashval is taken instead. 01886 uchar* ptr(int i0, bool createMissing, size_t* hashval=0); 01887 uchar* ptr(int i0, int i1, bool createMissing, size_t* hashval=0); 01888 uchar* ptr(int i0, int i1, int i2, bool createMissing, size_t* hashval=0); 01889 uchar* ptr(const int* idx, bool createMissing, size_t* hashval=0); 01890 01891 // higher-level element access functions: 01892 // ref<_Tp>(i0,...[,hashval]) - equivalent to *(_Tp*)ptr(i0,...true[,hashval]). 01893 // always return valid reference to the element. 01894 // If it's did not exist, it is created. 01895 // find<_Tp>(i0,...[,hashval]) - equivalent to (_const Tp*)ptr(i0,...false[,hashval]). 01896 // return pointer to the element or NULL pointer if the element is not there. 01897 // value<_Tp>(i0,...[,hashval]) - equivalent to 01898 // { const _Tp* p = find<_Tp>(i0,...[,hashval]); return p ? *p : _Tp(); } 01899 // that is, 0 is returned when the element is not there. 01900 // note that _Tp must match the actual matrix type - 01901 // the functions do not do any on-fly type conversion 01902 01903 // 1D case 01904 template<typename _Tp> _Tp& ref(int i0, size_t* hashval=0); 01905 template<typename _Tp> _Tp value(int i0, size_t* hashval=0) const; 01906 template<typename _Tp> const _Tp* find(int i0, size_t* hashval=0) const; 01907 01908 // 2D case 01909 template<typename _Tp> _Tp& ref(int i0, int i1, size_t* hashval=0); 01910 template<typename _Tp> _Tp value(int i0, int i1, size_t* hashval=0) const; 01911 template<typename _Tp> const _Tp* find(int i0, int i1, size_t* hashval=0) const; 01912 01913 // 3D case 01914 template<typename _Tp> _Tp& ref(int i0, int i1, int i2, size_t* hashval=0); 01915 template<typename _Tp> _Tp value(int i0, int i1, int i2, size_t* hashval=0) const; 01916 template<typename _Tp> const _Tp* find(int i0, int i1, int i2, size_t* hashval=0) const; 01917 01918 // n-D case 01919 template<typename _Tp> _Tp& ref(const int* idx, size_t* hashval=0); 01920 template<typename _Tp> _Tp value(const int* idx, size_t* hashval=0) const; 01921 template<typename _Tp> const _Tp* find(const int* idx, size_t* hashval=0) const; 01922 01923 // erase the specified matrix element. 01924 // When there is no such element, the methods do nothing 01925 void erase(int i0, int i1, size_t* hashval=0); 01926 void erase(int i0, int i1, int i2, size_t* hashval=0); 01927 void erase(const int* idx, size_t* hashval=0); 01928 01929 // return the matrix iterators, 01930 // pointing to the first sparse matrix element, 01931 SparseMatIterator begin(); 01932 SparseMatConstIterator begin() const; 01933 // ... or to the point after the last sparse matrix element 01934 SparseMatIterator end(); 01935 SparseMatConstIterator end() const; 01936 01937 // and the template forms of the above methods. 01938 // _Tp must match the actual matrix type. 01939 template<typename _Tp> SparseMatIterator_<_Tp> begin(); 01940 template<typename _Tp> SparseMatConstIterator_<_Tp> begin() const; 01941 template<typename _Tp> SparseMatIterator_<_Tp> end(); 01942 template<typename _Tp> SparseMatConstIterator_<_Tp> end() const; 01943 01944 // return value stored in the sparse martix node 01945 template<typename _Tp> _Tp& value(Node* n); 01946 template<typename _Tp> const _Tp& value(const Node* n) const; 01947 01949 Node* node(size_t nidx); 01950 const Node* node(size_t nidx) const; 01951 01952 uchar* newNode(const int* idx, size_t hashval); 01953 void removeNode(size_t hidx, size_t nidx, size_t previdx); 01954 void resizeHashTab(size_t newsize); 01955 01956 enum { MAGIC_VAL=0x42FD0000, MAX_DIM=CV_MAX_DIM, HASH_SCALE=0x5bd1e995, HASH_BIT=0x80000000 }; 01957 01958 int flags; 01959 Hdr* hdr; 01960 }; 01961 01962 01963 CV_EXPORTS void minMaxLoc(const SparseMat& a, double* minVal, 01964 double* maxVal, int* minIdx=0, int* maxIdx=0); 01965 CV_EXPORTS double norm( const SparseMat& src, int normType ); 01966 CV_EXPORTS void normalize( const SparseMat& src, SparseMat& dst, double alpha, int normType ); 01967 01968 class CV_EXPORTS SparseMatConstIterator 01969 { 01970 public: 01971 SparseMatConstIterator(); 01972 SparseMatConstIterator(const SparseMat* _m); 01973 SparseMatConstIterator(const SparseMatConstIterator& it); 01974 01975 SparseMatConstIterator& operator = (const SparseMatConstIterator& it); 01976 01977 template<typename _Tp> const _Tp& value() const; 01978 const SparseMat::Node* node() const; 01979 01980 SparseMatConstIterator& operator --(); 01981 SparseMatConstIterator operator --(int); 01982 SparseMatConstIterator& operator ++(); 01983 SparseMatConstIterator operator ++(int); 01984 01985 void seekEnd(); 01986 01987 const SparseMat* m; 01988 size_t hashidx; 01989 uchar* ptr; 01990 }; 01991 01992 class CV_EXPORTS SparseMatIterator : public SparseMatConstIterator 01993 { 01994 public: 01995 SparseMatIterator(); 01996 SparseMatIterator(SparseMat* _m); 01997 SparseMatIterator(SparseMat* _m, const int* idx); 01998 SparseMatIterator(const SparseMatIterator& it); 01999 02000 SparseMatIterator& operator = (const SparseMatIterator& it); 02001 template<typename _Tp> _Tp& value() const; 02002 SparseMat::Node* node() const; 02003 02004 SparseMatIterator& operator ++(); 02005 SparseMatIterator operator ++(int); 02006 }; 02007 02008 02009 template<typename _Tp> class CV_EXPORTS SparseMat_ : public SparseMat 02010 { 02011 public: 02012 typedef SparseMatIterator_<_Tp> iterator; 02013 typedef SparseMatConstIterator_<_Tp> const_iterator; 02014 02015 SparseMat_(); 02016 SparseMat_(int dims, const int* _sizes); 02017 SparseMat_(const SparseMat& m); 02018 SparseMat_(const SparseMat_& m); 02019 SparseMat_(const Mat& m); 02020 SparseMat_(const MatND& m); 02021 SparseMat_(const CvSparseMat* m); 02022 SparseMat_& operator = (const SparseMat& m); 02023 SparseMat_& operator = (const SparseMat_& m); 02024 SparseMat_& operator = (const Mat& m); 02025 SparseMat_& operator = (const MatND& m); 02026 02027 SparseMat_ clone() const; 02028 void create(int dims, const int* _sizes); 02029 operator CvSparseMat*() const; 02030 02031 int type() const; 02032 int depth() const; 02033 int channels() const; 02034 02035 _Tp& ref(int i0, size_t* hashval=0); 02036 _Tp operator()(int i0, size_t* hashval=0) const; 02037 _Tp& ref(int i0, int i1, size_t* hashval=0); 02038 _Tp operator()(int i0, int i1, size_t* hashval=0) const; 02039 _Tp& ref(int i0, int i1, int i2, size_t* hashval=0); 02040 _Tp operator()(int i0, int i1, int i2, size_t* hashval=0) const; 02041 _Tp& ref(const int* idx, size_t* hashval=0); 02042 _Tp operator()(const int* idx, size_t* hashval=0) const; 02043 02044 SparseMatIterator_<_Tp> begin(); 02045 SparseMatConstIterator_<_Tp> begin() const; 02046 SparseMatIterator_<_Tp> end(); 02047 SparseMatConstIterator_<_Tp> end() const; 02048 }; 02049 02050 template<typename _Tp> class CV_EXPORTS SparseMatConstIterator_ : public SparseMatConstIterator 02051 { 02052 public: 02053 typedef std::forward_iterator_tag iterator_category; 02054 02055 SparseMatConstIterator_(); 02056 SparseMatConstIterator_(const SparseMat_<_Tp>* _m); 02057 SparseMatConstIterator_(const SparseMatConstIterator_& it); 02058 02059 SparseMatConstIterator_& operator = (const SparseMatConstIterator_& it); 02060 const _Tp& operator *() const; 02061 02062 SparseMatConstIterator_& operator ++(); 02063 SparseMatConstIterator_ operator ++(int); 02064 }; 02065 02066 template<typename _Tp> class CV_EXPORTS SparseMatIterator_ : public SparseMatConstIterator_<_Tp> 02067 { 02068 public: 02069 typedef std::forward_iterator_tag iterator_category; 02070 02071 SparseMatIterator_(); 02072 SparseMatIterator_(SparseMat_<_Tp>* _m); 02073 SparseMatIterator_(const SparseMatIterator_& it); 02074 02075 SparseMatIterator_& operator = (const SparseMatIterator_& it); 02076 _Tp& operator *() const; 02077 02078 SparseMatIterator_& operator ++(); 02079 SparseMatIterator_ operator ++(int); 02080 }; 02081 02083 02084 class CV_EXPORTS KDTree 02085 { 02086 public: 02087 struct Node 02088 { 02089 Node() : idx(-1), left(-1), right(-1), boundary(0.f) {} 02090 Node(int _idx, int _left, int _right, float _boundary) 02091 : idx(_idx), left(_left), right(_right), boundary(_boundary) {} 02092 int idx; // split dimension; >=0 for nodes (dim), 02093 // < 0 for leaves (index of the point) 02094 int left, right; // node indices of left and right branches 02095 float boundary; // left if vec[dim]<=boundary, otherwise right 02096 }; 02097 02098 KDTree(); 02099 KDTree(const Mat& _points, bool copyAndReorderPoints=false); 02100 void build(const Mat& _points, bool copyAndReorderPoints=false); 02101 02102 int findNearest(const float* vec, int K, int Emax, int* neighborsIdx, 02103 Mat* neighbors=0, float* dist=0) const; 02104 int findNearest(const float* vec, int K, int Emax, 02105 vector<int>* neighborsIdx, 02106 Mat* neighbors=0, vector<float>* dist=0) const; 02107 void findOrthoRange(const float* minBounds, const float* maxBounds, 02108 vector<int>* neighborsIdx, Mat* neighbors=0) const; 02109 void getPoints(const int* idx, size_t nidx, Mat& pts) const; 02110 void getPoints(const Mat& idxs, Mat& pts) const; 02111 const float* getPoint(int ptidx) const; 02112 int dims() const; 02113 02114 vector<Node> nodes; 02115 Mat points; 02116 int maxDepth; 02117 int normType; 02118 }; 02119 02121 02122 class CV_EXPORTS FileNode; 02123 02124 class CV_EXPORTS FileStorage 02125 { 02126 public: 02127 enum { READ=0, WRITE=1, APPEND=2 }; 02128 enum { UNDEFINED=0, VALUE_EXPECTED=1, NAME_EXPECTED=2, INSIDE_MAP=4 }; 02129 FileStorage(); 02130 FileStorage(const string& filename, int flags); 02131 FileStorage(CvFileStorage* fs); 02132 virtual ~FileStorage(); 02133 02134 virtual bool open(const string& filename, int flags); 02135 virtual bool isOpened() const; 02136 virtual void release(); 02137 02138 FileNode getFirstTopLevelNode() const; 02139 FileNode root(int streamidx=0) const; 02140 FileNode operator[](const string& nodename) const; 02141 FileNode operator[](const char* nodename) const; 02142 02143 CvFileStorage* operator *() { return fs; } 02144 const CvFileStorage* operator *() const { return fs; } 02145 void writeRaw( const string& fmt, const uchar* vec, size_t len ); 02146 void writeObj( const string& name, const void* obj ); 02147 02148 static string getDefaultObjectName(const string& filename); 02149 02150 Ptr<CvFileStorage> fs; 02151 string elname; 02152 vector<char> structs; 02153 int state; 02154 }; 02155 02156 class CV_EXPORTS FileNodeIterator; 02157 02158 class CV_EXPORTS FileNode 02159 { 02160 public: 02161 enum { NONE=0, INT=1, REAL=2, FLOAT=REAL, STR=3, STRING=STR, REF=4, SEQ=5, MAP=6, TYPE_MASK=7, 02162 FLOW=8, USER=16, EMPTY=32, NAMED=64 }; 02163 FileNode(); 02164 FileNode(const CvFileStorage* fs, const CvFileNode* node); 02165 FileNode(const FileNode& node); 02166 FileNode operator[](const string& nodename) const; 02167 FileNode operator[](const char* nodename) const; 02168 FileNode operator[](int i) const; 02169 int type() const; 02170 int rawDataSize(const string& fmt) const; 02171 bool empty() const; 02172 bool isNone() const; 02173 bool isSeq() const; 02174 bool isMap() const; 02175 bool isInt() const; 02176 bool isReal() const; 02177 bool isString() const; 02178 bool isNamed() const; 02179 string name() const; 02180 size_t size() const; 02181 operator int() const; 02182 operator float() const; 02183 operator double() const; 02184 operator string() const; 02185 02186 CvFileNode* operator *(); 02187 const CvFileNode* operator* () const; 02188 02189 02190 FileNodeIterator begin() const; 02191 FileNodeIterator end() const; 02192 02193 void readRaw( const string& fmt, uchar* vec, size_t len ) const; 02194 void* readObj() const; 02195 02196 // do not use wrapper pointer classes for better efficiency 02197 const CvFileStorage* fs; 02198 const CvFileNode* node; 02199 }; 02200 02201 class CV_EXPORTS FileNodeIterator 02202 { 02203 public: 02204 FileNodeIterator(); 02205 FileNodeIterator(const CvFileStorage* fs, const CvFileNode* node, size_t ofs=0); 02206 FileNodeIterator(const FileNodeIterator& it); 02207 FileNode operator *() const; 02208 FileNode operator ->() const; 02209 02210 FileNodeIterator& operator ++(); 02211 FileNodeIterator operator ++(int); 02212 FileNodeIterator& operator --(); 02213 FileNodeIterator operator --(int); 02214 FileNodeIterator& operator += (int); 02215 FileNodeIterator& operator -= (int); 02216 02217 FileNodeIterator& readRaw( const string& fmt, uchar* vec, 02218 size_t maxCount=(size_t)INT_MAX ); 02219 02220 const CvFileStorage* fs; 02221 const CvFileNode* container; 02222 CvSeqReader reader; 02223 size_t remaining; 02224 }; 02225 02227 02228 // !!! NOTE that the wrappers are "thin", i.e. they do not call 02229 // any element constructors/destructors 02230 02231 template<typename _Tp> class SeqIterator; 02232 02233 typedef Ptr<CvMemStorage> MemStorage; 02234 02235 template<typename _Tp> class CV_EXPORTS Seq 02236 { 02237 public: 02238 typedef SeqIterator<_Tp> iterator; 02239 typedef SeqIterator<_Tp> const_iterator; 02240 02241 Seq(); 02242 Seq(const CvSeq* seq); 02243 Seq(MemStorage& storage, int headerSize = sizeof(CvSeq)); 02244 _Tp& operator [](int idx); 02245 const _Tp& operator[](int idx) const; 02246 SeqIterator<_Tp> begin() const; 02247 SeqIterator<_Tp> end() const; 02248 size_t size() const; 02249 int type() const; 02250 int depth() const; 02251 int channels() const; 02252 size_t elemSize() const; 02253 size_t index(const _Tp& elem) const; 02254 void push_back(const _Tp& elem); 02255 void push_front(const _Tp& elem); 02256 void push_back(const _Tp* elems, size_t count); 02257 void push_front(const _Tp* elems, size_t count); 02258 void insert(int idx, const _Tp& elem); 02259 void insert(int idx, const _Tp* elems, size_t count); 02260 void remove(int idx); 02261 void remove(const Range& r); 02262 02263 _Tp& front(); 02264 const _Tp& front() const; 02265 _Tp& back(); 02266 const _Tp& back() const; 02267 bool empty() const; 02268 02269 void clear(); 02270 void pop_front(); 02271 void pop_back(); 02272 void pop_front(_Tp* elems, size_t count); 02273 void pop_back(_Tp* elems, size_t count); 02274 02275 void copyTo(vector<_Tp>& vec, const Range& range=Range::all()) const; 02276 operator vector<_Tp>() const; 02277 02278 CvSeq* seq; 02279 }; 02280 02281 template<typename _Tp> class CV_EXPORTS SeqIterator : public CvSeqReader 02282 { 02283 public: 02284 SeqIterator(); 02285 SeqIterator(const Seq<_Tp>& seq, bool seekEnd=false); 02286 void seek(size_t pos); 02287 size_t tell() const; 02288 _Tp& operator *(); 02289 const _Tp& operator *() const; 02290 SeqIterator& operator ++(); 02291 SeqIterator operator ++(int) const; 02292 SeqIterator& operator --(); 02293 SeqIterator operator --(int) const; 02294 02295 SeqIterator& operator +=(int); 02296 SeqIterator& operator -=(int); 02297 02298 // this is index of the current element module seq->total*2 02299 // (to distinguish between 0 and seq->total) 02300 int index; 02301 }; 02302 02303 } 02304 02305 #endif // __cplusplus 02306 02307 #include "cxoperations.hpp" 02308 #include "cxmat.hpp" 02309 02310 #include "cxflann.h" // FLANN (Fast Library for Approximate Nearest Neighbors) 02311 02312 #endif /*_CXCORE_HPP_*/