imagecore 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +24 -0
- data/Gemfile +4 -0
- data/Rakefile +2 -0
- data/ext/imagecore/analyze_image.cxx +58 -0
- data/ext/imagecore/analyze_image.h +6 -0
- data/ext/imagecore/extconf.rb +9 -0
- data/ext/imagecore/imagecore.cxx +34 -0
- data/ext/opencv/core/___.c +3 -0
- data/ext/opencv/core/alloc.cpp +697 -0
- data/ext/opencv/core/array.cpp +3206 -0
- data/ext/opencv/core/datastructs.cpp +4064 -0
- data/ext/opencv/core/extconf.rb +22 -0
- data/ext/opencv/core/matrix.cpp +3777 -0
- data/ext/opencv/core/precomp.hpp +216 -0
- data/ext/opencv/core/system.cpp +832 -0
- data/ext/opencv/core/tables.cpp +3512 -0
- data/ext/opencv/highgui/___.c +3 -0
- data/ext/opencv/highgui/bitstrm.cpp +582 -0
- data/ext/opencv/highgui/bitstrm.hpp +182 -0
- data/ext/opencv/highgui/extconf.rb +28 -0
- data/ext/opencv/highgui/grfmt_base.cpp +128 -0
- data/ext/opencv/highgui/grfmt_base.hpp +113 -0
- data/ext/opencv/highgui/grfmt_bmp.cpp +564 -0
- data/ext/opencv/highgui/grfmt_bmp.hpp +99 -0
- data/ext/opencv/highgui/grfmt_exr.hpp +113 -0
- data/ext/opencv/highgui/grfmt_imageio.hpp +56 -0
- data/ext/opencv/highgui/grfmt_jpeg.cpp +622 -0
- data/ext/opencv/highgui/grfmt_jpeg.hpp +90 -0
- data/ext/opencv/highgui/grfmt_jpeg2000.cpp +529 -0
- data/ext/opencv/highgui/grfmt_jpeg2000.hpp +95 -0
- data/ext/opencv/highgui/grfmt_png.cpp +406 -0
- data/ext/opencv/highgui/grfmt_png.hpp +101 -0
- data/ext/opencv/highgui/grfmt_pxm.cpp +513 -0
- data/ext/opencv/highgui/grfmt_pxm.hpp +92 -0
- data/ext/opencv/highgui/grfmt_sunras.cpp +425 -0
- data/ext/opencv/highgui/grfmt_sunras.hpp +105 -0
- data/ext/opencv/highgui/grfmt_tiff.cpp +718 -0
- data/ext/opencv/highgui/grfmt_tiff.hpp +136 -0
- data/ext/opencv/highgui/grfmts.hpp +56 -0
- data/ext/opencv/highgui/loadsave.cpp +535 -0
- data/ext/opencv/highgui/precomp.hpp +223 -0
- data/ext/opencv/highgui/utils.cpp +689 -0
- data/ext/opencv/highgui/utils.hpp +128 -0
- data/ext/opencv/imgproc/___.c +3 -0
- data/ext/opencv/imgproc/_geom.h +72 -0
- data/ext/opencv/imgproc/color.cpp +3179 -0
- data/ext/opencv/imgproc/contours.cpp +1780 -0
- data/ext/opencv/imgproc/extconf.rb +11 -0
- data/ext/opencv/imgproc/filter.cpp +3063 -0
- data/ext/opencv/imgproc/precomp.hpp +159 -0
- data/ext/opencv/imgproc/shapedescr.cpp +1306 -0
- data/ext/opencv/imgproc/smooth.cpp +1566 -0
- data/ext/opencv/imgproc/tables.cpp +214 -0
- data/ext/opencv/imgproc/thresh.cpp +636 -0
- data/ext/opencv/imgproc/utils.cpp +242 -0
- data/ext/opencv/include/opencv2/core/core.hpp +4344 -0
- data/ext/opencv/include/opencv2/core/core_c.h +1885 -0
- data/ext/opencv/include/opencv2/core/internal.hpp +710 -0
- data/ext/opencv/include/opencv2/core/mat.hpp +2557 -0
- data/ext/opencv/include/opencv2/core/operations.hpp +3623 -0
- data/ext/opencv/include/opencv2/core/types_c.h +1875 -0
- data/ext/opencv/include/opencv2/core/version.hpp +58 -0
- data/ext/opencv/include/opencv2/highgui/highgui.hpp +198 -0
- data/ext/opencv/include/opencv2/highgui/highgui_c.h +506 -0
- data/ext/opencv/include/opencv2/imgproc/imgproc.hpp +1139 -0
- data/ext/opencv/include/opencv2/imgproc/imgproc_c.h +783 -0
- data/ext/opencv/include/opencv2/imgproc/types_c.h +538 -0
- data/imagecore.gemspec +20 -0
- data/lib/imagecore.rb +16 -0
- data/lib/imagecore/version.rb +3 -0
- metadata +119 -0
@@ -0,0 +1,242 @@
|
|
1
|
+
/*M///////////////////////////////////////////////////////////////////////////////////////
|
2
|
+
//
|
3
|
+
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
4
|
+
//
|
5
|
+
// By downloading, copying, installing or using the software you agree to this license.
|
6
|
+
// If you do not agree to this license, do not download, install,
|
7
|
+
// copy or use the software.
|
8
|
+
//
|
9
|
+
//
|
10
|
+
// Intel License Agreement
|
11
|
+
// For Open Source Computer Vision Library
|
12
|
+
//
|
13
|
+
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
14
|
+
// Third party copyrights are property of their respective owners.
|
15
|
+
//
|
16
|
+
// Redistribution and use in source and binary forms, with or without modification,
|
17
|
+
// are permitted provided that the following conditions are met:
|
18
|
+
//
|
19
|
+
// * Redistribution's of source code must retain the above copyright notice,
|
20
|
+
// this list of conditions and the following disclaimer.
|
21
|
+
//
|
22
|
+
// * Redistribution's in binary form must reproduce the above copyright notice,
|
23
|
+
// this list of conditions and the following disclaimer in the documentation
|
24
|
+
// and/or other materials provided with the distribution.
|
25
|
+
//
|
26
|
+
// * The name of Intel Corporation may not be used to endorse or promote products
|
27
|
+
// derived from this software without specific prior written permission.
|
28
|
+
//
|
29
|
+
// This software is provided by the copyright holders and contributors "as is" and
|
30
|
+
// any express or implied warranties, including, but not limited to, the implied
|
31
|
+
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
32
|
+
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
33
|
+
// indirect, incidental, special, exemplary, or consequential damages
|
34
|
+
// (including, but not limited to, procurement of substitute goods or services;
|
35
|
+
// loss of use, data, or profits; or business interruption) however caused
|
36
|
+
// and on any theory of liability, whether in contract, strict liability,
|
37
|
+
// or tort (including negligence or otherwise) arising in any way out of
|
38
|
+
// the use of this software, even if advised of the possibility of such damage.
|
39
|
+
//
|
40
|
+
//M*/
|
41
|
+
|
42
|
+
#include "precomp.hpp"
|
43
|
+
|
44
|
+
CV_IMPL CvSeq* cvPointSeqFromMat( int seq_kind, const CvArr* arr,
|
45
|
+
CvContour* contour_header, CvSeqBlock* block )
|
46
|
+
{
|
47
|
+
CV_Assert( arr != 0 && contour_header != 0 && block != 0 );
|
48
|
+
|
49
|
+
int eltype;
|
50
|
+
CvMat* mat = (CvMat*)arr;
|
51
|
+
|
52
|
+
if( !CV_IS_MAT( mat ))
|
53
|
+
CV_Error( CV_StsBadArg, "Input array is not a valid matrix" );
|
54
|
+
|
55
|
+
eltype = CV_MAT_TYPE( mat->type );
|
56
|
+
if( eltype != CV_32SC2 && eltype != CV_32FC2 )
|
57
|
+
CV_Error( CV_StsUnsupportedFormat,
|
58
|
+
"The matrix can not be converted to point sequence because of "
|
59
|
+
"inappropriate element type" );
|
60
|
+
|
61
|
+
if( (mat->width != 1 && mat->height != 1) || !CV_IS_MAT_CONT(mat->type))
|
62
|
+
CV_Error( CV_StsBadArg,
|
63
|
+
"The matrix converted to point sequence must be "
|
64
|
+
"1-dimensional and continuous" );
|
65
|
+
|
66
|
+
cvMakeSeqHeaderForArray(
|
67
|
+
(seq_kind & (CV_SEQ_KIND_MASK|CV_SEQ_FLAG_CLOSED)) | eltype,
|
68
|
+
sizeof(CvContour), CV_ELEM_SIZE(eltype), mat->data.ptr,
|
69
|
+
mat->width*mat->height, (CvSeq*)contour_header, block );
|
70
|
+
|
71
|
+
return (CvSeq*)contour_header;
|
72
|
+
}
|
73
|
+
|
74
|
+
namespace cv
|
75
|
+
{
|
76
|
+
|
77
|
+
static void copyMakeBorder_8u( const uchar* src, size_t srcstep, Size srcroi,
|
78
|
+
uchar* dst, size_t dststep, Size dstroi,
|
79
|
+
int top, int left, int cn, int borderType )
|
80
|
+
{
|
81
|
+
const int isz = (int)sizeof(int);
|
82
|
+
int i, j, k, elemSize = 1;
|
83
|
+
bool intMode = false;
|
84
|
+
|
85
|
+
if( (cn | srcstep | dststep | (size_t)src | (size_t)dst) % isz == 0 )
|
86
|
+
{
|
87
|
+
cn /= isz;
|
88
|
+
elemSize = isz;
|
89
|
+
intMode = true;
|
90
|
+
}
|
91
|
+
|
92
|
+
AutoBuffer<int> _tab((dstroi.width - srcroi.width)*cn);
|
93
|
+
int* tab = _tab;
|
94
|
+
int right = dstroi.width - srcroi.width - left;
|
95
|
+
int bottom = dstroi.height - srcroi.height - top;
|
96
|
+
|
97
|
+
for( i = 0; i < left; i++ )
|
98
|
+
{
|
99
|
+
j = borderInterpolate(i - left, srcroi.width, borderType)*cn;
|
100
|
+
for( k = 0; k < cn; k++ )
|
101
|
+
tab[i*cn + k] = j + k;
|
102
|
+
}
|
103
|
+
|
104
|
+
for( i = 0; i < right; i++ )
|
105
|
+
{
|
106
|
+
j = borderInterpolate(srcroi.width + i, srcroi.width, borderType)*cn;
|
107
|
+
for( k = 0; k < cn; k++ )
|
108
|
+
tab[(i+left)*cn + k] = j + k;
|
109
|
+
}
|
110
|
+
|
111
|
+
srcroi.width *= cn;
|
112
|
+
dstroi.width *= cn;
|
113
|
+
left *= cn;
|
114
|
+
right *= cn;
|
115
|
+
|
116
|
+
uchar* dstInner = dst + dststep*top + left*elemSize;
|
117
|
+
|
118
|
+
for( i = 0; i < srcroi.height; i++, dstInner += dststep, src += srcstep )
|
119
|
+
{
|
120
|
+
if( dstInner != src )
|
121
|
+
memcpy(dstInner, src, srcroi.width*elemSize);
|
122
|
+
|
123
|
+
if( intMode )
|
124
|
+
{
|
125
|
+
const int* isrc = (int*)src;
|
126
|
+
int* idstInner = (int*)dstInner;
|
127
|
+
for( j = 0; j < left; j++ )
|
128
|
+
idstInner[j - left] = isrc[tab[j]];
|
129
|
+
for( j = 0; j < right; j++ )
|
130
|
+
idstInner[j + srcroi.width] = isrc[tab[j + left]];
|
131
|
+
}
|
132
|
+
else
|
133
|
+
{
|
134
|
+
for( j = 0; j < left; j++ )
|
135
|
+
dstInner[j - left] = src[tab[j]];
|
136
|
+
for( j = 0; j < right; j++ )
|
137
|
+
dstInner[j + srcroi.width] = src[tab[j + left]];
|
138
|
+
}
|
139
|
+
}
|
140
|
+
|
141
|
+
dstroi.width *= elemSize;
|
142
|
+
dst += dststep*top;
|
143
|
+
|
144
|
+
for( i = 0; i < top; i++ )
|
145
|
+
{
|
146
|
+
j = borderInterpolate(i - top, srcroi.height, borderType);
|
147
|
+
memcpy(dst + (i - top)*dststep, dst + j*dststep, dstroi.width);
|
148
|
+
}
|
149
|
+
|
150
|
+
for( i = 0; i < bottom; i++ )
|
151
|
+
{
|
152
|
+
j = borderInterpolate(i + srcroi.height, srcroi.height, borderType);
|
153
|
+
memcpy(dst + (i + srcroi.height)*dststep, dst + j*dststep, dstroi.width);
|
154
|
+
}
|
155
|
+
}
|
156
|
+
|
157
|
+
|
158
|
+
static void copyMakeConstBorder_8u( const uchar* src, size_t srcstep, Size srcroi,
|
159
|
+
uchar* dst, size_t dststep, Size dstroi,
|
160
|
+
int top, int left, int cn, const uchar* value )
|
161
|
+
{
|
162
|
+
int i, j;
|
163
|
+
AutoBuffer<uchar> _constBuf(dstroi.width*cn);
|
164
|
+
uchar* constBuf = _constBuf;
|
165
|
+
int right = dstroi.width - srcroi.width - left;
|
166
|
+
int bottom = dstroi.height - srcroi.height - top;
|
167
|
+
|
168
|
+
for( i = 0; i < dstroi.width; i++ )
|
169
|
+
{
|
170
|
+
for( j = 0; j < cn; j++ )
|
171
|
+
constBuf[i*cn + j] = value[j];
|
172
|
+
}
|
173
|
+
|
174
|
+
srcroi.width *= cn;
|
175
|
+
dstroi.width *= cn;
|
176
|
+
left *= cn;
|
177
|
+
right *= cn;
|
178
|
+
|
179
|
+
uchar* dstInner = dst + dststep*top + left;
|
180
|
+
|
181
|
+
for( i = 0; i < srcroi.height; i++, dstInner += dststep, src += srcstep )
|
182
|
+
{
|
183
|
+
if( dstInner != src )
|
184
|
+
memcpy( dstInner, src, srcroi.width );
|
185
|
+
memcpy( dstInner - left, constBuf, left );
|
186
|
+
memcpy( dstInner + srcroi.width, constBuf, right );
|
187
|
+
}
|
188
|
+
|
189
|
+
dst += dststep*top;
|
190
|
+
|
191
|
+
for( i = 0; i < top; i++ )
|
192
|
+
memcpy(dst + (i - top)*dststep, constBuf, dstroi.width);
|
193
|
+
|
194
|
+
for( i = 0; i < bottom; i++ )
|
195
|
+
memcpy(dst + (i + srcroi.height)*dststep, constBuf, dstroi.width);
|
196
|
+
}
|
197
|
+
|
198
|
+
}
|
199
|
+
|
200
|
+
void cv::copyMakeBorder( InputArray _src, OutputArray _dst, int top, int bottom,
|
201
|
+
int left, int right, int borderType, const Scalar& value )
|
202
|
+
{
|
203
|
+
Mat src = _src.getMat();
|
204
|
+
CV_Assert( top >= 0 && bottom >= 0 && left >= 0 && right >= 0 );
|
205
|
+
|
206
|
+
_dst.create( src.rows + top + bottom, src.cols + left + right, src.type() );
|
207
|
+
Mat dst = _dst.getMat();
|
208
|
+
|
209
|
+
if( borderType != BORDER_CONSTANT )
|
210
|
+
copyMakeBorder_8u( src.data, src.step, src.size(),
|
211
|
+
dst.data, dst.step, dst.size(),
|
212
|
+
top, left, (int)src.elemSize(), borderType );
|
213
|
+
else
|
214
|
+
{
|
215
|
+
int cn = src.channels(), cn1 = cn;
|
216
|
+
AutoBuffer<double> buf(cn);
|
217
|
+
if( cn > 4 )
|
218
|
+
{
|
219
|
+
CV_Assert( value[0] == value[1] && value[0] == value[2] && value[0] == value[3] );
|
220
|
+
cn1 = 1;
|
221
|
+
}
|
222
|
+
scalarToRawData(value, buf, CV_MAKETYPE(src.depth(), cn1), cn);
|
223
|
+
copyMakeConstBorder_8u( src.data, src.step, src.size(),
|
224
|
+
dst.data, dst.step, dst.size(),
|
225
|
+
top, left, (int)src.elemSize(), (uchar*)(double*)buf );
|
226
|
+
}
|
227
|
+
}
|
228
|
+
|
229
|
+
|
230
|
+
CV_IMPL void
|
231
|
+
cvCopyMakeBorder( const CvArr* srcarr, CvArr* dstarr, CvPoint offset,
|
232
|
+
int borderType, CvScalar value )
|
233
|
+
{
|
234
|
+
cv::Mat src = cv::cvarrToMat(srcarr), dst = cv::cvarrToMat(dstarr);
|
235
|
+
int left = offset.x, right = dst.cols - src.cols - left;
|
236
|
+
int top = offset.y, bottom = dst.rows - src.rows - top;
|
237
|
+
|
238
|
+
CV_Assert( dst.type() == src.type() );
|
239
|
+
cv::copyMakeBorder( src, dst, top, bottom, left, right, borderType, value );
|
240
|
+
}
|
241
|
+
|
242
|
+
/* End of file. */
|
@@ -0,0 +1,4344 @@
|
|
1
|
+
/*! \file core.hpp
|
2
|
+
\brief The Core Functionality
|
3
|
+
*/
|
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-2011, 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 <cstddef>
|
59
|
+
#include <complex>
|
60
|
+
#include <map>
|
61
|
+
#include <new>
|
62
|
+
#include <string>
|
63
|
+
#include <vector>
|
64
|
+
#endif // SKIP_INCLUDES
|
65
|
+
|
66
|
+
/*! \namespace cv
|
67
|
+
Namespace where all the C++ OpenCV functionality resides
|
68
|
+
*/
|
69
|
+
namespace cv {
|
70
|
+
|
71
|
+
#undef abs
|
72
|
+
#undef min
|
73
|
+
#undef max
|
74
|
+
#undef Complex
|
75
|
+
|
76
|
+
using std::vector;
|
77
|
+
using std::string;
|
78
|
+
using std::ptrdiff_t;
|
79
|
+
|
80
|
+
template<typename _Tp> class CV_EXPORTS Size_;
|
81
|
+
template<typename _Tp> class CV_EXPORTS Point_;
|
82
|
+
template<typename _Tp> class CV_EXPORTS Rect_;
|
83
|
+
template<typename _Tp, int cn> class CV_EXPORTS Vec;
|
84
|
+
template<typename _Tp, int m, int n> class CV_EXPORTS Matx;
|
85
|
+
|
86
|
+
typedef std::string String;
|
87
|
+
typedef std::basic_string<wchar_t> WString;
|
88
|
+
|
89
|
+
class Mat;
|
90
|
+
class SparseMat;
|
91
|
+
typedef Mat MatND;
|
92
|
+
|
93
|
+
class CV_EXPORTS MatExpr;
|
94
|
+
class CV_EXPORTS MatOp_Base;
|
95
|
+
class CV_EXPORTS MatArg;
|
96
|
+
class CV_EXPORTS MatConstIterator;
|
97
|
+
|
98
|
+
template<typename _Tp> class CV_EXPORTS Mat_;
|
99
|
+
template<typename _Tp> class CV_EXPORTS MatIterator_;
|
100
|
+
template<typename _Tp> class CV_EXPORTS MatConstIterator_;
|
101
|
+
template<typename _Tp> class CV_EXPORTS MatCommaInitializer_;
|
102
|
+
|
103
|
+
CV_EXPORTS string fromUtf16(const WString& str);
|
104
|
+
CV_EXPORTS WString toUtf16(const string& str);
|
105
|
+
|
106
|
+
CV_EXPORTS string format( const char* fmt, ... );
|
107
|
+
CV_EXPORTS string tempfile( const char* suffix CV_DEFAULT(0));
|
108
|
+
|
109
|
+
// matrix decomposition types
|
110
|
+
enum { DECOMP_LU=0, DECOMP_SVD=1, DECOMP_EIG=2, DECOMP_CHOLESKY=3, DECOMP_QR=4, DECOMP_NORMAL=16 };
|
111
|
+
enum { NORM_INF=1, NORM_L1=2, NORM_L2=4, NORM_TYPE_MASK=7, NORM_RELATIVE=8, NORM_MINMAX=32};
|
112
|
+
enum { CMP_EQ=0, CMP_GT=1, CMP_GE=2, CMP_LT=3, CMP_LE=4, CMP_NE=5 };
|
113
|
+
enum { GEMM_1_T=1, GEMM_2_T=2, GEMM_3_T=4 };
|
114
|
+
enum { DFT_INVERSE=1, DFT_SCALE=2, DFT_ROWS=4, DFT_COMPLEX_OUTPUT=16, DFT_REAL_OUTPUT=32,
|
115
|
+
DCT_INVERSE = DFT_INVERSE, DCT_ROWS=DFT_ROWS };
|
116
|
+
|
117
|
+
|
118
|
+
/*!
|
119
|
+
The standard OpenCV exception class.
|
120
|
+
Instances of the class are thrown by various functions and methods in the case of critical errors.
|
121
|
+
*/
|
122
|
+
class CV_EXPORTS Exception : public std::exception
|
123
|
+
{
|
124
|
+
public:
|
125
|
+
/*!
|
126
|
+
Default constructor
|
127
|
+
*/
|
128
|
+
Exception();
|
129
|
+
/*!
|
130
|
+
Full constructor. Normally the constuctor is not called explicitly.
|
131
|
+
Instead, the macros CV_Error(), CV_Error_() and CV_Assert() are used.
|
132
|
+
*/
|
133
|
+
Exception(int _code, const string& _err, const string& _func, const string& _file, int _line);
|
134
|
+
virtual ~Exception() throw();
|
135
|
+
|
136
|
+
/*!
|
137
|
+
\return the error description and the context as a text string.
|
138
|
+
*/
|
139
|
+
virtual const char *what() const throw();
|
140
|
+
void formatMessage();
|
141
|
+
|
142
|
+
string msg; ///< the formatted error message
|
143
|
+
|
144
|
+
int code; ///< error code @see CVStatus
|
145
|
+
string err; ///< error description
|
146
|
+
string func; ///< function name. Available only when the compiler supports __func__ macro
|
147
|
+
string file; ///< source file name where the error has occured
|
148
|
+
int line; ///< line number in the source file where the error has occured
|
149
|
+
};
|
150
|
+
|
151
|
+
|
152
|
+
//! Signals an error and raises the exception.
|
153
|
+
|
154
|
+
/*!
|
155
|
+
By default the function prints information about the error to stderr,
|
156
|
+
then it either stops if setBreakOnError() had been called before or raises the exception.
|
157
|
+
It is possible to alternate error processing by using redirectError().
|
158
|
+
|
159
|
+
\param exc the exception raisen.
|
160
|
+
*/
|
161
|
+
CV_EXPORTS void error( const Exception& exc );
|
162
|
+
|
163
|
+
//! Sets/resets the break-on-error mode.
|
164
|
+
|
165
|
+
/*!
|
166
|
+
When the break-on-error mode is set, the default error handler
|
167
|
+
issues a hardware exception, which can make debugging more convenient.
|
168
|
+
|
169
|
+
\return the previous state
|
170
|
+
*/
|
171
|
+
CV_EXPORTS bool setBreakOnError(bool flag);
|
172
|
+
|
173
|
+
typedef int (CV_CDECL *ErrorCallback)( int status, const char* func_name,
|
174
|
+
const char* err_msg, const char* file_name,
|
175
|
+
int line, void* userdata );
|
176
|
+
|
177
|
+
//! Sets the new error handler and the optional user data.
|
178
|
+
|
179
|
+
/*!
|
180
|
+
The function sets the new error handler, called from cv::error().
|
181
|
+
|
182
|
+
\param errCallback the new error handler. If NULL, the default error handler is used.
|
183
|
+
\param userdata the optional user data pointer, passed to the callback.
|
184
|
+
\param prevUserdata the optional output parameter where the previous user data pointer is stored
|
185
|
+
|
186
|
+
\return the previous error handler
|
187
|
+
*/
|
188
|
+
CV_EXPORTS ErrorCallback redirectError( ErrorCallback errCallback,
|
189
|
+
void* userdata=0, void** prevUserdata=0);
|
190
|
+
|
191
|
+
#ifdef __GNUC__
|
192
|
+
#define CV_Error( code, msg ) cv::error( cv::Exception(code, msg, __func__, __FILE__, __LINE__) )
|
193
|
+
#define CV_Error_( code, args ) cv::error( cv::Exception(code, cv::format args, __func__, __FILE__, __LINE__) )
|
194
|
+
#define CV_Assert( expr ) if((expr)) ; else cv::error( cv::Exception(CV_StsAssert, #expr, __func__, __FILE__, __LINE__) )
|
195
|
+
#else
|
196
|
+
#define CV_Error( code, msg ) cv::error( cv::Exception(code, msg, "", __FILE__, __LINE__) )
|
197
|
+
#define CV_Error_( code, args ) cv::error( cv::Exception(code, cv::format args, "", __FILE__, __LINE__) )
|
198
|
+
#define CV_Assert( expr ) if((expr)) ; else cv::error( cv::Exception(CV_StsAssert, #expr, "", __FILE__, __LINE__) )
|
199
|
+
#endif
|
200
|
+
|
201
|
+
#ifdef _DEBUG
|
202
|
+
#define CV_DbgAssert(expr) CV_Assert(expr)
|
203
|
+
#else
|
204
|
+
#define CV_DbgAssert(expr)
|
205
|
+
#endif
|
206
|
+
|
207
|
+
CV_EXPORTS void setNumThreads(int nthreads);
|
208
|
+
CV_EXPORTS int getNumThreads();
|
209
|
+
CV_EXPORTS int getThreadNum();
|
210
|
+
|
211
|
+
//! Returns the number of ticks.
|
212
|
+
|
213
|
+
/*!
|
214
|
+
The function returns the number of ticks since the certain event (e.g. when the machine was turned on).
|
215
|
+
It can be used to initialize cv::RNG or to measure a function execution time by reading the tick count
|
216
|
+
before and after the function call. The granularity of ticks depends on the hardware and OS used. Use
|
217
|
+
cv::getTickFrequency() to convert ticks to seconds.
|
218
|
+
*/
|
219
|
+
CV_EXPORTS_W int64 getTickCount();
|
220
|
+
|
221
|
+
/*!
|
222
|
+
Returns the number of ticks per seconds.
|
223
|
+
|
224
|
+
The function returns the number of ticks (as returned by cv::getTickCount()) per second.
|
225
|
+
The following code computes the execution time in milliseconds:
|
226
|
+
|
227
|
+
\code
|
228
|
+
double exec_time = (double)getTickCount();
|
229
|
+
// do something ...
|
230
|
+
exec_time = ((double)getTickCount() - exec_time)*1000./getTickFrequency();
|
231
|
+
\endcode
|
232
|
+
*/
|
233
|
+
CV_EXPORTS_W double getTickFrequency();
|
234
|
+
|
235
|
+
/*!
|
236
|
+
Returns the number of CPU ticks.
|
237
|
+
|
238
|
+
On platforms where the feature is available, the function returns the number of CPU ticks
|
239
|
+
since the certain event (normally, the system power-on moment). Using this function
|
240
|
+
one can accurately measure the execution time of very small code fragments,
|
241
|
+
for which cv::getTickCount() granularity is not enough.
|
242
|
+
*/
|
243
|
+
CV_EXPORTS_W int64 getCPUTickCount();
|
244
|
+
|
245
|
+
/*!
|
246
|
+
Returns SSE etc. support status
|
247
|
+
|
248
|
+
The function returns true if certain hardware features are available.
|
249
|
+
Currently, the following features are recognized:
|
250
|
+
- CV_CPU_MMX - MMX
|
251
|
+
- CV_CPU_SSE - SSE
|
252
|
+
- CV_CPU_SSE2 - SSE 2
|
253
|
+
- CV_CPU_SSE3 - SSE 3
|
254
|
+
- CV_CPU_SSSE3 - SSSE 3
|
255
|
+
- CV_CPU_SSE4_1 - SSE 4.1
|
256
|
+
- CV_CPU_SSE4_2 - SSE 4.2
|
257
|
+
- CV_CPU_POPCNT - POPCOUNT
|
258
|
+
- CV_CPU_AVX - AVX
|
259
|
+
|
260
|
+
\note {Note that the function output is not static. Once you called cv::useOptimized(false),
|
261
|
+
most of the hardware acceleration is disabled and thus the function will returns false,
|
262
|
+
until you call cv::useOptimized(true)}
|
263
|
+
*/
|
264
|
+
CV_EXPORTS_W bool checkHardwareSupport(int feature);
|
265
|
+
|
266
|
+
//! returns the number of CPUs (including hyper-threading)
|
267
|
+
CV_EXPORTS_W int getNumberOfCPUs();
|
268
|
+
|
269
|
+
/*!
|
270
|
+
Allocates memory buffer
|
271
|
+
|
272
|
+
This is specialized OpenCV memory allocation function that returns properly aligned memory buffers.
|
273
|
+
The usage is identical to malloc(). The allocated buffers must be freed with cv::fastFree().
|
274
|
+
If there is not enough memory, the function calls cv::error(), which raises an exception.
|
275
|
+
|
276
|
+
\param bufSize buffer size in bytes
|
277
|
+
\return the allocated memory buffer.
|
278
|
+
*/
|
279
|
+
CV_EXPORTS void* fastMalloc(size_t bufSize);
|
280
|
+
|
281
|
+
/*!
|
282
|
+
Frees the memory allocated with cv::fastMalloc
|
283
|
+
|
284
|
+
This is the corresponding deallocation function for cv::fastMalloc().
|
285
|
+
When ptr==NULL, the function has no effect.
|
286
|
+
*/
|
287
|
+
CV_EXPORTS void fastFree(void* ptr);
|
288
|
+
|
289
|
+
template<typename _Tp> static inline _Tp* allocate(size_t n)
|
290
|
+
{
|
291
|
+
return new _Tp[n];
|
292
|
+
}
|
293
|
+
|
294
|
+
template<typename _Tp> static inline void deallocate(_Tp* ptr, size_t)
|
295
|
+
{
|
296
|
+
delete[] ptr;
|
297
|
+
}
|
298
|
+
|
299
|
+
/*!
|
300
|
+
Aligns pointer by the certain number of bytes
|
301
|
+
|
302
|
+
This small inline function aligns the pointer by the certian number of bytes by shifting
|
303
|
+
it forward by 0 or a positive offset.
|
304
|
+
*/
|
305
|
+
template<typename _Tp> static inline _Tp* alignPtr(_Tp* ptr, int n=(int)sizeof(_Tp))
|
306
|
+
{
|
307
|
+
return (_Tp*)(((size_t)ptr + n-1) & -n);
|
308
|
+
}
|
309
|
+
|
310
|
+
/*!
|
311
|
+
Aligns buffer size by the certain number of bytes
|
312
|
+
|
313
|
+
This small inline function aligns a buffer size by the certian number of bytes by enlarging it.
|
314
|
+
*/
|
315
|
+
static inline size_t alignSize(size_t sz, int n)
|
316
|
+
{
|
317
|
+
return (sz + n-1) & -n;
|
318
|
+
}
|
319
|
+
|
320
|
+
/*!
|
321
|
+
Turns on/off available optimization
|
322
|
+
|
323
|
+
The function turns on or off the optimized code in OpenCV. Some optimization can not be enabled
|
324
|
+
or disabled, but, for example, most of SSE code in OpenCV can be temporarily turned on or off this way.
|
325
|
+
|
326
|
+
\note{Since optimization may imply using special data structures, it may be unsafe
|
327
|
+
to call this function anywhere in the code. Instead, call it somewhere at the top level.}
|
328
|
+
*/
|
329
|
+
CV_EXPORTS_W void setUseOptimized(bool onoff);
|
330
|
+
|
331
|
+
/*!
|
332
|
+
Returns the current optimization status
|
333
|
+
|
334
|
+
The function returns the current optimization status, which is controlled by cv::setUseOptimized().
|
335
|
+
*/
|
336
|
+
CV_EXPORTS_W bool useOptimized();
|
337
|
+
|
338
|
+
/*!
|
339
|
+
The STL-compilant memory Allocator based on cv::fastMalloc() and cv::fastFree()
|
340
|
+
*/
|
341
|
+
template<typename _Tp> class CV_EXPORTS Allocator
|
342
|
+
{
|
343
|
+
public:
|
344
|
+
typedef _Tp value_type;
|
345
|
+
typedef value_type* pointer;
|
346
|
+
typedef const value_type* const_pointer;
|
347
|
+
typedef value_type& reference;
|
348
|
+
typedef const value_type& const_reference;
|
349
|
+
typedef size_t size_type;
|
350
|
+
typedef ptrdiff_t difference_type;
|
351
|
+
template<typename U> class rebind { typedef Allocator<U> other; };
|
352
|
+
|
353
|
+
explicit Allocator() {}
|
354
|
+
~Allocator() {}
|
355
|
+
explicit Allocator(Allocator const&) {}
|
356
|
+
template<typename U>
|
357
|
+
explicit Allocator(Allocator<U> const&) {}
|
358
|
+
|
359
|
+
// address
|
360
|
+
pointer address(reference r) { return &r; }
|
361
|
+
const_pointer address(const_reference r) { return &r; }
|
362
|
+
|
363
|
+
pointer allocate(size_type count, const void* =0)
|
364
|
+
{ return reinterpret_cast<pointer>(fastMalloc(count * sizeof (_Tp))); }
|
365
|
+
|
366
|
+
void deallocate(pointer p, size_type) {fastFree(p); }
|
367
|
+
|
368
|
+
size_type max_size() const
|
369
|
+
{ return max(static_cast<_Tp>(-1)/sizeof(_Tp), 1); }
|
370
|
+
|
371
|
+
void construct(pointer p, const _Tp& v) { new(static_cast<void*>(p)) _Tp(v); }
|
372
|
+
void destroy(pointer p) { p->~_Tp(); }
|
373
|
+
};
|
374
|
+
|
375
|
+
/////////////////////// Vec (used as element of multi-channel images /////////////////////
|
376
|
+
|
377
|
+
/*!
|
378
|
+
A helper class for cv::DataType
|
379
|
+
|
380
|
+
The class is specialized for each fundamental numerical data type supported by OpenCV.
|
381
|
+
It provides DataDepth<T>::value constant.
|
382
|
+
*/
|
383
|
+
template<typename _Tp> class CV_EXPORTS DataDepth {};
|
384
|
+
|
385
|
+
template<> class DataDepth<bool> { public: enum { value = CV_8U, fmt=(int)'u' }; };
|
386
|
+
template<> class DataDepth<uchar> { public: enum { value = CV_8U, fmt=(int)'u' }; };
|
387
|
+
template<> class DataDepth<schar> { public: enum { value = CV_8S, fmt=(int)'c' }; };
|
388
|
+
template<> class DataDepth<char> { public: enum { value = CV_8S, fmt=(int)'c' }; };
|
389
|
+
template<> class DataDepth<ushort> { public: enum { value = CV_16U, fmt=(int)'w' }; };
|
390
|
+
template<> class DataDepth<short> { public: enum { value = CV_16S, fmt=(int)'s' }; };
|
391
|
+
template<> class DataDepth<int> { public: enum { value = CV_32S, fmt=(int)'i' }; };
|
392
|
+
// this is temporary solution to support 32-bit unsigned integers
|
393
|
+
template<> class DataDepth<unsigned> { public: enum { value = CV_32S, fmt=(int)'i' }; };
|
394
|
+
template<> class DataDepth<float> { public: enum { value = CV_32F, fmt=(int)'f' }; };
|
395
|
+
template<> class DataDepth<double> { public: enum { value = CV_64F, fmt=(int)'d' }; };
|
396
|
+
template<typename _Tp> class DataDepth<_Tp*> { public: enum { value = CV_USRTYPE1, fmt=(int)'r' }; };
|
397
|
+
|
398
|
+
|
399
|
+
////////////////////////////// Small Matrix ///////////////////////////
|
400
|
+
|
401
|
+
/*!
|
402
|
+
A short numerical vector.
|
403
|
+
|
404
|
+
This template class represents short numerical vectors (of 1, 2, 3, 4 ... elements)
|
405
|
+
on which you can perform basic arithmetical operations, access individual elements using [] operator etc.
|
406
|
+
The vectors are allocated on stack, as opposite to std::valarray, std::vector, cv::Mat etc.,
|
407
|
+
which elements are dynamically allocated in the heap.
|
408
|
+
|
409
|
+
The template takes 2 parameters:
|
410
|
+
-# _Tp element type
|
411
|
+
-# cn the number of elements
|
412
|
+
|
413
|
+
In addition to the universal notation like Vec<float, 3>, you can use shorter aliases
|
414
|
+
for the most popular specialized variants of Vec, e.g. Vec3f ~ Vec<float, 3>.
|
415
|
+
*/
|
416
|
+
|
417
|
+
struct CV_EXPORTS Matx_AddOp {};
|
418
|
+
struct CV_EXPORTS Matx_SubOp {};
|
419
|
+
struct CV_EXPORTS Matx_ScaleOp {};
|
420
|
+
struct CV_EXPORTS Matx_MulOp {};
|
421
|
+
struct CV_EXPORTS Matx_MatMulOp {};
|
422
|
+
struct CV_EXPORTS Matx_TOp {};
|
423
|
+
|
424
|
+
template<typename _Tp, int m, int n> class CV_EXPORTS Matx
|
425
|
+
{
|
426
|
+
public:
|
427
|
+
typedef _Tp value_type;
|
428
|
+
typedef Matx<_Tp, MIN(m, n), 1> diag_type;
|
429
|
+
typedef Matx<_Tp, m, n> mat_type;
|
430
|
+
enum { depth = DataDepth<_Tp>::value, rows = m, cols = n, channels = rows*cols,
|
431
|
+
type = CV_MAKETYPE(depth, channels) };
|
432
|
+
|
433
|
+
//! default constructor
|
434
|
+
Matx();
|
435
|
+
|
436
|
+
Matx(_Tp v0); //!< 1x1 matrix
|
437
|
+
Matx(_Tp v0, _Tp v1); //!< 1x2 or 2x1 matrix
|
438
|
+
Matx(_Tp v0, _Tp v1, _Tp v2); //!< 1x3 or 3x1 matrix
|
439
|
+
Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3); //!< 1x4, 2x2 or 4x1 matrix
|
440
|
+
Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4); //!< 1x5 or 5x1 matrix
|
441
|
+
Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5); //!< 1x6, 2x3, 3x2 or 6x1 matrix
|
442
|
+
Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6); //!< 1x7 or 7x1 matrix
|
443
|
+
Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7); //!< 1x8, 2x4, 4x2 or 8x1 matrix
|
444
|
+
Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8); //!< 1x9, 3x3 or 9x1 matrix
|
445
|
+
Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8, _Tp v9); //!< 1x10, 2x5 or 5x2 or 10x1 matrix
|
446
|
+
Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3,
|
447
|
+
_Tp v4, _Tp v5, _Tp v6, _Tp v7,
|
448
|
+
_Tp v8, _Tp v9, _Tp v10, _Tp v11); //!< 1x12, 2x6, 3x4, 4x3, 6x2 or 12x1 matrix
|
449
|
+
Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3,
|
450
|
+
_Tp v4, _Tp v5, _Tp v6, _Tp v7,
|
451
|
+
_Tp v8, _Tp v9, _Tp v10, _Tp v11,
|
452
|
+
_Tp v12, _Tp v13, _Tp v14, _Tp v15); //!< 1x16, 4x4 or 16x1 matrix
|
453
|
+
explicit Matx(const _Tp* vals); //!< initialize from a plain array
|
454
|
+
|
455
|
+
static Matx all(_Tp alpha);
|
456
|
+
static Matx zeros();
|
457
|
+
static Matx ones();
|
458
|
+
static Matx eye();
|
459
|
+
static Matx diag(const diag_type& d);
|
460
|
+
static Matx randu(_Tp a, _Tp b);
|
461
|
+
static Matx randn(_Tp a, _Tp b);
|
462
|
+
|
463
|
+
//! dot product computed with the default precision
|
464
|
+
_Tp dot(const Matx<_Tp, m, n>& v) const;
|
465
|
+
|
466
|
+
//! dot product computed in double-precision arithmetics
|
467
|
+
double ddot(const Matx<_Tp, m, n>& v) const;
|
468
|
+
|
469
|
+
//! convertion to another data type
|
470
|
+
template<typename T2> operator Matx<T2, m, n>() const;
|
471
|
+
|
472
|
+
//! change the matrix shape
|
473
|
+
template<int m1, int n1> Matx<_Tp, m1, n1> reshape() const;
|
474
|
+
|
475
|
+
//! extract part of the matrix
|
476
|
+
template<int m1, int n1> Matx<_Tp, m1, n1> get_minor(int i, int j) const;
|
477
|
+
|
478
|
+
//! extract the matrix row
|
479
|
+
Matx<_Tp, 1, n> row(int i) const;
|
480
|
+
|
481
|
+
//! extract the matrix column
|
482
|
+
Matx<_Tp, m, 1> col(int i) const;
|
483
|
+
|
484
|
+
//! extract the matrix diagonal
|
485
|
+
Matx<_Tp, MIN(m,n), 1> diag() const;
|
486
|
+
|
487
|
+
//! transpose the matrix
|
488
|
+
Matx<_Tp, n, m> t() const;
|
489
|
+
|
490
|
+
//! invert matrix the matrix
|
491
|
+
Matx<_Tp, n, m> inv(int method=DECOMP_LU) const;
|
492
|
+
|
493
|
+
//! solve linear system
|
494
|
+
template<int l> Matx<_Tp, n, l> solve(const Matx<_Tp, m, l>& rhs, int flags=DECOMP_LU) const;
|
495
|
+
Matx<_Tp, n, 1> solve(const Matx<_Tp, m, 1>& rhs, int method) const;
|
496
|
+
|
497
|
+
//! multiply two matrices element-wise
|
498
|
+
Matx<_Tp, m, n> mul(const Matx<_Tp, m, n>& a) const;
|
499
|
+
|
500
|
+
//! element access
|
501
|
+
const _Tp& operator ()(int i, int j) const;
|
502
|
+
_Tp& operator ()(int i, int j);
|
503
|
+
|
504
|
+
//! 1D element access
|
505
|
+
const _Tp& operator ()(int i) const;
|
506
|
+
_Tp& operator ()(int i);
|
507
|
+
|
508
|
+
Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_AddOp);
|
509
|
+
Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_SubOp);
|
510
|
+
template<typename _T2> Matx(const Matx<_Tp, m, n>& a, _T2 alpha, Matx_ScaleOp);
|
511
|
+
Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_MulOp);
|
512
|
+
template<int l> Matx(const Matx<_Tp, m, l>& a, const Matx<_Tp, l, n>& b, Matx_MatMulOp);
|
513
|
+
Matx(const Matx<_Tp, n, m>& a, Matx_TOp);
|
514
|
+
|
515
|
+
_Tp val[m*n]; //< matrix elements
|
516
|
+
};
|
517
|
+
|
518
|
+
|
519
|
+
typedef Matx<float, 1, 2> Matx12f;
|
520
|
+
typedef Matx<double, 1, 2> Matx12d;
|
521
|
+
typedef Matx<float, 1, 3> Matx13f;
|
522
|
+
typedef Matx<double, 1, 3> Matx13d;
|
523
|
+
typedef Matx<float, 1, 4> Matx14f;
|
524
|
+
typedef Matx<double, 1, 4> Matx14d;
|
525
|
+
typedef Matx<float, 1, 6> Matx16f;
|
526
|
+
typedef Matx<double, 1, 6> Matx16d;
|
527
|
+
|
528
|
+
typedef Matx<float, 2, 1> Matx21f;
|
529
|
+
typedef Matx<double, 2, 1> Matx21d;
|
530
|
+
typedef Matx<float, 3, 1> Matx31f;
|
531
|
+
typedef Matx<double, 3, 1> Matx31d;
|
532
|
+
typedef Matx<float, 4, 1> Matx41f;
|
533
|
+
typedef Matx<double, 4, 1> Matx41d;
|
534
|
+
typedef Matx<float, 6, 1> Matx61f;
|
535
|
+
typedef Matx<double, 6, 1> Matx61d;
|
536
|
+
|
537
|
+
typedef Matx<float, 2, 2> Matx22f;
|
538
|
+
typedef Matx<double, 2, 2> Matx22d;
|
539
|
+
typedef Matx<float, 2, 3> Matx23f;
|
540
|
+
typedef Matx<double, 2, 3> Matx23d;
|
541
|
+
typedef Matx<float, 3, 2> Matx32f;
|
542
|
+
typedef Matx<double, 3, 2> Matx32d;
|
543
|
+
|
544
|
+
typedef Matx<float, 3, 3> Matx33f;
|
545
|
+
typedef Matx<double, 3, 3> Matx33d;
|
546
|
+
|
547
|
+
typedef Matx<float, 3, 4> Matx34f;
|
548
|
+
typedef Matx<double, 3, 4> Matx34d;
|
549
|
+
typedef Matx<float, 4, 3> Matx43f;
|
550
|
+
typedef Matx<double, 4, 3> Matx43d;
|
551
|
+
|
552
|
+
typedef Matx<float, 4, 4> Matx44f;
|
553
|
+
typedef Matx<double, 4, 4> Matx44d;
|
554
|
+
typedef Matx<float, 6, 6> Matx66f;
|
555
|
+
typedef Matx<double, 6, 6> Matx66d;
|
556
|
+
|
557
|
+
|
558
|
+
/*!
|
559
|
+
A short numerical vector.
|
560
|
+
|
561
|
+
This template class represents short numerical vectors (of 1, 2, 3, 4 ... elements)
|
562
|
+
on which you can perform basic arithmetical operations, access individual elements using [] operator etc.
|
563
|
+
The vectors are allocated on stack, as opposite to std::valarray, std::vector, cv::Mat etc.,
|
564
|
+
which elements are dynamically allocated in the heap.
|
565
|
+
|
566
|
+
The template takes 2 parameters:
|
567
|
+
-# _Tp element type
|
568
|
+
-# cn the number of elements
|
569
|
+
|
570
|
+
In addition to the universal notation like Vec<float, 3>, you can use shorter aliases
|
571
|
+
for the most popular specialized variants of Vec, e.g. Vec3f ~ Vec<float, 3>.
|
572
|
+
*/
|
573
|
+
template<typename _Tp, int cn> class CV_EXPORTS Vec : public Matx<_Tp, cn, 1>
|
574
|
+
{
|
575
|
+
public:
|
576
|
+
typedef _Tp value_type;
|
577
|
+
enum { depth = DataDepth<_Tp>::value, channels = cn, type = CV_MAKETYPE(depth, channels) };
|
578
|
+
|
579
|
+
//! default constructor
|
580
|
+
Vec();
|
581
|
+
|
582
|
+
Vec(_Tp v0); //!< 1-element vector constructor
|
583
|
+
Vec(_Tp v0, _Tp v1); //!< 2-element vector constructor
|
584
|
+
Vec(_Tp v0, _Tp v1, _Tp v2); //!< 3-element vector constructor
|
585
|
+
Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3); //!< 4-element vector constructor
|
586
|
+
Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4); //!< 5-element vector constructor
|
587
|
+
Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5); //!< 6-element vector constructor
|
588
|
+
Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6); //!< 7-element vector constructor
|
589
|
+
Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7); //!< 8-element vector constructor
|
590
|
+
Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8); //!< 9-element vector constructor
|
591
|
+
Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8, _Tp v9); //!< 10-element vector constructor
|
592
|
+
explicit Vec(const _Tp* values);
|
593
|
+
|
594
|
+
Vec(const Vec<_Tp, cn>& v);
|
595
|
+
|
596
|
+
static Vec all(_Tp alpha);
|
597
|
+
|
598
|
+
//! per-element multiplication
|
599
|
+
Vec mul(const Vec<_Tp, cn>& v) const;
|
600
|
+
|
601
|
+
/*!
|
602
|
+
cross product of the two 3D vectors.
|
603
|
+
|
604
|
+
For other dimensionalities the exception is raised
|
605
|
+
*/
|
606
|
+
Vec cross(const Vec& v) const;
|
607
|
+
//! convertion to another data type
|
608
|
+
template<typename T2> operator Vec<T2, cn>() const;
|
609
|
+
//! conversion to 4-element CvScalar.
|
610
|
+
operator CvScalar() const;
|
611
|
+
|
612
|
+
/*! element access */
|
613
|
+
const _Tp& operator [](int i) const;
|
614
|
+
_Tp& operator[](int i);
|
615
|
+
const _Tp& operator ()(int i) const;
|
616
|
+
_Tp& operator ()(int i);
|
617
|
+
|
618
|
+
Vec(const Matx<_Tp, cn, 1>& a, const Matx<_Tp, cn, 1>& b, Matx_AddOp);
|
619
|
+
Vec(const Matx<_Tp, cn, 1>& a, const Matx<_Tp, cn, 1>& b, Matx_SubOp);
|
620
|
+
template<typename _T2> Vec(const Matx<_Tp, cn, 1>& a, _T2 alpha, Matx_ScaleOp);
|
621
|
+
};
|
622
|
+
|
623
|
+
|
624
|
+
/* \typedef
|
625
|
+
|
626
|
+
Shorter aliases for the most popular specializations of Vec<T,n>
|
627
|
+
*/
|
628
|
+
typedef Vec<uchar, 2> Vec2b;
|
629
|
+
typedef Vec<uchar, 3> Vec3b;
|
630
|
+
typedef Vec<uchar, 4> Vec4b;
|
631
|
+
|
632
|
+
typedef Vec<short, 2> Vec2s;
|
633
|
+
typedef Vec<short, 3> Vec3s;
|
634
|
+
typedef Vec<short, 4> Vec4s;
|
635
|
+
|
636
|
+
typedef Vec<ushort, 2> Vec2w;
|
637
|
+
typedef Vec<ushort, 3> Vec3w;
|
638
|
+
typedef Vec<ushort, 4> Vec4w;
|
639
|
+
|
640
|
+
typedef Vec<int, 2> Vec2i;
|
641
|
+
typedef Vec<int, 3> Vec3i;
|
642
|
+
typedef Vec<int, 4> Vec4i;
|
643
|
+
typedef Vec<int, 6> Vec6i;
|
644
|
+
typedef Vec<int, 8> Vec8i;
|
645
|
+
|
646
|
+
typedef Vec<float, 2> Vec2f;
|
647
|
+
typedef Vec<float, 3> Vec3f;
|
648
|
+
typedef Vec<float, 4> Vec4f;
|
649
|
+
typedef Vec<float, 6> Vec6f;
|
650
|
+
|
651
|
+
typedef Vec<double, 2> Vec2d;
|
652
|
+
typedef Vec<double, 3> Vec3d;
|
653
|
+
typedef Vec<double, 4> Vec4d;
|
654
|
+
typedef Vec<double, 6> Vec6d;
|
655
|
+
|
656
|
+
|
657
|
+
//////////////////////////////// Complex //////////////////////////////
|
658
|
+
|
659
|
+
/*!
|
660
|
+
A complex number class.
|
661
|
+
|
662
|
+
The template class is similar and compatible with std::complex, however it provides slightly
|
663
|
+
more convenient access to the real and imaginary parts using through the simple field access, as opposite
|
664
|
+
to std::complex::real() and std::complex::imag().
|
665
|
+
*/
|
666
|
+
template<typename _Tp> class CV_EXPORTS Complex
|
667
|
+
{
|
668
|
+
public:
|
669
|
+
|
670
|
+
//! constructors
|
671
|
+
Complex();
|
672
|
+
Complex( _Tp _re, _Tp _im=0 );
|
673
|
+
Complex( const std::complex<_Tp>& c );
|
674
|
+
|
675
|
+
//! conversion to another data type
|
676
|
+
template<typename T2> operator Complex<T2>() const;
|
677
|
+
//! conjugation
|
678
|
+
Complex conj() const;
|
679
|
+
//! conversion to std::complex
|
680
|
+
operator std::complex<_Tp>() const;
|
681
|
+
|
682
|
+
_Tp re, im; //< the real and the imaginary parts
|
683
|
+
};
|
684
|
+
|
685
|
+
|
686
|
+
/*!
|
687
|
+
\typedef
|
688
|
+
*/
|
689
|
+
typedef Complex<float> Complexf;
|
690
|
+
typedef Complex<double> Complexd;
|
691
|
+
|
692
|
+
|
693
|
+
//////////////////////////////// Point_ ////////////////////////////////
|
694
|
+
|
695
|
+
/*!
|
696
|
+
template 2D point class.
|
697
|
+
|
698
|
+
The class defines a point in 2D space. Data type of the point coordinates is specified
|
699
|
+
as a template parameter. There are a few shorter aliases available for user convenience.
|
700
|
+
See cv::Point, cv::Point2i, cv::Point2f and cv::Point2d.
|
701
|
+
*/
|
702
|
+
template<typename _Tp> class CV_EXPORTS Point_
|
703
|
+
{
|
704
|
+
public:
|
705
|
+
typedef _Tp value_type;
|
706
|
+
|
707
|
+
// various constructors
|
708
|
+
Point_();
|
709
|
+
Point_(_Tp _x, _Tp _y);
|
710
|
+
Point_(const Point_& pt);
|
711
|
+
Point_(const CvPoint& pt);
|
712
|
+
Point_(const CvPoint2D32f& pt);
|
713
|
+
Point_(const Size_<_Tp>& sz);
|
714
|
+
Point_(const Vec<_Tp, 2>& v);
|
715
|
+
|
716
|
+
Point_& operator = (const Point_& pt);
|
717
|
+
//! conversion to another data type
|
718
|
+
template<typename _Tp2> operator Point_<_Tp2>() const;
|
719
|
+
|
720
|
+
//! conversion to the old-style C structures
|
721
|
+
operator CvPoint() const;
|
722
|
+
operator CvPoint2D32f() const;
|
723
|
+
operator Vec<_Tp, 2>() const;
|
724
|
+
|
725
|
+
//! dot product
|
726
|
+
_Tp dot(const Point_& pt) const;
|
727
|
+
//! dot product computed in double-precision arithmetics
|
728
|
+
double ddot(const Point_& pt) const;
|
729
|
+
//! checks whether the point is inside the specified rectangle
|
730
|
+
bool inside(const Rect_<_Tp>& r) const;
|
731
|
+
|
732
|
+
_Tp x, y; //< the point coordinates
|
733
|
+
};
|
734
|
+
|
735
|
+
/*!
|
736
|
+
template 3D point class.
|
737
|
+
|
738
|
+
The class defines a point in 3D space. Data type of the point coordinates is specified
|
739
|
+
as a template parameter.
|
740
|
+
|
741
|
+
\see cv::Point3i, cv::Point3f and cv::Point3d
|
742
|
+
*/
|
743
|
+
template<typename _Tp> class CV_EXPORTS Point3_
|
744
|
+
{
|
745
|
+
public:
|
746
|
+
typedef _Tp value_type;
|
747
|
+
|
748
|
+
// various constructors
|
749
|
+
Point3_();
|
750
|
+
Point3_(_Tp _x, _Tp _y, _Tp _z);
|
751
|
+
Point3_(const Point3_& pt);
|
752
|
+
explicit Point3_(const Point_<_Tp>& pt);
|
753
|
+
Point3_(const CvPoint3D32f& pt);
|
754
|
+
Point3_(const Vec<_Tp, 3>& v);
|
755
|
+
|
756
|
+
Point3_& operator = (const Point3_& pt);
|
757
|
+
//! conversion to another data type
|
758
|
+
template<typename _Tp2> operator Point3_<_Tp2>() const;
|
759
|
+
//! conversion to the old-style CvPoint...
|
760
|
+
operator CvPoint3D32f() const;
|
761
|
+
//! conversion to cv::Vec<>
|
762
|
+
operator Vec<_Tp, 3>() const;
|
763
|
+
|
764
|
+
//! dot product
|
765
|
+
_Tp dot(const Point3_& pt) const;
|
766
|
+
//! dot product computed in double-precision arithmetics
|
767
|
+
double ddot(const Point3_& pt) const;
|
768
|
+
//! cross product of the 2 3D points
|
769
|
+
Point3_ cross(const Point3_& pt) const;
|
770
|
+
|
771
|
+
_Tp x, y, z; //< the point coordinates
|
772
|
+
};
|
773
|
+
|
774
|
+
//////////////////////////////// Size_ ////////////////////////////////
|
775
|
+
|
776
|
+
/*!
|
777
|
+
The 2D size class
|
778
|
+
|
779
|
+
The class represents the size of a 2D rectangle, image size, matrix size etc.
|
780
|
+
Normally, cv::Size ~ cv::Size_<int> is used.
|
781
|
+
*/
|
782
|
+
template<typename _Tp> class CV_EXPORTS Size_
|
783
|
+
{
|
784
|
+
public:
|
785
|
+
typedef _Tp value_type;
|
786
|
+
|
787
|
+
//! various constructors
|
788
|
+
Size_();
|
789
|
+
Size_(_Tp _width, _Tp _height);
|
790
|
+
Size_(const Size_& sz);
|
791
|
+
Size_(const CvSize& sz);
|
792
|
+
Size_(const CvSize2D32f& sz);
|
793
|
+
Size_(const Point_<_Tp>& pt);
|
794
|
+
|
795
|
+
Size_& operator = (const Size_& sz);
|
796
|
+
//! the area (width*height)
|
797
|
+
_Tp area() const;
|
798
|
+
|
799
|
+
//! conversion of another data type.
|
800
|
+
template<typename _Tp2> operator Size_<_Tp2>() const;
|
801
|
+
|
802
|
+
//! conversion to the old-style OpenCV types
|
803
|
+
operator CvSize() const;
|
804
|
+
operator CvSize2D32f() const;
|
805
|
+
|
806
|
+
_Tp width, height; // the width and the height
|
807
|
+
};
|
808
|
+
|
809
|
+
//////////////////////////////// Rect_ ////////////////////////////////
|
810
|
+
|
811
|
+
/*!
|
812
|
+
The 2D up-right rectangle class
|
813
|
+
|
814
|
+
The class represents a 2D rectangle with coordinates of the specified data type.
|
815
|
+
Normally, cv::Rect ~ cv::Rect_<int> is used.
|
816
|
+
*/
|
817
|
+
template<typename _Tp> class CV_EXPORTS Rect_
|
818
|
+
{
|
819
|
+
public:
|
820
|
+
typedef _Tp value_type;
|
821
|
+
|
822
|
+
//! various constructors
|
823
|
+
Rect_();
|
824
|
+
Rect_(_Tp _x, _Tp _y, _Tp _width, _Tp _height);
|
825
|
+
Rect_(const Rect_& r);
|
826
|
+
Rect_(const CvRect& r);
|
827
|
+
Rect_(const Point_<_Tp>& org, const Size_<_Tp>& sz);
|
828
|
+
Rect_(const Point_<_Tp>& pt1, const Point_<_Tp>& pt2);
|
829
|
+
|
830
|
+
Rect_& operator = ( const Rect_& r );
|
831
|
+
//! the top-left corner
|
832
|
+
Point_<_Tp> tl() const;
|
833
|
+
//! the bottom-right corner
|
834
|
+
Point_<_Tp> br() const;
|
835
|
+
|
836
|
+
//! size (width, height) of the rectangle
|
837
|
+
Size_<_Tp> size() const;
|
838
|
+
//! area (width*height) of the rectangle
|
839
|
+
_Tp area() const;
|
840
|
+
|
841
|
+
//! conversion to another data type
|
842
|
+
template<typename _Tp2> operator Rect_<_Tp2>() const;
|
843
|
+
//! conversion to the old-style CvRect
|
844
|
+
operator CvRect() const;
|
845
|
+
|
846
|
+
//! checks whether the rectangle contains the point
|
847
|
+
bool contains(const Point_<_Tp>& pt) const;
|
848
|
+
|
849
|
+
_Tp x, y, width, height; //< the top-left corner, as well as width and height of the rectangle
|
850
|
+
};
|
851
|
+
|
852
|
+
|
853
|
+
/*!
|
854
|
+
\typedef
|
855
|
+
|
856
|
+
shorter aliases for the most popular cv::Point_<>, cv::Size_<> and cv::Rect_<> specializations
|
857
|
+
*/
|
858
|
+
typedef Point_<int> Point2i;
|
859
|
+
typedef Point2i Point;
|
860
|
+
typedef Size_<int> Size2i;
|
861
|
+
typedef Size2i Size;
|
862
|
+
typedef Rect_<int> Rect;
|
863
|
+
typedef Point_<float> Point2f;
|
864
|
+
typedef Point_<double> Point2d;
|
865
|
+
typedef Size_<float> Size2f;
|
866
|
+
typedef Point3_<int> Point3i;
|
867
|
+
typedef Point3_<float> Point3f;
|
868
|
+
typedef Point3_<double> Point3d;
|
869
|
+
|
870
|
+
|
871
|
+
/*!
|
872
|
+
The rotated 2D rectangle.
|
873
|
+
|
874
|
+
The class represents rotated (i.e. not up-right) rectangles on a plane.
|
875
|
+
Each rectangle is described by the center point (mass center), length of each side
|
876
|
+
(represented by cv::Size2f structure) and the rotation angle in degrees.
|
877
|
+
*/
|
878
|
+
class CV_EXPORTS RotatedRect
|
879
|
+
{
|
880
|
+
public:
|
881
|
+
//! various constructors
|
882
|
+
RotatedRect();
|
883
|
+
RotatedRect(const Point2f& _center, const Size2f& _size, float _angle);
|
884
|
+
RotatedRect(const CvBox2D& box);
|
885
|
+
|
886
|
+
//! returns 4 vertices of the rectangle
|
887
|
+
void points(Point2f pts[]) const;
|
888
|
+
//! returns the minimal up-right rectangle containing the rotated rectangle
|
889
|
+
Rect boundingRect() const;
|
890
|
+
//! conversion to the old-style CvBox2D structure
|
891
|
+
operator CvBox2D() const;
|
892
|
+
|
893
|
+
Point2f center; //< the rectangle mass center
|
894
|
+
Size2f size; //< width and height of the rectangle
|
895
|
+
float angle; //< the rotation angle. When the angle is 0, 90, 180, 270 etc., the rectangle becomes an up-right rectangle.
|
896
|
+
};
|
897
|
+
|
898
|
+
//////////////////////////////// Scalar_ ///////////////////////////////
|
899
|
+
|
900
|
+
/*!
|
901
|
+
The template scalar class.
|
902
|
+
|
903
|
+
This is partially specialized cv::Vec class with the number of elements = 4, i.e. a short vector of four elements.
|
904
|
+
Normally, cv::Scalar ~ cv::Scalar_<double> is used.
|
905
|
+
*/
|
906
|
+
template<typename _Tp> class CV_EXPORTS Scalar_ : public Vec<_Tp, 4>
|
907
|
+
{
|
908
|
+
public:
|
909
|
+
//! various constructors
|
910
|
+
Scalar_();
|
911
|
+
Scalar_(_Tp v0, _Tp v1, _Tp v2=0, _Tp v3=0);
|
912
|
+
Scalar_(const CvScalar& s);
|
913
|
+
Scalar_(_Tp v0);
|
914
|
+
|
915
|
+
//! returns a scalar with all elements set to v0
|
916
|
+
static Scalar_<_Tp> all(_Tp v0);
|
917
|
+
//! conversion to the old-style CvScalar
|
918
|
+
operator CvScalar() const;
|
919
|
+
|
920
|
+
//! conversion to another data type
|
921
|
+
template<typename T2> operator Scalar_<T2>() const;
|
922
|
+
|
923
|
+
//! per-element product
|
924
|
+
Scalar_<_Tp> mul(const Scalar_<_Tp>& t, double scale=1 ) const;
|
925
|
+
|
926
|
+
// returns (v0, -v1, -v2, -v3)
|
927
|
+
Scalar_<_Tp> conj() const;
|
928
|
+
|
929
|
+
// returns true iff v1 == v2 == v3 == 0
|
930
|
+
bool isReal() const;
|
931
|
+
};
|
932
|
+
|
933
|
+
typedef Scalar_<double> Scalar;
|
934
|
+
|
935
|
+
CV_EXPORTS void scalarToRawData(const Scalar& s, void* buf, int type, int unroll_to=0);
|
936
|
+
|
937
|
+
//////////////////////////////// Range /////////////////////////////////
|
938
|
+
|
939
|
+
/*!
|
940
|
+
The 2D range class
|
941
|
+
|
942
|
+
This is the class used to specify a continuous subsequence, i.e. part of a contour, or a column span in a matrix.
|
943
|
+
*/
|
944
|
+
class CV_EXPORTS Range
|
945
|
+
{
|
946
|
+
public:
|
947
|
+
Range();
|
948
|
+
Range(int _start, int _end);
|
949
|
+
Range(const CvSlice& slice);
|
950
|
+
int size() const;
|
951
|
+
bool empty() const;
|
952
|
+
static Range all();
|
953
|
+
operator CvSlice() const;
|
954
|
+
|
955
|
+
int start, end;
|
956
|
+
};
|
957
|
+
|
958
|
+
/////////////////////////////// DataType ////////////////////////////////
|
959
|
+
|
960
|
+
/*!
|
961
|
+
Informative template class for OpenCV "scalars".
|
962
|
+
|
963
|
+
The class is specialized for each primitive numerical type supported by OpenCV (such as unsigned char or float),
|
964
|
+
as well as for more complex types, like cv::Complex<>, std::complex<>, cv::Vec<> etc.
|
965
|
+
The common property of all such types (called "scalars", do not confuse it with cv::Scalar_)
|
966
|
+
is that each of them is basically a tuple of numbers of the same type. Each "scalar" can be represented
|
967
|
+
by the depth id (CV_8U ... CV_64F) and the number of channels.
|
968
|
+
OpenCV matrices, 2D or nD, dense or sparse, can store "scalars",
|
969
|
+
as long as the number of channels does not exceed CV_CN_MAX.
|
970
|
+
*/
|
971
|
+
template<typename _Tp> class DataType
|
972
|
+
{
|
973
|
+
public:
|
974
|
+
typedef _Tp value_type;
|
975
|
+
typedef value_type work_type;
|
976
|
+
typedef value_type channel_type;
|
977
|
+
typedef value_type vec_type;
|
978
|
+
|
979
|
+
enum { generic_type = 1, depth = -1, channels = 1, fmt=0,
|
980
|
+
type = CV_MAKETYPE(depth, channels) };
|
981
|
+
};
|
982
|
+
|
983
|
+
template<> class DataType<bool>
|
984
|
+
{
|
985
|
+
public:
|
986
|
+
typedef bool value_type;
|
987
|
+
typedef int work_type;
|
988
|
+
typedef value_type channel_type;
|
989
|
+
typedef value_type vec_type;
|
990
|
+
enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 1,
|
991
|
+
fmt=DataDepth<channel_type>::fmt,
|
992
|
+
type = CV_MAKETYPE(depth, channels) };
|
993
|
+
};
|
994
|
+
|
995
|
+
template<> class DataType<uchar>
|
996
|
+
{
|
997
|
+
public:
|
998
|
+
typedef uchar value_type;
|
999
|
+
typedef int work_type;
|
1000
|
+
typedef value_type channel_type;
|
1001
|
+
typedef value_type vec_type;
|
1002
|
+
enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 1,
|
1003
|
+
fmt=DataDepth<channel_type>::fmt,
|
1004
|
+
type = CV_MAKETYPE(depth, channels) };
|
1005
|
+
};
|
1006
|
+
|
1007
|
+
template<> class DataType<schar>
|
1008
|
+
{
|
1009
|
+
public:
|
1010
|
+
typedef schar value_type;
|
1011
|
+
typedef int work_type;
|
1012
|
+
typedef value_type channel_type;
|
1013
|
+
typedef value_type vec_type;
|
1014
|
+
enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 1,
|
1015
|
+
fmt=DataDepth<channel_type>::fmt,
|
1016
|
+
type = CV_MAKETYPE(depth, channels) };
|
1017
|
+
};
|
1018
|
+
|
1019
|
+
template<> class DataType<char>
|
1020
|
+
{
|
1021
|
+
public:
|
1022
|
+
typedef schar value_type;
|
1023
|
+
typedef int work_type;
|
1024
|
+
typedef value_type channel_type;
|
1025
|
+
typedef value_type vec_type;
|
1026
|
+
enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 1,
|
1027
|
+
fmt=DataDepth<channel_type>::fmt,
|
1028
|
+
type = CV_MAKETYPE(depth, channels) };
|
1029
|
+
};
|
1030
|
+
|
1031
|
+
template<> class DataType<ushort>
|
1032
|
+
{
|
1033
|
+
public:
|
1034
|
+
typedef ushort value_type;
|
1035
|
+
typedef int work_type;
|
1036
|
+
typedef value_type channel_type;
|
1037
|
+
typedef value_type vec_type;
|
1038
|
+
enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 1,
|
1039
|
+
fmt=DataDepth<channel_type>::fmt,
|
1040
|
+
type = CV_MAKETYPE(depth, channels) };
|
1041
|
+
};
|
1042
|
+
|
1043
|
+
template<> class DataType<short>
|
1044
|
+
{
|
1045
|
+
public:
|
1046
|
+
typedef short value_type;
|
1047
|
+
typedef int work_type;
|
1048
|
+
typedef value_type channel_type;
|
1049
|
+
typedef value_type vec_type;
|
1050
|
+
enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 1,
|
1051
|
+
fmt=DataDepth<channel_type>::fmt,
|
1052
|
+
type = CV_MAKETYPE(depth, channels) };
|
1053
|
+
};
|
1054
|
+
|
1055
|
+
template<> class DataType<int>
|
1056
|
+
{
|
1057
|
+
public:
|
1058
|
+
typedef int value_type;
|
1059
|
+
typedef value_type work_type;
|
1060
|
+
typedef value_type channel_type;
|
1061
|
+
typedef value_type vec_type;
|
1062
|
+
enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 1,
|
1063
|
+
fmt=DataDepth<channel_type>::fmt,
|
1064
|
+
type = CV_MAKETYPE(depth, channels) };
|
1065
|
+
};
|
1066
|
+
|
1067
|
+
template<> class DataType<float>
|
1068
|
+
{
|
1069
|
+
public:
|
1070
|
+
typedef float value_type;
|
1071
|
+
typedef value_type work_type;
|
1072
|
+
typedef value_type channel_type;
|
1073
|
+
typedef value_type vec_type;
|
1074
|
+
enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 1,
|
1075
|
+
fmt=DataDepth<channel_type>::fmt,
|
1076
|
+
type = CV_MAKETYPE(depth, channels) };
|
1077
|
+
};
|
1078
|
+
|
1079
|
+
template<> class DataType<double>
|
1080
|
+
{
|
1081
|
+
public:
|
1082
|
+
typedef double value_type;
|
1083
|
+
typedef value_type work_type;
|
1084
|
+
typedef value_type channel_type;
|
1085
|
+
typedef value_type vec_type;
|
1086
|
+
enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 1,
|
1087
|
+
fmt=DataDepth<channel_type>::fmt,
|
1088
|
+
type = CV_MAKETYPE(depth, channels) };
|
1089
|
+
};
|
1090
|
+
|
1091
|
+
template<typename _Tp, int cn> class DataType<Vec<_Tp, cn> >
|
1092
|
+
{
|
1093
|
+
public:
|
1094
|
+
typedef Vec<_Tp, cn> value_type;
|
1095
|
+
typedef Vec<typename DataType<_Tp>::work_type, cn> work_type;
|
1096
|
+
typedef _Tp channel_type;
|
1097
|
+
typedef value_type vec_type;
|
1098
|
+
enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = cn,
|
1099
|
+
fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt,
|
1100
|
+
type = CV_MAKETYPE(depth, channels) };
|
1101
|
+
};
|
1102
|
+
|
1103
|
+
template<typename _Tp> class DataType<std::complex<_Tp> >
|
1104
|
+
{
|
1105
|
+
public:
|
1106
|
+
typedef std::complex<_Tp> value_type;
|
1107
|
+
typedef value_type work_type;
|
1108
|
+
typedef _Tp channel_type;
|
1109
|
+
enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 2,
|
1110
|
+
fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt,
|
1111
|
+
type = CV_MAKETYPE(depth, channels) };
|
1112
|
+
typedef Vec<channel_type, channels> vec_type;
|
1113
|
+
};
|
1114
|
+
|
1115
|
+
template<typename _Tp> class DataType<Complex<_Tp> >
|
1116
|
+
{
|
1117
|
+
public:
|
1118
|
+
typedef Complex<_Tp> value_type;
|
1119
|
+
typedef value_type work_type;
|
1120
|
+
typedef _Tp channel_type;
|
1121
|
+
enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 2,
|
1122
|
+
fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt,
|
1123
|
+
type = CV_MAKETYPE(depth, channels) };
|
1124
|
+
typedef Vec<channel_type, channels> vec_type;
|
1125
|
+
};
|
1126
|
+
|
1127
|
+
template<typename _Tp> class DataType<Point_<_Tp> >
|
1128
|
+
{
|
1129
|
+
public:
|
1130
|
+
typedef Point_<_Tp> value_type;
|
1131
|
+
typedef Point_<typename DataType<_Tp>::work_type> work_type;
|
1132
|
+
typedef _Tp channel_type;
|
1133
|
+
enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 2,
|
1134
|
+
fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt,
|
1135
|
+
type = CV_MAKETYPE(depth, channels) };
|
1136
|
+
typedef Vec<channel_type, channels> vec_type;
|
1137
|
+
};
|
1138
|
+
|
1139
|
+
template<typename _Tp> class DataType<Point3_<_Tp> >
|
1140
|
+
{
|
1141
|
+
public:
|
1142
|
+
typedef Point3_<_Tp> value_type;
|
1143
|
+
typedef Point3_<typename DataType<_Tp>::work_type> work_type;
|
1144
|
+
typedef _Tp channel_type;
|
1145
|
+
enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 3,
|
1146
|
+
fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt,
|
1147
|
+
type = CV_MAKETYPE(depth, channels) };
|
1148
|
+
typedef Vec<channel_type, channels> vec_type;
|
1149
|
+
};
|
1150
|
+
|
1151
|
+
template<typename _Tp> class DataType<Size_<_Tp> >
|
1152
|
+
{
|
1153
|
+
public:
|
1154
|
+
typedef Size_<_Tp> value_type;
|
1155
|
+
typedef Size_<typename DataType<_Tp>::work_type> work_type;
|
1156
|
+
typedef _Tp channel_type;
|
1157
|
+
enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 2,
|
1158
|
+
fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt,
|
1159
|
+
type = CV_MAKETYPE(depth, channels) };
|
1160
|
+
typedef Vec<channel_type, channels> vec_type;
|
1161
|
+
};
|
1162
|
+
|
1163
|
+
template<typename _Tp> class DataType<Rect_<_Tp> >
|
1164
|
+
{
|
1165
|
+
public:
|
1166
|
+
typedef Rect_<_Tp> value_type;
|
1167
|
+
typedef Rect_<typename DataType<_Tp>::work_type> work_type;
|
1168
|
+
typedef _Tp channel_type;
|
1169
|
+
enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 4,
|
1170
|
+
fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt,
|
1171
|
+
type = CV_MAKETYPE(depth, channels) };
|
1172
|
+
typedef Vec<channel_type, channels> vec_type;
|
1173
|
+
};
|
1174
|
+
|
1175
|
+
template<typename _Tp> class DataType<Scalar_<_Tp> >
|
1176
|
+
{
|
1177
|
+
public:
|
1178
|
+
typedef Scalar_<_Tp> value_type;
|
1179
|
+
typedef Scalar_<typename DataType<_Tp>::work_type> work_type;
|
1180
|
+
typedef _Tp channel_type;
|
1181
|
+
enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 4,
|
1182
|
+
fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt,
|
1183
|
+
type = CV_MAKETYPE(depth, channels) };
|
1184
|
+
typedef Vec<channel_type, channels> vec_type;
|
1185
|
+
};
|
1186
|
+
|
1187
|
+
template<> class DataType<Range>
|
1188
|
+
{
|
1189
|
+
public:
|
1190
|
+
typedef Range value_type;
|
1191
|
+
typedef value_type work_type;
|
1192
|
+
typedef int channel_type;
|
1193
|
+
enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 2,
|
1194
|
+
fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt,
|
1195
|
+
type = CV_MAKETYPE(depth, channels) };
|
1196
|
+
typedef Vec<channel_type, channels> vec_type;
|
1197
|
+
};
|
1198
|
+
|
1199
|
+
|
1200
|
+
//////////////////// generic_type ref-counting pointer class for C/C++ objects ////////////////////////
|
1201
|
+
|
1202
|
+
/*!
|
1203
|
+
Smart pointer to dynamically allocated objects.
|
1204
|
+
|
1205
|
+
This is template pointer-wrapping class that stores the associated reference counter along with the
|
1206
|
+
object pointer. The class is similar to std::smart_ptr<> from the recent addons to the C++ standard,
|
1207
|
+
but is shorter to write :) and self-contained (i.e. does add any dependency on the compiler or an external library).
|
1208
|
+
|
1209
|
+
Basically, you can use "Ptr<MyObjectType> ptr" (or faster "const Ptr<MyObjectType>& ptr" for read-only access)
|
1210
|
+
everywhere instead of "MyObjectType* ptr", where MyObjectType is some C structure or a C++ class.
|
1211
|
+
To make it all work, you need to specialize Ptr<>::delete_obj(), like:
|
1212
|
+
|
1213
|
+
\code
|
1214
|
+
template<> void Ptr<MyObjectType>::delete_obj() { call_destructor_func(obj); }
|
1215
|
+
\endcode
|
1216
|
+
|
1217
|
+
\note{if MyObjectType is a C++ class with a destructor, you do not need to specialize delete_obj(),
|
1218
|
+
since the default implementation calls "delete obj;"}
|
1219
|
+
|
1220
|
+
\note{Another good property of the class is that the operations on the reference counter are atomic,
|
1221
|
+
i.e. it is safe to use the class in multi-threaded applications}
|
1222
|
+
*/
|
1223
|
+
template<typename _Tp> class CV_EXPORTS Ptr
|
1224
|
+
{
|
1225
|
+
public:
|
1226
|
+
//! empty constructor
|
1227
|
+
Ptr();
|
1228
|
+
//! take ownership of the pointer. The associated reference counter is allocated and set to 1
|
1229
|
+
Ptr(_Tp* _obj);
|
1230
|
+
//! calls release()
|
1231
|
+
~Ptr();
|
1232
|
+
//! copy constructor. Copies the members and calls addref()
|
1233
|
+
Ptr(const Ptr& ptr);
|
1234
|
+
//! copy operator. Calls ptr.addref() and release() before copying the members
|
1235
|
+
Ptr& operator = (const Ptr& ptr);
|
1236
|
+
//! increments the reference counter
|
1237
|
+
void addref();
|
1238
|
+
//! decrements the reference counter. If it reaches 0, delete_obj() is called
|
1239
|
+
void release();
|
1240
|
+
//! deletes the object. Override if needed
|
1241
|
+
void delete_obj();
|
1242
|
+
//! returns true iff obj==NULL
|
1243
|
+
bool empty() const;
|
1244
|
+
|
1245
|
+
|
1246
|
+
//! helper operators making "Ptr<T> ptr" use very similar to "T* ptr".
|
1247
|
+
_Tp* operator -> ();
|
1248
|
+
const _Tp* operator -> () const;
|
1249
|
+
|
1250
|
+
operator _Tp* ();
|
1251
|
+
operator const _Tp*() const;
|
1252
|
+
|
1253
|
+
protected:
|
1254
|
+
_Tp* obj; //< the object pointer.
|
1255
|
+
int* refcount; //< the associated reference counter
|
1256
|
+
};
|
1257
|
+
|
1258
|
+
|
1259
|
+
//////////////////////// Input/Output Array Arguments /////////////////////////////////
|
1260
|
+
|
1261
|
+
/*!
|
1262
|
+
Proxy datatype for passing Mat's and vector<>'s as input parameters
|
1263
|
+
*/
|
1264
|
+
class CV_EXPORTS _InputArray
|
1265
|
+
{
|
1266
|
+
public:
|
1267
|
+
enum { KIND_SHIFT=16, NONE=0<<KIND_SHIFT, MAT=1<<KIND_SHIFT,
|
1268
|
+
MATX=2<<KIND_SHIFT, STD_VECTOR=3<<KIND_SHIFT,
|
1269
|
+
STD_VECTOR_VECTOR=4<<KIND_SHIFT,
|
1270
|
+
STD_VECTOR_MAT=5<<KIND_SHIFT, EXPR=6<<KIND_SHIFT };
|
1271
|
+
_InputArray();
|
1272
|
+
_InputArray(const Mat& m);
|
1273
|
+
_InputArray(const MatExpr& expr);
|
1274
|
+
template<typename _Tp> _InputArray(const vector<_Tp>& vec);
|
1275
|
+
template<typename _Tp> _InputArray(const vector<vector<_Tp> >& vec);
|
1276
|
+
_InputArray(const vector<Mat>& vec);
|
1277
|
+
template<typename _Tp, int m, int n> _InputArray(const Matx<_Tp, m, n>& matx);
|
1278
|
+
_InputArray(const Scalar& s);
|
1279
|
+
_InputArray(const double& val);
|
1280
|
+
virtual Mat getMat(int i=-1) const;
|
1281
|
+
virtual void getMatVector(vector<Mat>& mv) const;
|
1282
|
+
virtual int kind() const;
|
1283
|
+
virtual Size size(int i=-1) const;
|
1284
|
+
virtual size_t total(int i=-1) const;
|
1285
|
+
virtual int type(int i=-1) const;
|
1286
|
+
virtual int depth(int i=-1) const;
|
1287
|
+
virtual int channels(int i=-1) const;
|
1288
|
+
virtual bool empty() const;
|
1289
|
+
|
1290
|
+
int flags;
|
1291
|
+
void* obj;
|
1292
|
+
Size sz;
|
1293
|
+
};
|
1294
|
+
|
1295
|
+
|
1296
|
+
enum
|
1297
|
+
{
|
1298
|
+
DEPTH_MASK_8U = 1 << CV_8U,
|
1299
|
+
DEPTH_MASK_8S = 1 << CV_8S,
|
1300
|
+
DEPTH_MASK_16U = 1 << CV_16U,
|
1301
|
+
DEPTH_MASK_16S = 1 << CV_16S,
|
1302
|
+
DEPTH_MASK_32S = 1 << CV_32S,
|
1303
|
+
DEPTH_MASK_32F = 1 << CV_32F,
|
1304
|
+
DEPTH_MASK_64F = 1 << CV_64F,
|
1305
|
+
DEPTH_MASK_ALL = (DEPTH_MASK_64F<<1)-1,
|
1306
|
+
DEPTH_MASK_ALL_BUT_8S = DEPTH_MASK_ALL & ~DEPTH_MASK_8S,
|
1307
|
+
DEPTH_MASK_FLT = DEPTH_MASK_32F + DEPTH_MASK_64F
|
1308
|
+
};
|
1309
|
+
|
1310
|
+
|
1311
|
+
/*!
|
1312
|
+
Proxy datatype for passing Mat's and vector<>'s as input parameters
|
1313
|
+
*/
|
1314
|
+
class CV_EXPORTS _OutputArray : public _InputArray
|
1315
|
+
{
|
1316
|
+
public:
|
1317
|
+
_OutputArray();
|
1318
|
+
_OutputArray(Mat& m);
|
1319
|
+
template<typename _Tp> _OutputArray(vector<_Tp>& vec);
|
1320
|
+
template<typename _Tp> _OutputArray(vector<vector<_Tp> >& vec);
|
1321
|
+
_OutputArray(vector<Mat>& vec);
|
1322
|
+
template<typename _Tp, int m, int n> _OutputArray(Matx<_Tp, m, n>& matx);
|
1323
|
+
virtual bool fixedSize() const;
|
1324
|
+
virtual bool fixedType() const;
|
1325
|
+
virtual bool needed() const;
|
1326
|
+
virtual Mat& getMatRef(int i=-1) const;
|
1327
|
+
virtual void create(Size sz, int type, int i=-1, bool allocateVector=false, int fixedDepthMask=0) const;
|
1328
|
+
virtual void create(int rows, int cols, int type, int i=-1, bool allowTransposed=false, int fixedDepthMask=0) const;
|
1329
|
+
virtual void create(int dims, const int* size, int type, int i=-1, bool allowTransposed=false, int fixedDepthMask=0) const;
|
1330
|
+
virtual void release() const;
|
1331
|
+
virtual void clear() const;
|
1332
|
+
};
|
1333
|
+
|
1334
|
+
typedef const _InputArray& InputArray;
|
1335
|
+
typedef InputArray InputArrayOfArrays;
|
1336
|
+
typedef const _OutputArray& OutputArray;
|
1337
|
+
typedef OutputArray OutputArrayOfArrays;
|
1338
|
+
typedef OutputArray InputOutputArray;
|
1339
|
+
typedef OutputArray InputOutputArrayOfArrays;
|
1340
|
+
|
1341
|
+
CV_EXPORTS OutputArray noArray();
|
1342
|
+
|
1343
|
+
/////////////////////////////////////// Mat ///////////////////////////////////////////
|
1344
|
+
|
1345
|
+
enum { MAGIC_MASK=0xFFFF0000, TYPE_MASK=0x00000FFF, DEPTH_MASK=7 };
|
1346
|
+
|
1347
|
+
static inline size_t getElemSize(int type) { return CV_ELEM_SIZE(type); }
|
1348
|
+
|
1349
|
+
/*!
|
1350
|
+
Custom array allocator
|
1351
|
+
|
1352
|
+
*/
|
1353
|
+
class CV_EXPORTS MatAllocator
|
1354
|
+
{
|
1355
|
+
public:
|
1356
|
+
MatAllocator() {}
|
1357
|
+
virtual ~MatAllocator() {}
|
1358
|
+
virtual void allocate(int dims, const int* sizes, int type, int*& refcount,
|
1359
|
+
uchar*& datastart, uchar*& data, size_t* step) = 0;
|
1360
|
+
virtual void deallocate(int* refcount, uchar* datastart, uchar* data) = 0;
|
1361
|
+
};
|
1362
|
+
|
1363
|
+
/*!
|
1364
|
+
The n-dimensional matrix class.
|
1365
|
+
|
1366
|
+
The class represents an n-dimensional dense numerical array that can act as
|
1367
|
+
a matrix, image, optical flow map, 3-focal tensor etc.
|
1368
|
+
It is very similar to CvMat and CvMatND types from earlier versions of OpenCV,
|
1369
|
+
and similarly to those types, the matrix can be multi-channel. It also fully supports ROI mechanism.
|
1370
|
+
|
1371
|
+
There are many different ways to create cv::Mat object. Here are the some popular ones:
|
1372
|
+
<ul>
|
1373
|
+
<li> using cv::Mat::create(nrows, ncols, type) method or
|
1374
|
+
the similar constructor cv::Mat::Mat(nrows, ncols, type[, fill_value]) constructor.
|
1375
|
+
A new matrix of the specified size and specifed type will be allocated.
|
1376
|
+
"type" has the same meaning as in cvCreateMat function,
|
1377
|
+
e.g. CV_8UC1 means 8-bit single-channel matrix, CV_32FC2 means 2-channel (i.e. complex)
|
1378
|
+
floating-point matrix etc:
|
1379
|
+
|
1380
|
+
\code
|
1381
|
+
// make 7x7 complex matrix filled with 1+3j.
|
1382
|
+
cv::Mat M(7,7,CV_32FC2,Scalar(1,3));
|
1383
|
+
// and now turn M to 100x60 15-channel 8-bit matrix.
|
1384
|
+
// The old content will be deallocated
|
1385
|
+
M.create(100,60,CV_8UC(15));
|
1386
|
+
\endcode
|
1387
|
+
|
1388
|
+
As noted in the introduction of this chapter, Mat::create()
|
1389
|
+
will only allocate a new matrix when the current matrix dimensionality
|
1390
|
+
or type are different from the specified.
|
1391
|
+
|
1392
|
+
<li> by using a copy constructor or assignment operator, where on the right side it can
|
1393
|
+
be a matrix or expression, see below. Again, as noted in the introduction,
|
1394
|
+
matrix assignment is O(1) operation because it only copies the header
|
1395
|
+
and increases the reference counter. cv::Mat::clone() method can be used to get a full
|
1396
|
+
(a.k.a. deep) copy of the matrix when you need it.
|
1397
|
+
|
1398
|
+
<li> by constructing a header for a part of another matrix. It can be a single row, single column,
|
1399
|
+
several rows, several columns, rectangular region in the matrix (called a minor in algebra) or
|
1400
|
+
a diagonal. Such operations are also O(1), because the new header will reference the same data.
|
1401
|
+
You can actually modify a part of the matrix using this feature, e.g.
|
1402
|
+
|
1403
|
+
\code
|
1404
|
+
// add 5-th row, multiplied by 3 to the 3rd row
|
1405
|
+
M.row(3) = M.row(3) + M.row(5)*3;
|
1406
|
+
|
1407
|
+
// now copy 7-th column to the 1-st column
|
1408
|
+
// M.col(1) = M.col(7); // this will not work
|
1409
|
+
Mat M1 = M.col(1);
|
1410
|
+
M.col(7).copyTo(M1);
|
1411
|
+
|
1412
|
+
// create new 320x240 image
|
1413
|
+
cv::Mat img(Size(320,240),CV_8UC3);
|
1414
|
+
// select a roi
|
1415
|
+
cv::Mat roi(img, Rect(10,10,100,100));
|
1416
|
+
// fill the ROI with (0,255,0) (which is green in RGB space);
|
1417
|
+
// the original 320x240 image will be modified
|
1418
|
+
roi = Scalar(0,255,0);
|
1419
|
+
\endcode
|
1420
|
+
|
1421
|
+
Thanks to the additional cv::Mat::datastart and cv::Mat::dataend members, it is possible to
|
1422
|
+
compute the relative sub-matrix position in the main "container" matrix using cv::Mat::locateROI():
|
1423
|
+
|
1424
|
+
\code
|
1425
|
+
Mat A = Mat::eye(10, 10, CV_32S);
|
1426
|
+
// extracts A columns, 1 (inclusive) to 3 (exclusive).
|
1427
|
+
Mat B = A(Range::all(), Range(1, 3));
|
1428
|
+
// extracts B rows, 5 (inclusive) to 9 (exclusive).
|
1429
|
+
// that is, C ~ A(Range(5, 9), Range(1, 3))
|
1430
|
+
Mat C = B(Range(5, 9), Range::all());
|
1431
|
+
Size size; Point ofs;
|
1432
|
+
C.locateROI(size, ofs);
|
1433
|
+
// size will be (width=10,height=10) and the ofs will be (x=1, y=5)
|
1434
|
+
\endcode
|
1435
|
+
|
1436
|
+
As in the case of whole matrices, if you need a deep copy, use cv::Mat::clone() method
|
1437
|
+
of the extracted sub-matrices.
|
1438
|
+
|
1439
|
+
<li> by making a header for user-allocated-data. It can be useful for
|
1440
|
+
<ol>
|
1441
|
+
<li> processing "foreign" data using OpenCV (e.g. when you implement
|
1442
|
+
a DirectShow filter or a processing module for gstreamer etc.), e.g.
|
1443
|
+
|
1444
|
+
\code
|
1445
|
+
void process_video_frame(const unsigned char* pixels,
|
1446
|
+
int width, int height, int step)
|
1447
|
+
{
|
1448
|
+
cv::Mat img(height, width, CV_8UC3, pixels, step);
|
1449
|
+
cv::GaussianBlur(img, img, cv::Size(7,7), 1.5, 1.5);
|
1450
|
+
}
|
1451
|
+
\endcode
|
1452
|
+
|
1453
|
+
<li> for quick initialization of small matrices and/or super-fast element access
|
1454
|
+
|
1455
|
+
\code
|
1456
|
+
double m[3][3] = {{a, b, c}, {d, e, f}, {g, h, i}};
|
1457
|
+
cv::Mat M = cv::Mat(3, 3, CV_64F, m).inv();
|
1458
|
+
\endcode
|
1459
|
+
</ol>
|
1460
|
+
|
1461
|
+
partial yet very common cases of this "user-allocated data" case are conversions
|
1462
|
+
from CvMat and IplImage to cv::Mat. For this purpose there are special constructors
|
1463
|
+
taking pointers to CvMat or IplImage and the optional
|
1464
|
+
flag indicating whether to copy the data or not.
|
1465
|
+
|
1466
|
+
Backward conversion from cv::Mat to CvMat or IplImage is provided via cast operators
|
1467
|
+
cv::Mat::operator CvMat() an cv::Mat::operator IplImage().
|
1468
|
+
The operators do not copy the data.
|
1469
|
+
|
1470
|
+
|
1471
|
+
\code
|
1472
|
+
IplImage* img = cvLoadImage("greatwave.jpg", 1);
|
1473
|
+
Mat mtx(img); // convert IplImage* -> cv::Mat
|
1474
|
+
CvMat oldmat = mtx; // convert cv::Mat -> CvMat
|
1475
|
+
CV_Assert(oldmat.cols == img->width && oldmat.rows == img->height &&
|
1476
|
+
oldmat.data.ptr == (uchar*)img->imageData && oldmat.step == img->widthStep);
|
1477
|
+
\endcode
|
1478
|
+
|
1479
|
+
<li> by using MATLAB-style matrix initializers, cv::Mat::zeros(), cv::Mat::ones(), cv::Mat::eye(), e.g.:
|
1480
|
+
|
1481
|
+
\code
|
1482
|
+
// create a double-precision identity martix and add it to M.
|
1483
|
+
M += Mat::eye(M.rows, M.cols, CV_64F);
|
1484
|
+
\endcode
|
1485
|
+
|
1486
|
+
<li> by using comma-separated initializer:
|
1487
|
+
|
1488
|
+
\code
|
1489
|
+
// create 3x3 double-precision identity matrix
|
1490
|
+
Mat M = (Mat_<double>(3,3) << 1, 0, 0, 0, 1, 0, 0, 0, 1);
|
1491
|
+
\endcode
|
1492
|
+
|
1493
|
+
here we first call constructor of cv::Mat_ class (that we describe further) with the proper matrix,
|
1494
|
+
and then we just put "<<" operator followed by comma-separated values that can be constants,
|
1495
|
+
variables, expressions etc. Also, note the extra parentheses that are needed to avoid compiler errors.
|
1496
|
+
|
1497
|
+
</ul>
|
1498
|
+
|
1499
|
+
Once matrix is created, it will be automatically managed by using reference-counting mechanism
|
1500
|
+
(unless the matrix header is built on top of user-allocated data,
|
1501
|
+
in which case you should handle the data by yourself).
|
1502
|
+
The matrix data will be deallocated when no one points to it;
|
1503
|
+
if you want to release the data pointed by a matrix header before the matrix destructor is called,
|
1504
|
+
use cv::Mat::release().
|
1505
|
+
|
1506
|
+
The next important thing to learn about the matrix class is element access. Here is how the matrix is stored.
|
1507
|
+
The elements are stored in row-major order (row by row). The cv::Mat::data member points to the first element of the first row,
|
1508
|
+
cv::Mat::rows contains the number of matrix rows and cv::Mat::cols - the number of matrix columns. There is yet another member,
|
1509
|
+
cv::Mat::step that is used to actually compute address of a matrix element. cv::Mat::step is needed because the matrix can be
|
1510
|
+
a part of another matrix or because there can some padding space in the end of each row for a proper alignment.
|
1511
|
+
|
1512
|
+
\image html roi.png
|
1513
|
+
|
1514
|
+
Given these parameters, address of the matrix element M_{ij} is computed as following:
|
1515
|
+
|
1516
|
+
addr(M_{ij})=M.data + M.step*i + j*M.elemSize()
|
1517
|
+
|
1518
|
+
if you know the matrix element type, e.g. it is float, then you can use cv::Mat::at() method:
|
1519
|
+
|
1520
|
+
addr(M_{ij})=&M.at<float>(i,j)
|
1521
|
+
|
1522
|
+
(where & is used to convert the reference returned by cv::Mat::at() to a pointer).
|
1523
|
+
if you need to process a whole row of matrix, the most efficient way is to get
|
1524
|
+
the pointer to the row first, and then just use plain C operator []:
|
1525
|
+
|
1526
|
+
\code
|
1527
|
+
// compute sum of positive matrix elements
|
1528
|
+
// (assuming that M is double-precision matrix)
|
1529
|
+
double sum=0;
|
1530
|
+
for(int i = 0; i < M.rows; i++)
|
1531
|
+
{
|
1532
|
+
const double* Mi = M.ptr<double>(i);
|
1533
|
+
for(int j = 0; j < M.cols; j++)
|
1534
|
+
sum += std::max(Mi[j], 0.);
|
1535
|
+
}
|
1536
|
+
\endcode
|
1537
|
+
|
1538
|
+
Some operations, like the above one, do not actually depend on the matrix shape,
|
1539
|
+
they just process elements of a matrix one by one (or elements from multiple matrices
|
1540
|
+
that are sitting in the same place, e.g. matrix addition). Such operations are called
|
1541
|
+
element-wise and it makes sense to check whether all the input/output matrices are continuous,
|
1542
|
+
i.e. have no gaps in the end of each row, and if yes, process them as a single long row:
|
1543
|
+
|
1544
|
+
\code
|
1545
|
+
// compute sum of positive matrix elements, optimized variant
|
1546
|
+
double sum=0;
|
1547
|
+
int cols = M.cols, rows = M.rows;
|
1548
|
+
if(M.isContinuous())
|
1549
|
+
{
|
1550
|
+
cols *= rows;
|
1551
|
+
rows = 1;
|
1552
|
+
}
|
1553
|
+
for(int i = 0; i < rows; i++)
|
1554
|
+
{
|
1555
|
+
const double* Mi = M.ptr<double>(i);
|
1556
|
+
for(int j = 0; j < cols; j++)
|
1557
|
+
sum += std::max(Mi[j], 0.);
|
1558
|
+
}
|
1559
|
+
\endcode
|
1560
|
+
in the case of continuous matrix the outer loop body will be executed just once,
|
1561
|
+
so the overhead will be smaller, which will be especially noticeable in the case of small matrices.
|
1562
|
+
|
1563
|
+
Finally, there are STL-style iterators that are smart enough to skip gaps between successive rows:
|
1564
|
+
\code
|
1565
|
+
// compute sum of positive matrix elements, iterator-based variant
|
1566
|
+
double sum=0;
|
1567
|
+
MatConstIterator_<double> it = M.begin<double>(), it_end = M.end<double>();
|
1568
|
+
for(; it != it_end; ++it)
|
1569
|
+
sum += std::max(*it, 0.);
|
1570
|
+
\endcode
|
1571
|
+
|
1572
|
+
The matrix iterators are random-access iterators, so they can be passed
|
1573
|
+
to any STL algorithm, including std::sort().
|
1574
|
+
*/
|
1575
|
+
class CV_EXPORTS Mat
|
1576
|
+
{
|
1577
|
+
public:
|
1578
|
+
//! default constructor
|
1579
|
+
Mat();
|
1580
|
+
//! constructs 2D matrix of the specified size and type
|
1581
|
+
// (_type is CV_8UC1, CV_64FC3, CV_32SC(12) etc.)
|
1582
|
+
Mat(int _rows, int _cols, int _type);
|
1583
|
+
Mat(Size _size, int _type);
|
1584
|
+
//! constucts 2D matrix and fills it with the specified value _s.
|
1585
|
+
Mat(int _rows, int _cols, int _type, const Scalar& _s);
|
1586
|
+
Mat(Size _size, int _type, const Scalar& _s);
|
1587
|
+
|
1588
|
+
//! constructs n-dimensional matrix
|
1589
|
+
Mat(int _ndims, const int* _sizes, int _type);
|
1590
|
+
Mat(int _ndims, const int* _sizes, int _type, const Scalar& _s);
|
1591
|
+
|
1592
|
+
//! copy constructor
|
1593
|
+
Mat(const Mat& m);
|
1594
|
+
//! constructor for matrix headers pointing to user-allocated data
|
1595
|
+
Mat(int _rows, int _cols, int _type, void* _data, size_t _step=AUTO_STEP);
|
1596
|
+
Mat(Size _size, int _type, void* _data, size_t _step=AUTO_STEP);
|
1597
|
+
Mat(int _ndims, const int* _sizes, int _type, void* _data, const size_t* _steps=0);
|
1598
|
+
|
1599
|
+
//! creates a matrix header for a part of the bigger matrix
|
1600
|
+
Mat(const Mat& m, const Range& rowRange, const Range& colRange=Range::all());
|
1601
|
+
Mat(const Mat& m, const Rect& roi);
|
1602
|
+
Mat(const Mat& m, const Range* ranges);
|
1603
|
+
//! converts old-style CvMat to the new matrix; the data is not copied by default
|
1604
|
+
Mat(const CvMat* m, bool copyData=false);
|
1605
|
+
//! converts old-style CvMatND to the new matrix; the data is not copied by default
|
1606
|
+
Mat(const CvMatND* m, bool copyData=false);
|
1607
|
+
//! converts old-style IplImage to the new matrix; the data is not copied by default
|
1608
|
+
Mat(const IplImage* img, bool copyData=false);
|
1609
|
+
//! builds matrix from std::vector with or without copying the data
|
1610
|
+
template<typename _Tp> explicit Mat(const vector<_Tp>& vec, bool copyData=false);
|
1611
|
+
//! builds matrix from cv::Vec; the data is copied by default
|
1612
|
+
template<typename _Tp, int n> explicit Mat(const Vec<_Tp, n>& vec,
|
1613
|
+
bool copyData=true);
|
1614
|
+
//! builds matrix from cv::Matx; the data is copied by default
|
1615
|
+
template<typename _Tp, int m, int n> explicit Mat(const Matx<_Tp, m, n>& mtx,
|
1616
|
+
bool copyData=true);
|
1617
|
+
//! builds matrix from a 2D point
|
1618
|
+
template<typename _Tp> explicit Mat(const Point_<_Tp>& pt, bool copyData=true);
|
1619
|
+
//! builds matrix from a 3D point
|
1620
|
+
template<typename _Tp> explicit Mat(const Point3_<_Tp>& pt, bool copyData=true);
|
1621
|
+
//! builds matrix from comma initializer
|
1622
|
+
template<typename _Tp> explicit Mat(const MatCommaInitializer_<_Tp>& commaInitializer);
|
1623
|
+
//! destructor - calls release()
|
1624
|
+
~Mat();
|
1625
|
+
//! assignment operators
|
1626
|
+
Mat& operator = (const Mat& m);
|
1627
|
+
Mat& operator = (const MatExpr& expr);
|
1628
|
+
|
1629
|
+
//! returns a new matrix header for the specified row
|
1630
|
+
Mat row(int y) const;
|
1631
|
+
//! returns a new matrix header for the specified column
|
1632
|
+
Mat col(int x) const;
|
1633
|
+
//! ... for the specified row span
|
1634
|
+
Mat rowRange(int startrow, int endrow) const;
|
1635
|
+
Mat rowRange(const Range& r) const;
|
1636
|
+
//! ... for the specified column span
|
1637
|
+
Mat colRange(int startcol, int endcol) const;
|
1638
|
+
Mat colRange(const Range& r) const;
|
1639
|
+
//! ... for the specified diagonal
|
1640
|
+
// (d=0 - the main diagonal,
|
1641
|
+
// >0 - a diagonal from the lower half,
|
1642
|
+
// <0 - a diagonal from the upper half)
|
1643
|
+
Mat diag(int d=0) const;
|
1644
|
+
//! constructs a square diagonal matrix which main diagonal is vector "d"
|
1645
|
+
static Mat diag(const Mat& d);
|
1646
|
+
|
1647
|
+
//! returns deep copy of the matrix, i.e. the data is copied
|
1648
|
+
Mat clone() const;
|
1649
|
+
//! copies the matrix content to "m".
|
1650
|
+
// It calls m.create(this->size(), this->type()).
|
1651
|
+
void copyTo( OutputArray m ) const;
|
1652
|
+
//! copies those matrix elements to "m" that are marked with non-zero mask elements.
|
1653
|
+
void copyTo( OutputArray m, InputArray mask ) const;
|
1654
|
+
//! converts matrix to another datatype with optional scalng. See cvConvertScale.
|
1655
|
+
void convertTo( OutputArray m, int rtype, double alpha=1, double beta=0 ) const;
|
1656
|
+
|
1657
|
+
void assignTo( Mat& m, int type=-1 ) const;
|
1658
|
+
|
1659
|
+
//! sets every matrix element to s
|
1660
|
+
Mat& operator = (const Scalar& s);
|
1661
|
+
//! sets some of the matrix elements to s, according to the mask
|
1662
|
+
Mat& setTo(InputArray value, InputArray mask=noArray());
|
1663
|
+
//! creates alternative matrix header for the same data, with different
|
1664
|
+
// number of channels and/or different number of rows. see cvReshape.
|
1665
|
+
Mat reshape(int _cn, int _rows=0) const;
|
1666
|
+
Mat reshape(int _cn, int _newndims, const int* _newsz) const;
|
1667
|
+
|
1668
|
+
//! matrix transposition by means of matrix expressions
|
1669
|
+
MatExpr t() const;
|
1670
|
+
//! matrix inversion by means of matrix expressions
|
1671
|
+
MatExpr inv(int method=DECOMP_LU) const;
|
1672
|
+
//! per-element matrix multiplication by means of matrix expressions
|
1673
|
+
MatExpr mul(InputArray m, double scale=1) const;
|
1674
|
+
|
1675
|
+
//! computes cross-product of 2 3D vectors
|
1676
|
+
Mat cross(InputArray m) const;
|
1677
|
+
//! computes dot-product
|
1678
|
+
double dot(InputArray m) const;
|
1679
|
+
|
1680
|
+
//! Matlab-style matrix initialization
|
1681
|
+
static MatExpr zeros(int rows, int cols, int type);
|
1682
|
+
static MatExpr zeros(Size size, int type);
|
1683
|
+
static MatExpr zeros(int ndims, const int* sz, int type);
|
1684
|
+
static MatExpr ones(int rows, int cols, int type);
|
1685
|
+
static MatExpr ones(Size size, int type);
|
1686
|
+
static MatExpr ones(int ndims, const int* sz, int type);
|
1687
|
+
static MatExpr eye(int rows, int cols, int type);
|
1688
|
+
static MatExpr eye(Size size, int type);
|
1689
|
+
|
1690
|
+
//! allocates new matrix data unless the matrix already has specified size and type.
|
1691
|
+
// previous data is unreferenced if needed.
|
1692
|
+
void create(int _rows, int _cols, int _type);
|
1693
|
+
void create(Size _size, int _type);
|
1694
|
+
void create(int _ndims, const int* _sizes, int _type);
|
1695
|
+
|
1696
|
+
//! increases the reference counter; use with care to avoid memleaks
|
1697
|
+
void addref();
|
1698
|
+
//! decreases reference counter;
|
1699
|
+
// deallocates the data when reference counter reaches 0.
|
1700
|
+
void release();
|
1701
|
+
|
1702
|
+
//! deallocates the matrix data
|
1703
|
+
void deallocate();
|
1704
|
+
//! internal use function; properly re-allocates _size, _step arrays
|
1705
|
+
void copySize(const Mat& m);
|
1706
|
+
|
1707
|
+
//! reserves enough space to fit sz hyper-planes
|
1708
|
+
void reserve(size_t sz);
|
1709
|
+
//! resizes matrix to the specified number of hyper-planes
|
1710
|
+
void resize(size_t sz);
|
1711
|
+
//! resizes matrix to the specified number of hyper-planes; initializes the newly added elements
|
1712
|
+
void resize(size_t sz, const Scalar& s);
|
1713
|
+
//! internal function
|
1714
|
+
void push_back_(const void* elem);
|
1715
|
+
//! adds element to the end of 1d matrix (or possibly multiple elements when _Tp=Mat)
|
1716
|
+
template<typename _Tp> void push_back(const _Tp& elem);
|
1717
|
+
template<typename _Tp> void push_back(const Mat_<_Tp>& elem);
|
1718
|
+
void push_back(const Mat& m);
|
1719
|
+
//! removes several hyper-planes from bottom of the matrix
|
1720
|
+
void pop_back(size_t nelems=1);
|
1721
|
+
|
1722
|
+
//! locates matrix header within a parent matrix. See below
|
1723
|
+
void locateROI( Size& wholeSize, Point& ofs ) const;
|
1724
|
+
//! moves/resizes the current matrix ROI inside the parent matrix.
|
1725
|
+
Mat& adjustROI( int dtop, int dbottom, int dleft, int dright );
|
1726
|
+
//! extracts a rectangular sub-matrix
|
1727
|
+
// (this is a generalized form of row, rowRange etc.)
|
1728
|
+
Mat operator()( Range rowRange, Range colRange ) const;
|
1729
|
+
Mat operator()( const Rect& roi ) const;
|
1730
|
+
Mat operator()( const Range* ranges ) const;
|
1731
|
+
|
1732
|
+
//! converts header to CvMat; no data is copied
|
1733
|
+
operator CvMat() const;
|
1734
|
+
//! converts header to CvMatND; no data is copied
|
1735
|
+
operator CvMatND() const;
|
1736
|
+
//! converts header to IplImage; no data is copied
|
1737
|
+
operator IplImage() const;
|
1738
|
+
|
1739
|
+
template<typename _Tp> operator vector<_Tp>() const;
|
1740
|
+
template<typename _Tp, int n> operator Vec<_Tp, n>() const;
|
1741
|
+
template<typename _Tp, int m, int n> operator Matx<_Tp, m, n>() const;
|
1742
|
+
|
1743
|
+
//! returns true iff the matrix data is continuous
|
1744
|
+
// (i.e. when there are no gaps between successive rows).
|
1745
|
+
// similar to CV_IS_MAT_CONT(cvmat->type)
|
1746
|
+
bool isContinuous() const;
|
1747
|
+
|
1748
|
+
//! returns true if the matrix is a submatrix of another matrix
|
1749
|
+
bool isSubmatrix() const;
|
1750
|
+
|
1751
|
+
//! returns element size in bytes,
|
1752
|
+
// similar to CV_ELEM_SIZE(cvmat->type)
|
1753
|
+
size_t elemSize() const;
|
1754
|
+
//! returns the size of element channel in bytes.
|
1755
|
+
size_t elemSize1() const;
|
1756
|
+
//! returns element type, similar to CV_MAT_TYPE(cvmat->type)
|
1757
|
+
int type() const;
|
1758
|
+
//! returns element type, similar to CV_MAT_DEPTH(cvmat->type)
|
1759
|
+
int depth() const;
|
1760
|
+
//! returns element type, similar to CV_MAT_CN(cvmat->type)
|
1761
|
+
int channels() const;
|
1762
|
+
//! returns step/elemSize1()
|
1763
|
+
size_t step1(int i=0) const;
|
1764
|
+
//! returns true if matrix data is NULL
|
1765
|
+
bool empty() const;
|
1766
|
+
//! returns the total number of matrix elements
|
1767
|
+
size_t total() const;
|
1768
|
+
|
1769
|
+
//! returns N if the matrix is 1-channel (N x ptdim) or ptdim-channel (1 x N) or (N x 1); negative number otherwise
|
1770
|
+
int checkVector(int elemChannels, int depth=-1, bool requireContinuous=true) const;
|
1771
|
+
|
1772
|
+
//! returns pointer to i0-th submatrix along the dimension #0
|
1773
|
+
uchar* ptr(int i0=0);
|
1774
|
+
const uchar* ptr(int i0=0) const;
|
1775
|
+
|
1776
|
+
//! returns pointer to (i0,i1) submatrix along the dimensions #0 and #1
|
1777
|
+
uchar* ptr(int i0, int i1);
|
1778
|
+
const uchar* ptr(int i0, int i1) const;
|
1779
|
+
|
1780
|
+
//! returns pointer to (i0,i1,i3) submatrix along the dimensions #0, #1, #2
|
1781
|
+
uchar* ptr(int i0, int i1, int i2);
|
1782
|
+
const uchar* ptr(int i0, int i1, int i2) const;
|
1783
|
+
|
1784
|
+
//! returns pointer to the matrix element
|
1785
|
+
uchar* ptr(const int* idx);
|
1786
|
+
//! returns read-only pointer to the matrix element
|
1787
|
+
const uchar* ptr(const int* idx) const;
|
1788
|
+
|
1789
|
+
template<int n> uchar* ptr(const Vec<int, n>& idx);
|
1790
|
+
template<int n> const uchar* ptr(const Vec<int, n>& idx) const;
|
1791
|
+
|
1792
|
+
//! template version of the above method
|
1793
|
+
template<typename _Tp> _Tp* ptr(int i0=0);
|
1794
|
+
template<typename _Tp> const _Tp* ptr(int i0=0) const;
|
1795
|
+
|
1796
|
+
template<typename _Tp> _Tp* ptr(int i0, int i1);
|
1797
|
+
template<typename _Tp> const _Tp* ptr(int i0, int i1) const;
|
1798
|
+
|
1799
|
+
template<typename _Tp> _Tp* ptr(int i0, int i1, int i2);
|
1800
|
+
template<typename _Tp> const _Tp* ptr(int i0, int i1, int i2) const;
|
1801
|
+
|
1802
|
+
template<typename _Tp> _Tp* ptr(const int* idx);
|
1803
|
+
template<typename _Tp> const _Tp* ptr(const int* idx) const;
|
1804
|
+
|
1805
|
+
template<typename _Tp, int n> _Tp* ptr(const Vec<int, n>& idx);
|
1806
|
+
template<typename _Tp, int n> const _Tp* ptr(const Vec<int, n>& idx) const;
|
1807
|
+
|
1808
|
+
//! the same as above, with the pointer dereferencing
|
1809
|
+
template<typename _Tp> _Tp& at(int i0=0);
|
1810
|
+
template<typename _Tp> const _Tp& at(int i0=0) const;
|
1811
|
+
|
1812
|
+
template<typename _Tp> _Tp& at(int i0, int i1);
|
1813
|
+
template<typename _Tp> const _Tp& at(int i0, int i1) const;
|
1814
|
+
|
1815
|
+
template<typename _Tp> _Tp& at(int i0, int i1, int i2);
|
1816
|
+
template<typename _Tp> const _Tp& at(int i0, int i1, int i2) const;
|
1817
|
+
|
1818
|
+
template<typename _Tp> _Tp& at(const int* idx);
|
1819
|
+
template<typename _Tp> const _Tp& at(const int* idx) const;
|
1820
|
+
|
1821
|
+
template<typename _Tp, int n> _Tp& at(const Vec<int, n>& idx);
|
1822
|
+
template<typename _Tp, int n> const _Tp& at(const Vec<int, n>& idx) const;
|
1823
|
+
|
1824
|
+
//! special versions for 2D arrays (especially convenient for referencing image pixels)
|
1825
|
+
template<typename _Tp> _Tp& at(Point pt);
|
1826
|
+
template<typename _Tp> const _Tp& at(Point pt) const;
|
1827
|
+
|
1828
|
+
//! template methods for iteration over matrix elements.
|
1829
|
+
// the iterators take care of skipping gaps in the end of rows (if any)
|
1830
|
+
template<typename _Tp> MatIterator_<_Tp> begin();
|
1831
|
+
template<typename _Tp> MatIterator_<_Tp> end();
|
1832
|
+
template<typename _Tp> MatConstIterator_<_Tp> begin() const;
|
1833
|
+
template<typename _Tp> MatConstIterator_<_Tp> end() const;
|
1834
|
+
|
1835
|
+
enum { MAGIC_VAL=0x42FF0000, AUTO_STEP=0, CONTINUOUS_FLAG=CV_MAT_CONT_FLAG, SUBMATRIX_FLAG=CV_SUBMAT_FLAG };
|
1836
|
+
|
1837
|
+
/*! includes several bit-fields:
|
1838
|
+
- the magic signature
|
1839
|
+
- continuity flag
|
1840
|
+
- depth
|
1841
|
+
- number of channels
|
1842
|
+
*/
|
1843
|
+
int flags;
|
1844
|
+
//! the matrix dimensionality, >= 2
|
1845
|
+
int dims;
|
1846
|
+
//! the number of rows and columns or (-1, -1) when the matrix has more than 2 dimensions
|
1847
|
+
int rows, cols;
|
1848
|
+
//! pointer to the data
|
1849
|
+
uchar* data;
|
1850
|
+
|
1851
|
+
//! pointer to the reference counter;
|
1852
|
+
// when matrix points to user-allocated data, the pointer is NULL
|
1853
|
+
int* refcount;
|
1854
|
+
|
1855
|
+
//! helper fields used in locateROI and adjustROI
|
1856
|
+
uchar* datastart;
|
1857
|
+
uchar* dataend;
|
1858
|
+
uchar* datalimit;
|
1859
|
+
|
1860
|
+
//! custom allocator
|
1861
|
+
MatAllocator* allocator;
|
1862
|
+
|
1863
|
+
struct CV_EXPORTS MSize
|
1864
|
+
{
|
1865
|
+
MSize(int* _p);
|
1866
|
+
Size operator()() const;
|
1867
|
+
const int& operator[](int i) const;
|
1868
|
+
int& operator[](int i);
|
1869
|
+
operator const int*() const;
|
1870
|
+
bool operator == (const MSize& sz) const;
|
1871
|
+
bool operator != (const MSize& sz) const;
|
1872
|
+
|
1873
|
+
int* p;
|
1874
|
+
};
|
1875
|
+
|
1876
|
+
struct CV_EXPORTS MStep
|
1877
|
+
{
|
1878
|
+
MStep();
|
1879
|
+
MStep(size_t s);
|
1880
|
+
const size_t& operator[](int i) const;
|
1881
|
+
size_t& operator[](int i);
|
1882
|
+
operator size_t() const;
|
1883
|
+
MStep& operator = (size_t s);
|
1884
|
+
|
1885
|
+
size_t* p;
|
1886
|
+
size_t buf[2];
|
1887
|
+
protected:
|
1888
|
+
MStep& operator = (const MStep&);
|
1889
|
+
};
|
1890
|
+
|
1891
|
+
MSize size;
|
1892
|
+
MStep step;
|
1893
|
+
};
|
1894
|
+
|
1895
|
+
|
1896
|
+
/*!
|
1897
|
+
Random Number Generator
|
1898
|
+
|
1899
|
+
The class implements RNG using Multiply-with-Carry algorithm
|
1900
|
+
*/
|
1901
|
+
class CV_EXPORTS RNG
|
1902
|
+
{
|
1903
|
+
public:
|
1904
|
+
enum { UNIFORM=0, NORMAL=1 };
|
1905
|
+
|
1906
|
+
RNG();
|
1907
|
+
RNG(uint64 _state);
|
1908
|
+
//! updates the state and returns the next 32-bit unsigned integer random number
|
1909
|
+
unsigned next();
|
1910
|
+
|
1911
|
+
operator uchar();
|
1912
|
+
operator schar();
|
1913
|
+
operator ushort();
|
1914
|
+
operator short();
|
1915
|
+
operator unsigned();
|
1916
|
+
//! returns a random integer sampled uniformly from [0, N).
|
1917
|
+
unsigned operator()(unsigned N);
|
1918
|
+
unsigned operator ()();
|
1919
|
+
operator int();
|
1920
|
+
operator float();
|
1921
|
+
operator double();
|
1922
|
+
//! returns uniformly distributed integer random number from [a,b) range
|
1923
|
+
int uniform(int a, int b);
|
1924
|
+
//! returns uniformly distributed floating-point random number from [a,b) range
|
1925
|
+
float uniform(float a, float b);
|
1926
|
+
//! returns uniformly distributed double-precision floating-point random number from [a,b) range
|
1927
|
+
double uniform(double a, double b);
|
1928
|
+
void fill( InputOutputArray mat, int distType, InputArray a, InputArray b );
|
1929
|
+
//! returns Gaussian random variate with mean zero.
|
1930
|
+
double gaussian(double sigma);
|
1931
|
+
|
1932
|
+
uint64 state;
|
1933
|
+
};
|
1934
|
+
|
1935
|
+
|
1936
|
+
/*!
|
1937
|
+
Termination criteria in iterative algorithms
|
1938
|
+
*/
|
1939
|
+
class CV_EXPORTS TermCriteria
|
1940
|
+
{
|
1941
|
+
public:
|
1942
|
+
enum
|
1943
|
+
{
|
1944
|
+
COUNT=1, //!< the maximum number of iterations or elements to compute
|
1945
|
+
MAX_ITER=COUNT, //!< ditto
|
1946
|
+
EPS=2 //!< the desired accuracy or change in parameters at which the iterative algorithm stops
|
1947
|
+
};
|
1948
|
+
|
1949
|
+
//! default constructor
|
1950
|
+
TermCriteria();
|
1951
|
+
//! full constructor
|
1952
|
+
TermCriteria(int _type, int _maxCount, double _epsilon);
|
1953
|
+
//! conversion from CvTermCriteria
|
1954
|
+
TermCriteria(const CvTermCriteria& criteria);
|
1955
|
+
//! conversion from CvTermCriteria
|
1956
|
+
operator CvTermCriteria() const;
|
1957
|
+
|
1958
|
+
int type; //!< the type of termination criteria: COUNT, EPS or COUNT + EPS
|
1959
|
+
int maxCount; // the maximum number of iterations/elements
|
1960
|
+
double epsilon; // the desired accuracy
|
1961
|
+
};
|
1962
|
+
|
1963
|
+
|
1964
|
+
//! swaps two matrices
|
1965
|
+
CV_EXPORTS void swap(Mat& a, Mat& b);
|
1966
|
+
|
1967
|
+
//! converts array (CvMat or IplImage) to cv::Mat
|
1968
|
+
CV_EXPORTS Mat cvarrToMat(const CvArr* arr, bool copyData=false,
|
1969
|
+
bool allowND=true, int coiMode=0);
|
1970
|
+
//! extracts Channel of Interest from CvMat or IplImage and makes cv::Mat out of it.
|
1971
|
+
CV_EXPORTS void extractImageCOI(const CvArr* arr, OutputArray coiimg, int coi=-1);
|
1972
|
+
//! inserts single-channel cv::Mat into a multi-channel CvMat or IplImage
|
1973
|
+
CV_EXPORTS void insertImageCOI(InputArray coiimg, CvArr* arr, int coi=-1);
|
1974
|
+
|
1975
|
+
//! adds one matrix to another (dst = src1 + src2)
|
1976
|
+
CV_EXPORTS_W void add(InputArray src1, InputArray src2, OutputArray dst,
|
1977
|
+
InputArray mask=noArray(), int dtype=-1);
|
1978
|
+
//! subtracts one matrix from another (dst = src1 - src2)
|
1979
|
+
CV_EXPORTS_W void subtract(InputArray src1, InputArray src2, OutputArray dst,
|
1980
|
+
InputArray mask=noArray(), int dtype=-1);
|
1981
|
+
|
1982
|
+
//! computes element-wise weighted product of the two arrays (dst = scale*src1*src2)
|
1983
|
+
CV_EXPORTS_W void multiply(InputArray src1, InputArray src2,
|
1984
|
+
OutputArray dst, double scale=1, int dtype=-1);
|
1985
|
+
|
1986
|
+
//! computes element-wise weighted quotient of the two arrays (dst = scale*src1/src2)
|
1987
|
+
CV_EXPORTS_W void divide(InputArray src1, InputArray src2, OutputArray dst,
|
1988
|
+
double scale=1, int dtype=-1);
|
1989
|
+
|
1990
|
+
//! computes element-wise weighted reciprocal of an array (dst = scale/src2)
|
1991
|
+
CV_EXPORTS_W void divide(double scale, InputArray src2,
|
1992
|
+
OutputArray dst, int dtype=-1);
|
1993
|
+
|
1994
|
+
//! adds scaled array to another one (dst = alpha*src1 + src2)
|
1995
|
+
CV_EXPORTS_W void scaleAdd(InputArray src1, double alpha, InputArray src2, OutputArray dst);
|
1996
|
+
|
1997
|
+
//! computes weighted sum of two arrays (dst = alpha*src1 + beta*src2 + gamma)
|
1998
|
+
CV_EXPORTS_W void addWeighted(InputArray src1, double alpha, InputArray src2,
|
1999
|
+
double beta, double gamma, OutputArray dst, int dtype=-1);
|
2000
|
+
|
2001
|
+
//! scales array elements, computes absolute values and converts the results to 8-bit unsigned integers: dst(i)=saturate_cast<uchar>abs(src(i)*alpha+beta)
|
2002
|
+
CV_EXPORTS_W void convertScaleAbs(InputArray src, OutputArray dst,
|
2003
|
+
double alpha=1, double beta=0);
|
2004
|
+
//! transforms array of numbers using a lookup table: dst(i)=lut(src(i))
|
2005
|
+
CV_EXPORTS_W void LUT(InputArray src, InputArray lut, OutputArray dst,
|
2006
|
+
int interpolation=0);
|
2007
|
+
|
2008
|
+
//! computes sum of array elements
|
2009
|
+
CV_EXPORTS_AS(sumElems) Scalar sum(InputArray src);
|
2010
|
+
//! computes the number of nonzero array elements
|
2011
|
+
CV_EXPORTS_W int countNonZero( InputArray src );
|
2012
|
+
//! computes mean value of selected array elements
|
2013
|
+
CV_EXPORTS_W Scalar mean(InputArray src, InputArray mask=noArray());
|
2014
|
+
//! computes mean value and standard deviation of all or selected array elements
|
2015
|
+
CV_EXPORTS_W void meanStdDev(InputArray src, OutputArray mean, OutputArray stddev,
|
2016
|
+
InputArray mask=noArray());
|
2017
|
+
//! computes norm of the selected array part
|
2018
|
+
CV_EXPORTS_W double norm(InputArray src1, int normType=NORM_L2, InputArray mask=noArray());
|
2019
|
+
//! computes norm of selected part of the difference between two arrays
|
2020
|
+
CV_EXPORTS_W double norm(InputArray src1, InputArray src2,
|
2021
|
+
int normType=NORM_L2, InputArray mask=noArray());
|
2022
|
+
//! scales and shifts array elements so that either the specified norm (alpha) or the minimum (alpha) and maximum (beta) array values get the specified values
|
2023
|
+
CV_EXPORTS_W void normalize( InputArray src, OutputArray dst, double alpha=1, double beta=0,
|
2024
|
+
int norm_type=NORM_L2, int dtype=-1, InputArray mask=noArray());
|
2025
|
+
|
2026
|
+
//! finds global minimum and maximum array elements and returns their values and their locations
|
2027
|
+
CV_EXPORTS_W void minMaxLoc(InputArray src, CV_OUT double* minVal,
|
2028
|
+
CV_OUT double* maxVal=0, CV_OUT Point* minLoc=0,
|
2029
|
+
CV_OUT Point* maxLoc=0, InputArray mask=noArray());
|
2030
|
+
CV_EXPORTS void minMaxIdx(InputArray src, double* minVal, double* maxVal,
|
2031
|
+
int* minIdx=0, int* maxIdx=0, InputArray mask=noArray());
|
2032
|
+
|
2033
|
+
//! transforms 2D matrix to 1D row or column vector by taking sum, minimum, maximum or mean value over all the rows
|
2034
|
+
CV_EXPORTS_W void reduce(InputArray src, OutputArray dst, int dim, int rtype, int dtype=-1);
|
2035
|
+
|
2036
|
+
//! makes multi-channel array out of several single-channel arrays
|
2037
|
+
CV_EXPORTS void merge(const Mat* mv, size_t count, OutputArray dst);
|
2038
|
+
//! makes multi-channel array out of several single-channel arrays
|
2039
|
+
CV_EXPORTS_W void merge(const vector<Mat>& mv, OutputArray dst);
|
2040
|
+
|
2041
|
+
//! copies each plane of a multi-channel array to a dedicated array
|
2042
|
+
CV_EXPORTS void split(const Mat& src, Mat* mvbegin);
|
2043
|
+
//! copies each plane of a multi-channel array to a dedicated array
|
2044
|
+
CV_EXPORTS_W void split(const Mat& m, CV_OUT vector<Mat>& mv);
|
2045
|
+
|
2046
|
+
//! copies selected channels from the input arrays to the selected channels of the output arrays
|
2047
|
+
CV_EXPORTS void mixChannels(const Mat* src, size_t nsrcs, Mat* dst, size_t ndsts,
|
2048
|
+
const int* fromTo, size_t npairs);
|
2049
|
+
CV_EXPORTS void mixChannels(const vector<Mat>& src, vector<Mat>& dst,
|
2050
|
+
const int* fromTo, size_t npairs);
|
2051
|
+
CV_EXPORTS_W void mixChannels(InputArrayOfArrays src, InputArrayOfArrays dst,
|
2052
|
+
const vector<int>& fromTo);
|
2053
|
+
|
2054
|
+
//! extracts a single channel from src (coi is 0-based index)
|
2055
|
+
CV_EXPORTS_W void extractChannel(InputArray src, OutputArray dst, int coi);
|
2056
|
+
|
2057
|
+
//! inserts a single channel to dst (coi is 0-based index)
|
2058
|
+
CV_EXPORTS_W void insertChannel(InputArray src, InputOutputArray dst, int coi);
|
2059
|
+
|
2060
|
+
//! reverses the order of the rows, columns or both in a matrix
|
2061
|
+
CV_EXPORTS_W void flip(InputArray src, OutputArray dst, int flipCode);
|
2062
|
+
|
2063
|
+
//! replicates the input matrix the specified number of times in the horizontal and/or vertical direction
|
2064
|
+
CV_EXPORTS_W void repeat(InputArray src, int ny, int nx, OutputArray dst);
|
2065
|
+
CV_EXPORTS Mat repeat(const Mat& src, int ny, int nx);
|
2066
|
+
|
2067
|
+
CV_EXPORTS void hconcat(const Mat* src, size_t nsrc, OutputArray dst);
|
2068
|
+
CV_EXPORTS void hconcat(InputArray src1, InputArray src2, OutputArray dst);
|
2069
|
+
CV_EXPORTS_W void hconcat(InputArray src, OutputArray dst);
|
2070
|
+
|
2071
|
+
CV_EXPORTS void vconcat(const Mat* src, size_t nsrc, OutputArray dst);
|
2072
|
+
CV_EXPORTS void vconcat(InputArray src1, InputArray src2, OutputArray dst);
|
2073
|
+
CV_EXPORTS_W void vconcat(InputArray src, OutputArray dst);
|
2074
|
+
|
2075
|
+
//! computes bitwise conjunction of the two arrays (dst = src1 & src2)
|
2076
|
+
CV_EXPORTS_W void bitwise_and(InputArray src1, InputArray src2,
|
2077
|
+
OutputArray dst, InputArray mask=noArray());
|
2078
|
+
//! computes bitwise disjunction of the two arrays (dst = src1 | src2)
|
2079
|
+
CV_EXPORTS_W void bitwise_or(InputArray src1, InputArray src2,
|
2080
|
+
OutputArray dst, InputArray mask=noArray());
|
2081
|
+
//! computes bitwise exclusive-or of the two arrays (dst = src1 ^ src2)
|
2082
|
+
CV_EXPORTS_W void bitwise_xor(InputArray src1, InputArray src2,
|
2083
|
+
OutputArray dst, InputArray mask=noArray());
|
2084
|
+
//! inverts each bit of array (dst = ~src)
|
2085
|
+
CV_EXPORTS_W void bitwise_not(InputArray src, OutputArray dst,
|
2086
|
+
InputArray mask=noArray());
|
2087
|
+
//! computes element-wise absolute difference of two arrays (dst = abs(src1 - src2))
|
2088
|
+
CV_EXPORTS_W void absdiff(InputArray src1, InputArray src2, OutputArray dst);
|
2089
|
+
//! set mask elements for those array elements which are within the element-specific bounding box (dst = lowerb <= src && src < upperb)
|
2090
|
+
CV_EXPORTS_W void inRange(InputArray src, InputArray lowerb,
|
2091
|
+
InputArray upperb, OutputArray dst);
|
2092
|
+
//! compares elements of two arrays (dst = src1 <cmpop> src2)
|
2093
|
+
CV_EXPORTS_W void compare(InputArray src1, InputArray src2, OutputArray dst, int cmpop);
|
2094
|
+
//! computes per-element minimum of two arrays (dst = min(src1, src2))
|
2095
|
+
CV_EXPORTS_W void min(InputArray src1, InputArray src2, OutputArray dst);
|
2096
|
+
//! computes per-element maximum of two arrays (dst = max(src1, src2))
|
2097
|
+
CV_EXPORTS_W void max(InputArray src1, InputArray src2, OutputArray dst);
|
2098
|
+
|
2099
|
+
//! computes per-element minimum of two arrays (dst = min(src1, src2))
|
2100
|
+
CV_EXPORTS void min(const Mat& src1, const Mat& src2, Mat& dst);
|
2101
|
+
//! computes per-element minimum of array and scalar (dst = min(src1, src2))
|
2102
|
+
CV_EXPORTS void min(const Mat& src1, double src2, Mat& dst);
|
2103
|
+
//! computes per-element maximum of two arrays (dst = max(src1, src2))
|
2104
|
+
CV_EXPORTS void max(const Mat& src1, const Mat& src2, Mat& dst);
|
2105
|
+
//! computes per-element maximum of array and scalar (dst = max(src1, src2))
|
2106
|
+
CV_EXPORTS void max(const Mat& src1, double src2, Mat& dst);
|
2107
|
+
|
2108
|
+
//! computes square root of each matrix element (dst = src**0.5)
|
2109
|
+
CV_EXPORTS_W void sqrt(InputArray src, OutputArray dst);
|
2110
|
+
//! raises the input matrix elements to the specified power (b = a**power)
|
2111
|
+
CV_EXPORTS_W void pow(InputArray src, double power, OutputArray dst);
|
2112
|
+
//! computes exponent of each matrix element (dst = e**src)
|
2113
|
+
CV_EXPORTS_W void exp(InputArray src, OutputArray dst);
|
2114
|
+
//! computes natural logarithm of absolute value of each matrix element: dst = log(abs(src))
|
2115
|
+
CV_EXPORTS_W void log(InputArray src, OutputArray dst);
|
2116
|
+
//! computes cube root of the argument
|
2117
|
+
CV_EXPORTS_W float cubeRoot(float val);
|
2118
|
+
//! computes the angle in degrees (0..360) of the vector (x,y)
|
2119
|
+
CV_EXPORTS_W float fastAtan2(float y, float x);
|
2120
|
+
//! converts polar coordinates to Cartesian
|
2121
|
+
CV_EXPORTS_W void polarToCart(InputArray magnitude, InputArray angle,
|
2122
|
+
OutputArray x, OutputArray y, bool angleInDegrees=false);
|
2123
|
+
//! converts Cartesian coordinates to polar
|
2124
|
+
CV_EXPORTS_W void cartToPolar(InputArray x, InputArray y,
|
2125
|
+
OutputArray magnitude, OutputArray angle,
|
2126
|
+
bool angleInDegrees=false);
|
2127
|
+
//! computes angle (angle(i)) of each (x(i), y(i)) vector
|
2128
|
+
CV_EXPORTS_W void phase(InputArray x, InputArray y, OutputArray angle,
|
2129
|
+
bool angleInDegrees=false);
|
2130
|
+
//! computes magnitude (magnitude(i)) of each (x(i), y(i)) vector
|
2131
|
+
CV_EXPORTS_W void magnitude(InputArray x, InputArray y, OutputArray magnitude);
|
2132
|
+
//! checks that each matrix element is within the specified range.
|
2133
|
+
CV_EXPORTS_W bool checkRange(InputArray a, bool quiet=true, CV_OUT Point* pt=0,
|
2134
|
+
double minVal=-DBL_MAX, double maxVal=DBL_MAX);
|
2135
|
+
//! implements generalized matrix product algorithm GEMM from BLAS
|
2136
|
+
CV_EXPORTS_W void gemm(InputArray src1, InputArray src2, double alpha,
|
2137
|
+
InputArray src3, double gamma, OutputArray dst, int flags=0);
|
2138
|
+
//! multiplies matrix by its transposition from the left or from the right
|
2139
|
+
CV_EXPORTS_W void mulTransposed( InputArray src, OutputArray dst, bool aTa,
|
2140
|
+
InputArray delta=noArray(),
|
2141
|
+
double scale=1, int dtype=-1 );
|
2142
|
+
//! transposes the matrix
|
2143
|
+
CV_EXPORTS_W void transpose(InputArray src, OutputArray dst);
|
2144
|
+
//! performs affine transformation of each element of multi-channel input matrix
|
2145
|
+
CV_EXPORTS_W void transform(InputArray src, OutputArray dst, InputArray m );
|
2146
|
+
//! performs perspective transformation of each element of multi-channel input matrix
|
2147
|
+
CV_EXPORTS_W void perspectiveTransform(InputArray src, OutputArray dst, InputArray m );
|
2148
|
+
|
2149
|
+
//! extends the symmetrical matrix from the lower half or from the upper half
|
2150
|
+
CV_EXPORTS_W void completeSymm(InputOutputArray mtx, bool lowerToUpper=false);
|
2151
|
+
//! initializes scaled identity matrix
|
2152
|
+
CV_EXPORTS_W void setIdentity(InputOutputArray mtx, const Scalar& s=Scalar(1));
|
2153
|
+
//! computes determinant of a square matrix
|
2154
|
+
CV_EXPORTS_W double determinant(InputArray mtx);
|
2155
|
+
//! computes trace of a matrix
|
2156
|
+
CV_EXPORTS_W Scalar trace(InputArray mtx);
|
2157
|
+
//! computes inverse or pseudo-inverse matrix
|
2158
|
+
CV_EXPORTS_W double invert(InputArray src, OutputArray dst, int flags=DECOMP_LU);
|
2159
|
+
//! solves linear system or a least-square problem
|
2160
|
+
CV_EXPORTS_W bool solve(InputArray src1, InputArray src2,
|
2161
|
+
OutputArray dst, int flags=DECOMP_LU);
|
2162
|
+
|
2163
|
+
enum
|
2164
|
+
{
|
2165
|
+
SORT_EVERY_ROW=0,
|
2166
|
+
SORT_EVERY_COLUMN=1,
|
2167
|
+
SORT_ASCENDING=0,
|
2168
|
+
SORT_DESCENDING=16
|
2169
|
+
};
|
2170
|
+
|
2171
|
+
//! sorts independently each matrix row or each matrix column
|
2172
|
+
CV_EXPORTS_W void sort(InputArray src, OutputArray dst, int flags);
|
2173
|
+
//! sorts independently each matrix row or each matrix column
|
2174
|
+
CV_EXPORTS_W void sortIdx(InputArray src, OutputArray dst, int flags);
|
2175
|
+
//! finds real roots of a cubic polynomial
|
2176
|
+
CV_EXPORTS_W int solveCubic(InputArray coeffs, OutputArray roots);
|
2177
|
+
//! finds real and complex roots of a polynomial
|
2178
|
+
CV_EXPORTS_W double solvePoly(InputArray coeffs, OutputArray roots, int maxIters=300);
|
2179
|
+
//! finds eigenvalues of a symmetric matrix
|
2180
|
+
CV_EXPORTS bool eigen(InputArray src, OutputArray eigenvalues, int lowindex=-1,
|
2181
|
+
int highindex=-1);
|
2182
|
+
//! finds eigenvalues and eigenvectors of a symmetric matrix
|
2183
|
+
CV_EXPORTS bool eigen(InputArray src, OutputArray eigenvalues,
|
2184
|
+
OutputArray eigenvectors,
|
2185
|
+
int lowindex=-1, int highindex=-1);
|
2186
|
+
CV_EXPORTS_W bool eigen(InputArray src, bool computeEigenvectors,
|
2187
|
+
OutputArray eigenvalues, OutputArray eigenvectors);
|
2188
|
+
|
2189
|
+
enum
|
2190
|
+
{
|
2191
|
+
COVAR_SCRAMBLED=0,
|
2192
|
+
COVAR_NORMAL=1,
|
2193
|
+
COVAR_USE_AVG=2,
|
2194
|
+
COVAR_SCALE=4,
|
2195
|
+
COVAR_ROWS=8,
|
2196
|
+
COVAR_COLS=16
|
2197
|
+
};
|
2198
|
+
|
2199
|
+
//! computes covariation matrix of a set of samples
|
2200
|
+
CV_EXPORTS void calcCovarMatrix( const Mat* samples, int nsamples, Mat& covar, Mat& mean,
|
2201
|
+
int flags, int ctype=CV_64F);
|
2202
|
+
//! computes covariation matrix of a set of samples
|
2203
|
+
CV_EXPORTS_W void calcCovarMatrix( InputArray samples, OutputArray covar,
|
2204
|
+
OutputArray mean, int flags, int ctype=CV_64F);
|
2205
|
+
|
2206
|
+
/*!
|
2207
|
+
Principal Component Analysis
|
2208
|
+
|
2209
|
+
The class PCA is used to compute the special basis for a set of vectors.
|
2210
|
+
The basis will consist of eigenvectors of the covariance matrix computed
|
2211
|
+
from the input set of vectors. After PCA is performed, vectors can be transformed from
|
2212
|
+
the original high-dimensional space to the subspace formed by a few most
|
2213
|
+
prominent eigenvectors (called the principal components),
|
2214
|
+
corresponding to the largest eigenvalues of the covariation matrix.
|
2215
|
+
Thus the dimensionality of the vector and the correlation between the coordinates is reduced.
|
2216
|
+
|
2217
|
+
The following sample is the function that takes two matrices. The first one stores the set
|
2218
|
+
of vectors (a row per vector) that is used to compute PCA, the second one stores another
|
2219
|
+
"test" set of vectors (a row per vector) that are first compressed with PCA,
|
2220
|
+
then reconstructed back and then the reconstruction error norm is computed and printed for each vector.
|
2221
|
+
|
2222
|
+
\code
|
2223
|
+
using namespace cv;
|
2224
|
+
|
2225
|
+
PCA compressPCA(const Mat& pcaset, int maxComponents,
|
2226
|
+
const Mat& testset, Mat& compressed)
|
2227
|
+
{
|
2228
|
+
PCA pca(pcaset, // pass the data
|
2229
|
+
Mat(), // we do not have a pre-computed mean vector,
|
2230
|
+
// so let the PCA engine to compute it
|
2231
|
+
CV_PCA_DATA_AS_ROW, // indicate that the vectors
|
2232
|
+
// are stored as matrix rows
|
2233
|
+
// (use CV_PCA_DATA_AS_COL if the vectors are
|
2234
|
+
// the matrix columns)
|
2235
|
+
maxComponents // specify, how many principal components to retain
|
2236
|
+
);
|
2237
|
+
// if there is no test data, just return the computed basis, ready-to-use
|
2238
|
+
if( !testset.data )
|
2239
|
+
return pca;
|
2240
|
+
CV_Assert( testset.cols == pcaset.cols );
|
2241
|
+
|
2242
|
+
compressed.create(testset.rows, maxComponents, testset.type());
|
2243
|
+
|
2244
|
+
Mat reconstructed;
|
2245
|
+
for( int i = 0; i < testset.rows; i++ )
|
2246
|
+
{
|
2247
|
+
Mat vec = testset.row(i), coeffs = compressed.row(i), reconstructed;
|
2248
|
+
// compress the vector, the result will be stored
|
2249
|
+
// in the i-th row of the output matrix
|
2250
|
+
pca.project(vec, coeffs);
|
2251
|
+
// and then reconstruct it
|
2252
|
+
pca.backProject(coeffs, reconstructed);
|
2253
|
+
// and measure the error
|
2254
|
+
printf("%d. diff = %g\n", i, norm(vec, reconstructed, NORM_L2));
|
2255
|
+
}
|
2256
|
+
return pca;
|
2257
|
+
}
|
2258
|
+
\endcode
|
2259
|
+
*/
|
2260
|
+
class CV_EXPORTS PCA
|
2261
|
+
{
|
2262
|
+
public:
|
2263
|
+
//! default constructor
|
2264
|
+
PCA();
|
2265
|
+
//! the constructor that performs PCA
|
2266
|
+
PCA(InputArray data, InputArray mean, int flags, int maxComponents=0);
|
2267
|
+
//! operator that performs PCA. The previously stored data, if any, is released
|
2268
|
+
PCA& operator()(InputArray data, InputArray mean, int flags, int maxComponents=0);
|
2269
|
+
//! projects vector from the original space to the principal components subspace
|
2270
|
+
Mat project(InputArray vec) const;
|
2271
|
+
//! projects vector from the original space to the principal components subspace
|
2272
|
+
void project(InputArray vec, OutputArray result) const;
|
2273
|
+
//! reconstructs the original vector from the projection
|
2274
|
+
Mat backProject(InputArray vec) const;
|
2275
|
+
//! reconstructs the original vector from the projection
|
2276
|
+
void backProject(InputArray vec, OutputArray result) const;
|
2277
|
+
|
2278
|
+
Mat eigenvectors; //!< eigenvectors of the covariation matrix
|
2279
|
+
Mat eigenvalues; //!< eigenvalues of the covariation matrix
|
2280
|
+
Mat mean; //!< mean value subtracted before the projection and added after the back projection
|
2281
|
+
};
|
2282
|
+
|
2283
|
+
CV_EXPORTS_W void PCACompute(InputArray data, CV_OUT InputOutputArray mean,
|
2284
|
+
OutputArray eigenvectors, int maxComponents=0);
|
2285
|
+
|
2286
|
+
CV_EXPORTS_W void PCAProject(InputArray data, InputArray mean,
|
2287
|
+
InputArray eigenvectors, OutputArray result);
|
2288
|
+
|
2289
|
+
CV_EXPORTS_W void PCABackProject(InputArray data, InputArray mean,
|
2290
|
+
InputArray eigenvectors, OutputArray result);
|
2291
|
+
|
2292
|
+
|
2293
|
+
/*!
|
2294
|
+
Singular Value Decomposition class
|
2295
|
+
|
2296
|
+
The class is used to compute Singular Value Decomposition of a floating-point matrix and then
|
2297
|
+
use it to solve least-square problems, under-determined linear systems, invert matrices,
|
2298
|
+
compute condition numbers etc.
|
2299
|
+
|
2300
|
+
For a bit faster operation you can pass flags=SVD::MODIFY_A|... to modify the decomposed matrix
|
2301
|
+
when it is not necessarily to preserve it. If you want to compute condition number of a matrix
|
2302
|
+
or absolute value of its determinant - you do not need SVD::u or SVD::vt,
|
2303
|
+
so you can pass flags=SVD::NO_UV|... . Another flag SVD::FULL_UV indicates that the full-size SVD::u and SVD::vt
|
2304
|
+
must be computed, which is not necessary most of the time.
|
2305
|
+
*/
|
2306
|
+
class CV_EXPORTS SVD
|
2307
|
+
{
|
2308
|
+
public:
|
2309
|
+
enum { MODIFY_A=1, NO_UV=2, FULL_UV=4 };
|
2310
|
+
//! the default constructor
|
2311
|
+
SVD();
|
2312
|
+
//! the constructor that performs SVD
|
2313
|
+
SVD( InputArray src, int flags=0 );
|
2314
|
+
//! the operator that performs SVD. The previously allocated SVD::u, SVD::w are SVD::vt are released.
|
2315
|
+
SVD& operator ()( InputArray src, int flags=0 );
|
2316
|
+
|
2317
|
+
//! decomposes matrix and stores the results to user-provided matrices
|
2318
|
+
static void compute( InputArray src, OutputArray w,
|
2319
|
+
OutputArray u, OutputArray vt, int flags=0 );
|
2320
|
+
//! computes singular values of a matrix
|
2321
|
+
static void compute( InputArray src, OutputArray w, int flags=0 );
|
2322
|
+
//! performs back substitution
|
2323
|
+
static void backSubst( InputArray w, InputArray u,
|
2324
|
+
InputArray vt, InputArray rhs,
|
2325
|
+
OutputArray dst );
|
2326
|
+
|
2327
|
+
template<typename _Tp, int m, int n, int nm> static void compute( const Matx<_Tp, m, n>& a,
|
2328
|
+
Matx<_Tp, nm, 1>& w, Matx<_Tp, m, nm>& u, Matx<_Tp, n, nm>& vt );
|
2329
|
+
template<typename _Tp, int m, int n, int nm> static void compute( const Matx<_Tp, m, n>& a,
|
2330
|
+
Matx<_Tp, nm, 1>& w );
|
2331
|
+
template<typename _Tp, int m, int n, int nm, int nb> static void backSubst( const Matx<_Tp, nm, 1>& w,
|
2332
|
+
const Matx<_Tp, m, nm>& u, const Matx<_Tp, n, nm>& vt, const Matx<_Tp, m, nb>& rhs, Matx<_Tp, n, nb>& dst );
|
2333
|
+
|
2334
|
+
//! finds dst = arg min_{|dst|=1} |m*dst|
|
2335
|
+
static void solveZ( InputArray src, OutputArray dst );
|
2336
|
+
//! performs back substitution, so that dst is the solution or pseudo-solution of m*dst = rhs, where m is the decomposed matrix
|
2337
|
+
void backSubst( InputArray rhs, OutputArray dst ) const;
|
2338
|
+
|
2339
|
+
Mat u, w, vt;
|
2340
|
+
};
|
2341
|
+
|
2342
|
+
//! computes SVD of src
|
2343
|
+
CV_EXPORTS_W void SVDecomp( InputArray src, CV_OUT OutputArray w,
|
2344
|
+
CV_OUT OutputArray u, CV_OUT OutputArray vt, int flags=0 );
|
2345
|
+
|
2346
|
+
//! performs back substitution for the previously computed SVD
|
2347
|
+
CV_EXPORTS_W void SVBackSubst( InputArray w, InputArray u, InputArray vt,
|
2348
|
+
InputArray rhs, CV_OUT OutputArray dst );
|
2349
|
+
|
2350
|
+
//! computes Mahalanobis distance between two vectors: sqrt((v1-v2)'*icovar*(v1-v2)), where icovar is the inverse covariation matrix
|
2351
|
+
CV_EXPORTS_W double Mahalanobis(InputArray v1, InputArray v2, InputArray icovar);
|
2352
|
+
//! a synonym for Mahalanobis
|
2353
|
+
CV_EXPORTS double Mahalonobis(InputArray v1, InputArray v2, InputArray icovar);
|
2354
|
+
|
2355
|
+
//! performs forward or inverse 1D or 2D Discrete Fourier Transformation
|
2356
|
+
CV_EXPORTS_W void dft(InputArray src, OutputArray dst, int flags=0, int nonzeroRows=0);
|
2357
|
+
//! performs inverse 1D or 2D Discrete Fourier Transformation
|
2358
|
+
CV_EXPORTS_W void idft(InputArray src, OutputArray dst, int flags=0, int nonzeroRows=0);
|
2359
|
+
//! performs forward or inverse 1D or 2D Discrete Cosine Transformation
|
2360
|
+
CV_EXPORTS_W void dct(InputArray src, OutputArray dst, int flags=0);
|
2361
|
+
//! performs inverse 1D or 2D Discrete Cosine Transformation
|
2362
|
+
CV_EXPORTS_W void idct(InputArray src, OutputArray dst, int flags=0);
|
2363
|
+
//! computes element-wise product of the two Fourier spectrums. The second spectrum can optionally be conjugated before the multiplication
|
2364
|
+
CV_EXPORTS_W void mulSpectrums(InputArray a, InputArray b, OutputArray c,
|
2365
|
+
int flags, bool conjB=false);
|
2366
|
+
//! computes the minimal vector size vecsize1 >= vecsize so that the dft() of the vector of length vecsize1 can be computed efficiently
|
2367
|
+
CV_EXPORTS_W int getOptimalDFTSize(int vecsize);
|
2368
|
+
|
2369
|
+
/*!
|
2370
|
+
Various k-Means flags
|
2371
|
+
*/
|
2372
|
+
enum
|
2373
|
+
{
|
2374
|
+
KMEANS_RANDOM_CENTERS=0, // Chooses random centers for k-Means initialization
|
2375
|
+
KMEANS_PP_CENTERS=2, // Uses k-Means++ algorithm for initialization
|
2376
|
+
KMEANS_USE_INITIAL_LABELS=1 // Uses the user-provided labels for K-Means initialization
|
2377
|
+
};
|
2378
|
+
//! clusters the input data using k-Means algorithm
|
2379
|
+
CV_EXPORTS_W double kmeans( InputArray data, int K, CV_OUT InputOutputArray bestLabels,
|
2380
|
+
TermCriteria criteria, int attempts,
|
2381
|
+
int flags, OutputArray centers=noArray() );
|
2382
|
+
|
2383
|
+
//! returns the thread-local Random number generator
|
2384
|
+
CV_EXPORTS RNG& theRNG();
|
2385
|
+
|
2386
|
+
//! returns the next unifomly-distributed random number of the specified type
|
2387
|
+
template<typename _Tp> static inline _Tp randu() { return (_Tp)theRNG(); }
|
2388
|
+
|
2389
|
+
//! fills array with uniformly-distributed random numbers from the range [low, high)
|
2390
|
+
CV_EXPORTS_W void randu(InputOutputArray dst, InputArray low, InputArray high);
|
2391
|
+
|
2392
|
+
//! fills array with normally-distributed random numbers with the specified mean and the standard deviation
|
2393
|
+
CV_EXPORTS_W void randn(InputOutputArray dst, InputArray mean, InputArray stddev);
|
2394
|
+
|
2395
|
+
//! shuffles the input array elements
|
2396
|
+
CV_EXPORTS void randShuffle(InputOutputArray dst, double iterFactor=1., RNG* rng=0);
|
2397
|
+
CV_EXPORTS_AS(randShuffle) void randShuffle_(InputOutputArray dst, double iterFactor=1.);
|
2398
|
+
|
2399
|
+
//! draws the line segment (pt1, pt2) in the image
|
2400
|
+
CV_EXPORTS_W void line(Mat& img, Point pt1, Point pt2, const Scalar& color,
|
2401
|
+
int thickness=1, int lineType=8, int shift=0);
|
2402
|
+
|
2403
|
+
//! draws the rectangle outline or a solid rectangle with the opposite corners pt1 and pt2 in the image
|
2404
|
+
CV_EXPORTS_W void rectangle(Mat& img, Point pt1, Point pt2,
|
2405
|
+
const Scalar& color, int thickness=1,
|
2406
|
+
int lineType=8, int shift=0);
|
2407
|
+
|
2408
|
+
//! draws the rectangle outline or a solid rectangle covering rec in the image
|
2409
|
+
CV_EXPORTS void rectangle(Mat& img, Rect rec,
|
2410
|
+
const Scalar& color, int thickness=1,
|
2411
|
+
int lineType=8, int shift=0);
|
2412
|
+
|
2413
|
+
//! draws the circle outline or a solid circle in the image
|
2414
|
+
CV_EXPORTS_W void circle(Mat& img, Point center, int radius,
|
2415
|
+
const Scalar& color, int thickness=1,
|
2416
|
+
int lineType=8, int shift=0);
|
2417
|
+
|
2418
|
+
//! draws an elliptic arc, ellipse sector or a rotated ellipse in the image
|
2419
|
+
CV_EXPORTS_W void ellipse(Mat& img, Point center, Size axes,
|
2420
|
+
double angle, double startAngle, double endAngle,
|
2421
|
+
const Scalar& color, int thickness=1,
|
2422
|
+
int lineType=8, int shift=0);
|
2423
|
+
|
2424
|
+
//! draws a rotated ellipse in the image
|
2425
|
+
CV_EXPORTS_W void ellipse(Mat& img, const RotatedRect& box, const Scalar& color,
|
2426
|
+
int thickness=1, int lineType=8);
|
2427
|
+
|
2428
|
+
//! draws a filled convex polygon in the image
|
2429
|
+
CV_EXPORTS void fillConvexPoly(Mat& img, const Point* pts, int npts,
|
2430
|
+
const Scalar& color, int lineType=8,
|
2431
|
+
int shift=0);
|
2432
|
+
CV_EXPORTS_W void fillConvexPoly(InputOutputArray img, InputArray points,
|
2433
|
+
const Scalar& color, int lineType=8,
|
2434
|
+
int shift=0);
|
2435
|
+
|
2436
|
+
//! fills an area bounded by one or more polygons
|
2437
|
+
CV_EXPORTS void fillPoly(Mat& img, const Point** pts,
|
2438
|
+
const int* npts, int ncontours,
|
2439
|
+
const Scalar& color, int lineType=8, int shift=0,
|
2440
|
+
Point offset=Point() );
|
2441
|
+
|
2442
|
+
CV_EXPORTS_W void fillPoly(InputOutputArray img, InputArrayOfArrays pts,
|
2443
|
+
const Scalar& color, int lineType=8, int shift=0,
|
2444
|
+
Point offset=Point() );
|
2445
|
+
|
2446
|
+
//! draws one or more polygonal curves
|
2447
|
+
CV_EXPORTS void polylines(Mat& img, const Point** pts, const int* npts,
|
2448
|
+
int ncontours, bool isClosed, const Scalar& color,
|
2449
|
+
int thickness=1, int lineType=8, int shift=0 );
|
2450
|
+
|
2451
|
+
CV_EXPORTS_W void polylines(InputOutputArray img, InputArrayOfArrays pts,
|
2452
|
+
bool isClosed, const Scalar& color,
|
2453
|
+
int thickness=1, int lineType=8, int shift=0 );
|
2454
|
+
|
2455
|
+
//! clips the line segment by the rectangle Rect(0, 0, imgSize.width, imgSize.height)
|
2456
|
+
CV_EXPORTS bool clipLine(Size imgSize, CV_IN_OUT Point& pt1, CV_IN_OUT Point& pt2);
|
2457
|
+
|
2458
|
+
//! clips the line segment by the rectangle imgRect
|
2459
|
+
CV_EXPORTS_W bool clipLine(Rect imgRect, CV_OUT CV_IN_OUT Point& pt1, CV_OUT CV_IN_OUT Point& pt2);
|
2460
|
+
|
2461
|
+
/*!
|
2462
|
+
Line iterator class
|
2463
|
+
|
2464
|
+
The class is used to iterate over all the pixels on the raster line
|
2465
|
+
segment connecting two specified points.
|
2466
|
+
*/
|
2467
|
+
class CV_EXPORTS LineIterator
|
2468
|
+
{
|
2469
|
+
public:
|
2470
|
+
//! intializes the iterator
|
2471
|
+
LineIterator( const Mat& img, Point pt1, Point pt2,
|
2472
|
+
int connectivity=8, bool leftToRight=false );
|
2473
|
+
//! returns pointer to the current pixel
|
2474
|
+
uchar* operator *();
|
2475
|
+
//! prefix increment operator (++it). shifts iterator to the next pixel
|
2476
|
+
LineIterator& operator ++();
|
2477
|
+
//! postfix increment operator (it++). shifts iterator to the next pixel
|
2478
|
+
LineIterator operator ++(int);
|
2479
|
+
//! returns coordinates of the current pixel
|
2480
|
+
Point pos() const;
|
2481
|
+
|
2482
|
+
uchar* ptr;
|
2483
|
+
const uchar* ptr0;
|
2484
|
+
int step, elemSize;
|
2485
|
+
int err, count;
|
2486
|
+
int minusDelta, plusDelta;
|
2487
|
+
int minusStep, plusStep;
|
2488
|
+
};
|
2489
|
+
|
2490
|
+
//! converts elliptic arc to a polygonal curve
|
2491
|
+
CV_EXPORTS_W void ellipse2Poly( Point center, Size axes, int angle,
|
2492
|
+
int arcStart, int arcEnd, int delta,
|
2493
|
+
CV_OUT vector<Point>& pts );
|
2494
|
+
|
2495
|
+
enum
|
2496
|
+
{
|
2497
|
+
FONT_HERSHEY_SIMPLEX = 0,
|
2498
|
+
FONT_HERSHEY_PLAIN = 1,
|
2499
|
+
FONT_HERSHEY_DUPLEX = 2,
|
2500
|
+
FONT_HERSHEY_COMPLEX = 3,
|
2501
|
+
FONT_HERSHEY_TRIPLEX = 4,
|
2502
|
+
FONT_HERSHEY_COMPLEX_SMALL = 5,
|
2503
|
+
FONT_HERSHEY_SCRIPT_SIMPLEX = 6,
|
2504
|
+
FONT_HERSHEY_SCRIPT_COMPLEX = 7,
|
2505
|
+
FONT_ITALIC = 16
|
2506
|
+
};
|
2507
|
+
|
2508
|
+
//! renders text string in the image
|
2509
|
+
CV_EXPORTS_W void putText( Mat& img, const string& text, Point org,
|
2510
|
+
int fontFace, double fontScale, Scalar color,
|
2511
|
+
int thickness=1, int linetype=8,
|
2512
|
+
bool bottomLeftOrigin=false );
|
2513
|
+
|
2514
|
+
//! returns bounding box of the text string
|
2515
|
+
CV_EXPORTS_W Size getTextSize(const string& text, int fontFace,
|
2516
|
+
double fontScale, int thickness,
|
2517
|
+
CV_OUT int* baseLine);
|
2518
|
+
|
2519
|
+
///////////////////////////////// Mat_<_Tp> ////////////////////////////////////
|
2520
|
+
|
2521
|
+
/*!
|
2522
|
+
Template matrix class derived from Mat
|
2523
|
+
|
2524
|
+
The class Mat_ is a "thin" template wrapper on top of cv::Mat. It does not have any extra data fields,
|
2525
|
+
nor it or cv::Mat have any virtual methods and thus references or pointers to these two classes
|
2526
|
+
can be safely converted one to another. But do it with care, for example:
|
2527
|
+
|
2528
|
+
\code
|
2529
|
+
// create 100x100 8-bit matrix
|
2530
|
+
Mat M(100,100,CV_8U);
|
2531
|
+
// this will compile fine. no any data conversion will be done.
|
2532
|
+
Mat_<float>& M1 = (Mat_<float>&)M;
|
2533
|
+
// the program will likely crash at the statement below
|
2534
|
+
M1(99,99) = 1.f;
|
2535
|
+
\endcode
|
2536
|
+
|
2537
|
+
While cv::Mat is sufficient in most cases, cv::Mat_ can be more convenient if you use a lot of element
|
2538
|
+
access operations and if you know matrix type at compile time.
|
2539
|
+
Note that cv::Mat::at<_Tp>(int y, int x) and cv::Mat_<_Tp>::operator ()(int y, int x) do absolutely the
|
2540
|
+
same thing and run at the same speed, but the latter is certainly shorter:
|
2541
|
+
|
2542
|
+
\code
|
2543
|
+
Mat_<double> M(20,20);
|
2544
|
+
for(int i = 0; i < M.rows; i++)
|
2545
|
+
for(int j = 0; j < M.cols; j++)
|
2546
|
+
M(i,j) = 1./(i+j+1);
|
2547
|
+
Mat E, V;
|
2548
|
+
eigen(M,E,V);
|
2549
|
+
cout << E.at<double>(0,0)/E.at<double>(M.rows-1,0);
|
2550
|
+
\endcode
|
2551
|
+
|
2552
|
+
It is easy to use Mat_ for multi-channel images/matrices - just pass cv::Vec as cv::Mat_ template parameter:
|
2553
|
+
|
2554
|
+
\code
|
2555
|
+
// allocate 320x240 color image and fill it with green (in RGB space)
|
2556
|
+
Mat_<Vec3b> img(240, 320, Vec3b(0,255,0));
|
2557
|
+
// now draw a diagonal white line
|
2558
|
+
for(int i = 0; i < 100; i++)
|
2559
|
+
img(i,i)=Vec3b(255,255,255);
|
2560
|
+
// and now modify the 2nd (red) channel of each pixel
|
2561
|
+
for(int i = 0; i < img.rows; i++)
|
2562
|
+
for(int j = 0; j < img.cols; j++)
|
2563
|
+
img(i,j)[2] ^= (uchar)(i ^ j); // img(y,x)[c] accesses c-th channel of the pixel (x,y)
|
2564
|
+
\endcode
|
2565
|
+
*/
|
2566
|
+
template<typename _Tp> class CV_EXPORTS Mat_ : public Mat
|
2567
|
+
{
|
2568
|
+
public:
|
2569
|
+
typedef _Tp value_type;
|
2570
|
+
typedef typename DataType<_Tp>::channel_type channel_type;
|
2571
|
+
typedef MatIterator_<_Tp> iterator;
|
2572
|
+
typedef MatConstIterator_<_Tp> const_iterator;
|
2573
|
+
|
2574
|
+
//! default constructor
|
2575
|
+
Mat_();
|
2576
|
+
//! equivalent to Mat(_rows, _cols, DataType<_Tp>::type)
|
2577
|
+
Mat_(int _rows, int _cols);
|
2578
|
+
//! constructor that sets each matrix element to specified value
|
2579
|
+
Mat_(int _rows, int _cols, const _Tp& value);
|
2580
|
+
//! equivalent to Mat(_size, DataType<_Tp>::type)
|
2581
|
+
explicit Mat_(Size _size);
|
2582
|
+
//! constructor that sets each matrix element to specified value
|
2583
|
+
Mat_(Size _size, const _Tp& value);
|
2584
|
+
//! n-dim array constructor
|
2585
|
+
Mat_(int _ndims, const int* _sizes);
|
2586
|
+
//! n-dim array constructor that sets each matrix element to specified value
|
2587
|
+
Mat_(int _ndims, const int* _sizes, const _Tp& value);
|
2588
|
+
//! copy/conversion contructor. If m is of different type, it's converted
|
2589
|
+
Mat_(const Mat& m);
|
2590
|
+
//! copy constructor
|
2591
|
+
Mat_(const Mat_& m);
|
2592
|
+
//! constructs a matrix on top of user-allocated data. step is in bytes(!!!), regardless of the type
|
2593
|
+
Mat_(int _rows, int _cols, _Tp* _data, size_t _step=AUTO_STEP);
|
2594
|
+
//! constructs n-dim matrix on top of user-allocated data. steps are in bytes(!!!), regardless of the type
|
2595
|
+
Mat_(int _ndims, const int* _sizes, _Tp* _data, const size_t* _steps=0);
|
2596
|
+
//! selects a submatrix
|
2597
|
+
Mat_(const Mat_& m, const Range& rowRange, const Range& colRange=Range::all());
|
2598
|
+
//! selects a submatrix
|
2599
|
+
Mat_(const Mat_& m, const Rect& roi);
|
2600
|
+
//! selects a submatrix, n-dim version
|
2601
|
+
Mat_(const Mat_& m, const Range* ranges);
|
2602
|
+
//! from a matrix expression
|
2603
|
+
explicit Mat_(const MatExpr& e);
|
2604
|
+
//! makes a matrix out of Vec, std::vector, Point_ or Point3_. The matrix will have a single column
|
2605
|
+
explicit Mat_(const vector<_Tp>& vec, bool copyData=false);
|
2606
|
+
template<int n> explicit Mat_(const Vec<typename DataType<_Tp>::channel_type, n>& vec, bool copyData=true);
|
2607
|
+
template<int m, int n> explicit Mat_(const Matx<typename DataType<_Tp>::channel_type, m, n>& mtx, bool copyData=true);
|
2608
|
+
explicit Mat_(const Point_<typename DataType<_Tp>::channel_type>& pt, bool copyData=true);
|
2609
|
+
explicit Mat_(const Point3_<typename DataType<_Tp>::channel_type>& pt, bool copyData=true);
|
2610
|
+
explicit Mat_(const MatCommaInitializer_<_Tp>& commaInitializer);
|
2611
|
+
|
2612
|
+
Mat_& operator = (const Mat& m);
|
2613
|
+
Mat_& operator = (const Mat_& m);
|
2614
|
+
//! set all the elements to s.
|
2615
|
+
Mat_& operator = (const _Tp& s);
|
2616
|
+
//! assign a matrix expression
|
2617
|
+
Mat_& operator = (const MatExpr& e);
|
2618
|
+
|
2619
|
+
//! iterators; they are smart enough to skip gaps in the end of rows
|
2620
|
+
iterator begin();
|
2621
|
+
iterator end();
|
2622
|
+
const_iterator begin() const;
|
2623
|
+
const_iterator end() const;
|
2624
|
+
|
2625
|
+
//! equivalent to Mat::create(_rows, _cols, DataType<_Tp>::type)
|
2626
|
+
void create(int _rows, int _cols);
|
2627
|
+
//! equivalent to Mat::create(_size, DataType<_Tp>::type)
|
2628
|
+
void create(Size _size);
|
2629
|
+
//! equivalent to Mat::create(_ndims, _sizes, DatType<_Tp>::type)
|
2630
|
+
void create(int _ndims, const int* _sizes);
|
2631
|
+
//! cross-product
|
2632
|
+
Mat_ cross(const Mat_& m) const;
|
2633
|
+
//! data type conversion
|
2634
|
+
template<typename T2> operator Mat_<T2>() const;
|
2635
|
+
//! overridden forms of Mat::row() etc.
|
2636
|
+
Mat_ row(int y) const;
|
2637
|
+
Mat_ col(int x) const;
|
2638
|
+
Mat_ diag(int d=0) const;
|
2639
|
+
Mat_ clone() const;
|
2640
|
+
|
2641
|
+
//! overridden forms of Mat::elemSize() etc.
|
2642
|
+
size_t elemSize() const;
|
2643
|
+
size_t elemSize1() const;
|
2644
|
+
int type() const;
|
2645
|
+
int depth() const;
|
2646
|
+
int channels() const;
|
2647
|
+
size_t step1(int i=0) const;
|
2648
|
+
//! returns step()/sizeof(_Tp)
|
2649
|
+
size_t stepT(int i=0) const;
|
2650
|
+
|
2651
|
+
//! overridden forms of Mat::zeros() etc. Data type is omitted, of course
|
2652
|
+
static MatExpr zeros(int rows, int cols);
|
2653
|
+
static MatExpr zeros(Size size);
|
2654
|
+
static MatExpr zeros(int _ndims, const int* _sizes);
|
2655
|
+
static MatExpr ones(int rows, int cols);
|
2656
|
+
static MatExpr ones(Size size);
|
2657
|
+
static MatExpr ones(int _ndims, const int* _sizes);
|
2658
|
+
static MatExpr eye(int rows, int cols);
|
2659
|
+
static MatExpr eye(Size size);
|
2660
|
+
|
2661
|
+
//! some more overriden methods
|
2662
|
+
Mat_ reshape(int _rows) const;
|
2663
|
+
Mat_& adjustROI( int dtop, int dbottom, int dleft, int dright );
|
2664
|
+
Mat_ operator()( const Range& rowRange, const Range& colRange ) const;
|
2665
|
+
Mat_ operator()( const Rect& roi ) const;
|
2666
|
+
Mat_ operator()( const Range* ranges ) const;
|
2667
|
+
|
2668
|
+
//! more convenient forms of row and element access operators
|
2669
|
+
_Tp* operator [](int y);
|
2670
|
+
const _Tp* operator [](int y) const;
|
2671
|
+
|
2672
|
+
//! returns reference to the specified element
|
2673
|
+
_Tp& operator ()(const int* idx);
|
2674
|
+
//! returns read-only reference to the specified element
|
2675
|
+
const _Tp& operator ()(const int* idx) const;
|
2676
|
+
|
2677
|
+
//! returns reference to the specified element
|
2678
|
+
template<int n> _Tp& operator ()(const Vec<int, n>& idx);
|
2679
|
+
//! returns read-only reference to the specified element
|
2680
|
+
template<int n> const _Tp& operator ()(const Vec<int, n>& idx) const;
|
2681
|
+
|
2682
|
+
//! returns reference to the specified element (1D case)
|
2683
|
+
_Tp& operator ()(int idx0);
|
2684
|
+
//! returns read-only reference to the specified element (1D case)
|
2685
|
+
const _Tp& operator ()(int idx0) const;
|
2686
|
+
//! returns reference to the specified element (2D case)
|
2687
|
+
_Tp& operator ()(int idx0, int idx1);
|
2688
|
+
//! returns read-only reference to the specified element (2D case)
|
2689
|
+
const _Tp& operator ()(int idx0, int idx1) const;
|
2690
|
+
//! returns reference to the specified element (3D case)
|
2691
|
+
_Tp& operator ()(int idx0, int idx1, int idx2);
|
2692
|
+
//! returns read-only reference to the specified element (3D case)
|
2693
|
+
const _Tp& operator ()(int idx0, int idx1, int idx2) const;
|
2694
|
+
|
2695
|
+
_Tp& operator ()(Point pt);
|
2696
|
+
const _Tp& operator ()(Point pt) const;
|
2697
|
+
|
2698
|
+
//! conversion to vector.
|
2699
|
+
operator vector<_Tp>() const;
|
2700
|
+
//! conversion to Vec
|
2701
|
+
template<int n> operator Vec<typename DataType<_Tp>::channel_type, n>() const;
|
2702
|
+
//! conversion to Matx
|
2703
|
+
template<int m, int n> operator Matx<typename DataType<_Tp>::channel_type, m, n>() const;
|
2704
|
+
};
|
2705
|
+
|
2706
|
+
typedef Mat_<uchar> Mat1b;
|
2707
|
+
typedef Mat_<Vec2b> Mat2b;
|
2708
|
+
typedef Mat_<Vec3b> Mat3b;
|
2709
|
+
typedef Mat_<Vec4b> Mat4b;
|
2710
|
+
|
2711
|
+
typedef Mat_<short> Mat1s;
|
2712
|
+
typedef Mat_<Vec2s> Mat2s;
|
2713
|
+
typedef Mat_<Vec3s> Mat3s;
|
2714
|
+
typedef Mat_<Vec4s> Mat4s;
|
2715
|
+
|
2716
|
+
typedef Mat_<ushort> Mat1w;
|
2717
|
+
typedef Mat_<Vec2w> Mat2w;
|
2718
|
+
typedef Mat_<Vec3w> Mat3w;
|
2719
|
+
typedef Mat_<Vec4w> Mat4w;
|
2720
|
+
|
2721
|
+
typedef Mat_<int> Mat1i;
|
2722
|
+
typedef Mat_<Vec2i> Mat2i;
|
2723
|
+
typedef Mat_<Vec3i> Mat3i;
|
2724
|
+
typedef Mat_<Vec4i> Mat4i;
|
2725
|
+
|
2726
|
+
typedef Mat_<float> Mat1f;
|
2727
|
+
typedef Mat_<Vec2f> Mat2f;
|
2728
|
+
typedef Mat_<Vec3f> Mat3f;
|
2729
|
+
typedef Mat_<Vec4f> Mat4f;
|
2730
|
+
|
2731
|
+
typedef Mat_<double> Mat1d;
|
2732
|
+
typedef Mat_<Vec2d> Mat2d;
|
2733
|
+
typedef Mat_<Vec3d> Mat3d;
|
2734
|
+
typedef Mat_<Vec4d> Mat4d;
|
2735
|
+
|
2736
|
+
//////////// Iterators & Comma initializers //////////////////
|
2737
|
+
|
2738
|
+
class CV_EXPORTS MatConstIterator
|
2739
|
+
{
|
2740
|
+
public:
|
2741
|
+
typedef uchar* value_type;
|
2742
|
+
typedef ptrdiff_t difference_type;
|
2743
|
+
typedef const uchar** pointer;
|
2744
|
+
typedef uchar* reference;
|
2745
|
+
typedef std::random_access_iterator_tag iterator_category;
|
2746
|
+
|
2747
|
+
//! default constructor
|
2748
|
+
MatConstIterator();
|
2749
|
+
//! constructor that sets the iterator to the beginning of the matrix
|
2750
|
+
MatConstIterator(const Mat* _m);
|
2751
|
+
//! constructor that sets the iterator to the specified element of the matrix
|
2752
|
+
MatConstIterator(const Mat* _m, int _row, int _col=0);
|
2753
|
+
//! constructor that sets the iterator to the specified element of the matrix
|
2754
|
+
MatConstIterator(const Mat* _m, Point _pt);
|
2755
|
+
//! constructor that sets the iterator to the specified element of the matrix
|
2756
|
+
MatConstIterator(const Mat* _m, const int* _idx);
|
2757
|
+
//! copy constructor
|
2758
|
+
MatConstIterator(const MatConstIterator& it);
|
2759
|
+
|
2760
|
+
//! copy operator
|
2761
|
+
MatConstIterator& operator = (const MatConstIterator& it);
|
2762
|
+
//! returns the current matrix element
|
2763
|
+
uchar* operator *() const;
|
2764
|
+
//! returns the i-th matrix element, relative to the current
|
2765
|
+
uchar* operator [](ptrdiff_t i) const;
|
2766
|
+
|
2767
|
+
//! shifts the iterator forward by the specified number of elements
|
2768
|
+
MatConstIterator& operator += (ptrdiff_t ofs);
|
2769
|
+
//! shifts the iterator backward by the specified number of elements
|
2770
|
+
MatConstIterator& operator -= (ptrdiff_t ofs);
|
2771
|
+
//! decrements the iterator
|
2772
|
+
MatConstIterator& operator --();
|
2773
|
+
//! decrements the iterator
|
2774
|
+
MatConstIterator operator --(int);
|
2775
|
+
//! increments the iterator
|
2776
|
+
MatConstIterator& operator ++();
|
2777
|
+
//! increments the iterator
|
2778
|
+
MatConstIterator operator ++(int);
|
2779
|
+
//! returns the current iterator position
|
2780
|
+
Point pos() const;
|
2781
|
+
//! returns the current iterator position
|
2782
|
+
void pos(int* _idx) const;
|
2783
|
+
ptrdiff_t lpos() const;
|
2784
|
+
void seek(ptrdiff_t ofs, bool relative=false);
|
2785
|
+
void seek(const int* _idx, bool relative=false);
|
2786
|
+
|
2787
|
+
const Mat* m;
|
2788
|
+
size_t elemSize;
|
2789
|
+
uchar* ptr;
|
2790
|
+
uchar* sliceStart;
|
2791
|
+
uchar* sliceEnd;
|
2792
|
+
};
|
2793
|
+
|
2794
|
+
/*!
|
2795
|
+
Matrix read-only iterator
|
2796
|
+
|
2797
|
+
*/
|
2798
|
+
template<typename _Tp>
|
2799
|
+
class CV_EXPORTS MatConstIterator_ : public MatConstIterator
|
2800
|
+
{
|
2801
|
+
public:
|
2802
|
+
typedef _Tp value_type;
|
2803
|
+
typedef ptrdiff_t difference_type;
|
2804
|
+
typedef const _Tp* pointer;
|
2805
|
+
typedef const _Tp& reference;
|
2806
|
+
typedef std::random_access_iterator_tag iterator_category;
|
2807
|
+
|
2808
|
+
//! default constructor
|
2809
|
+
MatConstIterator_();
|
2810
|
+
//! constructor that sets the iterator to the beginning of the matrix
|
2811
|
+
MatConstIterator_(const Mat_<_Tp>* _m);
|
2812
|
+
//! constructor that sets the iterator to the specified element of the matrix
|
2813
|
+
MatConstIterator_(const Mat_<_Tp>* _m, int _row, int _col=0);
|
2814
|
+
//! constructor that sets the iterator to the specified element of the matrix
|
2815
|
+
MatConstIterator_(const Mat_<_Tp>* _m, Point _pt);
|
2816
|
+
//! constructor that sets the iterator to the specified element of the matrix
|
2817
|
+
MatConstIterator_(const Mat_<_Tp>* _m, const int* _idx);
|
2818
|
+
//! copy constructor
|
2819
|
+
MatConstIterator_(const MatConstIterator_& it);
|
2820
|
+
|
2821
|
+
//! copy operator
|
2822
|
+
MatConstIterator_& operator = (const MatConstIterator_& it);
|
2823
|
+
//! returns the current matrix element
|
2824
|
+
_Tp operator *() const;
|
2825
|
+
//! returns the i-th matrix element, relative to the current
|
2826
|
+
_Tp operator [](ptrdiff_t i) const;
|
2827
|
+
|
2828
|
+
//! shifts the iterator forward by the specified number of elements
|
2829
|
+
MatConstIterator_& operator += (ptrdiff_t ofs);
|
2830
|
+
//! shifts the iterator backward by the specified number of elements
|
2831
|
+
MatConstIterator_& operator -= (ptrdiff_t ofs);
|
2832
|
+
//! decrements the iterator
|
2833
|
+
MatConstIterator_& operator --();
|
2834
|
+
//! decrements the iterator
|
2835
|
+
MatConstIterator_ operator --(int);
|
2836
|
+
//! increments the iterator
|
2837
|
+
MatConstIterator_& operator ++();
|
2838
|
+
//! increments the iterator
|
2839
|
+
MatConstIterator_ operator ++(int);
|
2840
|
+
//! returns the current iterator position
|
2841
|
+
Point pos() const;
|
2842
|
+
};
|
2843
|
+
|
2844
|
+
|
2845
|
+
/*!
|
2846
|
+
Matrix read-write iterator
|
2847
|
+
|
2848
|
+
*/
|
2849
|
+
template<typename _Tp>
|
2850
|
+
class CV_EXPORTS MatIterator_ : public MatConstIterator_<_Tp>
|
2851
|
+
{
|
2852
|
+
public:
|
2853
|
+
typedef _Tp* pointer;
|
2854
|
+
typedef _Tp& reference;
|
2855
|
+
typedef std::random_access_iterator_tag iterator_category;
|
2856
|
+
|
2857
|
+
//! the default constructor
|
2858
|
+
MatIterator_();
|
2859
|
+
//! constructor that sets the iterator to the beginning of the matrix
|
2860
|
+
MatIterator_(Mat_<_Tp>* _m);
|
2861
|
+
//! constructor that sets the iterator to the specified element of the matrix
|
2862
|
+
MatIterator_(Mat_<_Tp>* _m, int _row, int _col=0);
|
2863
|
+
//! constructor that sets the iterator to the specified element of the matrix
|
2864
|
+
MatIterator_(const Mat_<_Tp>* _m, Point _pt);
|
2865
|
+
//! constructor that sets the iterator to the specified element of the matrix
|
2866
|
+
MatIterator_(const Mat_<_Tp>* _m, const int* _idx);
|
2867
|
+
//! copy constructor
|
2868
|
+
MatIterator_(const MatIterator_& it);
|
2869
|
+
//! copy operator
|
2870
|
+
MatIterator_& operator = (const MatIterator_<_Tp>& it );
|
2871
|
+
|
2872
|
+
//! returns the current matrix element
|
2873
|
+
_Tp& operator *() const;
|
2874
|
+
//! returns the i-th matrix element, relative to the current
|
2875
|
+
_Tp& operator [](ptrdiff_t i) const;
|
2876
|
+
|
2877
|
+
//! shifts the iterator forward by the specified number of elements
|
2878
|
+
MatIterator_& operator += (ptrdiff_t ofs);
|
2879
|
+
//! shifts the iterator backward by the specified number of elements
|
2880
|
+
MatIterator_& operator -= (ptrdiff_t ofs);
|
2881
|
+
//! decrements the iterator
|
2882
|
+
MatIterator_& operator --();
|
2883
|
+
//! decrements the iterator
|
2884
|
+
MatIterator_ operator --(int);
|
2885
|
+
//! increments the iterator
|
2886
|
+
MatIterator_& operator ++();
|
2887
|
+
//! increments the iterator
|
2888
|
+
MatIterator_ operator ++(int);
|
2889
|
+
};
|
2890
|
+
|
2891
|
+
template<typename _Tp> class CV_EXPORTS MatOp_Iter_;
|
2892
|
+
|
2893
|
+
/*!
|
2894
|
+
Comma-separated Matrix Initializer
|
2895
|
+
|
2896
|
+
The class instances are usually not created explicitly.
|
2897
|
+
Instead, they are created on "matrix << firstValue" operator.
|
2898
|
+
|
2899
|
+
The sample below initializes 2x2 rotation matrix:
|
2900
|
+
|
2901
|
+
\code
|
2902
|
+
double angle = 30, a = cos(angle*CV_PI/180), b = sin(angle*CV_PI/180);
|
2903
|
+
Mat R = (Mat_<double>(2,2) << a, -b, b, a);
|
2904
|
+
\endcode
|
2905
|
+
*/
|
2906
|
+
template<typename _Tp> class CV_EXPORTS MatCommaInitializer_
|
2907
|
+
{
|
2908
|
+
public:
|
2909
|
+
//! the constructor, created by "matrix << firstValue" operator, where matrix is cv::Mat
|
2910
|
+
MatCommaInitializer_(Mat_<_Tp>* _m);
|
2911
|
+
//! the operator that takes the next value and put it to the matrix
|
2912
|
+
template<typename T2> MatCommaInitializer_<_Tp>& operator , (T2 v);
|
2913
|
+
//! another form of conversion operator
|
2914
|
+
Mat_<_Tp> operator *() const;
|
2915
|
+
operator Mat_<_Tp>() const;
|
2916
|
+
protected:
|
2917
|
+
MatIterator_<_Tp> it;
|
2918
|
+
};
|
2919
|
+
|
2920
|
+
|
2921
|
+
template<typename _Tp, int m, int n> class CV_EXPORTS MatxCommaInitializer
|
2922
|
+
{
|
2923
|
+
public:
|
2924
|
+
MatxCommaInitializer(Matx<_Tp, m, n>* _mtx);
|
2925
|
+
template<typename T2> MatxCommaInitializer<_Tp, m, n>& operator , (T2 val);
|
2926
|
+
Matx<_Tp, m, n> operator *() const;
|
2927
|
+
|
2928
|
+
Matx<_Tp, m, n>* dst;
|
2929
|
+
int idx;
|
2930
|
+
};
|
2931
|
+
|
2932
|
+
template<typename _Tp, int m> class CV_EXPORTS VecCommaInitializer : public MatxCommaInitializer<_Tp, m, 1>
|
2933
|
+
{
|
2934
|
+
public:
|
2935
|
+
VecCommaInitializer(Vec<_Tp, m>* _vec);
|
2936
|
+
template<typename T2> VecCommaInitializer<_Tp, m>& operator , (T2 val);
|
2937
|
+
Vec<_Tp, m> operator *() const;
|
2938
|
+
};
|
2939
|
+
|
2940
|
+
/*!
|
2941
|
+
Automatically Allocated Buffer Class
|
2942
|
+
|
2943
|
+
The class is used for temporary buffers in functions and methods.
|
2944
|
+
If a temporary buffer is usually small (a few K's of memory),
|
2945
|
+
but its size depends on the parameters, it makes sense to create a small
|
2946
|
+
fixed-size array on stack and use it if it's large enough. If the required buffer size
|
2947
|
+
is larger than the fixed size, another buffer of sufficient size is allocated dynamically
|
2948
|
+
and released after the processing. Therefore, in typical cases, when the buffer size is small,
|
2949
|
+
there is no overhead associated with malloc()/free().
|
2950
|
+
At the same time, there is no limit on the size of processed data.
|
2951
|
+
|
2952
|
+
This is what AutoBuffer does. The template takes 2 parameters - type of the buffer elements and
|
2953
|
+
the number of stack-allocated elements. Here is how the class is used:
|
2954
|
+
|
2955
|
+
\code
|
2956
|
+
void my_func(const cv::Mat& m)
|
2957
|
+
{
|
2958
|
+
cv::AutoBuffer<float, 1000> buf; // create automatic buffer containing 1000 floats
|
2959
|
+
|
2960
|
+
buf.allocate(m.rows); // if m.rows <= 1000, the pre-allocated buffer is used,
|
2961
|
+
// otherwise the buffer of "m.rows" floats will be allocated
|
2962
|
+
// dynamically and deallocated in cv::AutoBuffer destructor
|
2963
|
+
...
|
2964
|
+
}
|
2965
|
+
\endcode
|
2966
|
+
*/
|
2967
|
+
template<typename _Tp, size_t fixed_size=4096/sizeof(_Tp)+8> class CV_EXPORTS AutoBuffer
|
2968
|
+
{
|
2969
|
+
public:
|
2970
|
+
typedef _Tp value_type;
|
2971
|
+
enum { buffer_padding = (int)((16 + sizeof(_Tp) - 1)/sizeof(_Tp)) };
|
2972
|
+
|
2973
|
+
//! the default contructor
|
2974
|
+
AutoBuffer();
|
2975
|
+
//! constructor taking the real buffer size
|
2976
|
+
AutoBuffer(size_t _size);
|
2977
|
+
//! destructor. calls deallocate()
|
2978
|
+
~AutoBuffer();
|
2979
|
+
|
2980
|
+
//! allocates the new buffer of size _size. if the _size is small enough, stack-allocated buffer is used
|
2981
|
+
void allocate(size_t _size);
|
2982
|
+
//! deallocates the buffer if it was dynamically allocated
|
2983
|
+
void deallocate();
|
2984
|
+
//! returns pointer to the real buffer, stack-allocated or head-allocated
|
2985
|
+
operator _Tp* ();
|
2986
|
+
//! returns read-only pointer to the real buffer, stack-allocated or head-allocated
|
2987
|
+
operator const _Tp* () const;
|
2988
|
+
|
2989
|
+
protected:
|
2990
|
+
//! pointer to the real buffer, can point to buf if the buffer is small enough
|
2991
|
+
_Tp* ptr;
|
2992
|
+
//! size of the real buffer
|
2993
|
+
size_t size;
|
2994
|
+
//! pre-allocated buffer
|
2995
|
+
_Tp buf[fixed_size+buffer_padding];
|
2996
|
+
};
|
2997
|
+
|
2998
|
+
/////////////////////////// multi-dimensional dense matrix //////////////////////////
|
2999
|
+
|
3000
|
+
/*!
|
3001
|
+
n-Dimensional Dense Matrix Iterator Class.
|
3002
|
+
|
3003
|
+
The class cv::NAryMatIterator is used for iterating over one or more n-dimensional dense arrays (cv::Mat's).
|
3004
|
+
|
3005
|
+
The iterator is completely different from cv::Mat_ and cv::SparseMat_ iterators.
|
3006
|
+
It iterates through the slices (or planes), not the elements, where "slice" is a continuous part of the arrays.
|
3007
|
+
|
3008
|
+
Here is the example on how the iterator can be used to normalize 3D histogram:
|
3009
|
+
|
3010
|
+
\code
|
3011
|
+
void normalizeColorHist(Mat& hist)
|
3012
|
+
{
|
3013
|
+
#if 1
|
3014
|
+
// intialize iterator (the style is different from STL).
|
3015
|
+
// after initialization the iterator will contain
|
3016
|
+
// the number of slices or planes
|
3017
|
+
// the iterator will go through
|
3018
|
+
Mat* arrays[] = { &hist, 0 };
|
3019
|
+
Mat planes[1];
|
3020
|
+
NAryMatIterator it(arrays, planes);
|
3021
|
+
double s = 0;
|
3022
|
+
// iterate through the matrix. on each iteration
|
3023
|
+
// it.planes[i] (of type Mat) will be set to the current plane of
|
3024
|
+
// i-th n-dim matrix passed to the iterator constructor.
|
3025
|
+
for(int p = 0; p < it.nplanes; p++, ++it)
|
3026
|
+
s += sum(it.planes[0])[0];
|
3027
|
+
it = NAryMatIterator(hist);
|
3028
|
+
s = 1./s;
|
3029
|
+
for(int p = 0; p < it.nplanes; p++, ++it)
|
3030
|
+
it.planes[0] *= s;
|
3031
|
+
#elif 1
|
3032
|
+
// this is a shorter implementation of the above
|
3033
|
+
// using built-in operations on Mat
|
3034
|
+
double s = sum(hist)[0];
|
3035
|
+
hist.convertTo(hist, hist.type(), 1./s, 0);
|
3036
|
+
#else
|
3037
|
+
// and this is even shorter one
|
3038
|
+
// (assuming that the histogram elements are non-negative)
|
3039
|
+
normalize(hist, hist, 1, 0, NORM_L1);
|
3040
|
+
#endif
|
3041
|
+
}
|
3042
|
+
\endcode
|
3043
|
+
|
3044
|
+
You can iterate through several matrices simultaneously as long as they have the same geometry
|
3045
|
+
(dimensionality and all the dimension sizes are the same), which is useful for binary
|
3046
|
+
and n-ary operations on such matrices. Just pass those matrices to cv::MatNDIterator.
|
3047
|
+
Then, during the iteration it.planes[0], it.planes[1], ... will
|
3048
|
+
be the slices of the corresponding matrices
|
3049
|
+
*/
|
3050
|
+
class CV_EXPORTS NAryMatIterator
|
3051
|
+
{
|
3052
|
+
public:
|
3053
|
+
//! the default constructor
|
3054
|
+
NAryMatIterator();
|
3055
|
+
//! the full constructor taking arbitrary number of n-dim matrices
|
3056
|
+
NAryMatIterator(const Mat** arrays, uchar** ptrs, int narrays=-1);
|
3057
|
+
//! the full constructor taking arbitrary number of n-dim matrices
|
3058
|
+
NAryMatIterator(const Mat** arrays, Mat* planes, int narrays=-1);
|
3059
|
+
//! the separate iterator initialization method
|
3060
|
+
void init(const Mat** arrays, Mat* planes, uchar** ptrs, int narrays=-1);
|
3061
|
+
|
3062
|
+
//! proceeds to the next plane of every iterated matrix
|
3063
|
+
NAryMatIterator& operator ++();
|
3064
|
+
//! proceeds to the next plane of every iterated matrix (postfix increment operator)
|
3065
|
+
NAryMatIterator operator ++(int);
|
3066
|
+
|
3067
|
+
//! the iterated arrays
|
3068
|
+
const Mat** arrays;
|
3069
|
+
//! the current planes
|
3070
|
+
Mat* planes;
|
3071
|
+
//! data pointers
|
3072
|
+
uchar** ptrs;
|
3073
|
+
//! the number of arrays
|
3074
|
+
int narrays;
|
3075
|
+
//! the number of hyper-planes that the iterator steps through
|
3076
|
+
size_t nplanes;
|
3077
|
+
//! the size of each segment (in elements)
|
3078
|
+
size_t size;
|
3079
|
+
protected:
|
3080
|
+
int iterdepth;
|
3081
|
+
size_t idx;
|
3082
|
+
};
|
3083
|
+
|
3084
|
+
//typedef NAryMatIterator NAryMatNDIterator;
|
3085
|
+
|
3086
|
+
typedef void (*ConvertData)(const void* from, void* to, int cn);
|
3087
|
+
typedef void (*ConvertScaleData)(const void* from, void* to, int cn, double alpha, double beta);
|
3088
|
+
|
3089
|
+
//! returns the function for converting pixels from one data type to another
|
3090
|
+
CV_EXPORTS ConvertData getConvertElem(int fromType, int toType);
|
3091
|
+
//! returns the function for converting pixels from one data type to another with the optional scaling
|
3092
|
+
CV_EXPORTS ConvertScaleData getConvertScaleElem(int fromType, int toType);
|
3093
|
+
|
3094
|
+
|
3095
|
+
/////////////////////////// multi-dimensional sparse matrix //////////////////////////
|
3096
|
+
|
3097
|
+
class SparseMatIterator;
|
3098
|
+
class SparseMatConstIterator;
|
3099
|
+
template<typename _Tp> class SparseMatIterator_;
|
3100
|
+
template<typename _Tp> class SparseMatConstIterator_;
|
3101
|
+
|
3102
|
+
/*!
|
3103
|
+
Sparse matrix class.
|
3104
|
+
|
3105
|
+
The class represents multi-dimensional sparse numerical arrays. Such a sparse array can store elements
|
3106
|
+
of any type that cv::Mat is able to store. "Sparse" means that only non-zero elements
|
3107
|
+
are stored (though, as a result of some operations on a sparse matrix, some of its stored elements
|
3108
|
+
can actually become 0. It's user responsibility to detect such elements and delete them using cv::SparseMat::erase().
|
3109
|
+
The non-zero elements are stored in a hash table that grows when it's filled enough,
|
3110
|
+
so that the search time remains O(1) in average. Elements can be accessed using the following methods:
|
3111
|
+
|
3112
|
+
<ol>
|
3113
|
+
<li>Query operations: cv::SparseMat::ptr() and the higher-level cv::SparseMat::ref(),
|
3114
|
+
cv::SparseMat::value() and cv::SparseMat::find, for example:
|
3115
|
+
\code
|
3116
|
+
const int dims = 5;
|
3117
|
+
int size[] = {10, 10, 10, 10, 10};
|
3118
|
+
SparseMat sparse_mat(dims, size, CV_32F);
|
3119
|
+
for(int i = 0; i < 1000; i++)
|
3120
|
+
{
|
3121
|
+
int idx[dims];
|
3122
|
+
for(int k = 0; k < dims; k++)
|
3123
|
+
idx[k] = rand()%sparse_mat.size(k);
|
3124
|
+
sparse_mat.ref<float>(idx) += 1.f;
|
3125
|
+
}
|
3126
|
+
\endcode
|
3127
|
+
|
3128
|
+
<li>Sparse matrix iterators. Like cv::Mat iterators and unlike cv::Mat iterators, the sparse matrix iterators are STL-style,
|
3129
|
+
that is, the iteration is done as following:
|
3130
|
+
\code
|
3131
|
+
// prints elements of a sparse floating-point matrix and the sum of elements.
|
3132
|
+
SparseMatConstIterator_<float>
|
3133
|
+
it = sparse_mat.begin<float>(),
|
3134
|
+
it_end = sparse_mat.end<float>();
|
3135
|
+
double s = 0;
|
3136
|
+
int dims = sparse_mat.dims();
|
3137
|
+
for(; it != it_end; ++it)
|
3138
|
+
{
|
3139
|
+
// print element indices and the element value
|
3140
|
+
const Node* n = it.node();
|
3141
|
+
printf("(")
|
3142
|
+
for(int i = 0; i < dims; i++)
|
3143
|
+
printf("%3d%c", n->idx[i], i < dims-1 ? ',' : ')');
|
3144
|
+
printf(": %f\n", *it);
|
3145
|
+
s += *it;
|
3146
|
+
}
|
3147
|
+
printf("Element sum is %g\n", s);
|
3148
|
+
\endcode
|
3149
|
+
If you run this loop, you will notice that elements are enumerated
|
3150
|
+
in no any logical order (lexicographical etc.),
|
3151
|
+
they come in the same order as they stored in the hash table, i.e. semi-randomly.
|
3152
|
+
|
3153
|
+
You may collect pointers to the nodes and sort them to get the proper ordering.
|
3154
|
+
Note, however, that pointers to the nodes may become invalid when you add more
|
3155
|
+
elements to the matrix; this is because of possible buffer reallocation.
|
3156
|
+
|
3157
|
+
<li>A combination of the above 2 methods when you need to process 2 or more sparse
|
3158
|
+
matrices simultaneously, e.g. this is how you can compute unnormalized
|
3159
|
+
cross-correlation of the 2 floating-point sparse matrices:
|
3160
|
+
\code
|
3161
|
+
double crossCorr(const SparseMat& a, const SparseMat& b)
|
3162
|
+
{
|
3163
|
+
const SparseMat *_a = &a, *_b = &b;
|
3164
|
+
// if b contains less elements than a,
|
3165
|
+
// it's faster to iterate through b
|
3166
|
+
if(_a->nzcount() > _b->nzcount())
|
3167
|
+
std::swap(_a, _b);
|
3168
|
+
SparseMatConstIterator_<float> it = _a->begin<float>(),
|
3169
|
+
it_end = _a->end<float>();
|
3170
|
+
double ccorr = 0;
|
3171
|
+
for(; it != it_end; ++it)
|
3172
|
+
{
|
3173
|
+
// take the next element from the first matrix
|
3174
|
+
float avalue = *it;
|
3175
|
+
const Node* anode = it.node();
|
3176
|
+
// and try to find element with the same index in the second matrix.
|
3177
|
+
// since the hash value depends only on the element index,
|
3178
|
+
// we reuse hashvalue stored in the node
|
3179
|
+
float bvalue = _b->value<float>(anode->idx,&anode->hashval);
|
3180
|
+
ccorr += avalue*bvalue;
|
3181
|
+
}
|
3182
|
+
return ccorr;
|
3183
|
+
}
|
3184
|
+
\endcode
|
3185
|
+
</ol>
|
3186
|
+
*/
|
3187
|
+
class CV_EXPORTS SparseMat
|
3188
|
+
{
|
3189
|
+
public:
|
3190
|
+
typedef SparseMatIterator iterator;
|
3191
|
+
typedef SparseMatConstIterator const_iterator;
|
3192
|
+
|
3193
|
+
//! the sparse matrix header
|
3194
|
+
struct CV_EXPORTS Hdr
|
3195
|
+
{
|
3196
|
+
Hdr(int _dims, const int* _sizes, int _type);
|
3197
|
+
void clear();
|
3198
|
+
int refcount;
|
3199
|
+
int dims;
|
3200
|
+
int valueOffset;
|
3201
|
+
size_t nodeSize;
|
3202
|
+
size_t nodeCount;
|
3203
|
+
size_t freeList;
|
3204
|
+
vector<uchar> pool;
|
3205
|
+
vector<size_t> hashtab;
|
3206
|
+
int size[CV_MAX_DIM];
|
3207
|
+
};
|
3208
|
+
|
3209
|
+
//! sparse matrix node - element of a hash table
|
3210
|
+
struct CV_EXPORTS Node
|
3211
|
+
{
|
3212
|
+
//! hash value
|
3213
|
+
size_t hashval;
|
3214
|
+
//! index of the next node in the same hash table entry
|
3215
|
+
size_t next;
|
3216
|
+
//! index of the matrix element
|
3217
|
+
int idx[CV_MAX_DIM];
|
3218
|
+
};
|
3219
|
+
|
3220
|
+
//! default constructor
|
3221
|
+
SparseMat();
|
3222
|
+
//! creates matrix of the specified size and type
|
3223
|
+
SparseMat(int dims, const int* _sizes, int _type);
|
3224
|
+
//! copy constructor
|
3225
|
+
SparseMat(const SparseMat& m);
|
3226
|
+
//! converts dense 2d matrix to the sparse form
|
3227
|
+
/*!
|
3228
|
+
\param m the input matrix
|
3229
|
+
\param try1d if true and m is a single-column matrix (Nx1),
|
3230
|
+
then the sparse matrix will be 1-dimensional.
|
3231
|
+
*/
|
3232
|
+
explicit SparseMat(const Mat& m);
|
3233
|
+
//! converts old-style sparse matrix to the new-style. All the data is copied
|
3234
|
+
SparseMat(const CvSparseMat* m);
|
3235
|
+
//! the destructor
|
3236
|
+
~SparseMat();
|
3237
|
+
|
3238
|
+
//! assignment operator. This is O(1) operation, i.e. no data is copied
|
3239
|
+
SparseMat& operator = (const SparseMat& m);
|
3240
|
+
//! equivalent to the corresponding constructor
|
3241
|
+
SparseMat& operator = (const Mat& m);
|
3242
|
+
|
3243
|
+
//! creates full copy of the matrix
|
3244
|
+
SparseMat clone() const;
|
3245
|
+
|
3246
|
+
//! copies all the data to the destination matrix. All the previous content of m is erased
|
3247
|
+
void copyTo( SparseMat& m ) const;
|
3248
|
+
//! converts sparse matrix to dense matrix.
|
3249
|
+
void copyTo( Mat& m ) const;
|
3250
|
+
//! multiplies all the matrix elements by the specified scale factor alpha and converts the results to the specified data type
|
3251
|
+
void convertTo( SparseMat& m, int rtype, double alpha=1 ) const;
|
3252
|
+
//! converts sparse matrix to dense n-dim matrix with optional type conversion and scaling.
|
3253
|
+
/*!
|
3254
|
+
\param rtype The output matrix data type. When it is =-1, the output array will have the same data type as (*this)
|
3255
|
+
\param alpha The scale factor
|
3256
|
+
\param beta The optional delta added to the scaled values before the conversion
|
3257
|
+
*/
|
3258
|
+
void convertTo( Mat& m, int rtype, double alpha=1, double beta=0 ) const;
|
3259
|
+
|
3260
|
+
// not used now
|
3261
|
+
void assignTo( SparseMat& m, int type=-1 ) const;
|
3262
|
+
|
3263
|
+
//! reallocates sparse matrix.
|
3264
|
+
/*!
|
3265
|
+
If the matrix already had the proper size and type,
|
3266
|
+
it is simply cleared with clear(), otherwise,
|
3267
|
+
the old matrix is released (using release()) and the new one is allocated.
|
3268
|
+
*/
|
3269
|
+
void create(int dims, const int* _sizes, int _type);
|
3270
|
+
//! sets all the sparse matrix elements to 0, which means clearing the hash table.
|
3271
|
+
void clear();
|
3272
|
+
//! manually increments the reference counter to the header.
|
3273
|
+
void addref();
|
3274
|
+
// decrements the header reference counter. When the counter reaches 0, the header and all the underlying data are deallocated.
|
3275
|
+
void release();
|
3276
|
+
|
3277
|
+
//! converts sparse matrix to the old-style representation; all the elements are copied.
|
3278
|
+
operator CvSparseMat*() const;
|
3279
|
+
//! returns the size of each element in bytes (not including the overhead - the space occupied by SparseMat::Node elements)
|
3280
|
+
size_t elemSize() const;
|
3281
|
+
//! returns elemSize()/channels()
|
3282
|
+
size_t elemSize1() const;
|
3283
|
+
|
3284
|
+
//! returns type of sparse matrix elements
|
3285
|
+
int type() const;
|
3286
|
+
//! returns the depth of sparse matrix elements
|
3287
|
+
int depth() const;
|
3288
|
+
//! returns the number of channels
|
3289
|
+
int channels() const;
|
3290
|
+
|
3291
|
+
//! returns the array of sizes, or NULL if the matrix is not allocated
|
3292
|
+
const int* size() const;
|
3293
|
+
//! returns the size of i-th matrix dimension (or 0)
|
3294
|
+
int size(int i) const;
|
3295
|
+
//! returns the matrix dimensionality
|
3296
|
+
int dims() const;
|
3297
|
+
//! returns the number of non-zero elements (=the number of hash table nodes)
|
3298
|
+
size_t nzcount() const;
|
3299
|
+
|
3300
|
+
//! computes the element hash value (1D case)
|
3301
|
+
size_t hash(int i0) const;
|
3302
|
+
//! computes the element hash value (2D case)
|
3303
|
+
size_t hash(int i0, int i1) const;
|
3304
|
+
//! computes the element hash value (3D case)
|
3305
|
+
size_t hash(int i0, int i1, int i2) const;
|
3306
|
+
//! computes the element hash value (nD case)
|
3307
|
+
size_t hash(const int* idx) const;
|
3308
|
+
|
3309
|
+
//@{
|
3310
|
+
/*!
|
3311
|
+
specialized variants for 1D, 2D, 3D cases and the generic_type one for n-D case.
|
3312
|
+
|
3313
|
+
return pointer to the matrix element.
|
3314
|
+
<ul>
|
3315
|
+
<li>if the element is there (it's non-zero), the pointer to it is returned
|
3316
|
+
<li>if it's not there and createMissing=false, NULL pointer is returned
|
3317
|
+
<li>if it's not there and createMissing=true, then the new element
|
3318
|
+
is created and initialized with 0. Pointer to it is returned
|
3319
|
+
<li>if the optional hashval pointer is not NULL, the element hash value is
|
3320
|
+
not computed, but *hashval is taken instead.
|
3321
|
+
</ul>
|
3322
|
+
*/
|
3323
|
+
//! returns pointer to the specified element (1D case)
|
3324
|
+
uchar* ptr(int i0, bool createMissing, size_t* hashval=0);
|
3325
|
+
//! returns pointer to the specified element (2D case)
|
3326
|
+
uchar* ptr(int i0, int i1, bool createMissing, size_t* hashval=0);
|
3327
|
+
//! returns pointer to the specified element (3D case)
|
3328
|
+
uchar* ptr(int i0, int i1, int i2, bool createMissing, size_t* hashval=0);
|
3329
|
+
//! returns pointer to the specified element (nD case)
|
3330
|
+
uchar* ptr(const int* idx, bool createMissing, size_t* hashval=0);
|
3331
|
+
//@}
|
3332
|
+
|
3333
|
+
//@{
|
3334
|
+
/*!
|
3335
|
+
return read-write reference to the specified sparse matrix element.
|
3336
|
+
|
3337
|
+
ref<_Tp>(i0,...[,hashval]) is equivalent to *(_Tp*)ptr(i0,...,true[,hashval]).
|
3338
|
+
The methods always return a valid reference.
|
3339
|
+
If the element did not exist, it is created and initialiazed with 0.
|
3340
|
+
*/
|
3341
|
+
//! returns reference to the specified element (1D case)
|
3342
|
+
template<typename _Tp> _Tp& ref(int i0, size_t* hashval=0);
|
3343
|
+
//! returns reference to the specified element (2D case)
|
3344
|
+
template<typename _Tp> _Tp& ref(int i0, int i1, size_t* hashval=0);
|
3345
|
+
//! returns reference to the specified element (3D case)
|
3346
|
+
template<typename _Tp> _Tp& ref(int i0, int i1, int i2, size_t* hashval=0);
|
3347
|
+
//! returns reference to the specified element (nD case)
|
3348
|
+
template<typename _Tp> _Tp& ref(const int* idx, size_t* hashval=0);
|
3349
|
+
//@}
|
3350
|
+
|
3351
|
+
//@{
|
3352
|
+
/*!
|
3353
|
+
return value of the specified sparse matrix element.
|
3354
|
+
|
3355
|
+
value<_Tp>(i0,...[,hashval]) is equivalent
|
3356
|
+
|
3357
|
+
\code
|
3358
|
+
{ const _Tp* p = find<_Tp>(i0,...[,hashval]); return p ? *p : _Tp(); }
|
3359
|
+
\endcode
|
3360
|
+
|
3361
|
+
That is, if the element did not exist, the methods return 0.
|
3362
|
+
*/
|
3363
|
+
//! returns value of the specified element (1D case)
|
3364
|
+
template<typename _Tp> _Tp value(int i0, size_t* hashval=0) const;
|
3365
|
+
//! returns value of the specified element (2D case)
|
3366
|
+
template<typename _Tp> _Tp value(int i0, int i1, size_t* hashval=0) const;
|
3367
|
+
//! returns value of the specified element (3D case)
|
3368
|
+
template<typename _Tp> _Tp value(int i0, int i1, int i2, size_t* hashval=0) const;
|
3369
|
+
//! returns value of the specified element (nD case)
|
3370
|
+
template<typename _Tp> _Tp value(const int* idx, size_t* hashval=0) const;
|
3371
|
+
//@}
|
3372
|
+
|
3373
|
+
//@{
|
3374
|
+
/*!
|
3375
|
+
Return pointer to the specified sparse matrix element if it exists
|
3376
|
+
|
3377
|
+
find<_Tp>(i0,...[,hashval]) is equivalent to (_const Tp*)ptr(i0,...false[,hashval]).
|
3378
|
+
|
3379
|
+
If the specified element does not exist, the methods return NULL.
|
3380
|
+
*/
|
3381
|
+
//! returns pointer to the specified element (1D case)
|
3382
|
+
template<typename _Tp> const _Tp* find(int i0, size_t* hashval=0) const;
|
3383
|
+
//! returns pointer to the specified element (2D case)
|
3384
|
+
template<typename _Tp> const _Tp* find(int i0, int i1, size_t* hashval=0) const;
|
3385
|
+
//! returns pointer to the specified element (3D case)
|
3386
|
+
template<typename _Tp> const _Tp* find(int i0, int i1, int i2, size_t* hashval=0) const;
|
3387
|
+
//! returns pointer to the specified element (nD case)
|
3388
|
+
template<typename _Tp> const _Tp* find(const int* idx, size_t* hashval=0) const;
|
3389
|
+
|
3390
|
+
//! erases the specified element (2D case)
|
3391
|
+
void erase(int i0, int i1, size_t* hashval=0);
|
3392
|
+
//! erases the specified element (3D case)
|
3393
|
+
void erase(int i0, int i1, int i2, size_t* hashval=0);
|
3394
|
+
//! erases the specified element (nD case)
|
3395
|
+
void erase(const int* idx, size_t* hashval=0);
|
3396
|
+
|
3397
|
+
//@{
|
3398
|
+
/*!
|
3399
|
+
return the sparse matrix iterator pointing to the first sparse matrix element
|
3400
|
+
*/
|
3401
|
+
//! returns the sparse matrix iterator at the matrix beginning
|
3402
|
+
SparseMatIterator begin();
|
3403
|
+
//! returns the sparse matrix iterator at the matrix beginning
|
3404
|
+
template<typename _Tp> SparseMatIterator_<_Tp> begin();
|
3405
|
+
//! returns the read-only sparse matrix iterator at the matrix beginning
|
3406
|
+
SparseMatConstIterator begin() const;
|
3407
|
+
//! returns the read-only sparse matrix iterator at the matrix beginning
|
3408
|
+
template<typename _Tp> SparseMatConstIterator_<_Tp> begin() const;
|
3409
|
+
//@}
|
3410
|
+
/*!
|
3411
|
+
return the sparse matrix iterator pointing to the element following the last sparse matrix element
|
3412
|
+
*/
|
3413
|
+
//! returns the sparse matrix iterator at the matrix end
|
3414
|
+
SparseMatIterator end();
|
3415
|
+
//! returns the read-only sparse matrix iterator at the matrix end
|
3416
|
+
SparseMatConstIterator end() const;
|
3417
|
+
//! returns the typed sparse matrix iterator at the matrix end
|
3418
|
+
template<typename _Tp> SparseMatIterator_<_Tp> end();
|
3419
|
+
//! returns the typed read-only sparse matrix iterator at the matrix end
|
3420
|
+
template<typename _Tp> SparseMatConstIterator_<_Tp> end() const;
|
3421
|
+
|
3422
|
+
//! returns the value stored in the sparse martix node
|
3423
|
+
template<typename _Tp> _Tp& value(Node* n);
|
3424
|
+
//! returns the value stored in the sparse martix node
|
3425
|
+
template<typename _Tp> const _Tp& value(const Node* n) const;
|
3426
|
+
|
3427
|
+
////////////// some internal-use methods ///////////////
|
3428
|
+
Node* node(size_t nidx);
|
3429
|
+
const Node* node(size_t nidx) const;
|
3430
|
+
|
3431
|
+
uchar* newNode(const int* idx, size_t hashval);
|
3432
|
+
void removeNode(size_t hidx, size_t nidx, size_t previdx);
|
3433
|
+
void resizeHashTab(size_t newsize);
|
3434
|
+
|
3435
|
+
enum { MAGIC_VAL=0x42FD0000, MAX_DIM=CV_MAX_DIM, HASH_SCALE=0x5bd1e995, HASH_BIT=0x80000000 };
|
3436
|
+
|
3437
|
+
int flags;
|
3438
|
+
Hdr* hdr;
|
3439
|
+
};
|
3440
|
+
|
3441
|
+
//! finds global minimum and maximum sparse array elements and returns their values and their locations
|
3442
|
+
CV_EXPORTS void minMaxLoc(const SparseMat& a, double* minVal,
|
3443
|
+
double* maxVal, int* minIdx=0, int* maxIdx=0);
|
3444
|
+
//! computes norm of a sparse matrix
|
3445
|
+
CV_EXPORTS double norm( const SparseMat& src, int normType );
|
3446
|
+
//! scales and shifts array elements so that either the specified norm (alpha) or the minimum (alpha) and maximum (beta) array values get the specified values
|
3447
|
+
CV_EXPORTS void normalize( const SparseMat& src, SparseMat& dst, double alpha, int normType );
|
3448
|
+
|
3449
|
+
/*!
|
3450
|
+
Read-Only Sparse Matrix Iterator.
|
3451
|
+
Here is how to use the iterator to compute the sum of floating-point sparse matrix elements:
|
3452
|
+
|
3453
|
+
\code
|
3454
|
+
SparseMatConstIterator it = m.begin(), it_end = m.end();
|
3455
|
+
double s = 0;
|
3456
|
+
CV_Assert( m.type() == CV_32F );
|
3457
|
+
for( ; it != it_end; ++it )
|
3458
|
+
s += it.value<float>();
|
3459
|
+
\endcode
|
3460
|
+
*/
|
3461
|
+
class CV_EXPORTS SparseMatConstIterator
|
3462
|
+
{
|
3463
|
+
public:
|
3464
|
+
//! the default constructor
|
3465
|
+
SparseMatConstIterator();
|
3466
|
+
//! the full constructor setting the iterator to the first sparse matrix element
|
3467
|
+
SparseMatConstIterator(const SparseMat* _m);
|
3468
|
+
//! the copy constructor
|
3469
|
+
SparseMatConstIterator(const SparseMatConstIterator& it);
|
3470
|
+
|
3471
|
+
//! the assignment operator
|
3472
|
+
SparseMatConstIterator& operator = (const SparseMatConstIterator& it);
|
3473
|
+
|
3474
|
+
//! template method returning the current matrix element
|
3475
|
+
template<typename _Tp> const _Tp& value() const;
|
3476
|
+
//! returns the current node of the sparse matrix. it.node->idx is the current element index
|
3477
|
+
const SparseMat::Node* node() const;
|
3478
|
+
|
3479
|
+
//! moves iterator to the previous element
|
3480
|
+
SparseMatConstIterator& operator --();
|
3481
|
+
//! moves iterator to the previous element
|
3482
|
+
SparseMatConstIterator operator --(int);
|
3483
|
+
//! moves iterator to the next element
|
3484
|
+
SparseMatConstIterator& operator ++();
|
3485
|
+
//! moves iterator to the next element
|
3486
|
+
SparseMatConstIterator operator ++(int);
|
3487
|
+
|
3488
|
+
//! moves iterator to the element after the last element
|
3489
|
+
void seekEnd();
|
3490
|
+
|
3491
|
+
const SparseMat* m;
|
3492
|
+
size_t hashidx;
|
3493
|
+
uchar* ptr;
|
3494
|
+
};
|
3495
|
+
|
3496
|
+
/*!
|
3497
|
+
Read-write Sparse Matrix Iterator
|
3498
|
+
|
3499
|
+
The class is similar to cv::SparseMatConstIterator,
|
3500
|
+
but can be used for in-place modification of the matrix elements.
|
3501
|
+
*/
|
3502
|
+
class CV_EXPORTS SparseMatIterator : public SparseMatConstIterator
|
3503
|
+
{
|
3504
|
+
public:
|
3505
|
+
//! the default constructor
|
3506
|
+
SparseMatIterator();
|
3507
|
+
//! the full constructor setting the iterator to the first sparse matrix element
|
3508
|
+
SparseMatIterator(SparseMat* _m);
|
3509
|
+
//! the full constructor setting the iterator to the specified sparse matrix element
|
3510
|
+
SparseMatIterator(SparseMat* _m, const int* idx);
|
3511
|
+
//! the copy constructor
|
3512
|
+
SparseMatIterator(const SparseMatIterator& it);
|
3513
|
+
|
3514
|
+
//! the assignment operator
|
3515
|
+
SparseMatIterator& operator = (const SparseMatIterator& it);
|
3516
|
+
//! returns read-write reference to the current sparse matrix element
|
3517
|
+
template<typename _Tp> _Tp& value() const;
|
3518
|
+
//! returns pointer to the current sparse matrix node. it.node->idx is the index of the current element (do not modify it!)
|
3519
|
+
SparseMat::Node* node() const;
|
3520
|
+
|
3521
|
+
//! moves iterator to the next element
|
3522
|
+
SparseMatIterator& operator ++();
|
3523
|
+
//! moves iterator to the next element
|
3524
|
+
SparseMatIterator operator ++(int);
|
3525
|
+
};
|
3526
|
+
|
3527
|
+
/*!
|
3528
|
+
The Template Sparse Matrix class derived from cv::SparseMat
|
3529
|
+
|
3530
|
+
The class provides slightly more convenient operations for accessing elements.
|
3531
|
+
|
3532
|
+
\code
|
3533
|
+
SparseMat m;
|
3534
|
+
...
|
3535
|
+
SparseMat_<int> m_ = (SparseMat_<int>&)m;
|
3536
|
+
m_.ref(1)++; // equivalent to m.ref<int>(1)++;
|
3537
|
+
m_.ref(2) += m_(3); // equivalent to m.ref<int>(2) += m.value<int>(3);
|
3538
|
+
\endcode
|
3539
|
+
*/
|
3540
|
+
template<typename _Tp> class CV_EXPORTS SparseMat_ : public SparseMat
|
3541
|
+
{
|
3542
|
+
public:
|
3543
|
+
typedef SparseMatIterator_<_Tp> iterator;
|
3544
|
+
typedef SparseMatConstIterator_<_Tp> const_iterator;
|
3545
|
+
|
3546
|
+
//! the default constructor
|
3547
|
+
SparseMat_();
|
3548
|
+
//! the full constructor equivelent to SparseMat(dims, _sizes, DataType<_Tp>::type)
|
3549
|
+
SparseMat_(int dims, const int* _sizes);
|
3550
|
+
//! the copy constructor. If DataType<_Tp>.type != m.type(), the m elements are converted
|
3551
|
+
SparseMat_(const SparseMat& m);
|
3552
|
+
//! the copy constructor. This is O(1) operation - no data is copied
|
3553
|
+
SparseMat_(const SparseMat_& m);
|
3554
|
+
//! converts dense matrix to the sparse form
|
3555
|
+
SparseMat_(const Mat& m);
|
3556
|
+
//! converts the old-style sparse matrix to the C++ class. All the elements are copied
|
3557
|
+
SparseMat_(const CvSparseMat* m);
|
3558
|
+
//! the assignment operator. If DataType<_Tp>.type != m.type(), the m elements are converted
|
3559
|
+
SparseMat_& operator = (const SparseMat& m);
|
3560
|
+
//! the assignment operator. This is O(1) operation - no data is copied
|
3561
|
+
SparseMat_& operator = (const SparseMat_& m);
|
3562
|
+
//! converts dense matrix to the sparse form
|
3563
|
+
SparseMat_& operator = (const Mat& m);
|
3564
|
+
|
3565
|
+
//! makes full copy of the matrix. All the elements are duplicated
|
3566
|
+
SparseMat_ clone() const;
|
3567
|
+
//! equivalent to cv::SparseMat::create(dims, _sizes, DataType<_Tp>::type)
|
3568
|
+
void create(int dims, const int* _sizes);
|
3569
|
+
//! converts sparse matrix to the old-style CvSparseMat. All the elements are copied
|
3570
|
+
operator CvSparseMat*() const;
|
3571
|
+
|
3572
|
+
//! returns type of the matrix elements
|
3573
|
+
int type() const;
|
3574
|
+
//! returns depth of the matrix elements
|
3575
|
+
int depth() const;
|
3576
|
+
//! returns the number of channels in each matrix element
|
3577
|
+
int channels() const;
|
3578
|
+
|
3579
|
+
//! equivalent to SparseMat::ref<_Tp>(i0, hashval)
|
3580
|
+
_Tp& ref(int i0, size_t* hashval=0);
|
3581
|
+
//! equivalent to SparseMat::ref<_Tp>(i0, i1, hashval)
|
3582
|
+
_Tp& ref(int i0, int i1, size_t* hashval=0);
|
3583
|
+
//! equivalent to SparseMat::ref<_Tp>(i0, i1, i2, hashval)
|
3584
|
+
_Tp& ref(int i0, int i1, int i2, size_t* hashval=0);
|
3585
|
+
//! equivalent to SparseMat::ref<_Tp>(idx, hashval)
|
3586
|
+
_Tp& ref(const int* idx, size_t* hashval=0);
|
3587
|
+
|
3588
|
+
//! equivalent to SparseMat::value<_Tp>(i0, hashval)
|
3589
|
+
_Tp operator()(int i0, size_t* hashval=0) const;
|
3590
|
+
//! equivalent to SparseMat::value<_Tp>(i0, i1, hashval)
|
3591
|
+
_Tp operator()(int i0, int i1, size_t* hashval=0) const;
|
3592
|
+
//! equivalent to SparseMat::value<_Tp>(i0, i1, i2, hashval)
|
3593
|
+
_Tp operator()(int i0, int i1, int i2, size_t* hashval=0) const;
|
3594
|
+
//! equivalent to SparseMat::value<_Tp>(idx, hashval)
|
3595
|
+
_Tp operator()(const int* idx, size_t* hashval=0) const;
|
3596
|
+
|
3597
|
+
//! returns sparse matrix iterator pointing to the first sparse matrix element
|
3598
|
+
SparseMatIterator_<_Tp> begin();
|
3599
|
+
//! returns read-only sparse matrix iterator pointing to the first sparse matrix element
|
3600
|
+
SparseMatConstIterator_<_Tp> begin() const;
|
3601
|
+
//! returns sparse matrix iterator pointing to the element following the last sparse matrix element
|
3602
|
+
SparseMatIterator_<_Tp> end();
|
3603
|
+
//! returns read-only sparse matrix iterator pointing to the element following the last sparse matrix element
|
3604
|
+
SparseMatConstIterator_<_Tp> end() const;
|
3605
|
+
};
|
3606
|
+
|
3607
|
+
|
3608
|
+
/*!
|
3609
|
+
Template Read-Only Sparse Matrix Iterator Class.
|
3610
|
+
|
3611
|
+
This is the derived from SparseMatConstIterator class that
|
3612
|
+
introduces more convenient operator *() for accessing the current element.
|
3613
|
+
*/
|
3614
|
+
template<typename _Tp> class CV_EXPORTS SparseMatConstIterator_ : public SparseMatConstIterator
|
3615
|
+
{
|
3616
|
+
public:
|
3617
|
+
typedef std::forward_iterator_tag iterator_category;
|
3618
|
+
|
3619
|
+
//! the default constructor
|
3620
|
+
SparseMatConstIterator_();
|
3621
|
+
//! the full constructor setting the iterator to the first sparse matrix element
|
3622
|
+
SparseMatConstIterator_(const SparseMat_<_Tp>* _m);
|
3623
|
+
//! the copy constructor
|
3624
|
+
SparseMatConstIterator_(const SparseMatConstIterator_& it);
|
3625
|
+
|
3626
|
+
//! the assignment operator
|
3627
|
+
SparseMatConstIterator_& operator = (const SparseMatConstIterator_& it);
|
3628
|
+
//! the element access operator
|
3629
|
+
const _Tp& operator *() const;
|
3630
|
+
|
3631
|
+
//! moves iterator to the next element
|
3632
|
+
SparseMatConstIterator_& operator ++();
|
3633
|
+
//! moves iterator to the next element
|
3634
|
+
SparseMatConstIterator_ operator ++(int);
|
3635
|
+
};
|
3636
|
+
|
3637
|
+
/*!
|
3638
|
+
Template Read-Write Sparse Matrix Iterator Class.
|
3639
|
+
|
3640
|
+
This is the derived from cv::SparseMatConstIterator_ class that
|
3641
|
+
introduces more convenient operator *() for accessing the current element.
|
3642
|
+
*/
|
3643
|
+
template<typename _Tp> class CV_EXPORTS SparseMatIterator_ : public SparseMatConstIterator_<_Tp>
|
3644
|
+
{
|
3645
|
+
public:
|
3646
|
+
typedef std::forward_iterator_tag iterator_category;
|
3647
|
+
|
3648
|
+
//! the default constructor
|
3649
|
+
SparseMatIterator_();
|
3650
|
+
//! the full constructor setting the iterator to the first sparse matrix element
|
3651
|
+
SparseMatIterator_(SparseMat_<_Tp>* _m);
|
3652
|
+
//! the copy constructor
|
3653
|
+
SparseMatIterator_(const SparseMatIterator_& it);
|
3654
|
+
|
3655
|
+
//! the assignment operator
|
3656
|
+
SparseMatIterator_& operator = (const SparseMatIterator_& it);
|
3657
|
+
//! returns the reference to the current element
|
3658
|
+
_Tp& operator *() const;
|
3659
|
+
|
3660
|
+
//! moves the iterator to the next element
|
3661
|
+
SparseMatIterator_& operator ++();
|
3662
|
+
//! moves the iterator to the next element
|
3663
|
+
SparseMatIterator_ operator ++(int);
|
3664
|
+
};
|
3665
|
+
|
3666
|
+
//////////////////// Fast Nearest-Neighbor Search Structure ////////////////////
|
3667
|
+
|
3668
|
+
/*!
|
3669
|
+
Fast Nearest Neighbor Search Class.
|
3670
|
+
|
3671
|
+
The class implements D. Lowe BBF (Best-Bin-First) algorithm for the last
|
3672
|
+
approximate (or accurate) nearest neighbor search in multi-dimensional spaces.
|
3673
|
+
|
3674
|
+
First, a set of vectors is passed to KDTree::KDTree() constructor
|
3675
|
+
or KDTree::build() method, where it is reordered.
|
3676
|
+
|
3677
|
+
Then arbitrary vectors can be passed to KDTree::findNearest() methods, which
|
3678
|
+
find the K nearest neighbors among the vectors from the initial set.
|
3679
|
+
The user can balance between the speed and accuracy of the search by varying Emax
|
3680
|
+
parameter, which is the number of leaves that the algorithm checks.
|
3681
|
+
The larger parameter values yield more accurate results at the expense of lower processing speed.
|
3682
|
+
|
3683
|
+
\code
|
3684
|
+
KDTree T(points, false);
|
3685
|
+
const int K = 3, Emax = INT_MAX;
|
3686
|
+
int idx[K];
|
3687
|
+
float dist[K];
|
3688
|
+
T.findNearest(query_vec, K, Emax, idx, 0, dist);
|
3689
|
+
CV_Assert(dist[0] <= dist[1] && dist[1] <= dist[2]);
|
3690
|
+
\endcode
|
3691
|
+
*/
|
3692
|
+
class CV_EXPORTS_W KDTree
|
3693
|
+
{
|
3694
|
+
public:
|
3695
|
+
/*!
|
3696
|
+
The node of the search tree.
|
3697
|
+
*/
|
3698
|
+
struct Node
|
3699
|
+
{
|
3700
|
+
Node() : idx(-1), left(-1), right(-1), boundary(0.f) {}
|
3701
|
+
Node(int _idx, int _left, int _right, float _boundary)
|
3702
|
+
: idx(_idx), left(_left), right(_right), boundary(_boundary) {}
|
3703
|
+
//! split dimension; >=0 for nodes (dim), < 0 for leaves (index of the point)
|
3704
|
+
int idx;
|
3705
|
+
//! node indices of the left and the right branches
|
3706
|
+
int left, right;
|
3707
|
+
//! go to the left if query_vec[node.idx]<=node.boundary, otherwise go to the right
|
3708
|
+
float boundary;
|
3709
|
+
};
|
3710
|
+
|
3711
|
+
//! the default constructor
|
3712
|
+
CV_WRAP KDTree();
|
3713
|
+
//! the full constructor that builds the search tree
|
3714
|
+
CV_WRAP KDTree(InputArray points, bool copyAndReorderPoints=false);
|
3715
|
+
//! the full constructor that builds the search tree
|
3716
|
+
CV_WRAP KDTree(InputArray points, InputArray _labels,
|
3717
|
+
bool copyAndReorderPoints=false);
|
3718
|
+
//! builds the search tree
|
3719
|
+
CV_WRAP void build(InputArray points, bool copyAndReorderPoints=false);
|
3720
|
+
//! builds the search tree
|
3721
|
+
CV_WRAP void build(InputArray points, InputArray labels,
|
3722
|
+
bool copyAndReorderPoints=false);
|
3723
|
+
//! finds the K nearest neighbors of "vec" while looking at Emax (at most) leaves
|
3724
|
+
CV_WRAP int findNearest(InputArray vec, int K, int Emax,
|
3725
|
+
OutputArray neighborsIdx,
|
3726
|
+
OutputArray neighbors=noArray(),
|
3727
|
+
OutputArray dist=noArray(),
|
3728
|
+
OutputArray labels=noArray()) const;
|
3729
|
+
//! finds all the points from the initial set that belong to the specified box
|
3730
|
+
CV_WRAP void findOrthoRange(InputArray minBounds,
|
3731
|
+
InputArray maxBounds,
|
3732
|
+
OutputArray neighborsIdx,
|
3733
|
+
OutputArray neighbors=noArray(),
|
3734
|
+
OutputArray labels=noArray()) const;
|
3735
|
+
//! returns vectors with the specified indices
|
3736
|
+
CV_WRAP void getPoints(InputArray idx, OutputArray pts,
|
3737
|
+
OutputArray labels=noArray()) const;
|
3738
|
+
//! return a vector with the specified index
|
3739
|
+
const float* getPoint(int ptidx, int* label=0) const;
|
3740
|
+
//! returns the search space dimensionality
|
3741
|
+
CV_WRAP int dims() const;
|
3742
|
+
|
3743
|
+
vector<Node> nodes; //!< all the tree nodes
|
3744
|
+
CV_PROP Mat points; //!< all the points. It can be a reordered copy of the input vector set or the original vector set.
|
3745
|
+
CV_PROP vector<int> labels; //!< the parallel array of labels.
|
3746
|
+
CV_PROP int maxDepth; //!< maximum depth of the search tree. Do not modify it
|
3747
|
+
CV_PROP_RW int normType; //!< type of the distance (cv::NORM_L1 or cv::NORM_L2) used for search. Initially set to cv::NORM_L2, but you can modify it
|
3748
|
+
};
|
3749
|
+
|
3750
|
+
//////////////////////////////////////// XML & YAML I/O ////////////////////////////////////
|
3751
|
+
|
3752
|
+
class CV_EXPORTS FileNode;
|
3753
|
+
|
3754
|
+
/*!
|
3755
|
+
XML/YAML File Storage Class.
|
3756
|
+
|
3757
|
+
The class describes an object associated with XML or YAML file.
|
3758
|
+
It can be used to store data to such a file or read and decode the data.
|
3759
|
+
|
3760
|
+
The storage is organized as a tree of nested sequences (or lists) and mappings.
|
3761
|
+
Sequence is a heterogenious array, which elements are accessed by indices or sequentially using an iterator.
|
3762
|
+
Mapping is analogue of std::map or C structure, which elements are accessed by names.
|
3763
|
+
The most top level structure is a mapping.
|
3764
|
+
Leaves of the file storage tree are integers, floating-point numbers and text strings.
|
3765
|
+
|
3766
|
+
For example, the following code:
|
3767
|
+
|
3768
|
+
\code
|
3769
|
+
// open file storage for writing. Type of the file is determined from the extension
|
3770
|
+
FileStorage fs("test.yml", FileStorage::WRITE);
|
3771
|
+
fs << "test_int" << 5 << "test_real" << 3.1 << "test_string" << "ABCDEFGH";
|
3772
|
+
fs << "test_mat" << Mat::eye(3,3,CV_32F);
|
3773
|
+
|
3774
|
+
fs << "test_list" << "[" << 0.0000000000001 << 2 << CV_PI << -3435345 << "2-502 2-029 3egegeg" <<
|
3775
|
+
"{:" << "month" << 12 << "day" << 31 << "year" << 1969 << "}" << "]";
|
3776
|
+
fs << "test_map" << "{" << "x" << 1 << "y" << 2 << "width" << 100 << "height" << 200 << "lbp" << "[:";
|
3777
|
+
|
3778
|
+
const uchar arr[] = {0, 1, 1, 0, 1, 1, 0, 1};
|
3779
|
+
fs.writeRaw("u", arr, (int)(sizeof(arr)/sizeof(arr[0])));
|
3780
|
+
|
3781
|
+
fs << "]" << "}";
|
3782
|
+
\endcode
|
3783
|
+
|
3784
|
+
will produce the following file:
|
3785
|
+
|
3786
|
+
\verbatim
|
3787
|
+
%YAML:1.0
|
3788
|
+
test_int: 5
|
3789
|
+
test_real: 3.1000000000000001e+00
|
3790
|
+
test_string: ABCDEFGH
|
3791
|
+
test_mat: !!opencv-matrix
|
3792
|
+
rows: 3
|
3793
|
+
cols: 3
|
3794
|
+
dt: f
|
3795
|
+
data: [ 1., 0., 0., 0., 1., 0., 0., 0., 1. ]
|
3796
|
+
test_list:
|
3797
|
+
- 1.0000000000000000e-13
|
3798
|
+
- 2
|
3799
|
+
- 3.1415926535897931e+00
|
3800
|
+
- -3435345
|
3801
|
+
- "2-502 2-029 3egegeg"
|
3802
|
+
- { month:12, day:31, year:1969 }
|
3803
|
+
test_map:
|
3804
|
+
x: 1
|
3805
|
+
y: 2
|
3806
|
+
width: 100
|
3807
|
+
height: 200
|
3808
|
+
lbp: [ 0, 1, 1, 0, 1, 1, 0, 1 ]
|
3809
|
+
\endverbatim
|
3810
|
+
|
3811
|
+
and to read the file above, the following code can be used:
|
3812
|
+
|
3813
|
+
\code
|
3814
|
+
// open file storage for reading.
|
3815
|
+
// Type of the file is determined from the content, not the extension
|
3816
|
+
FileStorage fs("test.yml", FileStorage::READ);
|
3817
|
+
int test_int = (int)fs["test_int"];
|
3818
|
+
double test_real = (double)fs["test_real"];
|
3819
|
+
string test_string = (string)fs["test_string"];
|
3820
|
+
|
3821
|
+
Mat M;
|
3822
|
+
fs["test_mat"] >> M;
|
3823
|
+
|
3824
|
+
FileNode tl = fs["test_list"];
|
3825
|
+
CV_Assert(tl.type() == FileNode::SEQ && tl.size() == 6);
|
3826
|
+
double tl0 = (double)tl[0];
|
3827
|
+
int tl1 = (int)tl[1];
|
3828
|
+
double tl2 = (double)tl[2];
|
3829
|
+
int tl3 = (int)tl[3];
|
3830
|
+
string tl4 = (string)tl[4];
|
3831
|
+
CV_Assert(tl[5].type() == FileNode::MAP && tl[5].size() == 3);
|
3832
|
+
|
3833
|
+
int month = (int)tl[5]["month"];
|
3834
|
+
int day = (int)tl[5]["day"];
|
3835
|
+
int year = (int)tl[5]["year"];
|
3836
|
+
|
3837
|
+
FileNode tm = fs["test_map"];
|
3838
|
+
|
3839
|
+
int x = (int)tm["x"];
|
3840
|
+
int y = (int)tm["y"];
|
3841
|
+
int width = (int)tm["width"];
|
3842
|
+
int height = (int)tm["height"];
|
3843
|
+
|
3844
|
+
int lbp_val = 0;
|
3845
|
+
FileNodeIterator it = tm["lbp"].begin();
|
3846
|
+
|
3847
|
+
for(int k = 0; k < 8; k++, ++it)
|
3848
|
+
lbp_val |= ((int)*it) << k;
|
3849
|
+
\endcode
|
3850
|
+
*/
|
3851
|
+
class CV_EXPORTS_W FileStorage
|
3852
|
+
{
|
3853
|
+
public:
|
3854
|
+
//! file storage mode
|
3855
|
+
enum
|
3856
|
+
{
|
3857
|
+
READ=0, //! read mode
|
3858
|
+
WRITE=1, //! write mode
|
3859
|
+
APPEND=2 //! append mode
|
3860
|
+
};
|
3861
|
+
enum
|
3862
|
+
{
|
3863
|
+
UNDEFINED=0,
|
3864
|
+
VALUE_EXPECTED=1,
|
3865
|
+
NAME_EXPECTED=2,
|
3866
|
+
INSIDE_MAP=4
|
3867
|
+
};
|
3868
|
+
//! the default constructor
|
3869
|
+
CV_WRAP FileStorage();
|
3870
|
+
//! the full constructor that opens file storage for reading or writing
|
3871
|
+
CV_WRAP FileStorage(const string& filename, int flags, const string& encoding=string());
|
3872
|
+
//! the constructor that takes pointer to the C FileStorage structure
|
3873
|
+
FileStorage(CvFileStorage* fs);
|
3874
|
+
//! the destructor. calls release()
|
3875
|
+
virtual ~FileStorage();
|
3876
|
+
|
3877
|
+
//! opens file storage for reading or writing. The previous storage is closed with release()
|
3878
|
+
CV_WRAP virtual bool open(const string& filename, int flags, const string& encoding=string());
|
3879
|
+
//! returns true if the object is associated with currently opened file.
|
3880
|
+
CV_WRAP virtual bool isOpened() const;
|
3881
|
+
//! closes the file and releases all the memory buffers
|
3882
|
+
CV_WRAP virtual void release();
|
3883
|
+
|
3884
|
+
//! returns the first element of the top-level mapping
|
3885
|
+
CV_WRAP FileNode getFirstTopLevelNode() const;
|
3886
|
+
//! returns the top-level mapping. YAML supports multiple streams
|
3887
|
+
CV_WRAP FileNode root(int streamidx=0) const;
|
3888
|
+
//! returns the specified element of the top-level mapping
|
3889
|
+
FileNode operator[](const string& nodename) const;
|
3890
|
+
//! returns the specified element of the top-level mapping
|
3891
|
+
CV_WRAP FileNode operator[](const char* nodename) const;
|
3892
|
+
|
3893
|
+
//! returns pointer to the underlying C FileStorage structure
|
3894
|
+
CvFileStorage* operator *() { return fs; }
|
3895
|
+
//! returns pointer to the underlying C FileStorage structure
|
3896
|
+
const CvFileStorage* operator *() const { return fs; }
|
3897
|
+
//! writes one or more numbers of the specified format to the currently written structure
|
3898
|
+
void writeRaw( const string& fmt, const uchar* vec, size_t len );
|
3899
|
+
//! writes the registered C structure (CvMat, CvMatND, CvSeq). See cvWrite()
|
3900
|
+
void writeObj( const string& name, const void* obj );
|
3901
|
+
|
3902
|
+
//! returns the normalized object name for the specified file name
|
3903
|
+
static string getDefaultObjectName(const string& filename);
|
3904
|
+
|
3905
|
+
Ptr<CvFileStorage> fs; //!< the underlying C FileStorage structure
|
3906
|
+
string elname; //!< the currently written element
|
3907
|
+
vector<char> structs; //!< the stack of written structures
|
3908
|
+
int state; //!< the writer state
|
3909
|
+
};
|
3910
|
+
|
3911
|
+
class CV_EXPORTS FileNodeIterator;
|
3912
|
+
|
3913
|
+
/*!
|
3914
|
+
File Storage Node class
|
3915
|
+
|
3916
|
+
The node is used to store each and every element of the file storage opened for reading -
|
3917
|
+
from the primitive objects, such as numbers and text strings, to the complex nodes:
|
3918
|
+
sequences, mappings and the registered objects.
|
3919
|
+
|
3920
|
+
Note that file nodes are only used for navigating file storages opened for reading.
|
3921
|
+
When a file storage is opened for writing, no data is stored in memory after it is written.
|
3922
|
+
*/
|
3923
|
+
class CV_EXPORTS_W_SIMPLE FileNode
|
3924
|
+
{
|
3925
|
+
public:
|
3926
|
+
//! type of the file storage node
|
3927
|
+
enum
|
3928
|
+
{
|
3929
|
+
NONE=0, //!< empty node
|
3930
|
+
INT=1, //!< an integer
|
3931
|
+
REAL=2, //!< floating-point number
|
3932
|
+
FLOAT=REAL, //!< synonym or REAL
|
3933
|
+
STR=3, //!< text string in UTF-8 encoding
|
3934
|
+
STRING=STR, //!< synonym for STR
|
3935
|
+
REF=4, //!< integer of size size_t. Typically used for storing complex dynamic structures where some elements reference the others
|
3936
|
+
SEQ=5, //!< sequence
|
3937
|
+
MAP=6, //!< mapping
|
3938
|
+
TYPE_MASK=7,
|
3939
|
+
FLOW=8, //!< compact representation of a sequence or mapping. Used only by YAML writer
|
3940
|
+
USER=16, //!< a registered object (e.g. a matrix)
|
3941
|
+
EMPTY=32, //!< empty structure (sequence or mapping)
|
3942
|
+
NAMED=64 //!< the node has a name (i.e. it is element of a mapping)
|
3943
|
+
};
|
3944
|
+
//! the default constructor
|
3945
|
+
CV_WRAP FileNode();
|
3946
|
+
//! the full constructor wrapping CvFileNode structure.
|
3947
|
+
FileNode(const CvFileStorage* fs, const CvFileNode* node);
|
3948
|
+
//! the copy constructor
|
3949
|
+
FileNode(const FileNode& node);
|
3950
|
+
//! returns element of a mapping node
|
3951
|
+
FileNode operator[](const string& nodename) const;
|
3952
|
+
//! returns element of a mapping node
|
3953
|
+
CV_WRAP FileNode operator[](const char* nodename) const;
|
3954
|
+
//! returns element of a sequence node
|
3955
|
+
CV_WRAP FileNode operator[](int i) const;
|
3956
|
+
//! returns type of the node
|
3957
|
+
CV_WRAP int type() const;
|
3958
|
+
|
3959
|
+
//! returns true if the node is empty
|
3960
|
+
CV_WRAP bool empty() const;
|
3961
|
+
//! returns true if the node is a "none" object
|
3962
|
+
CV_WRAP bool isNone() const;
|
3963
|
+
//! returns true if the node is a sequence
|
3964
|
+
CV_WRAP bool isSeq() const;
|
3965
|
+
//! returns true if the node is a mapping
|
3966
|
+
CV_WRAP bool isMap() const;
|
3967
|
+
//! returns true if the node is an integer
|
3968
|
+
CV_WRAP bool isInt() const;
|
3969
|
+
//! returns true if the node is a floating-point number
|
3970
|
+
CV_WRAP bool isReal() const;
|
3971
|
+
//! returns true if the node is a text string
|
3972
|
+
CV_WRAP bool isString() const;
|
3973
|
+
//! returns true if the node has a name
|
3974
|
+
CV_WRAP bool isNamed() const;
|
3975
|
+
//! returns the node name or an empty string if the node is nameless
|
3976
|
+
CV_WRAP string name() const;
|
3977
|
+
//! returns the number of elements in the node, if it is a sequence or mapping, or 1 otherwise.
|
3978
|
+
CV_WRAP size_t size() const;
|
3979
|
+
//! returns the node content as an integer. If the node stores floating-point number, it is rounded.
|
3980
|
+
operator int() const;
|
3981
|
+
//! returns the node content as float
|
3982
|
+
operator float() const;
|
3983
|
+
//! returns the node content as double
|
3984
|
+
operator double() const;
|
3985
|
+
//! returns the node content as text string
|
3986
|
+
operator string() const;
|
3987
|
+
|
3988
|
+
//! returns pointer to the underlying file node
|
3989
|
+
CvFileNode* operator *();
|
3990
|
+
//! returns pointer to the underlying file node
|
3991
|
+
const CvFileNode* operator* () const;
|
3992
|
+
|
3993
|
+
//! returns iterator pointing to the first node element
|
3994
|
+
FileNodeIterator begin() const;
|
3995
|
+
//! returns iterator pointing to the element following the last node element
|
3996
|
+
FileNodeIterator end() const;
|
3997
|
+
|
3998
|
+
//! reads node elements to the buffer with the specified format
|
3999
|
+
void readRaw( const string& fmt, uchar* vec, size_t len ) const;
|
4000
|
+
//! reads the registered object and returns pointer to it
|
4001
|
+
void* readObj() const;
|
4002
|
+
|
4003
|
+
// do not use wrapper pointer classes for better efficiency
|
4004
|
+
const CvFileStorage* fs;
|
4005
|
+
const CvFileNode* node;
|
4006
|
+
};
|
4007
|
+
|
4008
|
+
|
4009
|
+
/*!
|
4010
|
+
File Node Iterator
|
4011
|
+
|
4012
|
+
The class is used for iterating sequences (usually) and mappings.
|
4013
|
+
*/
|
4014
|
+
class CV_EXPORTS FileNodeIterator
|
4015
|
+
{
|
4016
|
+
public:
|
4017
|
+
//! the default constructor
|
4018
|
+
FileNodeIterator();
|
4019
|
+
//! the full constructor set to the ofs-th element of the node
|
4020
|
+
FileNodeIterator(const CvFileStorage* fs, const CvFileNode* node, size_t ofs=0);
|
4021
|
+
//! the copy constructor
|
4022
|
+
FileNodeIterator(const FileNodeIterator& it);
|
4023
|
+
//! returns the currently observed element
|
4024
|
+
FileNode operator *() const;
|
4025
|
+
//! accesses the currently observed element methods
|
4026
|
+
FileNode operator ->() const;
|
4027
|
+
|
4028
|
+
//! moves iterator to the next node
|
4029
|
+
FileNodeIterator& operator ++ ();
|
4030
|
+
//! moves iterator to the next node
|
4031
|
+
FileNodeIterator operator ++ (int);
|
4032
|
+
//! moves iterator to the previous node
|
4033
|
+
FileNodeIterator& operator -- ();
|
4034
|
+
//! moves iterator to the previous node
|
4035
|
+
FileNodeIterator operator -- (int);
|
4036
|
+
//! moves iterator forward by the specified offset (possibly negative)
|
4037
|
+
FileNodeIterator& operator += (int);
|
4038
|
+
//! moves iterator backward by the specified offset (possibly negative)
|
4039
|
+
FileNodeIterator& operator -= (int);
|
4040
|
+
|
4041
|
+
//! reads the next maxCount elements (or less, if the sequence/mapping last element occurs earlier) to the buffer with the specified format
|
4042
|
+
FileNodeIterator& readRaw( const string& fmt, uchar* vec,
|
4043
|
+
size_t maxCount=(size_t)INT_MAX );
|
4044
|
+
|
4045
|
+
const CvFileStorage* fs;
|
4046
|
+
const CvFileNode* container;
|
4047
|
+
CvSeqReader reader;
|
4048
|
+
size_t remaining;
|
4049
|
+
};
|
4050
|
+
|
4051
|
+
////////////// convenient wrappers for operating old-style dynamic structures //////////////
|
4052
|
+
|
4053
|
+
template<typename _Tp> class SeqIterator;
|
4054
|
+
|
4055
|
+
typedef Ptr<CvMemStorage> MemStorage;
|
4056
|
+
|
4057
|
+
/*!
|
4058
|
+
Template Sequence Class derived from CvSeq
|
4059
|
+
|
4060
|
+
The class provides more convenient access to sequence elements,
|
4061
|
+
STL-style operations and iterators.
|
4062
|
+
|
4063
|
+
\note The class is targeted for simple data types,
|
4064
|
+
i.e. no constructors or destructors
|
4065
|
+
are called for the sequence elements.
|
4066
|
+
*/
|
4067
|
+
template<typename _Tp> class CV_EXPORTS Seq
|
4068
|
+
{
|
4069
|
+
public:
|
4070
|
+
typedef SeqIterator<_Tp> iterator;
|
4071
|
+
typedef SeqIterator<_Tp> const_iterator;
|
4072
|
+
|
4073
|
+
//! the default constructor
|
4074
|
+
Seq();
|
4075
|
+
//! the constructor for wrapping CvSeq structure. The real element type in CvSeq should match _Tp.
|
4076
|
+
Seq(const CvSeq* seq);
|
4077
|
+
//! creates the empty sequence that resides in the specified storage
|
4078
|
+
Seq(MemStorage& storage, int headerSize = sizeof(CvSeq));
|
4079
|
+
//! returns read-write reference to the specified element
|
4080
|
+
_Tp& operator [](int idx);
|
4081
|
+
//! returns read-only reference to the specified element
|
4082
|
+
const _Tp& operator[](int idx) const;
|
4083
|
+
//! returns iterator pointing to the beginning of the sequence
|
4084
|
+
SeqIterator<_Tp> begin() const;
|
4085
|
+
//! returns iterator pointing to the element following the last sequence element
|
4086
|
+
SeqIterator<_Tp> end() const;
|
4087
|
+
//! returns the number of elements in the sequence
|
4088
|
+
size_t size() const;
|
4089
|
+
//! returns the type of sequence elements (CV_8UC1 ... CV_64FC(CV_CN_MAX) ...)
|
4090
|
+
int type() const;
|
4091
|
+
//! returns the depth of sequence elements (CV_8U ... CV_64F)
|
4092
|
+
int depth() const;
|
4093
|
+
//! returns the number of channels in each sequence element
|
4094
|
+
int channels() const;
|
4095
|
+
//! returns the size of each sequence element
|
4096
|
+
size_t elemSize() const;
|
4097
|
+
//! returns index of the specified sequence element
|
4098
|
+
size_t index(const _Tp& elem) const;
|
4099
|
+
//! appends the specified element to the end of the sequence
|
4100
|
+
void push_back(const _Tp& elem);
|
4101
|
+
//! appends the specified element to the front of the sequence
|
4102
|
+
void push_front(const _Tp& elem);
|
4103
|
+
//! appends zero or more elements to the end of the sequence
|
4104
|
+
void push_back(const _Tp* elems, size_t count);
|
4105
|
+
//! appends zero or more elements to the front of the sequence
|
4106
|
+
void push_front(const _Tp* elems, size_t count);
|
4107
|
+
//! inserts the specified element to the specified position
|
4108
|
+
void insert(int idx, const _Tp& elem);
|
4109
|
+
//! inserts zero or more elements to the specified position
|
4110
|
+
void insert(int idx, const _Tp* elems, size_t count);
|
4111
|
+
//! removes element at the specified position
|
4112
|
+
void remove(int idx);
|
4113
|
+
//! removes the specified subsequence
|
4114
|
+
void remove(const Range& r);
|
4115
|
+
|
4116
|
+
//! returns reference to the first sequence element
|
4117
|
+
_Tp& front();
|
4118
|
+
//! returns read-only reference to the first sequence element
|
4119
|
+
const _Tp& front() const;
|
4120
|
+
//! returns reference to the last sequence element
|
4121
|
+
_Tp& back();
|
4122
|
+
//! returns read-only reference to the last sequence element
|
4123
|
+
const _Tp& back() const;
|
4124
|
+
//! returns true iff the sequence contains no elements
|
4125
|
+
bool empty() const;
|
4126
|
+
|
4127
|
+
//! removes all the elements from the sequence
|
4128
|
+
void clear();
|
4129
|
+
//! removes the first element from the sequence
|
4130
|
+
void pop_front();
|
4131
|
+
//! removes the last element from the sequence
|
4132
|
+
void pop_back();
|
4133
|
+
//! removes zero or more elements from the beginning of the sequence
|
4134
|
+
void pop_front(_Tp* elems, size_t count);
|
4135
|
+
//! removes zero or more elements from the end of the sequence
|
4136
|
+
void pop_back(_Tp* elems, size_t count);
|
4137
|
+
|
4138
|
+
//! copies the whole sequence or the sequence slice to the specified vector
|
4139
|
+
void copyTo(vector<_Tp>& vec, const Range& range=Range::all()) const;
|
4140
|
+
//! returns the vector containing all the sequence elements
|
4141
|
+
operator vector<_Tp>() const;
|
4142
|
+
|
4143
|
+
CvSeq* seq;
|
4144
|
+
};
|
4145
|
+
|
4146
|
+
|
4147
|
+
/*!
|
4148
|
+
STL-style Sequence Iterator inherited from the CvSeqReader structure
|
4149
|
+
*/
|
4150
|
+
template<typename _Tp> class CV_EXPORTS SeqIterator : public CvSeqReader
|
4151
|
+
{
|
4152
|
+
public:
|
4153
|
+
//! the default constructor
|
4154
|
+
SeqIterator();
|
4155
|
+
//! the constructor setting the iterator to the beginning or to the end of the sequence
|
4156
|
+
SeqIterator(const Seq<_Tp>& seq, bool seekEnd=false);
|
4157
|
+
//! positions the iterator within the sequence
|
4158
|
+
void seek(size_t pos);
|
4159
|
+
//! reports the current iterator position
|
4160
|
+
size_t tell() const;
|
4161
|
+
//! returns reference to the current sequence element
|
4162
|
+
_Tp& operator *();
|
4163
|
+
//! returns read-only reference to the current sequence element
|
4164
|
+
const _Tp& operator *() const;
|
4165
|
+
//! moves iterator to the next sequence element
|
4166
|
+
SeqIterator& operator ++();
|
4167
|
+
//! moves iterator to the next sequence element
|
4168
|
+
SeqIterator operator ++(int) const;
|
4169
|
+
//! moves iterator to the previous sequence element
|
4170
|
+
SeqIterator& operator --();
|
4171
|
+
//! moves iterator to the previous sequence element
|
4172
|
+
SeqIterator operator --(int) const;
|
4173
|
+
|
4174
|
+
//! moves iterator forward by the specified offset (possibly negative)
|
4175
|
+
SeqIterator& operator +=(int);
|
4176
|
+
//! moves iterator backward by the specified offset (possibly negative)
|
4177
|
+
SeqIterator& operator -=(int);
|
4178
|
+
|
4179
|
+
// this is index of the current element module seq->total*2
|
4180
|
+
// (to distinguish between 0 and seq->total)
|
4181
|
+
int index;
|
4182
|
+
};
|
4183
|
+
|
4184
|
+
|
4185
|
+
#if 0
|
4186
|
+
class CV_EXPORTS AlgorithmImpl;
|
4187
|
+
|
4188
|
+
/*!
|
4189
|
+
Base class for high-level OpenCV algorithms
|
4190
|
+
*/
|
4191
|
+
class CV_EXPORTS Algorithm
|
4192
|
+
{
|
4193
|
+
public:
|
4194
|
+
virtual ~Algorithm();
|
4195
|
+
virtual string name() const;
|
4196
|
+
|
4197
|
+
template<typename _Tp> _Tp get(int paramId) const;
|
4198
|
+
template<typename _Tp> bool set(int paramId, const _Tp& value);
|
4199
|
+
string paramName(int paramId) const;
|
4200
|
+
string paramHelp(int paramId) const;
|
4201
|
+
int paramType(int paramId) const;
|
4202
|
+
int findParam(const string& name) const;
|
4203
|
+
template<typename _Tp> _Tp paramDefaultValue(int paramId) const;
|
4204
|
+
template<typename _Tp> bool paramRange(int paramId, _Tp& minVal, _Tp& maxVal) const;
|
4205
|
+
|
4206
|
+
virtual void getParams(vector<int>& ids) const;
|
4207
|
+
virtual void write(vector<uchar>& buf) const;
|
4208
|
+
virtual bool read(const vector<uchar>& buf);
|
4209
|
+
|
4210
|
+
typedef Algorithm* (*Constructor)(void);
|
4211
|
+
static void add(const string& name, Constructor create);
|
4212
|
+
static void getList(vector<string>& algorithms);
|
4213
|
+
static Ptr<Algorithm> create(const string& name);
|
4214
|
+
|
4215
|
+
protected:
|
4216
|
+
template<typename _Tp> void addParam(int propId, _Tp& value, bool readOnly, const string& name,
|
4217
|
+
const string& help=string(), const _Tp& defaultValue=_Tp(),
|
4218
|
+
_Tp (Algorithm::*getter)()=0, bool (Algorithm::*setter)(const _Tp&)=0);
|
4219
|
+
template<typename _Tp> void setParamRange(int propId, const _Tp& minVal, const _Tp& maxVal);
|
4220
|
+
|
4221
|
+
bool set_(int paramId, int argType, const void* value);
|
4222
|
+
void get_(int paramId, int argType, void* value);
|
4223
|
+
void paramDefaultValue_(int paramId, int argType, void* value);
|
4224
|
+
void paramRange_(int paramId, int argType, void* minval, void* maxval);
|
4225
|
+
void addParam_(int propId, int argType, void* value, bool readOnly, const string& name,
|
4226
|
+
const string& help, const void* defaultValue, void* getter, void* setter);
|
4227
|
+
void setParamRange_(int propId, int argType, const void* minVal, const void* maxVal);
|
4228
|
+
|
4229
|
+
Ptr<AlgorithmImpl> impl;
|
4230
|
+
};
|
4231
|
+
#endif
|
4232
|
+
|
4233
|
+
/*!
|
4234
|
+
"\nThe CommandLineParser class is designed for command line arguments parsing\n"
|
4235
|
+
"Keys map: \n"
|
4236
|
+
"Before you start to work with CommandLineParser you have to create a map for keys.\n"
|
4237
|
+
" It will look like this\n"
|
4238
|
+
" const char* keys =\n"
|
4239
|
+
" {\n"
|
4240
|
+
" { s| string| 123asd |string parameter}\n"
|
4241
|
+
" { d| digit | 100 |digit parameter }\n"
|
4242
|
+
" { c|noCamera|false |without camera }\n"
|
4243
|
+
" { 1| |some text|help }\n"
|
4244
|
+
" { 2| |333 |another help }\n"
|
4245
|
+
" };\n"
|
4246
|
+
"Usage syntax: \n"
|
4247
|
+
" \"{\" - start of parameter string.\n"
|
4248
|
+
" \"}\" - end of parameter string\n"
|
4249
|
+
" \"|\" - separator between short name, full name, default value and help\n"
|
4250
|
+
"Supported syntax: \n"
|
4251
|
+
" --key1=arg1 <If a key with '--' must has an argument\n"
|
4252
|
+
" you have to assign it through '=' sign.> \n"
|
4253
|
+
"<If the key with '--' doesn't have any argument, it means that it is a bool key>\n"
|
4254
|
+
" -key2=arg2 <If a key with '-' must has an argument \n"
|
4255
|
+
" you have to assign it through '=' sign.> \n"
|
4256
|
+
"If the key with '-' doesn't have any argument, it means that it is a bool key\n"
|
4257
|
+
" key3 <This key can't has any parameter> \n"
|
4258
|
+
"Usage: \n"
|
4259
|
+
" Imagine that the input parameters are next:\n"
|
4260
|
+
" -s=string_value --digit=250 --noCamera lena.jpg 10000\n"
|
4261
|
+
" CommandLineParser parser(argc, argv, keys) - create a parser object\n"
|
4262
|
+
" parser.get<string>(\"s\" or \"string\") will return you first parameter value\n"
|
4263
|
+
" parser.get<string>(\"s\", false or \"string\", false) will return you first parameter value\n"
|
4264
|
+
" without spaces in end and begin\n"
|
4265
|
+
" parser.get<int>(\"d\" or \"digit\") will return you second parameter value.\n"
|
4266
|
+
" It also works with 'unsigned int', 'double', and 'float' types>\n"
|
4267
|
+
" parser.get<bool>(\"c\" or \"noCamera\") will return you true .\n"
|
4268
|
+
" If you enter this key in commandline>\n"
|
4269
|
+
" It return you false otherwise.\n"
|
4270
|
+
" parser.get<string>(\"1\") will return you the first argument without parameter (lena.jpg) \n"
|
4271
|
+
" parser.get<int>(\"2\") will return you the second argument without parameter (10000)\n"
|
4272
|
+
" It also works with 'unsigned int', 'double', and 'float' types \n"
|
4273
|
+
*/
|
4274
|
+
class CV_EXPORTS CommandLineParser
|
4275
|
+
{
|
4276
|
+
public:
|
4277
|
+
|
4278
|
+
//! the default constructor
|
4279
|
+
CommandLineParser(int argc, const char* argv[], const char* key_map);
|
4280
|
+
|
4281
|
+
//! get parameter, you can choose: delete spaces in end and begin or not
|
4282
|
+
template<typename _Tp>
|
4283
|
+
_Tp get(const std::string& name, bool space_delete=true)
|
4284
|
+
{
|
4285
|
+
if (!has(name))
|
4286
|
+
{
|
4287
|
+
return _Tp();
|
4288
|
+
}
|
4289
|
+
std::string str = getString(name);
|
4290
|
+
return analizeValue<_Tp>(str, space_delete);
|
4291
|
+
}
|
4292
|
+
|
4293
|
+
//! print short name, full name, current value and help for all params
|
4294
|
+
void printParams();
|
4295
|
+
|
4296
|
+
protected:
|
4297
|
+
std::map<std::string, std::vector<std::string> > data;
|
4298
|
+
std::string getString(const std::string& name);
|
4299
|
+
|
4300
|
+
bool has(const std::string& keys);
|
4301
|
+
|
4302
|
+
template<typename _Tp>
|
4303
|
+
_Tp analizeValue(const std::string& str, bool space_delete=false);
|
4304
|
+
|
4305
|
+
template<typename _Tp>
|
4306
|
+
static _Tp getData(const std::string& str)
|
4307
|
+
{
|
4308
|
+
_Tp res;
|
4309
|
+
std::stringstream s1(str);
|
4310
|
+
s1 >> res;
|
4311
|
+
return res;
|
4312
|
+
}
|
4313
|
+
|
4314
|
+
template<typename _Tp>
|
4315
|
+
_Tp fromStringNumber(const std::string& str);//the default conversion function for numbers
|
4316
|
+
|
4317
|
+
};
|
4318
|
+
|
4319
|
+
template<> CV_EXPORTS
|
4320
|
+
bool CommandLineParser::get<bool>(const std::string& name, bool space_delete);
|
4321
|
+
|
4322
|
+
template<> CV_EXPORTS
|
4323
|
+
std::string CommandLineParser::analizeValue<std::string>(const std::string& str, bool space_delete);
|
4324
|
+
|
4325
|
+
template<> CV_EXPORTS
|
4326
|
+
int CommandLineParser::analizeValue<int>(const std::string& str, bool space_delete);
|
4327
|
+
|
4328
|
+
template<> CV_EXPORTS
|
4329
|
+
unsigned CommandLineParser::analizeValue<unsigned int>(const std::string& str, bool space_delete);
|
4330
|
+
|
4331
|
+
template<> CV_EXPORTS
|
4332
|
+
float CommandLineParser::analizeValue<float>(const std::string& str, bool space_delete);
|
4333
|
+
|
4334
|
+
template<> CV_EXPORTS
|
4335
|
+
double CommandLineParser::analizeValue<double>(const std::string& str, bool space_delete);
|
4336
|
+
|
4337
|
+
}
|
4338
|
+
|
4339
|
+
#endif // __cplusplus
|
4340
|
+
|
4341
|
+
#include "opencv2/core/operations.hpp"
|
4342
|
+
#include "opencv2/core/mat.hpp"
|
4343
|
+
|
4344
|
+
#endif /*__OPENCV_CORE_HPP__*/
|