1
/*M///////////////////////////////////////////////////////////////////////////////////////
3
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
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.
11
// For Open Source Computer Vision Library
13
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
16
// Third party copyrights are property of their respective owners.
18
// Redistribution and use in source and binary forms, with or without modification,
19
// are permitted provided that the following conditions are met:
21
// * Redistribution's of source code must retain the above copyright notice,
22
// this list of conditions and the following disclaimer.
24
// * Redistribution's in binary form must reproduce the above copyright notice,
25
// this list of conditions and the following disclaimer in the documentation
26
// and/or other materials provided with the distribution.
28
// * The name of the copyright holders may not be used to endorse or promote products
29
// derived from this software without specific prior written permission.
31
// This software is provided by the copyright holders and contributors "as is" and
32
// any express or implied warranties, including, but not limited to, the implied
33
// warranties of merchantability and fitness for a particular purpose are disclaimed.
34
// In no event shall the Intel Corporation or contributors be liable for any direct,
35
// indirect, incidental, special, exemplary, or consequential damages
36
// (including, but not limited to, procurement of substitute goods or services;
37
// loss of use, data, or profits; or business interruption) however caused
38
// and on any theory of liability, whether in contract, strict liability,
39
// or tort (including negligence or otherwise) arising in any way out of
40
// the use of this software, even if advised of the possibility of such damage.
44
#ifndef __OPENCV_CORE_TYPES_HPP__
45
#define __OPENCV_CORE_TYPES_HPP__
48
# error types.hpp header must be compiled as C++
55
#include "opencv2/core/cvdef.h"
56
#include "opencv2/core/cvstd.hpp"
57
#include "opencv2/core/matx.hpp"
62
//! @addtogroup core_basic
65
//////////////////////////////// Complex //////////////////////////////
67
/** @brief A complex number class.
69
The template class is similar and compatible with std::complex, however it provides slightly
70
more convenient access to the real and imaginary parts using through the simple field access, as opposite
71
to std::complex::real() and std::complex::imag().
73
template<typename _Tp> class Complex
79
Complex( _Tp _re, _Tp _im = 0 );
81
//! conversion to another data type
82
template<typename T2> operator Complex<T2>() const;
86
_Tp re, im; //< the real and the imaginary parts
89
typedef Complex<float> Complexf;
90
typedef Complex<double> Complexd;
92
template<typename _Tp> class DataType< Complex<_Tp> >
95
typedef Complex<_Tp> value_type;
96
typedef value_type work_type;
97
typedef _Tp channel_type;
99
enum { generic_type = 0,
100
depth = DataType<channel_type>::depth,
102
fmt = DataType<channel_type>::fmt + ((channels - 1) << 8),
103
type = CV_MAKETYPE(depth, channels) };
105
typedef Vec<channel_type, channels> vec_type;
110
//////////////////////////////// Point_ ////////////////////////////////
112
/** @brief Template class for 2D points specified by its coordinates `x` and `y`.
114
An instance of the class is interchangeable with C structures, CvPoint and CvPoint2D32f . There is
115
also a cast operator to convert point coordinates to the specified type. The conversion from
116
floating-point coordinates to integer coordinates is done by rounding. Commonly, the conversion
117
uses this operation for each of the coordinates. Besides the class members listed in the
118
declaration above, the following operations on points are implemented:
129
double value = norm(pt); // L2 norm
133
For your convenience, the following type aliases are defined:
135
typedef Point_<int> Point2i;
136
typedef Point2i Point;
137
typedef Point_<float> Point2f;
138
typedef Point_<double> Point2d;
142
Point2f a(0.3f, 0.f), b(0.f, 0.4f);
143
Point pt = (a + b)*10.f;
144
cout << pt.x << ", " << pt.y << endl;
147
template<typename _Tp> class Point_
150
typedef _Tp value_type;
152
// various constructors
154
Point_(_Tp _x, _Tp _y);
155
Point_(const Point_& pt);
156
Point_(const Size_<_Tp>& sz);
157
Point_(const Vec<_Tp, 2>& v);
159
Point_& operator = (const Point_& pt);
160
//! conversion to another data type
161
template<typename _Tp2> operator Point_<_Tp2>() const;
163
//! conversion to the old-style C structures
164
operator Vec<_Tp, 2>() const;
167
_Tp dot(const Point_& pt) const;
168
//! dot product computed in double-precision arithmetics
169
double ddot(const Point_& pt) const;
171
double cross(const Point_& pt) const;
172
//! checks whether the point is inside the specified rectangle
173
bool inside(const Rect_<_Tp>& r) const;
175
_Tp x, y; //< the point coordinates
178
typedef Point_<int> Point2i;
179
typedef Point_<float> Point2f;
180
typedef Point_<double> Point2d;
181
typedef Point2i Point;
183
template<typename _Tp> class DataType< Point_<_Tp> >
186
typedef Point_<_Tp> value_type;
187
typedef Point_<typename DataType<_Tp>::work_type> work_type;
188
typedef _Tp channel_type;
190
enum { generic_type = 0,
191
depth = DataType<channel_type>::depth,
193
fmt = DataType<channel_type>::fmt + ((channels - 1) << 8),
194
type = CV_MAKETYPE(depth, channels)
197
typedef Vec<channel_type, channels> vec_type;
202
//////////////////////////////// Point3_ ////////////////////////////////
204
/** @brief Template class for 3D points specified by its coordinates `x`, `y` and `z`.
206
An instance of the class is interchangeable with the C structure CvPoint2D32f . Similarly to
207
Point_ , the coordinates of 3D points can be converted to another type. The vector arithmetic and
208
comparison operations are also supported.
210
The following Point3_\<\> aliases are available:
212
typedef Point3_<int> Point3i;
213
typedef Point3_<float> Point3f;
214
typedef Point3_<double> Point3d;
216
@see cv::Point3i, cv::Point3f and cv::Point3d
218
template<typename _Tp> class Point3_
221
typedef _Tp value_type;
223
// various constructors
225
Point3_(_Tp _x, _Tp _y, _Tp _z);
226
Point3_(const Point3_& pt);
227
explicit Point3_(const Point_<_Tp>& pt);
228
Point3_(const Vec<_Tp, 3>& v);
230
Point3_& operator = (const Point3_& pt);
231
//! conversion to another data type
232
template<typename _Tp2> operator Point3_<_Tp2>() const;
233
//! conversion to cv::Vec<>
234
operator Vec<_Tp, 3>() const;
237
_Tp dot(const Point3_& pt) const;
238
//! dot product computed in double-precision arithmetics
239
double ddot(const Point3_& pt) const;
240
//! cross product of the 2 3D points
241
Point3_ cross(const Point3_& pt) const;
243
_Tp x, y, z; //< the point coordinates
246
typedef Point3_<int> Point3i;
247
typedef Point3_<float> Point3f;
248
typedef Point3_<double> Point3d;
250
template<typename _Tp> class DataType< Point3_<_Tp> >
253
typedef Point3_<_Tp> value_type;
254
typedef Point3_<typename DataType<_Tp>::work_type> work_type;
255
typedef _Tp channel_type;
257
enum { generic_type = 0,
258
depth = DataType<channel_type>::depth,
260
fmt = DataType<channel_type>::fmt + ((channels - 1) << 8),
261
type = CV_MAKETYPE(depth, channels)
264
typedef Vec<channel_type, channels> vec_type;
269
//////////////////////////////// Size_ ////////////////////////////////
271
/** @brief Template class for specifying the size of an image or rectangle.
273
The class includes two members called width and height. The structure can be converted to and from
274
the old OpenCV structures CvSize and CvSize2D32f . The same set of arithmetic and comparison
275
operations as for Point_ is available.
277
OpenCV defines the following Size_\<\> aliases:
279
typedef Size_<int> Size2i;
281
typedef Size_<float> Size2f;
284
template<typename _Tp> class Size_
287
typedef _Tp value_type;
289
//! various constructors
291
Size_(_Tp _width, _Tp _height);
292
Size_(const Size_& sz);
293
Size_(const Point_<_Tp>& pt);
295
Size_& operator = (const Size_& sz);
296
//! the area (width*height)
299
//! conversion of another data type.
300
template<typename _Tp2> operator Size_<_Tp2>() const;
302
_Tp width, height; // the width and the height
305
typedef Size_<int> Size2i;
306
typedef Size_<float> Size2f;
307
typedef Size_<double> Size2d;
310
template<typename _Tp> class DataType< Size_<_Tp> >
313
typedef Size_<_Tp> value_type;
314
typedef Size_<typename DataType<_Tp>::work_type> work_type;
315
typedef _Tp channel_type;
317
enum { generic_type = 0,
318
depth = DataType<channel_type>::depth,
320
fmt = DataType<channel_type>::fmt + ((channels - 1) << 8),
321
type = CV_MAKETYPE(depth, channels)
324
typedef Vec<channel_type, channels> vec_type;
329
//////////////////////////////// Rect_ ////////////////////////////////
331
/** @brief Template class for 2D rectangles
333
described by the following parameters:
334
- Coordinates of the top-left corner. This is a default interpretation of Rect_::x and Rect_::y
335
in OpenCV. Though, in your algorithms you may count x and y from the bottom-left corner.
336
- Rectangle width and height.
338
OpenCV typically assumes that the top and left boundary of the rectangle are inclusive, while the
339
right and bottom boundaries are not. For example, the method Rect_::contains returns true if
341
\f[x \leq pt.x < x+width,
342
y \leq pt.y < y+height\f]
344
Virtually every loop over an image ROI in OpenCV (where ROI is specified by Rect_\<int\> ) is
347
for(int y = roi.y; y < roi.y + roi.height; y++)
348
for(int x = roi.x; x < roi.x + roi.width; x++)
353
In addition to the class members, the following operations on rectangles are implemented:
354
- \f$\texttt{rect} = \texttt{rect} \pm \texttt{point}\f$ (shifting a rectangle by a certain offset)
355
- \f$\texttt{rect} = \texttt{rect} \pm \texttt{size}\f$ (expanding or shrinking a rectangle by a
357
- rect += point, rect -= point, rect += size, rect -= size (augmenting operations)
358
- rect = rect1 & rect2 (rectangle intersection)
359
- rect = rect1 | rect2 (minimum area rectangle containing rect1 and rect2 )
360
- rect &= rect1, rect |= rect1 (and the corresponding augmenting operations)
361
- rect == rect1, rect != rect1 (rectangle comparison)
363
This is an example how the partial ordering on rectangles can be established (rect1 \f$\subseteq\f$
366
template<typename _Tp> inline bool
367
operator <= (const Rect_<_Tp>& r1, const Rect_<_Tp>& r2)
369
return (r1 & r2) == r1;
372
For your convenience, the Rect_\<\> alias is available: cv::Rect
374
template<typename _Tp> class Rect_
377
typedef _Tp value_type;
379
//! various constructors
381
Rect_(_Tp _x, _Tp _y, _Tp _width, _Tp _height);
382
Rect_(const Rect_& r);
383
Rect_(const Point_<_Tp>& org, const Size_<_Tp>& sz);
384
Rect_(const Point_<_Tp>& pt1, const Point_<_Tp>& pt2);
386
Rect_& operator = ( const Rect_& r );
387
//! the top-left corner
388
Point_<_Tp> tl() const;
389
//! the bottom-right corner
390
Point_<_Tp> br() const;
392
//! size (width, height) of the rectangle
393
Size_<_Tp> size() const;
394
//! area (width*height) of the rectangle
397
//! conversion to another data type
398
template<typename _Tp2> operator Rect_<_Tp2>() const;
400
//! checks whether the rectangle contains the point
401
bool contains(const Point_<_Tp>& pt) const;
403
_Tp x, y, width, height; //< the top-left corner, as well as width and height of the rectangle
406
typedef Rect_<int> Rect2i;
407
typedef Rect_<float> Rect2f;
408
typedef Rect_<double> Rect2d;
411
template<typename _Tp> class DataType< Rect_<_Tp> >
414
typedef Rect_<_Tp> value_type;
415
typedef Rect_<typename DataType<_Tp>::work_type> work_type;
416
typedef _Tp channel_type;
418
enum { generic_type = 0,
419
depth = DataType<channel_type>::depth,
421
fmt = DataType<channel_type>::fmt + ((channels - 1) << 8),
422
type = CV_MAKETYPE(depth, channels)
425
typedef Vec<channel_type, channels> vec_type;
430
///////////////////////////// RotatedRect /////////////////////////////
432
/** @brief The class represents rotated (i.e. not up-right) rectangles on a plane.
434
Each rectangle is specified by the center point (mass center), length of each side (represented by
435
cv::Size2f structure) and the rotation angle in degrees.
437
The sample below demonstrates how to use RotatedRect:
439
Mat image(200, 200, CV_8UC3, Scalar(0));
440
RotatedRect rRect = RotatedRect(Point2f(100,100), Size2f(100,50), 30);
443
rRect.points(vertices);
444
for (int i = 0; i < 4; i++)
445
line(image, vertices[i], vertices[(i+1)%4], Scalar(0,255,0));
447
Rect brect = rRect.boundingRect();
448
rectangle(image, brect, Scalar(255,0,0));
450
imshow("rectangles", image);
453
![image](pics/rotatedrect.png)
455
@sa CamShift, fitEllipse, minAreaRect, CvBox2D
457
class CV_EXPORTS RotatedRect
460
//! various constructors
463
@param center The rectangle mass center.
464
@param size Width and height of the rectangle.
465
@param angle The rotation angle in a clockwise direction. When the angle is 0, 90, 180, 270 etc.,
466
the rectangle becomes an up-right rectangle.
468
RotatedRect(const Point2f& center, const Size2f& size, float angle);
470
Any 3 end points of the RotatedRect. They must be given in order (either clockwise or
473
RotatedRect(const Point2f& point1, const Point2f& point2, const Point2f& point3);
475
/** returns 4 vertices of the rectangle
476
@param pts The points array for storing rectangle vertices.
478
void points(Point2f pts[]) const;
479
//! returns the minimal up-right rectangle containing the rotated rectangle
480
Rect boundingRect() const;
482
Point2f center; //< the rectangle mass center
483
Size2f size; //< width and height of the rectangle
484
float angle; //< the rotation angle. When the angle is 0, 90, 180, 270 etc., the rectangle becomes an up-right rectangle.
487
template<> class DataType< RotatedRect >
490
typedef RotatedRect value_type;
491
typedef value_type work_type;
492
typedef float channel_type;
494
enum { generic_type = 0,
495
depth = DataType<channel_type>::depth,
496
channels = (int)sizeof(value_type)/sizeof(channel_type), // 5
497
fmt = DataType<channel_type>::fmt + ((channels - 1) << 8),
498
type = CV_MAKETYPE(depth, channels)
501
typedef Vec<channel_type, channels> vec_type;
506
//////////////////////////////// Range /////////////////////////////////
508
/** @brief Template class specifying a continuous subsequence (slice) of a sequence.
510
The class is used to specify a row or a column span in a matrix ( Mat ) and for many other purposes.
511
Range(a,b) is basically the same as a:b in Matlab or a..b in Python. As in Python, start is an
512
inclusive left boundary of the range and end is an exclusive right boundary of the range. Such a
513
half-opened interval is usually denoted as \f$[start,end)\f$ .
515
The static method Range::all() returns a special variable that means "the whole sequence" or "the
516
whole range", just like " : " in Matlab or " ... " in Python. All the methods and functions in
517
OpenCV that take Range support this special Range::all() value. But, of course, in case of your own
518
custom processing, you will probably have to check and handle it explicitly:
520
void my_function(..., const Range& r, ....)
522
if(r == Range::all()) {
523
// process all the data
526
// process [r.start, r.end)
531
class CV_EXPORTS Range
535
Range(int _start, int _end);
543
template<> class DataType<Range>
546
typedef Range value_type;
547
typedef value_type work_type;
548
typedef int channel_type;
550
enum { generic_type = 0,
551
depth = DataType<channel_type>::depth,
553
fmt = DataType<channel_type>::fmt + ((channels - 1) << 8),
554
type = CV_MAKETYPE(depth, channels)
557
typedef Vec<channel_type, channels> vec_type;
562
//////////////////////////////// Scalar_ ///////////////////////////////
564
/** @brief Template class for a 4-element vector derived from Vec.
566
Being derived from Vec\<_Tp, 4\> , Scalar_ and Scalar can be used just as typical 4-element
567
vectors. In addition, they can be converted to/from CvScalar . The type Scalar is widely used in
568
OpenCV to pass pixel values.
570
template<typename _Tp> class Scalar_ : public Vec<_Tp, 4>
573
//! various constructors
575
Scalar_(_Tp v0, _Tp v1, _Tp v2=0, _Tp v3=0);
578
template<typename _Tp2, int cn>
579
Scalar_(const Vec<_Tp2, cn>& v);
581
//! returns a scalar with all elements set to v0
582
static Scalar_<_Tp> all(_Tp v0);
584
//! conversion to another data type
585
template<typename T2> operator Scalar_<T2>() const;
587
//! per-element product
588
Scalar_<_Tp> mul(const Scalar_<_Tp>& a, double scale=1 ) const;
590
// returns (v0, -v1, -v2, -v3)
591
Scalar_<_Tp> conj() const;
593
// returns true iff v1 == v2 == v3 == 0
597
typedef Scalar_<double> Scalar;
599
template<typename _Tp> class DataType< Scalar_<_Tp> >
602
typedef Scalar_<_Tp> value_type;
603
typedef Scalar_<typename DataType<_Tp>::work_type> work_type;
604
typedef _Tp channel_type;
606
enum { generic_type = 0,
607
depth = DataType<channel_type>::depth,
609
fmt = DataType<channel_type>::fmt + ((channels - 1) << 8),
610
type = CV_MAKETYPE(depth, channels)
613
typedef Vec<channel_type, channels> vec_type;
618
/////////////////////////////// KeyPoint ////////////////////////////////
620
/** @brief Data structure for salient point detectors.
622
The class instance stores a keypoint, i.e. a point feature found by one of many available keypoint
623
detectors, such as Harris corner detector, cv::FAST, cv::StarDetector, cv::SURF, cv::SIFT,
626
The keypoint is characterized by the 2D position, scale (proportional to the diameter of the
627
neighborhood that needs to be taken into account), orientation and some other parameters. The
628
keypoint neighborhood is then analyzed by another algorithm that builds a descriptor (usually
629
represented as a feature vector). The keypoints representing the same object in different images
630
can then be matched using cv::KDTree or another method.
632
class CV_EXPORTS_W_SIMPLE KeyPoint
635
//! the default constructor
638
@param _pt x & y coordinates of the keypoint
639
@param _size keypoint diameter
640
@param _angle keypoint orientation
641
@param _response keypoint detector response on the keypoint (that is, strength of the keypoint)
642
@param _octave pyramid octave in which the keypoint has been detected
643
@param _class_id object id
645
KeyPoint(Point2f _pt, float _size, float _angle=-1, float _response=0, int _octave=0, int _class_id=-1);
647
@param x x-coordinate of the keypoint
648
@param y y-coordinate of the keypoint
649
@param _size keypoint diameter
650
@param _angle keypoint orientation
651
@param _response keypoint detector response on the keypoint (that is, strength of the keypoint)
652
@param _octave pyramid octave in which the keypoint has been detected
653
@param _class_id object id
655
CV_WRAP KeyPoint(float x, float y, float _size, float _angle=-1, float _response=0, int _octave=0, int _class_id=-1);
660
This method converts vector of keypoints to vector of points or the reverse, where each keypoint is
661
assigned the same size and the same orientation.
663
@param keypoints Keypoints obtained from any feature detection algorithm like SIFT/SURF/ORB
664
@param points2f Array of (x,y) coordinates of each keypoint
665
@param keypointIndexes Array of indexes of keypoints to be converted to points. (Acts like a mask to
666
convert only specified keypoints)
668
CV_WRAP static void convert(const std::vector<KeyPoint>& keypoints,
669
CV_OUT std::vector<Point2f>& points2f,
670
const std::vector<int>& keypointIndexes=std::vector<int>());
672
@param points2f Array of (x,y) coordinates of each keypoint
673
@param keypoints Keypoints obtained from any feature detection algorithm like SIFT/SURF/ORB
674
@param size keypoint diameter
675
@param response keypoint detector response on the keypoint (that is, strength of the keypoint)
676
@param octave pyramid octave in which the keypoint has been detected
677
@param class_id object id
679
CV_WRAP static void convert(const std::vector<Point2f>& points2f,
680
CV_OUT std::vector<KeyPoint>& keypoints,
681
float size=1, float response=1, int octave=0, int class_id=-1);
684
This method computes overlap for pair of keypoints. Overlap is the ratio between area of keypoint
685
regions' intersection and area of keypoint regions' union (considering keypoint region as circle).
686
If they don't overlap, we get zero. If they coincide at same location with same size, we get 1.
687
@param kp1 First keypoint
688
@param kp2 Second keypoint
690
CV_WRAP static float overlap(const KeyPoint& kp1, const KeyPoint& kp2);
692
CV_PROP_RW Point2f pt; //!< coordinates of the keypoints
693
CV_PROP_RW float size; //!< diameter of the meaningful keypoint neighborhood
694
CV_PROP_RW float angle; //!< computed orientation of the keypoint (-1 if not applicable);
695
//!< it's in [0,360) degrees and measured relative to
696
//!< image coordinate system, ie in clockwise.
697
CV_PROP_RW float response; //!< the response by which the most strong keypoints have been selected. Can be used for the further sorting or subsampling
698
CV_PROP_RW int octave; //!< octave (pyramid layer) from which the keypoint has been extracted
699
CV_PROP_RW int class_id; //!< object class (if the keypoints need to be clustered by an object they belong to)
702
template<> class DataType<KeyPoint>
705
typedef KeyPoint value_type;
706
typedef float work_type;
707
typedef float channel_type;
709
enum { generic_type = 0,
710
depth = DataType<channel_type>::depth,
711
channels = (int)(sizeof(value_type)/sizeof(channel_type)), // 7
712
fmt = DataType<channel_type>::fmt + ((channels - 1) << 8),
713
type = CV_MAKETYPE(depth, channels)
716
typedef Vec<channel_type, channels> vec_type;
721
//////////////////////////////// DMatch /////////////////////////////////
723
/** @brief Class for matching keypoint descriptors
725
query descriptor index, train descriptor index, train image index, and distance between
728
class CV_EXPORTS_W_SIMPLE DMatch
732
CV_WRAP DMatch(int _queryIdx, int _trainIdx, float _distance);
733
CV_WRAP DMatch(int _queryIdx, int _trainIdx, int _imgIdx, float _distance);
735
CV_PROP_RW int queryIdx; // query descriptor index
736
CV_PROP_RW int trainIdx; // train descriptor index
737
CV_PROP_RW int imgIdx; // train image index
739
CV_PROP_RW float distance;
742
bool operator<(const DMatch &m) const;
745
template<> class DataType<DMatch>
748
typedef DMatch value_type;
749
typedef int work_type;
750
typedef int channel_type;
752
enum { generic_type = 0,
753
depth = DataType<channel_type>::depth,
754
channels = (int)(sizeof(value_type)/sizeof(channel_type)), // 4
755
fmt = DataType<channel_type>::fmt + ((channels - 1) << 8),
756
type = CV_MAKETYPE(depth, channels)
759
typedef Vec<channel_type, channels> vec_type;
764
///////////////////////////// TermCriteria //////////////////////////////
766
/** @brief The class defining termination criteria for iterative algorithms.
768
You can initialize it by default constructor and then override any parameters, or the structure may
769
be fully initialized using the advanced variant of the constructor.
771
class CV_EXPORTS TermCriteria
775
Criteria type, can be one of: COUNT, EPS or COUNT + EPS
779
COUNT=1, //!< the maximum number of iterations or elements to compute
780
MAX_ITER=COUNT, //!< ditto
781
EPS=2 //!< the desired accuracy or change in parameters at which the iterative algorithm stops
784
//! default constructor
787
@param type The type of termination criteria, one of TermCriteria::Type
788
@param maxCount The maximum number of iterations or elements to compute.
789
@param epsilon The desired accuracy or change in parameters at which the iterative algorithm stops.
791
TermCriteria(int type, int maxCount, double epsilon);
793
int type; //!< the type of termination criteria: COUNT, EPS or COUNT + EPS
794
int maxCount; // the maximum number of iterations/elements
795
double epsilon; // the desired accuracy
801
///////////////////////// raster image moments //////////////////////////
803
//! @addtogroup imgproc_shape
806
/** @brief struct returned by cv::moments
808
The spatial moments \f$\texttt{Moments::m}_{ji}\f$ are computed as:
810
\f[\texttt{m} _{ji}= \sum _{x,y} \left ( \texttt{array} (x,y) \cdot x^j \cdot y^i \right )\f]
812
The central moments \f$\texttt{Moments::mu}_{ji}\f$ are computed as:
814
\f[\texttt{mu} _{ji}= \sum _{x,y} \left ( \texttt{array} (x,y) \cdot (x - \bar{x} )^j \cdot (y - \bar{y} )^i \right )\f]
816
where \f$(\bar{x}, \bar{y})\f$ is the mass center:
818
\f[\bar{x} = \frac{\texttt{m}_{10}}{\texttt{m}_{00}} , \; \bar{y} = \frac{\texttt{m}_{01}}{\texttt{m}_{00}}\f]
820
The normalized central moments \f$\texttt{Moments::nu}_{ij}\f$ are computed as:
822
\f[\texttt{nu} _{ji}= \frac{\texttt{mu}_{ji}}{\texttt{m}_{00}^{(i+j)/2+1}} .\f]
825
\f$\texttt{mu}_{00}=\texttt{m}_{00}\f$, \f$\texttt{nu}_{00}=1\f$
826
\f$\texttt{nu}_{10}=\texttt{mu}_{10}=\texttt{mu}_{01}=\texttt{mu}_{10}=0\f$ , hence the values are not
829
The moments of a contour are defined in the same way but computed using the Green's formula (see
830
<http://en.wikipedia.org/wiki/Green_theorem>). So, due to a limited raster resolution, the moments
831
computed for a contour are slightly different from the moments computed for the same rasterized
835
Since the contour moments are computed using Green formula, you may get seemingly odd results for
836
contours with self-intersections, e.g. a zero area (m00) for butterfly-shaped contours.
838
class CV_EXPORTS_W_MAP Moments
841
//! the default constructor
843
//! the full constructor
844
Moments(double m00, double m10, double m01, double m20, double m11,
845
double m02, double m30, double m21, double m12, double m03 );
846
////! the conversion from CvMoments
847
//Moments( const CvMoments& moments );
848
////! the conversion to CvMoments
849
//operator CvMoments() const;
851
//! @name spatial moments
853
CV_PROP_RW double m00, m10, m01, m20, m11, m02, m30, m21, m12, m03;
856
//! @name central moments
858
CV_PROP_RW double mu20, mu11, mu02, mu30, mu21, mu12, mu03;
861
//! @name central normalized moments
863
CV_PROP_RW double nu20, nu11, nu02, nu30, nu21, nu12, nu03;
867
template<> class DataType<Moments>
870
typedef Moments value_type;
871
typedef double work_type;
872
typedef double channel_type;
874
enum { generic_type = 0,
875
depth = DataType<channel_type>::depth,
876
channels = (int)(sizeof(value_type)/sizeof(channel_type)), // 24
877
fmt = DataType<channel_type>::fmt + ((channels - 1) << 8),
878
type = CV_MAKETYPE(depth, channels)
881
typedef Vec<channel_type, channels> vec_type;
888
/////////////////////////////////////////////////////////////////////////
889
///////////////////////////// Implementation ////////////////////////////
890
/////////////////////////////////////////////////////////////////////////
892
//////////////////////////////// Complex ////////////////////////////////
894
template<typename _Tp> inline
895
Complex<_Tp>::Complex()
898
template<typename _Tp> inline
899
Complex<_Tp>::Complex( _Tp _re, _Tp _im )
900
: re(_re), im(_im) {}
902
template<typename _Tp> template<typename T2> inline
903
Complex<_Tp>::operator Complex<T2>() const
905
return Complex<T2>(saturate_cast<T2>(re), saturate_cast<T2>(im));
908
template<typename _Tp> inline
909
Complex<_Tp> Complex<_Tp>::conj() const
911
return Complex<_Tp>(re, -im);
915
template<typename _Tp> static inline
916
bool operator == (const Complex<_Tp>& a, const Complex<_Tp>& b)
918
return a.re == b.re && a.im == b.im;
921
template<typename _Tp> static inline
922
bool operator != (const Complex<_Tp>& a, const Complex<_Tp>& b)
924
return a.re != b.re || a.im != b.im;
927
template<typename _Tp> static inline
928
Complex<_Tp> operator + (const Complex<_Tp>& a, const Complex<_Tp>& b)
930
return Complex<_Tp>( a.re + b.re, a.im + b.im );
933
template<typename _Tp> static inline
934
Complex<_Tp>& operator += (Complex<_Tp>& a, const Complex<_Tp>& b)
936
a.re += b.re; a.im += b.im;
940
template<typename _Tp> static inline
941
Complex<_Tp> operator - (const Complex<_Tp>& a, const Complex<_Tp>& b)
943
return Complex<_Tp>( a.re - b.re, a.im - b.im );
946
template<typename _Tp> static inline
947
Complex<_Tp>& operator -= (Complex<_Tp>& a, const Complex<_Tp>& b)
949
a.re -= b.re; a.im -= b.im;
953
template<typename _Tp> static inline
954
Complex<_Tp> operator - (const Complex<_Tp>& a)
956
return Complex<_Tp>(-a.re, -a.im);
959
template<typename _Tp> static inline
960
Complex<_Tp> operator * (const Complex<_Tp>& a, const Complex<_Tp>& b)
962
return Complex<_Tp>( a.re*b.re - a.im*b.im, a.re*b.im + a.im*b.re );
965
template<typename _Tp> static inline
966
Complex<_Tp> operator * (const Complex<_Tp>& a, _Tp b)
968
return Complex<_Tp>( a.re*b, a.im*b );
971
template<typename _Tp> static inline
972
Complex<_Tp> operator * (_Tp b, const Complex<_Tp>& a)
974
return Complex<_Tp>( a.re*b, a.im*b );
977
template<typename _Tp> static inline
978
Complex<_Tp> operator + (const Complex<_Tp>& a, _Tp b)
980
return Complex<_Tp>( a.re + b, a.im );
983
template<typename _Tp> static inline
984
Complex<_Tp> operator - (const Complex<_Tp>& a, _Tp b)
985
{ return Complex<_Tp>( a.re - b, a.im ); }
987
template<typename _Tp> static inline
988
Complex<_Tp> operator + (_Tp b, const Complex<_Tp>& a)
990
return Complex<_Tp>( a.re + b, a.im );
993
template<typename _Tp> static inline
994
Complex<_Tp> operator - (_Tp b, const Complex<_Tp>& a)
996
return Complex<_Tp>( b - a.re, -a.im );
999
template<typename _Tp> static inline
1000
Complex<_Tp>& operator += (Complex<_Tp>& a, _Tp b)
1002
a.re += b; return a;
1005
template<typename _Tp> static inline
1006
Complex<_Tp>& operator -= (Complex<_Tp>& a, _Tp b)
1008
a.re -= b; return a;
1011
template<typename _Tp> static inline
1012
Complex<_Tp>& operator *= (Complex<_Tp>& a, _Tp b)
1014
a.re *= b; a.im *= b; return a;
1017
template<typename _Tp> static inline
1018
double abs(const Complex<_Tp>& a)
1020
return std::sqrt( (double)a.re*a.re + (double)a.im*a.im);
1023
template<typename _Tp> static inline
1024
Complex<_Tp> operator / (const Complex<_Tp>& a, const Complex<_Tp>& b)
1026
double t = 1./((double)b.re*b.re + (double)b.im*b.im);
1027
return Complex<_Tp>( (_Tp)((a.re*b.re + a.im*b.im)*t),
1028
(_Tp)((-a.re*b.im + a.im*b.re)*t) );
1031
template<typename _Tp> static inline
1032
Complex<_Tp>& operator /= (Complex<_Tp>& a, const Complex<_Tp>& b)
1037
template<typename _Tp> static inline
1038
Complex<_Tp> operator / (const Complex<_Tp>& a, _Tp b)
1041
return Complex<_Tp>( a.re*t, a.im*t );
1044
template<typename _Tp> static inline
1045
Complex<_Tp> operator / (_Tp b, const Complex<_Tp>& a)
1047
return Complex<_Tp>(b)/a;
1050
template<typename _Tp> static inline
1051
Complex<_Tp> operator /= (const Complex<_Tp>& a, _Tp b)
1054
a.re *= t; a.im *= t; return a;
1059
//////////////////////////////// 2D Point ///////////////////////////////
1061
template<typename _Tp> inline
1062
Point_<_Tp>::Point_()
1065
template<typename _Tp> inline
1066
Point_<_Tp>::Point_(_Tp _x, _Tp _y)
1069
template<typename _Tp> inline
1070
Point_<_Tp>::Point_(const Point_& pt)
1071
: x(pt.x), y(pt.y) {}
1073
template<typename _Tp> inline
1074
Point_<_Tp>::Point_(const Size_<_Tp>& sz)
1075
: x(sz.width), y(sz.height) {}
1077
template<typename _Tp> inline
1078
Point_<_Tp>::Point_(const Vec<_Tp,2>& v)
1079
: x(v[0]), y(v[1]) {}
1081
template<typename _Tp> inline
1082
Point_<_Tp>& Point_<_Tp>::operator = (const Point_& pt)
1088
template<typename _Tp> template<typename _Tp2> inline
1089
Point_<_Tp>::operator Point_<_Tp2>() const
1091
return Point_<_Tp2>(saturate_cast<_Tp2>(x), saturate_cast<_Tp2>(y));
1094
template<typename _Tp> inline
1095
Point_<_Tp>::operator Vec<_Tp, 2>() const
1097
return Vec<_Tp, 2>(x, y);
1100
template<typename _Tp> inline
1101
_Tp Point_<_Tp>::dot(const Point_& pt) const
1103
return saturate_cast<_Tp>(x*pt.x + y*pt.y);
1106
template<typename _Tp> inline
1107
double Point_<_Tp>::ddot(const Point_& pt) const
1109
return (double)x*pt.x + (double)y*pt.y;
1112
template<typename _Tp> inline
1113
double Point_<_Tp>::cross(const Point_& pt) const
1115
return (double)x*pt.y - (double)y*pt.x;
1118
template<typename _Tp> inline bool
1119
Point_<_Tp>::inside( const Rect_<_Tp>& r ) const
1121
return r.contains(*this);
1125
template<typename _Tp> static inline
1126
Point_<_Tp>& operator += (Point_<_Tp>& a, const Point_<_Tp>& b)
1133
template<typename _Tp> static inline
1134
Point_<_Tp>& operator -= (Point_<_Tp>& a, const Point_<_Tp>& b)
1141
template<typename _Tp> static inline
1142
Point_<_Tp>& operator *= (Point_<_Tp>& a, int b)
1144
a.x = saturate_cast<_Tp>(a.x * b);
1145
a.y = saturate_cast<_Tp>(a.y * b);
1149
template<typename _Tp> static inline
1150
Point_<_Tp>& operator *= (Point_<_Tp>& a, float b)
1152
a.x = saturate_cast<_Tp>(a.x * b);
1153
a.y = saturate_cast<_Tp>(a.y * b);
1157
template<typename _Tp> static inline
1158
Point_<_Tp>& operator *= (Point_<_Tp>& a, double b)
1160
a.x = saturate_cast<_Tp>(a.x * b);
1161
a.y = saturate_cast<_Tp>(a.y * b);
1165
template<typename _Tp> static inline
1166
Point_<_Tp>& operator /= (Point_<_Tp>& a, int b)
1168
a.x = saturate_cast<_Tp>(a.x / b);
1169
a.y = saturate_cast<_Tp>(a.y / b);
1173
template<typename _Tp> static inline
1174
Point_<_Tp>& operator /= (Point_<_Tp>& a, float b)
1176
a.x = saturate_cast<_Tp>(a.x / b);
1177
a.y = saturate_cast<_Tp>(a.y / b);
1181
template<typename _Tp> static inline
1182
Point_<_Tp>& operator /= (Point_<_Tp>& a, double b)
1184
a.x = saturate_cast<_Tp>(a.x / b);
1185
a.y = saturate_cast<_Tp>(a.y / b);
1189
template<typename _Tp> static inline
1190
double norm(const Point_<_Tp>& pt)
1192
return std::sqrt((double)pt.x*pt.x + (double)pt.y*pt.y);
1195
template<typename _Tp> static inline
1196
bool operator == (const Point_<_Tp>& a, const Point_<_Tp>& b)
1198
return a.x == b.x && a.y == b.y;
1201
template<typename _Tp> static inline
1202
bool operator != (const Point_<_Tp>& a, const Point_<_Tp>& b)
1204
return a.x != b.x || a.y != b.y;
1207
template<typename _Tp> static inline
1208
Point_<_Tp> operator + (const Point_<_Tp>& a, const Point_<_Tp>& b)
1210
return Point_<_Tp>( saturate_cast<_Tp>(a.x + b.x), saturate_cast<_Tp>(a.y + b.y) );
1213
template<typename _Tp> static inline
1214
Point_<_Tp> operator - (const Point_<_Tp>& a, const Point_<_Tp>& b)
1216
return Point_<_Tp>( saturate_cast<_Tp>(a.x - b.x), saturate_cast<_Tp>(a.y - b.y) );
1219
template<typename _Tp> static inline
1220
Point_<_Tp> operator - (const Point_<_Tp>& a)
1222
return Point_<_Tp>( saturate_cast<_Tp>(-a.x), saturate_cast<_Tp>(-a.y) );
1225
template<typename _Tp> static inline
1226
Point_<_Tp> operator * (const Point_<_Tp>& a, int b)
1228
return Point_<_Tp>( saturate_cast<_Tp>(a.x*b), saturate_cast<_Tp>(a.y*b) );
1231
template<typename _Tp> static inline
1232
Point_<_Tp> operator * (int a, const Point_<_Tp>& b)
1234
return Point_<_Tp>( saturate_cast<_Tp>(b.x*a), saturate_cast<_Tp>(b.y*a) );
1237
template<typename _Tp> static inline
1238
Point_<_Tp> operator * (const Point_<_Tp>& a, float b)
1240
return Point_<_Tp>( saturate_cast<_Tp>(a.x*b), saturate_cast<_Tp>(a.y*b) );
1243
template<typename _Tp> static inline
1244
Point_<_Tp> operator * (float a, const Point_<_Tp>& b)
1246
return Point_<_Tp>( saturate_cast<_Tp>(b.x*a), saturate_cast<_Tp>(b.y*a) );
1249
template<typename _Tp> static inline
1250
Point_<_Tp> operator * (const Point_<_Tp>& a, double b)
1252
return Point_<_Tp>( saturate_cast<_Tp>(a.x*b), saturate_cast<_Tp>(a.y*b) );
1255
template<typename _Tp> static inline
1256
Point_<_Tp> operator * (double a, const Point_<_Tp>& b)
1258
return Point_<_Tp>( saturate_cast<_Tp>(b.x*a), saturate_cast<_Tp>(b.y*a) );
1261
template<typename _Tp> static inline
1262
Point_<_Tp> operator * (const Matx<_Tp, 2, 2>& a, const Point_<_Tp>& b)
1264
Matx<_Tp, 2, 1> tmp = a * Vec<_Tp,2>(b.x, b.y);
1265
return Point_<_Tp>(tmp.val[0], tmp.val[1]);
1268
template<typename _Tp> static inline
1269
Point3_<_Tp> operator * (const Matx<_Tp, 3, 3>& a, const Point_<_Tp>& b)
1271
Matx<_Tp, 3, 1> tmp = a * Vec<_Tp,3>(b.x, b.y, 1);
1272
return Point3_<_Tp>(tmp.val[0], tmp.val[1], tmp.val[2]);
1275
template<typename _Tp> static inline
1276
Point_<_Tp> operator / (const Point_<_Tp>& a, int b)
1283
template<typename _Tp> static inline
1284
Point_<_Tp> operator / (const Point_<_Tp>& a, float b)
1291
template<typename _Tp> static inline
1292
Point_<_Tp> operator / (const Point_<_Tp>& a, double b)
1301
//////////////////////////////// 3D Point ///////////////////////////////
1303
template<typename _Tp> inline
1304
Point3_<_Tp>::Point3_()
1305
: x(0), y(0), z(0) {}
1307
template<typename _Tp> inline
1308
Point3_<_Tp>::Point3_(_Tp _x, _Tp _y, _Tp _z)
1309
: x(_x), y(_y), z(_z) {}
1311
template<typename _Tp> inline
1312
Point3_<_Tp>::Point3_(const Point3_& pt)
1313
: x(pt.x), y(pt.y), z(pt.z) {}
1315
template<typename _Tp> inline
1316
Point3_<_Tp>::Point3_(const Point_<_Tp>& pt)
1317
: x(pt.x), y(pt.y), z(_Tp()) {}
1319
template<typename _Tp> inline
1320
Point3_<_Tp>::Point3_(const Vec<_Tp, 3>& v)
1321
: x(v[0]), y(v[1]), z(v[2]) {}
1323
template<typename _Tp> template<typename _Tp2> inline
1324
Point3_<_Tp>::operator Point3_<_Tp2>() const
1326
return Point3_<_Tp2>(saturate_cast<_Tp2>(x), saturate_cast<_Tp2>(y), saturate_cast<_Tp2>(z));
1329
template<typename _Tp> inline
1330
Point3_<_Tp>::operator Vec<_Tp, 3>() const
1332
return Vec<_Tp, 3>(x, y, z);
1335
template<typename _Tp> inline
1336
Point3_<_Tp>& Point3_<_Tp>::operator = (const Point3_& pt)
1338
x = pt.x; y = pt.y; z = pt.z;
1342
template<typename _Tp> inline
1343
_Tp Point3_<_Tp>::dot(const Point3_& pt) const
1345
return saturate_cast<_Tp>(x*pt.x + y*pt.y + z*pt.z);
1348
template<typename _Tp> inline
1349
double Point3_<_Tp>::ddot(const Point3_& pt) const
1351
return (double)x*pt.x + (double)y*pt.y + (double)z*pt.z;
1354
template<typename _Tp> inline
1355
Point3_<_Tp> Point3_<_Tp>::cross(const Point3_<_Tp>& pt) const
1357
return Point3_<_Tp>(y*pt.z - z*pt.y, z*pt.x - x*pt.z, x*pt.y - y*pt.x);
1361
template<typename _Tp> static inline
1362
Point3_<_Tp>& operator += (Point3_<_Tp>& a, const Point3_<_Tp>& b)
1370
template<typename _Tp> static inline
1371
Point3_<_Tp>& operator -= (Point3_<_Tp>& a, const Point3_<_Tp>& b)
1379
template<typename _Tp> static inline
1380
Point3_<_Tp>& operator *= (Point3_<_Tp>& a, int b)
1382
a.x = saturate_cast<_Tp>(a.x * b);
1383
a.y = saturate_cast<_Tp>(a.y * b);
1384
a.z = saturate_cast<_Tp>(a.z * b);
1388
template<typename _Tp> static inline
1389
Point3_<_Tp>& operator *= (Point3_<_Tp>& a, float b)
1391
a.x = saturate_cast<_Tp>(a.x * b);
1392
a.y = saturate_cast<_Tp>(a.y * b);
1393
a.z = saturate_cast<_Tp>(a.z * b);
1397
template<typename _Tp> static inline
1398
Point3_<_Tp>& operator *= (Point3_<_Tp>& a, double b)
1400
a.x = saturate_cast<_Tp>(a.x * b);
1401
a.y = saturate_cast<_Tp>(a.y * b);
1402
a.z = saturate_cast<_Tp>(a.z * b);
1406
template<typename _Tp> static inline
1407
Point3_<_Tp>& operator /= (Point3_<_Tp>& a, int b)
1409
a.x = saturate_cast<_Tp>(a.x / b);
1410
a.y = saturate_cast<_Tp>(a.y / b);
1411
a.z = saturate_cast<_Tp>(a.z / b);
1415
template<typename _Tp> static inline
1416
Point3_<_Tp>& operator /= (Point3_<_Tp>& a, float b)
1418
a.x = saturate_cast<_Tp>(a.x / b);
1419
a.y = saturate_cast<_Tp>(a.y / b);
1420
a.z = saturate_cast<_Tp>(a.z / b);
1424
template<typename _Tp> static inline
1425
Point3_<_Tp>& operator /= (Point3_<_Tp>& a, double b)
1427
a.x = saturate_cast<_Tp>(a.x / b);
1428
a.y = saturate_cast<_Tp>(a.y / b);
1429
a.z = saturate_cast<_Tp>(a.z / b);
1433
template<typename _Tp> static inline
1434
double norm(const Point3_<_Tp>& pt)
1436
return std::sqrt((double)pt.x*pt.x + (double)pt.y*pt.y + (double)pt.z*pt.z);
1439
template<typename _Tp> static inline
1440
bool operator == (const Point3_<_Tp>& a, const Point3_<_Tp>& b)
1442
return a.x == b.x && a.y == b.y && a.z == b.z;
1445
template<typename _Tp> static inline
1446
bool operator != (const Point3_<_Tp>& a, const Point3_<_Tp>& b)
1448
return a.x != b.x || a.y != b.y || a.z != b.z;
1451
template<typename _Tp> static inline
1452
Point3_<_Tp> operator + (const Point3_<_Tp>& a, const Point3_<_Tp>& b)
1454
return Point3_<_Tp>( saturate_cast<_Tp>(a.x + b.x), saturate_cast<_Tp>(a.y + b.y), saturate_cast<_Tp>(a.z + b.z));
1457
template<typename _Tp> static inline
1458
Point3_<_Tp> operator - (const Point3_<_Tp>& a, const Point3_<_Tp>& b)
1460
return Point3_<_Tp>( saturate_cast<_Tp>(a.x - b.x), saturate_cast<_Tp>(a.y - b.y), saturate_cast<_Tp>(a.z - b.z));
1463
template<typename _Tp> static inline
1464
Point3_<_Tp> operator - (const Point3_<_Tp>& a)
1466
return Point3_<_Tp>( saturate_cast<_Tp>(-a.x), saturate_cast<_Tp>(-a.y), saturate_cast<_Tp>(-a.z) );
1469
template<typename _Tp> static inline
1470
Point3_<_Tp> operator * (const Point3_<_Tp>& a, int b)
1472
return Point3_<_Tp>( saturate_cast<_Tp>(a.x*b), saturate_cast<_Tp>(a.y*b), saturate_cast<_Tp>(a.z*b) );
1475
template<typename _Tp> static inline
1476
Point3_<_Tp> operator * (int a, const Point3_<_Tp>& b)
1478
return Point3_<_Tp>( saturate_cast<_Tp>(b.x * a), saturate_cast<_Tp>(b.y * a), saturate_cast<_Tp>(b.z * a) );
1481
template<typename _Tp> static inline
1482
Point3_<_Tp> operator * (const Point3_<_Tp>& a, float b)
1484
return Point3_<_Tp>( saturate_cast<_Tp>(a.x * b), saturate_cast<_Tp>(a.y * b), saturate_cast<_Tp>(a.z * b) );
1487
template<typename _Tp> static inline
1488
Point3_<_Tp> operator * (float a, const Point3_<_Tp>& b)
1490
return Point3_<_Tp>( saturate_cast<_Tp>(b.x * a), saturate_cast<_Tp>(b.y * a), saturate_cast<_Tp>(b.z * a) );
1493
template<typename _Tp> static inline
1494
Point3_<_Tp> operator * (const Point3_<_Tp>& a, double b)
1496
return Point3_<_Tp>( saturate_cast<_Tp>(a.x * b), saturate_cast<_Tp>(a.y * b), saturate_cast<_Tp>(a.z * b) );
1499
template<typename _Tp> static inline
1500
Point3_<_Tp> operator * (double a, const Point3_<_Tp>& b)
1502
return Point3_<_Tp>( saturate_cast<_Tp>(b.x * a), saturate_cast<_Tp>(b.y * a), saturate_cast<_Tp>(b.z * a) );
1505
template<typename _Tp> static inline
1506
Point3_<_Tp> operator * (const Matx<_Tp, 3, 3>& a, const Point3_<_Tp>& b)
1508
Matx<_Tp, 3, 1> tmp = a * Vec<_Tp,3>(b.x, b.y, b.z);
1509
return Point3_<_Tp>(tmp.val[0], tmp.val[1], tmp.val[2]);
1512
template<typename _Tp> static inline
1513
Matx<_Tp, 4, 1> operator * (const Matx<_Tp, 4, 4>& a, const Point3_<_Tp>& b)
1515
return a * Matx<_Tp, 4, 1>(b.x, b.y, b.z, 1);
1518
template<typename _Tp> static inline
1519
Point3_<_Tp> operator / (const Point3_<_Tp>& a, int b)
1521
Point3_<_Tp> tmp(a);
1526
template<typename _Tp> static inline
1527
Point3_<_Tp> operator / (const Point3_<_Tp>& a, float b)
1529
Point3_<_Tp> tmp(a);
1534
template<typename _Tp> static inline
1535
Point3_<_Tp> operator / (const Point3_<_Tp>& a, double b)
1537
Point3_<_Tp> tmp(a);
1544
////////////////////////////////// Size /////////////////////////////////
1546
template<typename _Tp> inline
1548
: width(0), height(0) {}
1550
template<typename _Tp> inline
1551
Size_<_Tp>::Size_(_Tp _width, _Tp _height)
1552
: width(_width), height(_height) {}
1554
template<typename _Tp> inline
1555
Size_<_Tp>::Size_(const Size_& sz)
1556
: width(sz.width), height(sz.height) {}
1558
template<typename _Tp> inline
1559
Size_<_Tp>::Size_(const Point_<_Tp>& pt)
1560
: width(pt.x), height(pt.y) {}
1562
template<typename _Tp> template<typename _Tp2> inline
1563
Size_<_Tp>::operator Size_<_Tp2>() const
1565
return Size_<_Tp2>(saturate_cast<_Tp2>(width), saturate_cast<_Tp2>(height));
1568
template<typename _Tp> inline
1569
Size_<_Tp>& Size_<_Tp>::operator = (const Size_<_Tp>& sz)
1571
width = sz.width; height = sz.height;
1575
template<typename _Tp> inline
1576
_Tp Size_<_Tp>::area() const
1578
return width * height;
1581
template<typename _Tp> static inline
1582
Size_<_Tp>& operator *= (Size_<_Tp>& a, _Tp b)
1589
template<typename _Tp> static inline
1590
Size_<_Tp> operator * (const Size_<_Tp>& a, _Tp b)
1597
template<typename _Tp> static inline
1598
Size_<_Tp>& operator /= (Size_<_Tp>& a, _Tp b)
1605
template<typename _Tp> static inline
1606
Size_<_Tp> operator / (const Size_<_Tp>& a, _Tp b)
1613
template<typename _Tp> static inline
1614
Size_<_Tp>& operator += (Size_<_Tp>& a, const Size_<_Tp>& b)
1617
a.height += b.height;
1621
template<typename _Tp> static inline
1622
Size_<_Tp> operator + (const Size_<_Tp>& a, const Size_<_Tp>& b)
1629
template<typename _Tp> static inline
1630
Size_<_Tp>& operator -= (Size_<_Tp>& a, const Size_<_Tp>& b)
1633
a.height -= b.height;
1637
template<typename _Tp> static inline
1638
Size_<_Tp> operator - (const Size_<_Tp>& a, const Size_<_Tp>& b)
1645
template<typename _Tp> static inline
1646
bool operator == (const Size_<_Tp>& a, const Size_<_Tp>& b)
1648
return a.width == b.width && a.height == b.height;
1651
template<typename _Tp> static inline
1652
bool operator != (const Size_<_Tp>& a, const Size_<_Tp>& b)
1659
////////////////////////////////// Rect /////////////////////////////////
1661
template<typename _Tp> inline
1663
: x(0), y(0), width(0), height(0) {}
1665
template<typename _Tp> inline
1666
Rect_<_Tp>::Rect_(_Tp _x, _Tp _y, _Tp _width, _Tp _height)
1667
: x(_x), y(_y), width(_width), height(_height) {}
1669
template<typename _Tp> inline
1670
Rect_<_Tp>::Rect_(const Rect_<_Tp>& r)
1671
: x(r.x), y(r.y), width(r.width), height(r.height) {}
1673
template<typename _Tp> inline
1674
Rect_<_Tp>::Rect_(const Point_<_Tp>& org, const Size_<_Tp>& sz)
1675
: x(org.x), y(org.y), width(sz.width), height(sz.height) {}
1677
template<typename _Tp> inline
1678
Rect_<_Tp>::Rect_(const Point_<_Tp>& pt1, const Point_<_Tp>& pt2)
1680
x = std::min(pt1.x, pt2.x);
1681
y = std::min(pt1.y, pt2.y);
1682
width = std::max(pt1.x, pt2.x) - x;
1683
height = std::max(pt1.y, pt2.y) - y;
1686
template<typename _Tp> inline
1687
Rect_<_Tp>& Rect_<_Tp>::operator = ( const Rect_<_Tp>& r )
1696
template<typename _Tp> inline
1697
Point_<_Tp> Rect_<_Tp>::tl() const
1699
return Point_<_Tp>(x,y);
1702
template<typename _Tp> inline
1703
Point_<_Tp> Rect_<_Tp>::br() const
1705
return Point_<_Tp>(x + width, y + height);
1708
template<typename _Tp> inline
1709
Size_<_Tp> Rect_<_Tp>::size() const
1711
return Size_<_Tp>(width, height);
1714
template<typename _Tp> inline
1715
_Tp Rect_<_Tp>::area() const
1717
return width * height;
1720
template<typename _Tp> template<typename _Tp2> inline
1721
Rect_<_Tp>::operator Rect_<_Tp2>() const
1723
return Rect_<_Tp2>(saturate_cast<_Tp2>(x), saturate_cast<_Tp2>(y), saturate_cast<_Tp2>(width), saturate_cast<_Tp2>(height));
1726
template<typename _Tp> inline
1727
bool Rect_<_Tp>::contains(const Point_<_Tp>& pt) const
1729
return x <= pt.x && pt.x < x + width && y <= pt.y && pt.y < y + height;
1733
template<typename _Tp> static inline
1734
Rect_<_Tp>& operator += ( Rect_<_Tp>& a, const Point_<_Tp>& b )
1741
template<typename _Tp> static inline
1742
Rect_<_Tp>& operator -= ( Rect_<_Tp>& a, const Point_<_Tp>& b )
1749
template<typename _Tp> static inline
1750
Rect_<_Tp>& operator += ( Rect_<_Tp>& a, const Size_<_Tp>& b )
1753
a.height += b.height;
1757
template<typename _Tp> static inline
1758
Rect_<_Tp>& operator -= ( Rect_<_Tp>& a, const Size_<_Tp>& b )
1761
a.height -= b.height;
1765
template<typename _Tp> static inline
1766
Rect_<_Tp>& operator &= ( Rect_<_Tp>& a, const Rect_<_Tp>& b )
1768
_Tp x1 = std::max(a.x, b.x);
1769
_Tp y1 = std::max(a.y, b.y);
1770
a.width = std::min(a.x + a.width, b.x + b.width) - x1;
1771
a.height = std::min(a.y + a.height, b.y + b.height) - y1;
1774
if( a.width <= 0 || a.height <= 0 )
1779
template<typename _Tp> static inline
1780
Rect_<_Tp>& operator |= ( Rect_<_Tp>& a, const Rect_<_Tp>& b )
1782
_Tp x1 = std::min(a.x, b.x);
1783
_Tp y1 = std::min(a.y, b.y);
1784
a.width = std::max(a.x + a.width, b.x + b.width) - x1;
1785
a.height = std::max(a.y + a.height, b.y + b.height) - y1;
1791
template<typename _Tp> static inline
1792
bool operator == (const Rect_<_Tp>& a, const Rect_<_Tp>& b)
1794
return a.x == b.x && a.y == b.y && a.width == b.width && a.height == b.height;
1797
template<typename _Tp> static inline
1798
bool operator != (const Rect_<_Tp>& a, const Rect_<_Tp>& b)
1800
return a.x != b.x || a.y != b.y || a.width != b.width || a.height != b.height;
1803
template<typename _Tp> static inline
1804
Rect_<_Tp> operator + (const Rect_<_Tp>& a, const Point_<_Tp>& b)
1806
return Rect_<_Tp>( a.x + b.x, a.y + b.y, a.width, a.height );
1809
template<typename _Tp> static inline
1810
Rect_<_Tp> operator - (const Rect_<_Tp>& a, const Point_<_Tp>& b)
1812
return Rect_<_Tp>( a.x - b.x, a.y - b.y, a.width, a.height );
1815
template<typename _Tp> static inline
1816
Rect_<_Tp> operator + (const Rect_<_Tp>& a, const Size_<_Tp>& b)
1818
return Rect_<_Tp>( a.x, a.y, a.width + b.width, a.height + b.height );
1821
template<typename _Tp> static inline
1822
Rect_<_Tp> operator & (const Rect_<_Tp>& a, const Rect_<_Tp>& b)
1828
template<typename _Tp> static inline
1829
Rect_<_Tp> operator | (const Rect_<_Tp>& a, const Rect_<_Tp>& b)
1837
////////////////////////////// RotatedRect //////////////////////////////
1840
RotatedRect::RotatedRect()
1841
: center(), size(), angle(0) {}
1844
RotatedRect::RotatedRect(const Point2f& _center, const Size2f& _size, float _angle)
1845
: center(_center), size(_size), angle(_angle) {}
1849
///////////////////////////////// Range /////////////////////////////////
1853
: start(0), end(0) {}
1856
Range::Range(int _start, int _end)
1857
: start(_start), end(_end) {}
1860
int Range::size() const
1866
bool Range::empty() const
1868
return start == end;
1874
return Range(INT_MIN, INT_MAX);
1879
bool operator == (const Range& r1, const Range& r2)
1881
return r1.start == r2.start && r1.end == r2.end;
1885
bool operator != (const Range& r1, const Range& r2)
1891
bool operator !(const Range& r)
1893
return r.start == r.end;
1897
Range operator & (const Range& r1, const Range& r2)
1899
Range r(std::max(r1.start, r2.start), std::min(r1.end, r2.end));
1900
r.end = std::max(r.end, r.start);
1905
Range& operator &= (Range& r1, const Range& r2)
1912
Range operator + (const Range& r1, int delta)
1914
return Range(r1.start + delta, r1.end + delta);
1918
Range operator + (int delta, const Range& r1)
1920
return Range(r1.start + delta, r1.end + delta);
1924
Range operator - (const Range& r1, int delta)
1926
return r1 + (-delta);
1931
///////////////////////////////// Scalar ////////////////////////////////
1933
template<typename _Tp> inline
1934
Scalar_<_Tp>::Scalar_()
1936
this->val[0] = this->val[1] = this->val[2] = this->val[3] = 0;
1939
template<typename _Tp> inline
1940
Scalar_<_Tp>::Scalar_(_Tp v0, _Tp v1, _Tp v2, _Tp v3)
1948
template<typename _Tp> template<typename _Tp2, int cn> inline
1949
Scalar_<_Tp>::Scalar_(const Vec<_Tp2, cn>& v)
1952
for( i = 0; i < (cn < 4 ? cn : 4); i++ )
1953
this->val[i] = cv::saturate_cast<_Tp>(v.val[i]);
1958
template<typename _Tp> inline
1959
Scalar_<_Tp>::Scalar_(_Tp v0)
1962
this->val[1] = this->val[2] = this->val[3] = 0;
1965
template<typename _Tp> inline
1966
Scalar_<_Tp> Scalar_<_Tp>::all(_Tp v0)
1968
return Scalar_<_Tp>(v0, v0, v0, v0);
1972
template<typename _Tp> inline
1973
Scalar_<_Tp> Scalar_<_Tp>::mul(const Scalar_<_Tp>& a, double scale ) const
1975
return Scalar_<_Tp>(saturate_cast<_Tp>(this->val[0] * a.val[0] * scale),
1976
saturate_cast<_Tp>(this->val[1] * a.val[1] * scale),
1977
saturate_cast<_Tp>(this->val[2] * a.val[2] * scale),
1978
saturate_cast<_Tp>(this->val[3] * a.val[3] * scale));
1981
template<typename _Tp> inline
1982
Scalar_<_Tp> Scalar_<_Tp>::conj() const
1984
return Scalar_<_Tp>(saturate_cast<_Tp>( this->val[0]),
1985
saturate_cast<_Tp>(-this->val[1]),
1986
saturate_cast<_Tp>(-this->val[2]),
1987
saturate_cast<_Tp>(-this->val[3]));
1990
template<typename _Tp> inline
1991
bool Scalar_<_Tp>::isReal() const
1993
return this->val[1] == 0 && this->val[2] == 0 && this->val[3] == 0;
1997
template<typename _Tp> template<typename T2> inline
1998
Scalar_<_Tp>::operator Scalar_<T2>() const
2000
return Scalar_<T2>(saturate_cast<T2>(this->val[0]),
2001
saturate_cast<T2>(this->val[1]),
2002
saturate_cast<T2>(this->val[2]),
2003
saturate_cast<T2>(this->val[3]));
2007
template<typename _Tp> static inline
2008
Scalar_<_Tp>& operator += (Scalar_<_Tp>& a, const Scalar_<_Tp>& b)
2010
a.val[0] += b.val[0];
2011
a.val[1] += b.val[1];
2012
a.val[2] += b.val[2];
2013
a.val[3] += b.val[3];
2017
template<typename _Tp> static inline
2018
Scalar_<_Tp>& operator -= (Scalar_<_Tp>& a, const Scalar_<_Tp>& b)
2020
a.val[0] -= b.val[0];
2021
a.val[1] -= b.val[1];
2022
a.val[2] -= b.val[2];
2023
a.val[3] -= b.val[3];
2027
template<typename _Tp> static inline
2028
Scalar_<_Tp>& operator *= ( Scalar_<_Tp>& a, _Tp v )
2037
template<typename _Tp> static inline
2038
bool operator == ( const Scalar_<_Tp>& a, const Scalar_<_Tp>& b )
2040
return a.val[0] == b.val[0] && a.val[1] == b.val[1] &&
2041
a.val[2] == b.val[2] && a.val[3] == b.val[3];
2044
template<typename _Tp> static inline
2045
bool operator != ( const Scalar_<_Tp>& a, const Scalar_<_Tp>& b )
2047
return a.val[0] != b.val[0] || a.val[1] != b.val[1] ||
2048
a.val[2] != b.val[2] || a.val[3] != b.val[3];
2051
template<typename _Tp> static inline
2052
Scalar_<_Tp> operator + (const Scalar_<_Tp>& a, const Scalar_<_Tp>& b)
2054
return Scalar_<_Tp>(a.val[0] + b.val[0],
2055
a.val[1] + b.val[1],
2056
a.val[2] + b.val[2],
2057
a.val[3] + b.val[3]);
2060
template<typename _Tp> static inline
2061
Scalar_<_Tp> operator - (const Scalar_<_Tp>& a, const Scalar_<_Tp>& b)
2063
return Scalar_<_Tp>(saturate_cast<_Tp>(a.val[0] - b.val[0]),
2064
saturate_cast<_Tp>(a.val[1] - b.val[1]),
2065
saturate_cast<_Tp>(a.val[2] - b.val[2]),
2066
saturate_cast<_Tp>(a.val[3] - b.val[3]));
2069
template<typename _Tp> static inline
2070
Scalar_<_Tp> operator * (const Scalar_<_Tp>& a, _Tp alpha)
2072
return Scalar_<_Tp>(a.val[0] * alpha,
2078
template<typename _Tp> static inline
2079
Scalar_<_Tp> operator * (_Tp alpha, const Scalar_<_Tp>& a)
2084
template<typename _Tp> static inline
2085
Scalar_<_Tp> operator - (const Scalar_<_Tp>& a)
2087
return Scalar_<_Tp>(saturate_cast<_Tp>(-a.val[0]),
2088
saturate_cast<_Tp>(-a.val[1]),
2089
saturate_cast<_Tp>(-a.val[2]),
2090
saturate_cast<_Tp>(-a.val[3]));
2094
template<typename _Tp> static inline
2095
Scalar_<_Tp> operator * (const Scalar_<_Tp>& a, const Scalar_<_Tp>& b)
2097
return Scalar_<_Tp>(saturate_cast<_Tp>(a[0]*b[0] - a[1]*b[1] - a[2]*b[2] - a[3]*b[3]),
2098
saturate_cast<_Tp>(a[0]*b[1] + a[1]*b[0] + a[2]*b[3] - a[3]*b[2]),
2099
saturate_cast<_Tp>(a[0]*b[2] - a[1]*b[3] + a[2]*b[0] + a[3]*b[1]),
2100
saturate_cast<_Tp>(a[0]*b[3] + a[1]*b[2] - a[2]*b[1] + a[3]*b[0]));
2103
template<typename _Tp> static inline
2104
Scalar_<_Tp>& operator *= (Scalar_<_Tp>& a, const Scalar_<_Tp>& b)
2110
template<typename _Tp> static inline
2111
Scalar_<_Tp> operator / (const Scalar_<_Tp>& a, _Tp alpha)
2113
return Scalar_<_Tp>(a.val[0] / alpha,
2119
template<typename _Tp> static inline
2120
Scalar_<float> operator / (const Scalar_<float>& a, float alpha)
2122
float s = 1 / alpha;
2123
return Scalar_<float>(a.val[0] * s, a.val[1] * s, a.val[2] * s, a.val[3] * s);
2126
template<typename _Tp> static inline
2127
Scalar_<double> operator / (const Scalar_<double>& a, double alpha)
2129
double s = 1 / alpha;
2130
return Scalar_<double>(a.val[0] * s, a.val[1] * s, a.val[2] * s, a.val[3] * s);
2133
template<typename _Tp> static inline
2134
Scalar_<_Tp>& operator /= (Scalar_<_Tp>& a, _Tp alpha)
2140
template<typename _Tp> static inline
2141
Scalar_<_Tp> operator / (_Tp a, const Scalar_<_Tp>& b)
2143
_Tp s = a / (b[0]*b[0] + b[1]*b[1] + b[2]*b[2] + b[3]*b[3]);
2144
return b.conj() * s;
2147
template<typename _Tp> static inline
2148
Scalar_<_Tp> operator / (const Scalar_<_Tp>& a, const Scalar_<_Tp>& b)
2150
return a * ((_Tp)1 / b);
2153
template<typename _Tp> static inline
2154
Scalar_<_Tp>& operator /= (Scalar_<_Tp>& a, const Scalar_<_Tp>& b)
2160
template<typename _Tp> static inline
2161
Scalar operator * (const Matx<_Tp, 4, 4>& a, const Scalar& b)
2163
Matx<double, 4, 1> c((Matx<double, 4, 4>)a, b, Matx_MatMulOp());
2164
return reinterpret_cast<const Scalar&>(c);
2168
Scalar operator * (const Matx<double, 4, 4>& a, const Scalar& b)
2170
Matx<double, 4, 1> c(a, b, Matx_MatMulOp());
2171
return reinterpret_cast<const Scalar&>(c);
2176
//////////////////////////////// KeyPoint ///////////////////////////////
2179
KeyPoint::KeyPoint()
2180
: pt(0,0), size(0), angle(-1), response(0), octave(0), class_id(-1) {}
2183
KeyPoint::KeyPoint(Point2f _pt, float _size, float _angle, float _response, int _octave, int _class_id)
2184
: pt(_pt), size(_size), angle(_angle), response(_response), octave(_octave), class_id(_class_id) {}
2187
KeyPoint::KeyPoint(float x, float y, float _size, float _angle, float _response, int _octave, int _class_id)
2188
: pt(x, y), size(_size), angle(_angle), response(_response), octave(_octave), class_id(_class_id) {}
2192
///////////////////////////////// DMatch ////////////////////////////////
2196
: queryIdx(-1), trainIdx(-1), imgIdx(-1), distance(FLT_MAX) {}
2199
DMatch::DMatch(int _queryIdx, int _trainIdx, float _distance)
2200
: queryIdx(_queryIdx), trainIdx(_trainIdx), imgIdx(-1), distance(_distance) {}
2203
DMatch::DMatch(int _queryIdx, int _trainIdx, int _imgIdx, float _distance)
2204
: queryIdx(_queryIdx), trainIdx(_trainIdx), imgIdx(_imgIdx), distance(_distance) {}
2207
bool DMatch::operator < (const DMatch &m) const
2209
return distance < m.distance;
2214
////////////////////////////// TermCriteria /////////////////////////////
2217
TermCriteria::TermCriteria()
2218
: type(0), maxCount(0), epsilon(0) {}
2221
TermCriteria::TermCriteria(int _type, int _maxCount, double _epsilon)
2222
: type(_type), maxCount(_maxCount), epsilon(_epsilon) {}
2228
#endif //__OPENCV_CORE_TYPES_HPP__