Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
489bd59b
Commit
489bd59b
authored
Mar 28, 2013
by
Andrey Kamaev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move implementation of C++ container classes to types.hpp
parent
6c071cbd
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
1232 additions
and
798 deletions
+1232
-798
cvstd.inl.hpp
modules/core/include/opencv2/core/cvstd.inl.hpp
+16
-0
operations.hpp
modules/core/include/opencv2/core/operations.hpp
+0
-763
types.hpp
modules/core/include/opencv2/core/types.hpp
+1216
-35
No files found.
modules/core/include/opencv2/core/cvstd.inl.hpp
View file @
489bd59b
...
...
@@ -52,6 +52,22 @@ namespace cv
{
#ifndef OPENCV_NOSTL
template
<
typename
_Tp
>
class
DataType
<
std
::
complex
<
_Tp
>
>
{
public
:
typedef
std
::
complex
<
_Tp
>
value_type
;
typedef
value_type
work_type
;
typedef
_Tp
channel_type
;
enum
{
generic_type
=
0
,
depth
=
DataType
<
channel_type
>::
depth
,
channels
=
2
,
fmt
=
DataType
<
channel_type
>::
fmt
+
((
channels
-
1
)
<<
8
),
type
=
CV_MAKETYPE
(
depth
,
channels
)
};
typedef
Vec
<
channel_type
,
channels
>
vec_type
;
};
inline
String
::
String
(
const
std
::
string
&
str
)
:
cstr_
(
0
),
len_
(
0
)
{
if
(
!
str
.
empty
())
...
...
modules/core/include/opencv2/core/operations.hpp
View file @
489bd59b
...
...
@@ -231,769 +231,6 @@ Matx<_Tp, n, l> Matx<_Tp, m, n>::solve(const Matx<_Tp, m, l>& rhs, int method) c
return
ok
?
x
:
Matx
<
_Tp
,
n
,
l
>::
zeros
();
}
template
<
typename
_Tp
>
static
inline
Point_
<
_Tp
>
operator
*
(
const
Matx
<
_Tp
,
2
,
2
>&
a
,
const
Point_
<
_Tp
>&
b
)
{
Matx
<
_Tp
,
2
,
1
>
tmp
=
a
*
Vec
<
_Tp
,
2
>
(
b
.
x
,
b
.
y
);
return
Point_
<
_Tp
>
(
tmp
.
val
[
0
],
tmp
.
val
[
1
]);
}
template
<
typename
_Tp
>
static
inline
Point3_
<
_Tp
>
operator
*
(
const
Matx
<
_Tp
,
3
,
3
>&
a
,
const
Point3_
<
_Tp
>&
b
)
{
Matx
<
_Tp
,
3
,
1
>
tmp
=
a
*
Vec
<
_Tp
,
3
>
(
b
.
x
,
b
.
y
,
b
.
z
);
return
Point3_
<
_Tp
>
(
tmp
.
val
[
0
],
tmp
.
val
[
1
],
tmp
.
val
[
2
]);
}
template
<
typename
_Tp
>
static
inline
Point3_
<
_Tp
>
operator
*
(
const
Matx
<
_Tp
,
3
,
3
>&
a
,
const
Point_
<
_Tp
>&
b
)
{
Matx
<
_Tp
,
3
,
1
>
tmp
=
a
*
Vec
<
_Tp
,
3
>
(
b
.
x
,
b
.
y
,
1
);
return
Point3_
<
_Tp
>
(
tmp
.
val
[
0
],
tmp
.
val
[
1
],
tmp
.
val
[
2
]);
}
template
<
typename
_Tp
>
static
inline
Matx
<
_Tp
,
4
,
1
>
operator
*
(
const
Matx
<
_Tp
,
4
,
4
>&
a
,
const
Point3_
<
_Tp
>&
b
)
{
return
a
*
Matx
<
_Tp
,
4
,
1
>
(
b
.
x
,
b
.
y
,
b
.
z
,
1
);
}
template
<
typename
_Tp
>
static
inline
Scalar
operator
*
(
const
Matx
<
_Tp
,
4
,
4
>&
a
,
const
Scalar
&
b
)
{
Matx
<
double
,
4
,
1
>
c
((
Matx
<
double
,
4
,
4
>
)
a
,
b
,
Matx_MatMulOp
());
return
reinterpret_cast
<
const
Scalar
&>
(
c
);
}
template
<>
inline
Scalar
operator
*
(
const
Matx
<
double
,
4
,
4
>&
a
,
const
Scalar
&
b
)
{
Matx
<
double
,
4
,
1
>
c
(
a
,
b
,
Matx_MatMulOp
());
return
reinterpret_cast
<
const
Scalar
&>
(
c
);
}
//////////////////////////////// Complex //////////////////////////////
template
<
typename
_Tp
>
inline
Complex
<
_Tp
>::
Complex
()
:
re
(
0
),
im
(
0
)
{}
template
<
typename
_Tp
>
inline
Complex
<
_Tp
>::
Complex
(
_Tp
_re
,
_Tp
_im
)
:
re
(
_re
),
im
(
_im
)
{}
template
<
typename
_Tp
>
template
<
typename
T2
>
inline
Complex
<
_Tp
>::
operator
Complex
<
T2
>
()
const
{
return
Complex
<
T2
>
(
saturate_cast
<
T2
>
(
re
),
saturate_cast
<
T2
>
(
im
));
}
template
<
typename
_Tp
>
inline
Complex
<
_Tp
>
Complex
<
_Tp
>::
conj
()
const
{
return
Complex
<
_Tp
>
(
re
,
-
im
);
}
template
<
typename
_Tp
>
static
inline
bool
operator
==
(
const
Complex
<
_Tp
>&
a
,
const
Complex
<
_Tp
>&
b
)
{
return
a
.
re
==
b
.
re
&&
a
.
im
==
b
.
im
;
}
template
<
typename
_Tp
>
static
inline
bool
operator
!=
(
const
Complex
<
_Tp
>&
a
,
const
Complex
<
_Tp
>&
b
)
{
return
a
.
re
!=
b
.
re
||
a
.
im
!=
b
.
im
;
}
template
<
typename
_Tp
>
static
inline
Complex
<
_Tp
>
operator
+
(
const
Complex
<
_Tp
>&
a
,
const
Complex
<
_Tp
>&
b
)
{
return
Complex
<
_Tp
>
(
a
.
re
+
b
.
re
,
a
.
im
+
b
.
im
);
}
template
<
typename
_Tp
>
static
inline
Complex
<
_Tp
>&
operator
+=
(
Complex
<
_Tp
>&
a
,
const
Complex
<
_Tp
>&
b
)
{
a
.
re
+=
b
.
re
;
a
.
im
+=
b
.
im
;
return
a
;
}
template
<
typename
_Tp
>
static
inline
Complex
<
_Tp
>
operator
-
(
const
Complex
<
_Tp
>&
a
,
const
Complex
<
_Tp
>&
b
)
{
return
Complex
<
_Tp
>
(
a
.
re
-
b
.
re
,
a
.
im
-
b
.
im
);
}
template
<
typename
_Tp
>
static
inline
Complex
<
_Tp
>&
operator
-=
(
Complex
<
_Tp
>&
a
,
const
Complex
<
_Tp
>&
b
)
{
a
.
re
-=
b
.
re
;
a
.
im
-=
b
.
im
;
return
a
;
}
template
<
typename
_Tp
>
static
inline
Complex
<
_Tp
>
operator
-
(
const
Complex
<
_Tp
>&
a
)
{
return
Complex
<
_Tp
>
(
-
a
.
re
,
-
a
.
im
);
}
template
<
typename
_Tp
>
static
inline
Complex
<
_Tp
>
operator
*
(
const
Complex
<
_Tp
>&
a
,
const
Complex
<
_Tp
>&
b
)
{
return
Complex
<
_Tp
>
(
a
.
re
*
b
.
re
-
a
.
im
*
b
.
im
,
a
.
re
*
b
.
im
+
a
.
im
*
b
.
re
);
}
template
<
typename
_Tp
>
static
inline
Complex
<
_Tp
>
operator
*
(
const
Complex
<
_Tp
>&
a
,
_Tp
b
)
{
return
Complex
<
_Tp
>
(
a
.
re
*
b
,
a
.
im
*
b
);
}
template
<
typename
_Tp
>
static
inline
Complex
<
_Tp
>
operator
*
(
_Tp
b
,
const
Complex
<
_Tp
>&
a
)
{
return
Complex
<
_Tp
>
(
a
.
re
*
b
,
a
.
im
*
b
);
}
template
<
typename
_Tp
>
static
inline
Complex
<
_Tp
>
operator
+
(
const
Complex
<
_Tp
>&
a
,
_Tp
b
)
{
return
Complex
<
_Tp
>
(
a
.
re
+
b
,
a
.
im
);
}
template
<
typename
_Tp
>
static
inline
Complex
<
_Tp
>
operator
-
(
const
Complex
<
_Tp
>&
a
,
_Tp
b
)
{
return
Complex
<
_Tp
>
(
a
.
re
-
b
,
a
.
im
);
}
template
<
typename
_Tp
>
static
inline
Complex
<
_Tp
>
operator
+
(
_Tp
b
,
const
Complex
<
_Tp
>&
a
)
{
return
Complex
<
_Tp
>
(
a
.
re
+
b
,
a
.
im
);
}
template
<
typename
_Tp
>
static
inline
Complex
<
_Tp
>
operator
-
(
_Tp
b
,
const
Complex
<
_Tp
>&
a
)
{
return
Complex
<
_Tp
>
(
b
-
a
.
re
,
-
a
.
im
);
}
template
<
typename
_Tp
>
static
inline
Complex
<
_Tp
>&
operator
+=
(
Complex
<
_Tp
>&
a
,
_Tp
b
)
{
a
.
re
+=
b
;
return
a
;
}
template
<
typename
_Tp
>
static
inline
Complex
<
_Tp
>&
operator
-=
(
Complex
<
_Tp
>&
a
,
_Tp
b
)
{
a
.
re
-=
b
;
return
a
;
}
template
<
typename
_Tp
>
static
inline
Complex
<
_Tp
>&
operator
*=
(
Complex
<
_Tp
>&
a
,
_Tp
b
)
{
a
.
re
*=
b
;
a
.
im
*=
b
;
return
a
;
}
template
<
typename
_Tp
>
static
inline
double
abs
(
const
Complex
<
_Tp
>&
a
)
{
return
std
::
sqrt
(
(
double
)
a
.
re
*
a
.
re
+
(
double
)
a
.
im
*
a
.
im
);
}
template
<
typename
_Tp
>
static
inline
Complex
<
_Tp
>
operator
/
(
const
Complex
<
_Tp
>&
a
,
const
Complex
<
_Tp
>&
b
)
{
double
t
=
1.
/
((
double
)
b
.
re
*
b
.
re
+
(
double
)
b
.
im
*
b
.
im
);
return
Complex
<
_Tp
>
(
(
_Tp
)((
a
.
re
*
b
.
re
+
a
.
im
*
b
.
im
)
*
t
),
(
_Tp
)((
-
a
.
re
*
b
.
im
+
a
.
im
*
b
.
re
)
*
t
)
);
}
template
<
typename
_Tp
>
static
inline
Complex
<
_Tp
>&
operator
/=
(
Complex
<
_Tp
>&
a
,
const
Complex
<
_Tp
>&
b
)
{
return
(
a
=
a
/
b
);
}
template
<
typename
_Tp
>
static
inline
Complex
<
_Tp
>
operator
/
(
const
Complex
<
_Tp
>&
a
,
_Tp
b
)
{
_Tp
t
=
(
_Tp
)
1
/
b
;
return
Complex
<
_Tp
>
(
a
.
re
*
t
,
a
.
im
*
t
);
}
template
<
typename
_Tp
>
static
inline
Complex
<
_Tp
>
operator
/
(
_Tp
b
,
const
Complex
<
_Tp
>&
a
)
{
return
Complex
<
_Tp
>
(
b
)
/
a
;
}
template
<
typename
_Tp
>
static
inline
Complex
<
_Tp
>
operator
/=
(
const
Complex
<
_Tp
>&
a
,
_Tp
b
)
{
_Tp
t
=
(
_Tp
)
1
/
b
;
a
.
re
*=
t
;
a
.
im
*=
t
;
return
a
;
}
//////////////////////////////// 2D Point ////////////////////////////////
template
<
typename
_Tp
>
inline
Point_
<
_Tp
>::
Point_
()
:
x
(
0
),
y
(
0
)
{}
template
<
typename
_Tp
>
inline
Point_
<
_Tp
>::
Point_
(
_Tp
_x
,
_Tp
_y
)
:
x
(
_x
),
y
(
_y
)
{}
template
<
typename
_Tp
>
inline
Point_
<
_Tp
>::
Point_
(
const
Point_
&
pt
)
:
x
(
pt
.
x
),
y
(
pt
.
y
)
{}
template
<
typename
_Tp
>
inline
Point_
<
_Tp
>::
Point_
(
const
Size_
<
_Tp
>&
sz
)
:
x
(
sz
.
width
),
y
(
sz
.
height
)
{}
template
<
typename
_Tp
>
inline
Point_
<
_Tp
>::
Point_
(
const
Vec
<
_Tp
,
2
>&
v
)
:
x
(
v
[
0
]),
y
(
v
[
1
])
{}
template
<
typename
_Tp
>
inline
Point_
<
_Tp
>&
Point_
<
_Tp
>::
operator
=
(
const
Point_
&
pt
)
{
x
=
pt
.
x
;
y
=
pt
.
y
;
return
*
this
;
}
template
<
typename
_Tp
>
template
<
typename
_Tp2
>
inline
Point_
<
_Tp
>::
operator
Point_
<
_Tp2
>
()
const
{
return
Point_
<
_Tp2
>
(
saturate_cast
<
_Tp2
>
(
x
),
saturate_cast
<
_Tp2
>
(
y
));
}
template
<
typename
_Tp
>
inline
Point_
<
_Tp
>::
operator
Vec
<
_Tp
,
2
>
()
const
{
return
Vec
<
_Tp
,
2
>
(
x
,
y
);
}
template
<
typename
_Tp
>
inline
_Tp
Point_
<
_Tp
>::
dot
(
const
Point_
&
pt
)
const
{
return
saturate_cast
<
_Tp
>
(
x
*
pt
.
x
+
y
*
pt
.
y
);
}
template
<
typename
_Tp
>
inline
double
Point_
<
_Tp
>::
ddot
(
const
Point_
&
pt
)
const
{
return
(
double
)
x
*
pt
.
x
+
(
double
)
y
*
pt
.
y
;
}
template
<
typename
_Tp
>
inline
double
Point_
<
_Tp
>::
cross
(
const
Point_
&
pt
)
const
{
return
(
double
)
x
*
pt
.
y
-
(
double
)
y
*
pt
.
x
;
}
template
<
typename
_Tp
>
static
inline
Point_
<
_Tp
>&
operator
+=
(
Point_
<
_Tp
>&
a
,
const
Point_
<
_Tp
>&
b
)
{
a
.
x
=
saturate_cast
<
_Tp
>
(
a
.
x
+
b
.
x
);
a
.
y
=
saturate_cast
<
_Tp
>
(
a
.
y
+
b
.
y
);
return
a
;
}
template
<
typename
_Tp
>
static
inline
Point_
<
_Tp
>&
operator
-=
(
Point_
<
_Tp
>&
a
,
const
Point_
<
_Tp
>&
b
)
{
a
.
x
=
saturate_cast
<
_Tp
>
(
a
.
x
-
b
.
x
);
a
.
y
=
saturate_cast
<
_Tp
>
(
a
.
y
-
b
.
y
);
return
a
;
}
template
<
typename
_Tp
>
static
inline
Point_
<
_Tp
>&
operator
*=
(
Point_
<
_Tp
>&
a
,
int
b
)
{
a
.
x
=
saturate_cast
<
_Tp
>
(
a
.
x
*
b
);
a
.
y
=
saturate_cast
<
_Tp
>
(
a
.
y
*
b
);
return
a
;
}
template
<
typename
_Tp
>
static
inline
Point_
<
_Tp
>&
operator
*=
(
Point_
<
_Tp
>&
a
,
float
b
)
{
a
.
x
=
saturate_cast
<
_Tp
>
(
a
.
x
*
b
);
a
.
y
=
saturate_cast
<
_Tp
>
(
a
.
y
*
b
);
return
a
;
}
template
<
typename
_Tp
>
static
inline
Point_
<
_Tp
>&
operator
*=
(
Point_
<
_Tp
>&
a
,
double
b
)
{
a
.
x
=
saturate_cast
<
_Tp
>
(
a
.
x
*
b
);
a
.
y
=
saturate_cast
<
_Tp
>
(
a
.
y
*
b
);
return
a
;
}
template
<
typename
_Tp
>
static
inline
double
norm
(
const
Point_
<
_Tp
>&
pt
)
{
return
std
::
sqrt
((
double
)
pt
.
x
*
pt
.
x
+
(
double
)
pt
.
y
*
pt
.
y
);
}
template
<
typename
_Tp
>
static
inline
bool
operator
==
(
const
Point_
<
_Tp
>&
a
,
const
Point_
<
_Tp
>&
b
)
{
return
a
.
x
==
b
.
x
&&
a
.
y
==
b
.
y
;
}
template
<
typename
_Tp
>
static
inline
bool
operator
!=
(
const
Point_
<
_Tp
>&
a
,
const
Point_
<
_Tp
>&
b
)
{
return
a
.
x
!=
b
.
x
||
a
.
y
!=
b
.
y
;
}
template
<
typename
_Tp
>
static
inline
Point_
<
_Tp
>
operator
+
(
const
Point_
<
_Tp
>&
a
,
const
Point_
<
_Tp
>&
b
)
{
return
Point_
<
_Tp
>
(
saturate_cast
<
_Tp
>
(
a
.
x
+
b
.
x
),
saturate_cast
<
_Tp
>
(
a
.
y
+
b
.
y
)
);
}
template
<
typename
_Tp
>
static
inline
Point_
<
_Tp
>
operator
-
(
const
Point_
<
_Tp
>&
a
,
const
Point_
<
_Tp
>&
b
)
{
return
Point_
<
_Tp
>
(
saturate_cast
<
_Tp
>
(
a
.
x
-
b
.
x
),
saturate_cast
<
_Tp
>
(
a
.
y
-
b
.
y
)
);
}
template
<
typename
_Tp
>
static
inline
Point_
<
_Tp
>
operator
-
(
const
Point_
<
_Tp
>&
a
)
{
return
Point_
<
_Tp
>
(
saturate_cast
<
_Tp
>
(
-
a
.
x
),
saturate_cast
<
_Tp
>
(
-
a
.
y
)
);
}
template
<
typename
_Tp
>
static
inline
Point_
<
_Tp
>
operator
*
(
const
Point_
<
_Tp
>&
a
,
int
b
)
{
return
Point_
<
_Tp
>
(
saturate_cast
<
_Tp
>
(
a
.
x
*
b
),
saturate_cast
<
_Tp
>
(
a
.
y
*
b
)
);
}
template
<
typename
_Tp
>
static
inline
Point_
<
_Tp
>
operator
*
(
int
a
,
const
Point_
<
_Tp
>&
b
)
{
return
Point_
<
_Tp
>
(
saturate_cast
<
_Tp
>
(
b
.
x
*
a
),
saturate_cast
<
_Tp
>
(
b
.
y
*
a
)
);
}
template
<
typename
_Tp
>
static
inline
Point_
<
_Tp
>
operator
*
(
const
Point_
<
_Tp
>&
a
,
float
b
)
{
return
Point_
<
_Tp
>
(
saturate_cast
<
_Tp
>
(
a
.
x
*
b
),
saturate_cast
<
_Tp
>
(
a
.
y
*
b
)
);
}
template
<
typename
_Tp
>
static
inline
Point_
<
_Tp
>
operator
*
(
float
a
,
const
Point_
<
_Tp
>&
b
)
{
return
Point_
<
_Tp
>
(
saturate_cast
<
_Tp
>
(
b
.
x
*
a
),
saturate_cast
<
_Tp
>
(
b
.
y
*
a
)
);
}
template
<
typename
_Tp
>
static
inline
Point_
<
_Tp
>
operator
*
(
const
Point_
<
_Tp
>&
a
,
double
b
)
{
return
Point_
<
_Tp
>
(
saturate_cast
<
_Tp
>
(
a
.
x
*
b
),
saturate_cast
<
_Tp
>
(
a
.
y
*
b
)
);
}
template
<
typename
_Tp
>
static
inline
Point_
<
_Tp
>
operator
*
(
double
a
,
const
Point_
<
_Tp
>&
b
)
{
return
Point_
<
_Tp
>
(
saturate_cast
<
_Tp
>
(
b
.
x
*
a
),
saturate_cast
<
_Tp
>
(
b
.
y
*
a
)
);
}
//////////////////////////////// 3D Point ////////////////////////////////
template
<
typename
_Tp
>
inline
Point3_
<
_Tp
>::
Point3_
()
:
x
(
0
),
y
(
0
),
z
(
0
)
{}
template
<
typename
_Tp
>
inline
Point3_
<
_Tp
>::
Point3_
(
_Tp
_x
,
_Tp
_y
,
_Tp
_z
)
:
x
(
_x
),
y
(
_y
),
z
(
_z
)
{}
template
<
typename
_Tp
>
inline
Point3_
<
_Tp
>::
Point3_
(
const
Point3_
&
pt
)
:
x
(
pt
.
x
),
y
(
pt
.
y
),
z
(
pt
.
z
)
{}
template
<
typename
_Tp
>
inline
Point3_
<
_Tp
>::
Point3_
(
const
Point_
<
_Tp
>&
pt
)
:
x
(
pt
.
x
),
y
(
pt
.
y
),
z
(
_Tp
())
{}
template
<
typename
_Tp
>
inline
Point3_
<
_Tp
>::
Point3_
(
const
Vec
<
_Tp
,
3
>&
v
)
:
x
(
v
[
0
]),
y
(
v
[
1
]),
z
(
v
[
2
])
{}
template
<
typename
_Tp
>
template
<
typename
_Tp2
>
inline
Point3_
<
_Tp
>::
operator
Point3_
<
_Tp2
>
()
const
{
return
Point3_
<
_Tp2
>
(
saturate_cast
<
_Tp2
>
(
x
),
saturate_cast
<
_Tp2
>
(
y
),
saturate_cast
<
_Tp2
>
(
z
));
}
template
<
typename
_Tp
>
inline
Point3_
<
_Tp
>::
operator
Vec
<
_Tp
,
3
>
()
const
{
return
Vec
<
_Tp
,
3
>
(
x
,
y
,
z
);
}
template
<
typename
_Tp
>
inline
Point3_
<
_Tp
>&
Point3_
<
_Tp
>::
operator
=
(
const
Point3_
&
pt
)
{
x
=
pt
.
x
;
y
=
pt
.
y
;
z
=
pt
.
z
;
return
*
this
;
}
template
<
typename
_Tp
>
inline
_Tp
Point3_
<
_Tp
>::
dot
(
const
Point3_
&
pt
)
const
{
return
saturate_cast
<
_Tp
>
(
x
*
pt
.
x
+
y
*
pt
.
y
+
z
*
pt
.
z
);
}
template
<
typename
_Tp
>
inline
double
Point3_
<
_Tp
>::
ddot
(
const
Point3_
&
pt
)
const
{
return
(
double
)
x
*
pt
.
x
+
(
double
)
y
*
pt
.
y
+
(
double
)
z
*
pt
.
z
;
}
template
<
typename
_Tp
>
inline
Point3_
<
_Tp
>
Point3_
<
_Tp
>::
cross
(
const
Point3_
<
_Tp
>&
pt
)
const
{
return
Point3_
<
_Tp
>
(
y
*
pt
.
z
-
z
*
pt
.
y
,
z
*
pt
.
x
-
x
*
pt
.
z
,
x
*
pt
.
y
-
y
*
pt
.
x
);
}
template
<
typename
_Tp
>
static
inline
Point3_
<
_Tp
>&
operator
+=
(
Point3_
<
_Tp
>&
a
,
const
Point3_
<
_Tp
>&
b
)
{
a
.
x
=
saturate_cast
<
_Tp
>
(
a
.
x
+
b
.
x
);
a
.
y
=
saturate_cast
<
_Tp
>
(
a
.
y
+
b
.
y
);
a
.
z
=
saturate_cast
<
_Tp
>
(
a
.
z
+
b
.
z
);
return
a
;
}
template
<
typename
_Tp
>
static
inline
Point3_
<
_Tp
>&
operator
-=
(
Point3_
<
_Tp
>&
a
,
const
Point3_
<
_Tp
>&
b
)
{
a
.
x
=
saturate_cast
<
_Tp
>
(
a
.
x
-
b
.
x
);
a
.
y
=
saturate_cast
<
_Tp
>
(
a
.
y
-
b
.
y
);
a
.
z
=
saturate_cast
<
_Tp
>
(
a
.
z
-
b
.
z
);
return
a
;
}
template
<
typename
_Tp
>
static
inline
Point3_
<
_Tp
>&
operator
*=
(
Point3_
<
_Tp
>&
a
,
int
b
)
{
a
.
x
=
saturate_cast
<
_Tp
>
(
a
.
x
*
b
);
a
.
y
=
saturate_cast
<
_Tp
>
(
a
.
y
*
b
);
a
.
z
=
saturate_cast
<
_Tp
>
(
a
.
z
*
b
);
return
a
;
}
template
<
typename
_Tp
>
static
inline
Point3_
<
_Tp
>&
operator
*=
(
Point3_
<
_Tp
>&
a
,
float
b
)
{
a
.
x
=
saturate_cast
<
_Tp
>
(
a
.
x
*
b
);
a
.
y
=
saturate_cast
<
_Tp
>
(
a
.
y
*
b
);
a
.
z
=
saturate_cast
<
_Tp
>
(
a
.
z
*
b
);
return
a
;
}
template
<
typename
_Tp
>
static
inline
Point3_
<
_Tp
>&
operator
*=
(
Point3_
<
_Tp
>&
a
,
double
b
)
{
a
.
x
=
saturate_cast
<
_Tp
>
(
a
.
x
*
b
);
a
.
y
=
saturate_cast
<
_Tp
>
(
a
.
y
*
b
);
a
.
z
=
saturate_cast
<
_Tp
>
(
a
.
z
*
b
);
return
a
;
}
template
<
typename
_Tp
>
static
inline
double
norm
(
const
Point3_
<
_Tp
>&
pt
)
{
return
std
::
sqrt
((
double
)
pt
.
x
*
pt
.
x
+
(
double
)
pt
.
y
*
pt
.
y
+
(
double
)
pt
.
z
*
pt
.
z
);
}
template
<
typename
_Tp
>
static
inline
bool
operator
==
(
const
Point3_
<
_Tp
>&
a
,
const
Point3_
<
_Tp
>&
b
)
{
return
a
.
x
==
b
.
x
&&
a
.
y
==
b
.
y
&&
a
.
z
==
b
.
z
;
}
template
<
typename
_Tp
>
static
inline
bool
operator
!=
(
const
Point3_
<
_Tp
>&
a
,
const
Point3_
<
_Tp
>&
b
)
{
return
a
.
x
!=
b
.
x
||
a
.
y
!=
b
.
y
||
a
.
z
!=
b
.
z
;
}
template
<
typename
_Tp
>
static
inline
Point3_
<
_Tp
>
operator
+
(
const
Point3_
<
_Tp
>&
a
,
const
Point3_
<
_Tp
>&
b
)
{
return
Point3_
<
_Tp
>
(
saturate_cast
<
_Tp
>
(
a
.
x
+
b
.
x
),
saturate_cast
<
_Tp
>
(
a
.
y
+
b
.
y
),
saturate_cast
<
_Tp
>
(
a
.
z
+
b
.
z
));
}
template
<
typename
_Tp
>
static
inline
Point3_
<
_Tp
>
operator
-
(
const
Point3_
<
_Tp
>&
a
,
const
Point3_
<
_Tp
>&
b
)
{
return
Point3_
<
_Tp
>
(
saturate_cast
<
_Tp
>
(
a
.
x
-
b
.
x
),
saturate_cast
<
_Tp
>
(
a
.
y
-
b
.
y
),
saturate_cast
<
_Tp
>
(
a
.
z
-
b
.
z
));
}
template
<
typename
_Tp
>
static
inline
Point3_
<
_Tp
>
operator
-
(
const
Point3_
<
_Tp
>&
a
)
{
return
Point3_
<
_Tp
>
(
saturate_cast
<
_Tp
>
(
-
a
.
x
),
saturate_cast
<
_Tp
>
(
-
a
.
y
),
saturate_cast
<
_Tp
>
(
-
a
.
z
)
);
}
template
<
typename
_Tp
>
static
inline
Point3_
<
_Tp
>
operator
*
(
const
Point3_
<
_Tp
>&
a
,
int
b
)
{
return
Point3_
<
_Tp
>
(
saturate_cast
<
_Tp
>
(
a
.
x
*
b
),
saturate_cast
<
_Tp
>
(
a
.
y
*
b
),
saturate_cast
<
_Tp
>
(
a
.
z
*
b
)
);
}
template
<
typename
_Tp
>
static
inline
Point3_
<
_Tp
>
operator
*
(
int
a
,
const
Point3_
<
_Tp
>&
b
)
{
return
Point3_
<
_Tp
>
(
saturate_cast
<
_Tp
>
(
b
.
x
*
a
),
saturate_cast
<
_Tp
>
(
b
.
y
*
a
),
saturate_cast
<
_Tp
>
(
b
.
z
*
a
)
);
}
template
<
typename
_Tp
>
static
inline
Point3_
<
_Tp
>
operator
*
(
const
Point3_
<
_Tp
>&
a
,
float
b
)
{
return
Point3_
<
_Tp
>
(
saturate_cast
<
_Tp
>
(
a
.
x
*
b
),
saturate_cast
<
_Tp
>
(
a
.
y
*
b
),
saturate_cast
<
_Tp
>
(
a
.
z
*
b
)
);
}
template
<
typename
_Tp
>
static
inline
Point3_
<
_Tp
>
operator
*
(
float
a
,
const
Point3_
<
_Tp
>&
b
)
{
return
Point3_
<
_Tp
>
(
saturate_cast
<
_Tp
>
(
b
.
x
*
a
),
saturate_cast
<
_Tp
>
(
b
.
y
*
a
),
saturate_cast
<
_Tp
>
(
b
.
z
*
a
)
);
}
template
<
typename
_Tp
>
static
inline
Point3_
<
_Tp
>
operator
*
(
const
Point3_
<
_Tp
>&
a
,
double
b
)
{
return
Point3_
<
_Tp
>
(
saturate_cast
<
_Tp
>
(
a
.
x
*
b
),
saturate_cast
<
_Tp
>
(
a
.
y
*
b
),
saturate_cast
<
_Tp
>
(
a
.
z
*
b
)
);
}
template
<
typename
_Tp
>
static
inline
Point3_
<
_Tp
>
operator
*
(
double
a
,
const
Point3_
<
_Tp
>&
b
)
{
return
Point3_
<
_Tp
>
(
saturate_cast
<
_Tp
>
(
b
.
x
*
a
),
saturate_cast
<
_Tp
>
(
b
.
y
*
a
),
saturate_cast
<
_Tp
>
(
b
.
z
*
a
)
);
}
//////////////////////////////// Size ////////////////////////////////
template
<
typename
_Tp
>
inline
Size_
<
_Tp
>::
Size_
()
:
width
(
0
),
height
(
0
)
{}
template
<
typename
_Tp
>
inline
Size_
<
_Tp
>::
Size_
(
_Tp
_width
,
_Tp
_height
)
:
width
(
_width
),
height
(
_height
)
{}
template
<
typename
_Tp
>
inline
Size_
<
_Tp
>::
Size_
(
const
Size_
&
sz
)
:
width
(
sz
.
width
),
height
(
sz
.
height
)
{}
template
<
typename
_Tp
>
inline
Size_
<
_Tp
>::
Size_
(
const
Point_
<
_Tp
>&
pt
)
:
width
(
pt
.
x
),
height
(
pt
.
y
)
{}
template
<
typename
_Tp
>
template
<
typename
_Tp2
>
inline
Size_
<
_Tp
>::
operator
Size_
<
_Tp2
>
()
const
{
return
Size_
<
_Tp2
>
(
saturate_cast
<
_Tp2
>
(
width
),
saturate_cast
<
_Tp2
>
(
height
));
}
template
<
typename
_Tp
>
inline
Size_
<
_Tp
>&
Size_
<
_Tp
>::
operator
=
(
const
Size_
<
_Tp
>&
sz
)
{
width
=
sz
.
width
;
height
=
sz
.
height
;
return
*
this
;
}
template
<
typename
_Tp
>
static
inline
Size_
<
_Tp
>
operator
*
(
const
Size_
<
_Tp
>&
a
,
_Tp
b
)
{
return
Size_
<
_Tp
>
(
a
.
width
*
b
,
a
.
height
*
b
);
}
template
<
typename
_Tp
>
static
inline
Size_
<
_Tp
>
operator
+
(
const
Size_
<
_Tp
>&
a
,
const
Size_
<
_Tp
>&
b
)
{
return
Size_
<
_Tp
>
(
a
.
width
+
b
.
width
,
a
.
height
+
b
.
height
);
}
template
<
typename
_Tp
>
static
inline
Size_
<
_Tp
>
operator
-
(
const
Size_
<
_Tp
>&
a
,
const
Size_
<
_Tp
>&
b
)
{
return
Size_
<
_Tp
>
(
a
.
width
-
b
.
width
,
a
.
height
-
b
.
height
);
}
template
<
typename
_Tp
>
inline
_Tp
Size_
<
_Tp
>::
area
()
const
{
return
width
*
height
;
}
template
<
typename
_Tp
>
static
inline
Size_
<
_Tp
>&
operator
+=
(
Size_
<
_Tp
>&
a
,
const
Size_
<
_Tp
>&
b
)
{
a
.
width
+=
b
.
width
;
a
.
height
+=
b
.
height
;
return
a
;
}
template
<
typename
_Tp
>
static
inline
Size_
<
_Tp
>&
operator
-=
(
Size_
<
_Tp
>&
a
,
const
Size_
<
_Tp
>&
b
)
{
a
.
width
-=
b
.
width
;
a
.
height
-=
b
.
height
;
return
a
;
}
template
<
typename
_Tp
>
static
inline
bool
operator
==
(
const
Size_
<
_Tp
>&
a
,
const
Size_
<
_Tp
>&
b
)
{
return
a
.
width
==
b
.
width
&&
a
.
height
==
b
.
height
;
}
template
<
typename
_Tp
>
static
inline
bool
operator
!=
(
const
Size_
<
_Tp
>&
a
,
const
Size_
<
_Tp
>&
b
)
{
return
a
.
width
!=
b
.
width
||
a
.
height
!=
b
.
height
;
}
//////////////////////////////// Rect ////////////////////////////////
template
<
typename
_Tp
>
inline
Rect_
<
_Tp
>::
Rect_
()
:
x
(
0
),
y
(
0
),
width
(
0
),
height
(
0
)
{}
template
<
typename
_Tp
>
inline
Rect_
<
_Tp
>::
Rect_
(
_Tp
_x
,
_Tp
_y
,
_Tp
_width
,
_Tp
_height
)
:
x
(
_x
),
y
(
_y
),
width
(
_width
),
height
(
_height
)
{}
template
<
typename
_Tp
>
inline
Rect_
<
_Tp
>::
Rect_
(
const
Rect_
<
_Tp
>&
r
)
:
x
(
r
.
x
),
y
(
r
.
y
),
width
(
r
.
width
),
height
(
r
.
height
)
{}
template
<
typename
_Tp
>
inline
Rect_
<
_Tp
>::
Rect_
(
const
Point_
<
_Tp
>&
org
,
const
Size_
<
_Tp
>&
sz
)
:
x
(
org
.
x
),
y
(
org
.
y
),
width
(
sz
.
width
),
height
(
sz
.
height
)
{}
template
<
typename
_Tp
>
inline
Rect_
<
_Tp
>::
Rect_
(
const
Point_
<
_Tp
>&
pt1
,
const
Point_
<
_Tp
>&
pt2
)
{
x
=
std
::
min
(
pt1
.
x
,
pt2
.
x
);
y
=
std
::
min
(
pt1
.
y
,
pt2
.
y
);
width
=
std
::
max
(
pt1
.
x
,
pt2
.
x
)
-
x
;
height
=
std
::
max
(
pt1
.
y
,
pt2
.
y
)
-
y
;
}
template
<
typename
_Tp
>
inline
Rect_
<
_Tp
>&
Rect_
<
_Tp
>::
operator
=
(
const
Rect_
<
_Tp
>&
r
)
{
x
=
r
.
x
;
y
=
r
.
y
;
width
=
r
.
width
;
height
=
r
.
height
;
return
*
this
;
}
template
<
typename
_Tp
>
inline
Point_
<
_Tp
>
Rect_
<
_Tp
>::
tl
()
const
{
return
Point_
<
_Tp
>
(
x
,
y
);
}
template
<
typename
_Tp
>
inline
Point_
<
_Tp
>
Rect_
<
_Tp
>::
br
()
const
{
return
Point_
<
_Tp
>
(
x
+
width
,
y
+
height
);
}
template
<
typename
_Tp
>
static
inline
Rect_
<
_Tp
>&
operator
+=
(
Rect_
<
_Tp
>&
a
,
const
Point_
<
_Tp
>&
b
)
{
a
.
x
+=
b
.
x
;
a
.
y
+=
b
.
y
;
return
a
;
}
template
<
typename
_Tp
>
static
inline
Rect_
<
_Tp
>&
operator
-=
(
Rect_
<
_Tp
>&
a
,
const
Point_
<
_Tp
>&
b
)
{
a
.
x
-=
b
.
x
;
a
.
y
-=
b
.
y
;
return
a
;
}
template
<
typename
_Tp
>
static
inline
Rect_
<
_Tp
>&
operator
+=
(
Rect_
<
_Tp
>&
a
,
const
Size_
<
_Tp
>&
b
)
{
a
.
width
+=
b
.
width
;
a
.
height
+=
b
.
height
;
return
a
;
}
template
<
typename
_Tp
>
static
inline
Rect_
<
_Tp
>&
operator
-=
(
Rect_
<
_Tp
>&
a
,
const
Size_
<
_Tp
>&
b
)
{
a
.
width
-=
b
.
width
;
a
.
height
-=
b
.
height
;
return
a
;
}
template
<
typename
_Tp
>
static
inline
Rect_
<
_Tp
>&
operator
&=
(
Rect_
<
_Tp
>&
a
,
const
Rect_
<
_Tp
>&
b
)
{
_Tp
x1
=
std
::
max
(
a
.
x
,
b
.
x
),
y1
=
std
::
max
(
a
.
y
,
b
.
y
);
a
.
width
=
std
::
min
(
a
.
x
+
a
.
width
,
b
.
x
+
b
.
width
)
-
x1
;
a
.
height
=
std
::
min
(
a
.
y
+
a
.
height
,
b
.
y
+
b
.
height
)
-
y1
;
a
.
x
=
x1
;
a
.
y
=
y1
;
if
(
a
.
width
<=
0
||
a
.
height
<=
0
)
a
=
Rect
();
return
a
;
}
template
<
typename
_Tp
>
static
inline
Rect_
<
_Tp
>&
operator
|=
(
Rect_
<
_Tp
>&
a
,
const
Rect_
<
_Tp
>&
b
)
{
_Tp
x1
=
std
::
min
(
a
.
x
,
b
.
x
),
y1
=
std
::
min
(
a
.
y
,
b
.
y
);
a
.
width
=
std
::
max
(
a
.
x
+
a
.
width
,
b
.
x
+
b
.
width
)
-
x1
;
a
.
height
=
std
::
max
(
a
.
y
+
a
.
height
,
b
.
y
+
b
.
height
)
-
y1
;
a
.
x
=
x1
;
a
.
y
=
y1
;
return
a
;
}
template
<
typename
_Tp
>
inline
Size_
<
_Tp
>
Rect_
<
_Tp
>::
size
()
const
{
return
Size_
<
_Tp
>
(
width
,
height
);
}
template
<
typename
_Tp
>
inline
_Tp
Rect_
<
_Tp
>::
area
()
const
{
return
width
*
height
;
}
template
<
typename
_Tp
>
template
<
typename
_Tp2
>
inline
Rect_
<
_Tp
>::
operator
Rect_
<
_Tp2
>
()
const
{
return
Rect_
<
_Tp2
>
(
saturate_cast
<
_Tp2
>
(
x
),
saturate_cast
<
_Tp2
>
(
y
),
saturate_cast
<
_Tp2
>
(
width
),
saturate_cast
<
_Tp2
>
(
height
));
}
template
<
typename
_Tp
>
inline
bool
Rect_
<
_Tp
>::
contains
(
const
Point_
<
_Tp
>&
pt
)
const
{
return
x
<=
pt
.
x
&&
pt
.
x
<
x
+
width
&&
y
<=
pt
.
y
&&
pt
.
y
<
y
+
height
;
}
template
<
typename
_Tp
>
static
inline
bool
operator
==
(
const
Rect_
<
_Tp
>&
a
,
const
Rect_
<
_Tp
>&
b
)
{
return
a
.
x
==
b
.
x
&&
a
.
y
==
b
.
y
&&
a
.
width
==
b
.
width
&&
a
.
height
==
b
.
height
;
}
template
<
typename
_Tp
>
static
inline
bool
operator
!=
(
const
Rect_
<
_Tp
>&
a
,
const
Rect_
<
_Tp
>&
b
)
{
return
a
.
x
!=
b
.
x
||
a
.
y
!=
b
.
y
||
a
.
width
!=
b
.
width
||
a
.
height
!=
b
.
height
;
}
template
<
typename
_Tp
>
static
inline
Rect_
<
_Tp
>
operator
+
(
const
Rect_
<
_Tp
>&
a
,
const
Point_
<
_Tp
>&
b
)
{
return
Rect_
<
_Tp
>
(
a
.
x
+
b
.
x
,
a
.
y
+
b
.
y
,
a
.
width
,
a
.
height
);
}
template
<
typename
_Tp
>
static
inline
Rect_
<
_Tp
>
operator
-
(
const
Rect_
<
_Tp
>&
a
,
const
Point_
<
_Tp
>&
b
)
{
return
Rect_
<
_Tp
>
(
a
.
x
-
b
.
x
,
a
.
y
-
b
.
y
,
a
.
width
,
a
.
height
);
}
template
<
typename
_Tp
>
static
inline
Rect_
<
_Tp
>
operator
+
(
const
Rect_
<
_Tp
>&
a
,
const
Size_
<
_Tp
>&
b
)
{
return
Rect_
<
_Tp
>
(
a
.
x
,
a
.
y
,
a
.
width
+
b
.
width
,
a
.
height
+
b
.
height
);
}
template
<
typename
_Tp
>
static
inline
Rect_
<
_Tp
>
operator
&
(
const
Rect_
<
_Tp
>&
a
,
const
Rect_
<
_Tp
>&
b
)
{
Rect_
<
_Tp
>
c
=
a
;
return
c
&=
b
;
}
template
<
typename
_Tp
>
static
inline
Rect_
<
_Tp
>
operator
|
(
const
Rect_
<
_Tp
>&
a
,
const
Rect_
<
_Tp
>&
b
)
{
Rect_
<
_Tp
>
c
=
a
;
return
c
|=
b
;
}
template
<
typename
_Tp
>
inline
bool
Point_
<
_Tp
>::
inside
(
const
Rect_
<
_Tp
>&
r
)
const
{
return
r
.
contains
(
*
this
);
}
inline
RotatedRect
::
RotatedRect
()
{
angle
=
0
;
}
inline
RotatedRect
::
RotatedRect
(
const
Point2f
&
_center
,
const
Size2f
&
_size
,
float
_angle
)
:
center
(
_center
),
size
(
_size
),
angle
(
_angle
)
{}
//////////////////////////////// Scalar_ ///////////////////////////////
template
<
typename
_Tp
>
inline
Scalar_
<
_Tp
>::
Scalar_
()
{
this
->
val
[
0
]
=
this
->
val
[
1
]
=
this
->
val
[
2
]
=
this
->
val
[
3
]
=
0
;
}
template
<
typename
_Tp
>
inline
Scalar_
<
_Tp
>::
Scalar_
(
_Tp
v0
,
_Tp
v1
,
_Tp
v2
,
_Tp
v3
)
{
this
->
val
[
0
]
=
v0
;
this
->
val
[
1
]
=
v1
;
this
->
val
[
2
]
=
v2
;
this
->
val
[
3
]
=
v3
;
}
template
<
typename
_Tp
>
template
<
typename
_Tp2
,
int
cn
>
inline
Scalar_
<
_Tp
>::
Scalar_
(
const
Vec
<
_Tp2
,
cn
>&
v
)
{
int
i
;
for
(
i
=
0
;
i
<
(
cn
<
4
?
cn
:
4
);
i
++
)
this
->
val
[
i
]
=
cv
::
saturate_cast
<
_Tp
>
(
v
.
val
[
i
]);
for
(
;
i
<
4
;
i
++
)
this
->
val
[
i
]
=
0
;
}
template
<
typename
_Tp
>
inline
Scalar_
<
_Tp
>::
Scalar_
(
_Tp
v0
)
{
this
->
val
[
0
]
=
v0
;
this
->
val
[
1
]
=
this
->
val
[
2
]
=
this
->
val
[
3
]
=
0
;
}
template
<
typename
_Tp
>
inline
Scalar_
<
_Tp
>
Scalar_
<
_Tp
>::
all
(
_Tp
v0
)
{
return
Scalar_
<
_Tp
>
(
v0
,
v0
,
v0
,
v0
);
}
template
<
typename
_Tp
>
template
<
typename
T2
>
inline
Scalar_
<
_Tp
>::
operator
Scalar_
<
T2
>
()
const
{
return
Scalar_
<
T2
>
(
saturate_cast
<
T2
>
(
this
->
val
[
0
]),
saturate_cast
<
T2
>
(
this
->
val
[
1
]),
saturate_cast
<
T2
>
(
this
->
val
[
2
]),
saturate_cast
<
T2
>
(
this
->
val
[
3
]));
}
template
<
typename
_Tp
>
static
inline
Scalar_
<
_Tp
>&
operator
+=
(
Scalar_
<
_Tp
>&
a
,
const
Scalar_
<
_Tp
>&
b
)
{
a
.
val
[
0
]
=
saturate_cast
<
_Tp
>
(
a
.
val
[
0
]
+
b
.
val
[
0
]);
a
.
val
[
1
]
=
saturate_cast
<
_Tp
>
(
a
.
val
[
1
]
+
b
.
val
[
1
]);
a
.
val
[
2
]
=
saturate_cast
<
_Tp
>
(
a
.
val
[
2
]
+
b
.
val
[
2
]);
a
.
val
[
3
]
=
saturate_cast
<
_Tp
>
(
a
.
val
[
3
]
+
b
.
val
[
3
]);
return
a
;
}
template
<
typename
_Tp
>
static
inline
Scalar_
<
_Tp
>&
operator
-=
(
Scalar_
<
_Tp
>&
a
,
const
Scalar_
<
_Tp
>&
b
)
{
a
.
val
[
0
]
=
saturate_cast
<
_Tp
>
(
a
.
val
[
0
]
-
b
.
val
[
0
]);
a
.
val
[
1
]
=
saturate_cast
<
_Tp
>
(
a
.
val
[
1
]
-
b
.
val
[
1
]);
a
.
val
[
2
]
=
saturate_cast
<
_Tp
>
(
a
.
val
[
2
]
-
b
.
val
[
2
]);
a
.
val
[
3
]
=
saturate_cast
<
_Tp
>
(
a
.
val
[
3
]
-
b
.
val
[
3
]);
return
a
;
}
template
<
typename
_Tp
>
static
inline
Scalar_
<
_Tp
>&
operator
*=
(
Scalar_
<
_Tp
>&
a
,
_Tp
v
)
{
a
.
val
[
0
]
=
saturate_cast
<
_Tp
>
(
a
.
val
[
0
]
*
v
);
a
.
val
[
1
]
=
saturate_cast
<
_Tp
>
(
a
.
val
[
1
]
*
v
);
a
.
val
[
2
]
=
saturate_cast
<
_Tp
>
(
a
.
val
[
2
]
*
v
);
a
.
val
[
3
]
=
saturate_cast
<
_Tp
>
(
a
.
val
[
3
]
*
v
);
return
a
;
}
template
<
typename
_Tp
>
inline
Scalar_
<
_Tp
>
Scalar_
<
_Tp
>::
mul
(
const
Scalar_
<
_Tp
>&
t
,
double
scale
)
const
{
return
Scalar_
<
_Tp
>
(
saturate_cast
<
_Tp
>
(
this
->
val
[
0
]
*
t
.
val
[
0
]
*
scale
),
saturate_cast
<
_Tp
>
(
this
->
val
[
1
]
*
t
.
val
[
1
]
*
scale
),
saturate_cast
<
_Tp
>
(
this
->
val
[
2
]
*
t
.
val
[
2
]
*
scale
),
saturate_cast
<
_Tp
>
(
this
->
val
[
3
]
*
t
.
val
[
3
]
*
scale
));
}
template
<
typename
_Tp
>
static
inline
bool
operator
==
(
const
Scalar_
<
_Tp
>&
a
,
const
Scalar_
<
_Tp
>&
b
)
{
return
a
.
val
[
0
]
==
b
.
val
[
0
]
&&
a
.
val
[
1
]
==
b
.
val
[
1
]
&&
a
.
val
[
2
]
==
b
.
val
[
2
]
&&
a
.
val
[
3
]
==
b
.
val
[
3
];
}
template
<
typename
_Tp
>
static
inline
bool
operator
!=
(
const
Scalar_
<
_Tp
>&
a
,
const
Scalar_
<
_Tp
>&
b
)
{
return
a
.
val
[
0
]
!=
b
.
val
[
0
]
||
a
.
val
[
1
]
!=
b
.
val
[
1
]
||
a
.
val
[
2
]
!=
b
.
val
[
2
]
||
a
.
val
[
3
]
!=
b
.
val
[
3
];
}
template
<
typename
_Tp
>
static
inline
Scalar_
<
_Tp
>
operator
+
(
const
Scalar_
<
_Tp
>&
a
,
const
Scalar_
<
_Tp
>&
b
)
{
return
Scalar_
<
_Tp
>
(
saturate_cast
<
_Tp
>
(
a
.
val
[
0
]
+
b
.
val
[
0
]),
saturate_cast
<
_Tp
>
(
a
.
val
[
1
]
+
b
.
val
[
1
]),
saturate_cast
<
_Tp
>
(
a
.
val
[
2
]
+
b
.
val
[
2
]),
saturate_cast
<
_Tp
>
(
a
.
val
[
3
]
+
b
.
val
[
3
]));
}
template
<
typename
_Tp
>
static
inline
Scalar_
<
_Tp
>
operator
-
(
const
Scalar_
<
_Tp
>&
a
,
const
Scalar_
<
_Tp
>&
b
)
{
return
Scalar_
<
_Tp
>
(
saturate_cast
<
_Tp
>
(
a
.
val
[
0
]
-
b
.
val
[
0
]),
saturate_cast
<
_Tp
>
(
a
.
val
[
1
]
-
b
.
val
[
1
]),
saturate_cast
<
_Tp
>
(
a
.
val
[
2
]
-
b
.
val
[
2
]),
saturate_cast
<
_Tp
>
(
a
.
val
[
3
]
-
b
.
val
[
3
]));
}
template
<
typename
_Tp
>
static
inline
Scalar_
<
_Tp
>
operator
*
(
const
Scalar_
<
_Tp
>&
a
,
_Tp
alpha
)
{
return
Scalar_
<
_Tp
>
(
saturate_cast
<
_Tp
>
(
a
.
val
[
0
]
*
alpha
),
saturate_cast
<
_Tp
>
(
a
.
val
[
1
]
*
alpha
),
saturate_cast
<
_Tp
>
(
a
.
val
[
2
]
*
alpha
),
saturate_cast
<
_Tp
>
(
a
.
val
[
3
]
*
alpha
));
}
template
<
typename
_Tp
>
static
inline
Scalar_
<
_Tp
>
operator
*
(
_Tp
alpha
,
const
Scalar_
<
_Tp
>&
a
)
{
return
a
*
alpha
;
}
template
<
typename
_Tp
>
static
inline
Scalar_
<
_Tp
>
operator
-
(
const
Scalar_
<
_Tp
>&
a
)
{
return
Scalar_
<
_Tp
>
(
saturate_cast
<
_Tp
>
(
-
a
.
val
[
0
]),
saturate_cast
<
_Tp
>
(
-
a
.
val
[
1
]),
saturate_cast
<
_Tp
>
(
-
a
.
val
[
2
]),
saturate_cast
<
_Tp
>
(
-
a
.
val
[
3
]));
}
template
<
typename
_Tp
>
static
inline
Scalar_
<
_Tp
>
operator
*
(
const
Scalar_
<
_Tp
>&
a
,
const
Scalar_
<
_Tp
>&
b
)
{
return
Scalar_
<
_Tp
>
(
saturate_cast
<
_Tp
>
(
a
[
0
]
*
b
[
0
]
-
a
[
1
]
*
b
[
1
]
-
a
[
2
]
*
b
[
2
]
-
a
[
3
]
*
b
[
3
]),
saturate_cast
<
_Tp
>
(
a
[
0
]
*
b
[
1
]
+
a
[
1
]
*
b
[
0
]
+
a
[
2
]
*
b
[
3
]
-
a
[
3
]
*
b
[
2
]),
saturate_cast
<
_Tp
>
(
a
[
0
]
*
b
[
2
]
-
a
[
1
]
*
b
[
3
]
+
a
[
2
]
*
b
[
0
]
+
a
[
3
]
*
b
[
1
]),
saturate_cast
<
_Tp
>
(
a
[
0
]
*
b
[
3
]
+
a
[
1
]
*
b
[
2
]
-
a
[
2
]
*
b
[
1
]
+
a
[
3
]
*
b
[
0
]));
}
template
<
typename
_Tp
>
static
inline
Scalar_
<
_Tp
>&
operator
*=
(
Scalar_
<
_Tp
>&
a
,
const
Scalar_
<
_Tp
>&
b
)
{
a
=
a
*
b
;
return
a
;
}
template
<
typename
_Tp
>
inline
Scalar_
<
_Tp
>
Scalar_
<
_Tp
>::
conj
()
const
{
return
Scalar_
<
_Tp
>
(
saturate_cast
<
_Tp
>
(
this
->
val
[
0
]),
saturate_cast
<
_Tp
>
(
-
this
->
val
[
1
]),
saturate_cast
<
_Tp
>
(
-
this
->
val
[
2
]),
saturate_cast
<
_Tp
>
(
-
this
->
val
[
3
]));
}
template
<
typename
_Tp
>
inline
bool
Scalar_
<
_Tp
>::
isReal
()
const
{
return
this
->
val
[
1
]
==
0
&&
this
->
val
[
2
]
==
0
&&
this
->
val
[
3
]
==
0
;
}
template
<
typename
_Tp
>
static
inline
Scalar_
<
_Tp
>
operator
/
(
const
Scalar_
<
_Tp
>&
a
,
_Tp
alpha
)
{
return
Scalar_
<
_Tp
>
(
saturate_cast
<
_Tp
>
(
a
.
val
[
0
]
/
alpha
),
saturate_cast
<
_Tp
>
(
a
.
val
[
1
]
/
alpha
),
saturate_cast
<
_Tp
>
(
a
.
val
[
2
]
/
alpha
),
saturate_cast
<
_Tp
>
(
a
.
val
[
3
]
/
alpha
));
}
template
<
typename
_Tp
>
static
inline
Scalar_
<
float
>
operator
/
(
const
Scalar_
<
float
>&
a
,
float
alpha
)
{
float
s
=
1
/
alpha
;
return
Scalar_
<
float
>
(
a
.
val
[
0
]
*
s
,
a
.
val
[
1
]
*
s
,
a
.
val
[
2
]
*
s
,
a
.
val
[
3
]
*
s
);
}
template
<
typename
_Tp
>
static
inline
Scalar_
<
double
>
operator
/
(
const
Scalar_
<
double
>&
a
,
double
alpha
)
{
double
s
=
1
/
alpha
;
return
Scalar_
<
double
>
(
a
.
val
[
0
]
*
s
,
a
.
val
[
1
]
*
s
,
a
.
val
[
2
]
*
s
,
a
.
val
[
3
]
*
s
);
}
template
<
typename
_Tp
>
static
inline
Scalar_
<
_Tp
>&
operator
/=
(
Scalar_
<
_Tp
>&
a
,
_Tp
alpha
)
{
a
=
a
/
alpha
;
return
a
;
}
template
<
typename
_Tp
>
static
inline
Scalar_
<
_Tp
>
operator
/
(
_Tp
a
,
const
Scalar_
<
_Tp
>&
b
)
{
_Tp
s
=
a
/
(
b
[
0
]
*
b
[
0
]
+
b
[
1
]
*
b
[
1
]
+
b
[
2
]
*
b
[
2
]
+
b
[
3
]
*
b
[
3
]);
return
b
.
conj
()
*
s
;
}
template
<
typename
_Tp
>
static
inline
Scalar_
<
_Tp
>
operator
/
(
const
Scalar_
<
_Tp
>&
a
,
const
Scalar_
<
_Tp
>&
b
)
{
return
a
*
((
_Tp
)
1
/
b
);
}
template
<
typename
_Tp
>
static
inline
Scalar_
<
_Tp
>&
operator
/=
(
Scalar_
<
_Tp
>&
a
,
const
Scalar_
<
_Tp
>&
b
)
{
a
=
a
/
b
;
return
a
;
}
//////////////////////////////// Range /////////////////////////////////
inline
Range
::
Range
()
:
start
(
0
),
end
(
0
)
{}
inline
Range
::
Range
(
int
_start
,
int
_end
)
:
start
(
_start
),
end
(
_end
)
{}
inline
int
Range
::
size
()
const
{
return
end
-
start
;
}
inline
bool
Range
::
empty
()
const
{
return
start
==
end
;
}
inline
Range
Range
::
all
()
{
return
Range
(
INT_MIN
,
INT_MAX
);
}
static
inline
bool
operator
==
(
const
Range
&
r1
,
const
Range
&
r2
)
{
return
r1
.
start
==
r2
.
start
&&
r1
.
end
==
r2
.
end
;
}
static
inline
bool
operator
!=
(
const
Range
&
r1
,
const
Range
&
r2
)
{
return
!
(
r1
==
r2
);
}
static
inline
bool
operator
!
(
const
Range
&
r
)
{
return
r
.
start
==
r
.
end
;
}
static
inline
Range
operator
&
(
const
Range
&
r1
,
const
Range
&
r2
)
{
Range
r
(
std
::
max
(
r1
.
start
,
r2
.
start
),
std
::
min
(
r1
.
end
,
r2
.
end
));
r
.
end
=
std
::
max
(
r
.
end
,
r
.
start
);
return
r
;
}
static
inline
Range
&
operator
&=
(
Range
&
r1
,
const
Range
&
r2
)
{
r1
=
r1
&
r2
;
return
r1
;
}
static
inline
Range
operator
+
(
const
Range
&
r1
,
int
delta
)
{
return
Range
(
r1
.
start
+
delta
,
r1
.
end
+
delta
);
}
static
inline
Range
operator
+
(
int
delta
,
const
Range
&
r1
)
{
return
Range
(
r1
.
start
+
delta
,
r1
.
end
+
delta
);
}
static
inline
Range
operator
-
(
const
Range
&
r1
,
int
delta
)
{
return
r1
+
(
-
delta
);
}
//////////////////////////////// Vector ////////////////////////////////
...
...
modules/core/include/opencv2/core/types.hpp
View file @
489bd59b
...
...
@@ -74,7 +74,7 @@ public:
//! constructors
Complex
();
Complex
(
_Tp
_re
,
_Tp
_im
=
0
);
Complex
(
_Tp
_re
,
_Tp
_im
=
0
);
//! conversion to another data type
template
<
typename
T2
>
operator
Complex
<
T2
>
()
const
;
...
...
@@ -82,11 +82,6 @@ public:
Complex
conj
()
const
;
_Tp
re
,
im
;
//< the real and the imaginary parts
#ifndef OPENCV_NOSTL
Complex
(
const
std
::
complex
<
_Tp
>&
c
);
operator
std
::
complex
<
_Tp
>
()
const
;
#endif
};
/*!
...
...
@@ -98,24 +93,6 @@ typedef Complex<double> Complexd;
/*!
traits
*/
#ifndef OPENCV_NOSTL
template
<
typename
_Tp
>
class
DataType
<
std
::
complex
<
_Tp
>
>
{
public
:
typedef
std
::
complex
<
_Tp
>
value_type
;
typedef
value_type
work_type
;
typedef
_Tp
channel_type
;
enum
{
generic_type
=
0
,
depth
=
DataType
<
channel_type
>::
depth
,
channels
=
2
,
fmt
=
DataType
<
channel_type
>::
fmt
+
((
channels
-
1
)
<<
8
),
type
=
CV_MAKETYPE
(
depth
,
channels
)
};
typedef
Vec
<
channel_type
,
channels
>
vec_type
;
};
#endif // OPENCV_NOSTL
template
<
typename
_Tp
>
class
DataType
<
Complex
<
_Tp
>
>
{
public
:
...
...
@@ -422,6 +399,26 @@ public:
float
angle
;
//< the rotation angle. When the angle is 0, 90, 180, 270 etc., the rectangle becomes an up-right rectangle.
};
/*!
traits
*/
template
<>
class
DataType
<
RotatedRect
>
{
public
:
typedef
RotatedRect
value_type
;
typedef
value_type
work_type
;
typedef
float
channel_type
;
enum
{
generic_type
=
0
,
depth
=
DataType
<
channel_type
>::
depth
,
channels
=
(
int
)
sizeof
(
value_type
)
/
sizeof
(
channel_type
),
// 5
fmt
=
DataType
<
channel_type
>::
fmt
+
((
channels
-
1
)
<<
8
),
type
=
CV_MAKETYPE
(
depth
,
channels
)
};
typedef
Vec
<
channel_type
,
channels
>
vec_type
;
};
//////////////////////////////// Range /////////////////////////////////
...
...
@@ -598,13 +595,6 @@ public:
};
inline
KeyPoint
::
KeyPoint
()
:
pt
(
0
,
0
),
size
(
0
),
angle
(
-
1
),
response
(
0
),
octave
(
0
),
class_id
(
-
1
)
{}
inline
KeyPoint
::
KeyPoint
(
Point2f
_pt
,
float
_size
,
float
_angle
,
float
_response
,
int
_octave
,
int
_class_id
)
:
pt
(
_pt
),
size
(
_size
),
angle
(
_angle
),
response
(
_response
),
octave
(
_octave
),
class_id
(
_class_id
)
{}
inline
KeyPoint
::
KeyPoint
(
float
x
,
float
y
,
float
_size
,
float
_angle
,
float
_response
,
int
_octave
,
int
_class_id
)
:
pt
(
x
,
y
),
size
(
_size
),
angle
(
_angle
),
response
(
_response
),
octave
(
_octave
),
class_id
(
_class_id
)
{}
//////////////////////////////// DMatch /////////////////////////////////
...
...
@@ -648,13 +638,1204 @@ public:
typedef
Vec
<
channel_type
,
channels
>
vec_type
;
};
inline
DMatch
::
DMatch
()
:
queryIdx
(
-
1
),
trainIdx
(
-
1
),
imgIdx
(
-
1
),
distance
(
FLT_MAX
)
{}
inline
DMatch
::
DMatch
(
int
_queryIdx
,
int
_trainIdx
,
float
_distance
)
/////////////////////////////////////////////////////////////////////////
///////////////////////////// Implementation ////////////////////////////
/////////////////////////////////////////////////////////////////////////
//////////////////////////////// Complex ////////////////////////////////
template
<
typename
_Tp
>
inline
Complex
<
_Tp
>::
Complex
()
:
re
(
0
),
im
(
0
)
{}
template
<
typename
_Tp
>
inline
Complex
<
_Tp
>::
Complex
(
_Tp
_re
,
_Tp
_im
)
:
re
(
_re
),
im
(
_im
)
{}
template
<
typename
_Tp
>
template
<
typename
T2
>
inline
Complex
<
_Tp
>::
operator
Complex
<
T2
>
()
const
{
return
Complex
<
T2
>
(
saturate_cast
<
T2
>
(
re
),
saturate_cast
<
T2
>
(
im
));
}
template
<
typename
_Tp
>
inline
Complex
<
_Tp
>
Complex
<
_Tp
>::
conj
()
const
{
return
Complex
<
_Tp
>
(
re
,
-
im
);
}
template
<
typename
_Tp
>
static
inline
bool
operator
==
(
const
Complex
<
_Tp
>&
a
,
const
Complex
<
_Tp
>&
b
)
{
return
a
.
re
==
b
.
re
&&
a
.
im
==
b
.
im
;
}
template
<
typename
_Tp
>
static
inline
bool
operator
!=
(
const
Complex
<
_Tp
>&
a
,
const
Complex
<
_Tp
>&
b
)
{
return
a
.
re
!=
b
.
re
||
a
.
im
!=
b
.
im
;
}
template
<
typename
_Tp
>
static
inline
Complex
<
_Tp
>
operator
+
(
const
Complex
<
_Tp
>&
a
,
const
Complex
<
_Tp
>&
b
)
{
return
Complex
<
_Tp
>
(
a
.
re
+
b
.
re
,
a
.
im
+
b
.
im
);
}
template
<
typename
_Tp
>
static
inline
Complex
<
_Tp
>&
operator
+=
(
Complex
<
_Tp
>&
a
,
const
Complex
<
_Tp
>&
b
)
{
a
.
re
+=
b
.
re
;
a
.
im
+=
b
.
im
;
return
a
;
}
template
<
typename
_Tp
>
static
inline
Complex
<
_Tp
>
operator
-
(
const
Complex
<
_Tp
>&
a
,
const
Complex
<
_Tp
>&
b
)
{
return
Complex
<
_Tp
>
(
a
.
re
-
b
.
re
,
a
.
im
-
b
.
im
);
}
template
<
typename
_Tp
>
static
inline
Complex
<
_Tp
>&
operator
-=
(
Complex
<
_Tp
>&
a
,
const
Complex
<
_Tp
>&
b
)
{
a
.
re
-=
b
.
re
;
a
.
im
-=
b
.
im
;
return
a
;
}
template
<
typename
_Tp
>
static
inline
Complex
<
_Tp
>
operator
-
(
const
Complex
<
_Tp
>&
a
)
{
return
Complex
<
_Tp
>
(
-
a
.
re
,
-
a
.
im
);
}
template
<
typename
_Tp
>
static
inline
Complex
<
_Tp
>
operator
*
(
const
Complex
<
_Tp
>&
a
,
const
Complex
<
_Tp
>&
b
)
{
return
Complex
<
_Tp
>
(
a
.
re
*
b
.
re
-
a
.
im
*
b
.
im
,
a
.
re
*
b
.
im
+
a
.
im
*
b
.
re
);
}
template
<
typename
_Tp
>
static
inline
Complex
<
_Tp
>
operator
*
(
const
Complex
<
_Tp
>&
a
,
_Tp
b
)
{
return
Complex
<
_Tp
>
(
a
.
re
*
b
,
a
.
im
*
b
);
}
template
<
typename
_Tp
>
static
inline
Complex
<
_Tp
>
operator
*
(
_Tp
b
,
const
Complex
<
_Tp
>&
a
)
{
return
Complex
<
_Tp
>
(
a
.
re
*
b
,
a
.
im
*
b
);
}
template
<
typename
_Tp
>
static
inline
Complex
<
_Tp
>
operator
+
(
const
Complex
<
_Tp
>&
a
,
_Tp
b
)
{
return
Complex
<
_Tp
>
(
a
.
re
+
b
,
a
.
im
);
}
template
<
typename
_Tp
>
static
inline
Complex
<
_Tp
>
operator
-
(
const
Complex
<
_Tp
>&
a
,
_Tp
b
)
{
return
Complex
<
_Tp
>
(
a
.
re
-
b
,
a
.
im
);
}
template
<
typename
_Tp
>
static
inline
Complex
<
_Tp
>
operator
+
(
_Tp
b
,
const
Complex
<
_Tp
>&
a
)
{
return
Complex
<
_Tp
>
(
a
.
re
+
b
,
a
.
im
);
}
template
<
typename
_Tp
>
static
inline
Complex
<
_Tp
>
operator
-
(
_Tp
b
,
const
Complex
<
_Tp
>&
a
)
{
return
Complex
<
_Tp
>
(
b
-
a
.
re
,
-
a
.
im
);
}
template
<
typename
_Tp
>
static
inline
Complex
<
_Tp
>&
operator
+=
(
Complex
<
_Tp
>&
a
,
_Tp
b
)
{
a
.
re
+=
b
;
return
a
;
}
template
<
typename
_Tp
>
static
inline
Complex
<
_Tp
>&
operator
-=
(
Complex
<
_Tp
>&
a
,
_Tp
b
)
{
a
.
re
-=
b
;
return
a
;
}
template
<
typename
_Tp
>
static
inline
Complex
<
_Tp
>&
operator
*=
(
Complex
<
_Tp
>&
a
,
_Tp
b
)
{
a
.
re
*=
b
;
a
.
im
*=
b
;
return
a
;
}
template
<
typename
_Tp
>
static
inline
double
abs
(
const
Complex
<
_Tp
>&
a
)
{
return
std
::
sqrt
(
(
double
)
a
.
re
*
a
.
re
+
(
double
)
a
.
im
*
a
.
im
);
}
template
<
typename
_Tp
>
static
inline
Complex
<
_Tp
>
operator
/
(
const
Complex
<
_Tp
>&
a
,
const
Complex
<
_Tp
>&
b
)
{
double
t
=
1.
/
((
double
)
b
.
re
*
b
.
re
+
(
double
)
b
.
im
*
b
.
im
);
return
Complex
<
_Tp
>
(
(
_Tp
)((
a
.
re
*
b
.
re
+
a
.
im
*
b
.
im
)
*
t
),
(
_Tp
)((
-
a
.
re
*
b
.
im
+
a
.
im
*
b
.
re
)
*
t
)
);
}
template
<
typename
_Tp
>
static
inline
Complex
<
_Tp
>&
operator
/=
(
Complex
<
_Tp
>&
a
,
const
Complex
<
_Tp
>&
b
)
{
return
(
a
=
a
/
b
);
}
template
<
typename
_Tp
>
static
inline
Complex
<
_Tp
>
operator
/
(
const
Complex
<
_Tp
>&
a
,
_Tp
b
)
{
_Tp
t
=
(
_Tp
)
1
/
b
;
return
Complex
<
_Tp
>
(
a
.
re
*
t
,
a
.
im
*
t
);
}
template
<
typename
_Tp
>
static
inline
Complex
<
_Tp
>
operator
/
(
_Tp
b
,
const
Complex
<
_Tp
>&
a
)
{
return
Complex
<
_Tp
>
(
b
)
/
a
;
}
template
<
typename
_Tp
>
static
inline
Complex
<
_Tp
>
operator
/=
(
const
Complex
<
_Tp
>&
a
,
_Tp
b
)
{
_Tp
t
=
(
_Tp
)
1
/
b
;
a
.
re
*=
t
;
a
.
im
*=
t
;
return
a
;
}
//////////////////////////////// 2D Point ///////////////////////////////
template
<
typename
_Tp
>
inline
Point_
<
_Tp
>::
Point_
()
:
x
(
0
),
y
(
0
)
{}
template
<
typename
_Tp
>
inline
Point_
<
_Tp
>::
Point_
(
_Tp
_x
,
_Tp
_y
)
:
x
(
_x
),
y
(
_y
)
{}
template
<
typename
_Tp
>
inline
Point_
<
_Tp
>::
Point_
(
const
Point_
&
pt
)
:
x
(
pt
.
x
),
y
(
pt
.
y
)
{}
template
<
typename
_Tp
>
inline
Point_
<
_Tp
>::
Point_
(
const
Size_
<
_Tp
>&
sz
)
:
x
(
sz
.
width
),
y
(
sz
.
height
)
{}
template
<
typename
_Tp
>
inline
Point_
<
_Tp
>::
Point_
(
const
Vec
<
_Tp
,
2
>&
v
)
:
x
(
v
[
0
]),
y
(
v
[
1
])
{}
template
<
typename
_Tp
>
inline
Point_
<
_Tp
>&
Point_
<
_Tp
>::
operator
=
(
const
Point_
&
pt
)
{
x
=
pt
.
x
;
y
=
pt
.
y
;
return
*
this
;
}
template
<
typename
_Tp
>
template
<
typename
_Tp2
>
inline
Point_
<
_Tp
>::
operator
Point_
<
_Tp2
>
()
const
{
return
Point_
<
_Tp2
>
(
saturate_cast
<
_Tp2
>
(
x
),
saturate_cast
<
_Tp2
>
(
y
));
}
template
<
typename
_Tp
>
inline
Point_
<
_Tp
>::
operator
Vec
<
_Tp
,
2
>
()
const
{
return
Vec
<
_Tp
,
2
>
(
x
,
y
);
}
template
<
typename
_Tp
>
inline
_Tp
Point_
<
_Tp
>::
dot
(
const
Point_
&
pt
)
const
{
return
saturate_cast
<
_Tp
>
(
x
*
pt
.
x
+
y
*
pt
.
y
);
}
template
<
typename
_Tp
>
inline
double
Point_
<
_Tp
>::
ddot
(
const
Point_
&
pt
)
const
{
return
(
double
)
x
*
pt
.
x
+
(
double
)
y
*
pt
.
y
;
}
template
<
typename
_Tp
>
inline
double
Point_
<
_Tp
>::
cross
(
const
Point_
&
pt
)
const
{
return
(
double
)
x
*
pt
.
y
-
(
double
)
y
*
pt
.
x
;
}
template
<
typename
_Tp
>
inline
bool
Point_
<
_Tp
>::
inside
(
const
Rect_
<
_Tp
>&
r
)
const
{
return
r
.
contains
(
*
this
);
}
template
<
typename
_Tp
>
static
inline
Point_
<
_Tp
>&
operator
+=
(
Point_
<
_Tp
>&
a
,
const
Point_
<
_Tp
>&
b
)
{
a
.
x
+=
b
.
x
;
a
.
y
+=
b
.
y
;
return
a
;
}
template
<
typename
_Tp
>
static
inline
Point_
<
_Tp
>&
operator
-=
(
Point_
<
_Tp
>&
a
,
const
Point_
<
_Tp
>&
b
)
{
a
.
x
-=
b
.
x
;
a
.
y
-=
b
.
y
;
return
a
;
}
template
<
typename
_Tp
>
static
inline
Point_
<
_Tp
>&
operator
*=
(
Point_
<
_Tp
>&
a
,
int
b
)
{
a
.
x
=
saturate_cast
<
_Tp
>
(
a
.
x
*
b
);
a
.
y
=
saturate_cast
<
_Tp
>
(
a
.
y
*
b
);
return
a
;
}
template
<
typename
_Tp
>
static
inline
Point_
<
_Tp
>&
operator
*=
(
Point_
<
_Tp
>&
a
,
float
b
)
{
a
.
x
=
saturate_cast
<
_Tp
>
(
a
.
x
*
b
);
a
.
y
=
saturate_cast
<
_Tp
>
(
a
.
y
*
b
);
return
a
;
}
template
<
typename
_Tp
>
static
inline
Point_
<
_Tp
>&
operator
*=
(
Point_
<
_Tp
>&
a
,
double
b
)
{
a
.
x
=
saturate_cast
<
_Tp
>
(
a
.
x
*
b
);
a
.
y
=
saturate_cast
<
_Tp
>
(
a
.
y
*
b
);
return
a
;
}
template
<
typename
_Tp
>
static
inline
double
norm
(
const
Point_
<
_Tp
>&
pt
)
{
return
std
::
sqrt
((
double
)
pt
.
x
*
pt
.
x
+
(
double
)
pt
.
y
*
pt
.
y
);
}
template
<
typename
_Tp
>
static
inline
bool
operator
==
(
const
Point_
<
_Tp
>&
a
,
const
Point_
<
_Tp
>&
b
)
{
return
a
.
x
==
b
.
x
&&
a
.
y
==
b
.
y
;
}
template
<
typename
_Tp
>
static
inline
bool
operator
!=
(
const
Point_
<
_Tp
>&
a
,
const
Point_
<
_Tp
>&
b
)
{
return
a
.
x
!=
b
.
x
||
a
.
y
!=
b
.
y
;
}
template
<
typename
_Tp
>
static
inline
Point_
<
_Tp
>
operator
+
(
const
Point_
<
_Tp
>&
a
,
const
Point_
<
_Tp
>&
b
)
{
return
Point_
<
_Tp
>
(
saturate_cast
<
_Tp
>
(
a
.
x
+
b
.
x
),
saturate_cast
<
_Tp
>
(
a
.
y
+
b
.
y
)
);
}
template
<
typename
_Tp
>
static
inline
Point_
<
_Tp
>
operator
-
(
const
Point_
<
_Tp
>&
a
,
const
Point_
<
_Tp
>&
b
)
{
return
Point_
<
_Tp
>
(
saturate_cast
<
_Tp
>
(
a
.
x
-
b
.
x
),
saturate_cast
<
_Tp
>
(
a
.
y
-
b
.
y
)
);
}
template
<
typename
_Tp
>
static
inline
Point_
<
_Tp
>
operator
-
(
const
Point_
<
_Tp
>&
a
)
{
return
Point_
<
_Tp
>
(
saturate_cast
<
_Tp
>
(
-
a
.
x
),
saturate_cast
<
_Tp
>
(
-
a
.
y
)
);
}
template
<
typename
_Tp
>
static
inline
Point_
<
_Tp
>
operator
*
(
const
Point_
<
_Tp
>&
a
,
int
b
)
{
return
Point_
<
_Tp
>
(
saturate_cast
<
_Tp
>
(
a
.
x
*
b
),
saturate_cast
<
_Tp
>
(
a
.
y
*
b
)
);
}
template
<
typename
_Tp
>
static
inline
Point_
<
_Tp
>
operator
*
(
int
a
,
const
Point_
<
_Tp
>&
b
)
{
return
Point_
<
_Tp
>
(
saturate_cast
<
_Tp
>
(
b
.
x
*
a
),
saturate_cast
<
_Tp
>
(
b
.
y
*
a
)
);
}
template
<
typename
_Tp
>
static
inline
Point_
<
_Tp
>
operator
*
(
const
Point_
<
_Tp
>&
a
,
float
b
)
{
return
Point_
<
_Tp
>
(
saturate_cast
<
_Tp
>
(
a
.
x
*
b
),
saturate_cast
<
_Tp
>
(
a
.
y
*
b
)
);
}
template
<
typename
_Tp
>
static
inline
Point_
<
_Tp
>
operator
*
(
float
a
,
const
Point_
<
_Tp
>&
b
)
{
return
Point_
<
_Tp
>
(
saturate_cast
<
_Tp
>
(
b
.
x
*
a
),
saturate_cast
<
_Tp
>
(
b
.
y
*
a
)
);
}
template
<
typename
_Tp
>
static
inline
Point_
<
_Tp
>
operator
*
(
const
Point_
<
_Tp
>&
a
,
double
b
)
{
return
Point_
<
_Tp
>
(
saturate_cast
<
_Tp
>
(
a
.
x
*
b
),
saturate_cast
<
_Tp
>
(
a
.
y
*
b
)
);
}
template
<
typename
_Tp
>
static
inline
Point_
<
_Tp
>
operator
*
(
double
a
,
const
Point_
<
_Tp
>&
b
)
{
return
Point_
<
_Tp
>
(
saturate_cast
<
_Tp
>
(
b
.
x
*
a
),
saturate_cast
<
_Tp
>
(
b
.
y
*
a
)
);
}
template
<
typename
_Tp
>
static
inline
Point_
<
_Tp
>
operator
*
(
const
Matx
<
_Tp
,
2
,
2
>&
a
,
const
Point_
<
_Tp
>&
b
)
{
Matx
<
_Tp
,
2
,
1
>
tmp
=
a
*
Vec
<
_Tp
,
2
>
(
b
.
x
,
b
.
y
);
return
Point_
<
_Tp
>
(
tmp
.
val
[
0
],
tmp
.
val
[
1
]);
}
template
<
typename
_Tp
>
static
inline
Point3_
<
_Tp
>
operator
*
(
const
Matx
<
_Tp
,
3
,
3
>&
a
,
const
Point_
<
_Tp
>&
b
)
{
Matx
<
_Tp
,
3
,
1
>
tmp
=
a
*
Vec
<
_Tp
,
3
>
(
b
.
x
,
b
.
y
,
1
);
return
Point3_
<
_Tp
>
(
tmp
.
val
[
0
],
tmp
.
val
[
1
],
tmp
.
val
[
2
]);
}
//////////////////////////////// 3D Point ///////////////////////////////
template
<
typename
_Tp
>
inline
Point3_
<
_Tp
>::
Point3_
()
:
x
(
0
),
y
(
0
),
z
(
0
)
{}
template
<
typename
_Tp
>
inline
Point3_
<
_Tp
>::
Point3_
(
_Tp
_x
,
_Tp
_y
,
_Tp
_z
)
:
x
(
_x
),
y
(
_y
),
z
(
_z
)
{}
template
<
typename
_Tp
>
inline
Point3_
<
_Tp
>::
Point3_
(
const
Point3_
&
pt
)
:
x
(
pt
.
x
),
y
(
pt
.
y
),
z
(
pt
.
z
)
{}
template
<
typename
_Tp
>
inline
Point3_
<
_Tp
>::
Point3_
(
const
Point_
<
_Tp
>&
pt
)
:
x
(
pt
.
x
),
y
(
pt
.
y
),
z
(
_Tp
())
{}
template
<
typename
_Tp
>
inline
Point3_
<
_Tp
>::
Point3_
(
const
Vec
<
_Tp
,
3
>&
v
)
:
x
(
v
[
0
]),
y
(
v
[
1
]),
z
(
v
[
2
])
{}
template
<
typename
_Tp
>
template
<
typename
_Tp2
>
inline
Point3_
<
_Tp
>::
operator
Point3_
<
_Tp2
>
()
const
{
return
Point3_
<
_Tp2
>
(
saturate_cast
<
_Tp2
>
(
x
),
saturate_cast
<
_Tp2
>
(
y
),
saturate_cast
<
_Tp2
>
(
z
));
}
template
<
typename
_Tp
>
inline
Point3_
<
_Tp
>::
operator
Vec
<
_Tp
,
3
>
()
const
{
return
Vec
<
_Tp
,
3
>
(
x
,
y
,
z
);
}
template
<
typename
_Tp
>
inline
Point3_
<
_Tp
>&
Point3_
<
_Tp
>::
operator
=
(
const
Point3_
&
pt
)
{
x
=
pt
.
x
;
y
=
pt
.
y
;
z
=
pt
.
z
;
return
*
this
;
}
template
<
typename
_Tp
>
inline
_Tp
Point3_
<
_Tp
>::
dot
(
const
Point3_
&
pt
)
const
{
return
saturate_cast
<
_Tp
>
(
x
*
pt
.
x
+
y
*
pt
.
y
+
z
*
pt
.
z
);
}
template
<
typename
_Tp
>
inline
double
Point3_
<
_Tp
>::
ddot
(
const
Point3_
&
pt
)
const
{
return
(
double
)
x
*
pt
.
x
+
(
double
)
y
*
pt
.
y
+
(
double
)
z
*
pt
.
z
;
}
template
<
typename
_Tp
>
inline
Point3_
<
_Tp
>
Point3_
<
_Tp
>::
cross
(
const
Point3_
<
_Tp
>&
pt
)
const
{
return
Point3_
<
_Tp
>
(
y
*
pt
.
z
-
z
*
pt
.
y
,
z
*
pt
.
x
-
x
*
pt
.
z
,
x
*
pt
.
y
-
y
*
pt
.
x
);
}
template
<
typename
_Tp
>
static
inline
Point3_
<
_Tp
>&
operator
+=
(
Point3_
<
_Tp
>&
a
,
const
Point3_
<
_Tp
>&
b
)
{
a
.
x
+=
b
.
x
;
a
.
y
+=
b
.
y
;
a
.
z
+=
b
.
z
;
return
a
;
}
template
<
typename
_Tp
>
static
inline
Point3_
<
_Tp
>&
operator
-=
(
Point3_
<
_Tp
>&
a
,
const
Point3_
<
_Tp
>&
b
)
{
a
.
x
-=
b
.
x
;
a
.
y
-=
b
.
y
;
a
.
z
-=
b
.
z
;
return
a
;
}
template
<
typename
_Tp
>
static
inline
Point3_
<
_Tp
>&
operator
*=
(
Point3_
<
_Tp
>&
a
,
int
b
)
{
a
.
x
=
saturate_cast
<
_Tp
>
(
a
.
x
*
b
);
a
.
y
=
saturate_cast
<
_Tp
>
(
a
.
y
*
b
);
a
.
z
=
saturate_cast
<
_Tp
>
(
a
.
z
*
b
);
return
a
;
}
template
<
typename
_Tp
>
static
inline
Point3_
<
_Tp
>&
operator
*=
(
Point3_
<
_Tp
>&
a
,
float
b
)
{
a
.
x
=
saturate_cast
<
_Tp
>
(
a
.
x
*
b
);
a
.
y
=
saturate_cast
<
_Tp
>
(
a
.
y
*
b
);
a
.
z
=
saturate_cast
<
_Tp
>
(
a
.
z
*
b
);
return
a
;
}
template
<
typename
_Tp
>
static
inline
Point3_
<
_Tp
>&
operator
*=
(
Point3_
<
_Tp
>&
a
,
double
b
)
{
a
.
x
=
saturate_cast
<
_Tp
>
(
a
.
x
*
b
);
a
.
y
=
saturate_cast
<
_Tp
>
(
a
.
y
*
b
);
a
.
z
=
saturate_cast
<
_Tp
>
(
a
.
z
*
b
);
return
a
;
}
template
<
typename
_Tp
>
static
inline
double
norm
(
const
Point3_
<
_Tp
>&
pt
)
{
return
std
::
sqrt
((
double
)
pt
.
x
*
pt
.
x
+
(
double
)
pt
.
y
*
pt
.
y
+
(
double
)
pt
.
z
*
pt
.
z
);
}
template
<
typename
_Tp
>
static
inline
bool
operator
==
(
const
Point3_
<
_Tp
>&
a
,
const
Point3_
<
_Tp
>&
b
)
{
return
a
.
x
==
b
.
x
&&
a
.
y
==
b
.
y
&&
a
.
z
==
b
.
z
;
}
template
<
typename
_Tp
>
static
inline
bool
operator
!=
(
const
Point3_
<
_Tp
>&
a
,
const
Point3_
<
_Tp
>&
b
)
{
return
a
.
x
!=
b
.
x
||
a
.
y
!=
b
.
y
||
a
.
z
!=
b
.
z
;
}
template
<
typename
_Tp
>
static
inline
Point3_
<
_Tp
>
operator
+
(
const
Point3_
<
_Tp
>&
a
,
const
Point3_
<
_Tp
>&
b
)
{
return
Point3_
<
_Tp
>
(
saturate_cast
<
_Tp
>
(
a
.
x
+
b
.
x
),
saturate_cast
<
_Tp
>
(
a
.
y
+
b
.
y
),
saturate_cast
<
_Tp
>
(
a
.
z
+
b
.
z
));
}
template
<
typename
_Tp
>
static
inline
Point3_
<
_Tp
>
operator
-
(
const
Point3_
<
_Tp
>&
a
,
const
Point3_
<
_Tp
>&
b
)
{
return
Point3_
<
_Tp
>
(
saturate_cast
<
_Tp
>
(
a
.
x
-
b
.
x
),
saturate_cast
<
_Tp
>
(
a
.
y
-
b
.
y
),
saturate_cast
<
_Tp
>
(
a
.
z
-
b
.
z
));
}
template
<
typename
_Tp
>
static
inline
Point3_
<
_Tp
>
operator
-
(
const
Point3_
<
_Tp
>&
a
)
{
return
Point3_
<
_Tp
>
(
saturate_cast
<
_Tp
>
(
-
a
.
x
),
saturate_cast
<
_Tp
>
(
-
a
.
y
),
saturate_cast
<
_Tp
>
(
-
a
.
z
)
);
}
template
<
typename
_Tp
>
static
inline
Point3_
<
_Tp
>
operator
*
(
const
Point3_
<
_Tp
>&
a
,
int
b
)
{
return
Point3_
<
_Tp
>
(
saturate_cast
<
_Tp
>
(
a
.
x
*
b
),
saturate_cast
<
_Tp
>
(
a
.
y
*
b
),
saturate_cast
<
_Tp
>
(
a
.
z
*
b
)
);
}
template
<
typename
_Tp
>
static
inline
Point3_
<
_Tp
>
operator
*
(
int
a
,
const
Point3_
<
_Tp
>&
b
)
{
return
Point3_
<
_Tp
>
(
saturate_cast
<
_Tp
>
(
b
.
x
*
a
),
saturate_cast
<
_Tp
>
(
b
.
y
*
a
),
saturate_cast
<
_Tp
>
(
b
.
z
*
a
)
);
}
template
<
typename
_Tp
>
static
inline
Point3_
<
_Tp
>
operator
*
(
const
Point3_
<
_Tp
>&
a
,
float
b
)
{
return
Point3_
<
_Tp
>
(
saturate_cast
<
_Tp
>
(
a
.
x
*
b
),
saturate_cast
<
_Tp
>
(
a
.
y
*
b
),
saturate_cast
<
_Tp
>
(
a
.
z
*
b
)
);
}
template
<
typename
_Tp
>
static
inline
Point3_
<
_Tp
>
operator
*
(
float
a
,
const
Point3_
<
_Tp
>&
b
)
{
return
Point3_
<
_Tp
>
(
saturate_cast
<
_Tp
>
(
b
.
x
*
a
),
saturate_cast
<
_Tp
>
(
b
.
y
*
a
),
saturate_cast
<
_Tp
>
(
b
.
z
*
a
)
);
}
template
<
typename
_Tp
>
static
inline
Point3_
<
_Tp
>
operator
*
(
const
Point3_
<
_Tp
>&
a
,
double
b
)
{
return
Point3_
<
_Tp
>
(
saturate_cast
<
_Tp
>
(
a
.
x
*
b
),
saturate_cast
<
_Tp
>
(
a
.
y
*
b
),
saturate_cast
<
_Tp
>
(
a
.
z
*
b
)
);
}
template
<
typename
_Tp
>
static
inline
Point3_
<
_Tp
>
operator
*
(
double
a
,
const
Point3_
<
_Tp
>&
b
)
{
return
Point3_
<
_Tp
>
(
saturate_cast
<
_Tp
>
(
b
.
x
*
a
),
saturate_cast
<
_Tp
>
(
b
.
y
*
a
),
saturate_cast
<
_Tp
>
(
b
.
z
*
a
)
);
}
template
<
typename
_Tp
>
static
inline
Point3_
<
_Tp
>
operator
*
(
const
Matx
<
_Tp
,
3
,
3
>&
a
,
const
Point3_
<
_Tp
>&
b
)
{
Matx
<
_Tp
,
3
,
1
>
tmp
=
a
*
Vec
<
_Tp
,
3
>
(
b
.
x
,
b
.
y
,
b
.
z
);
return
Point3_
<
_Tp
>
(
tmp
.
val
[
0
],
tmp
.
val
[
1
],
tmp
.
val
[
2
]);
}
template
<
typename
_Tp
>
static
inline
Matx
<
_Tp
,
4
,
1
>
operator
*
(
const
Matx
<
_Tp
,
4
,
4
>&
a
,
const
Point3_
<
_Tp
>&
b
)
{
return
a
*
Matx
<
_Tp
,
4
,
1
>
(
b
.
x
,
b
.
y
,
b
.
z
,
1
);
}
////////////////////////////////// Size /////////////////////////////////
template
<
typename
_Tp
>
inline
Size_
<
_Tp
>::
Size_
()
:
width
(
0
),
height
(
0
)
{}
template
<
typename
_Tp
>
inline
Size_
<
_Tp
>::
Size_
(
_Tp
_width
,
_Tp
_height
)
:
width
(
_width
),
height
(
_height
)
{}
template
<
typename
_Tp
>
inline
Size_
<
_Tp
>::
Size_
(
const
Size_
&
sz
)
:
width
(
sz
.
width
),
height
(
sz
.
height
)
{}
template
<
typename
_Tp
>
inline
Size_
<
_Tp
>::
Size_
(
const
Point_
<
_Tp
>&
pt
)
:
width
(
pt
.
x
),
height
(
pt
.
y
)
{}
template
<
typename
_Tp
>
template
<
typename
_Tp2
>
inline
Size_
<
_Tp
>::
operator
Size_
<
_Tp2
>
()
const
{
return
Size_
<
_Tp2
>
(
saturate_cast
<
_Tp2
>
(
width
),
saturate_cast
<
_Tp2
>
(
height
));
}
template
<
typename
_Tp
>
inline
Size_
<
_Tp
>&
Size_
<
_Tp
>::
operator
=
(
const
Size_
<
_Tp
>&
sz
)
{
width
=
sz
.
width
;
height
=
sz
.
height
;
return
*
this
;
}
template
<
typename
_Tp
>
inline
_Tp
Size_
<
_Tp
>::
area
()
const
{
return
width
*
height
;
}
template
<
typename
_Tp
>
static
inline
Size_
<
_Tp
>
operator
*
(
const
Size_
<
_Tp
>&
a
,
_Tp
b
)
{
return
Size_
<
_Tp
>
(
a
.
width
*
b
,
a
.
height
*
b
);
}
template
<
typename
_Tp
>
static
inline
Size_
<
_Tp
>
operator
+
(
const
Size_
<
_Tp
>&
a
,
const
Size_
<
_Tp
>&
b
)
{
return
Size_
<
_Tp
>
(
a
.
width
+
b
.
width
,
a
.
height
+
b
.
height
);
}
template
<
typename
_Tp
>
static
inline
Size_
<
_Tp
>
operator
-
(
const
Size_
<
_Tp
>&
a
,
const
Size_
<
_Tp
>&
b
)
{
return
Size_
<
_Tp
>
(
a
.
width
-
b
.
width
,
a
.
height
-
b
.
height
);
}
template
<
typename
_Tp
>
static
inline
Size_
<
_Tp
>&
operator
+=
(
Size_
<
_Tp
>&
a
,
const
Size_
<
_Tp
>&
b
)
{
a
.
width
+=
b
.
width
;
a
.
height
+=
b
.
height
;
return
a
;
}
template
<
typename
_Tp
>
static
inline
Size_
<
_Tp
>&
operator
-=
(
Size_
<
_Tp
>&
a
,
const
Size_
<
_Tp
>&
b
)
{
a
.
width
-=
b
.
width
;
a
.
height
-=
b
.
height
;
return
a
;
}
template
<
typename
_Tp
>
static
inline
bool
operator
==
(
const
Size_
<
_Tp
>&
a
,
const
Size_
<
_Tp
>&
b
)
{
return
a
.
width
==
b
.
width
&&
a
.
height
==
b
.
height
;
}
template
<
typename
_Tp
>
static
inline
bool
operator
!=
(
const
Size_
<
_Tp
>&
a
,
const
Size_
<
_Tp
>&
b
)
{
return
a
.
width
!=
b
.
width
||
a
.
height
!=
b
.
height
;
}
////////////////////////////////// Rect /////////////////////////////////
template
<
typename
_Tp
>
inline
Rect_
<
_Tp
>::
Rect_
()
:
x
(
0
),
y
(
0
),
width
(
0
),
height
(
0
)
{}
template
<
typename
_Tp
>
inline
Rect_
<
_Tp
>::
Rect_
(
_Tp
_x
,
_Tp
_y
,
_Tp
_width
,
_Tp
_height
)
:
x
(
_x
),
y
(
_y
),
width
(
_width
),
height
(
_height
)
{}
template
<
typename
_Tp
>
inline
Rect_
<
_Tp
>::
Rect_
(
const
Rect_
<
_Tp
>&
r
)
:
x
(
r
.
x
),
y
(
r
.
y
),
width
(
r
.
width
),
height
(
r
.
height
)
{}
template
<
typename
_Tp
>
inline
Rect_
<
_Tp
>::
Rect_
(
const
Point_
<
_Tp
>&
org
,
const
Size_
<
_Tp
>&
sz
)
:
x
(
org
.
x
),
y
(
org
.
y
),
width
(
sz
.
width
),
height
(
sz
.
height
)
{}
template
<
typename
_Tp
>
inline
Rect_
<
_Tp
>::
Rect_
(
const
Point_
<
_Tp
>&
pt1
,
const
Point_
<
_Tp
>&
pt2
)
{
x
=
std
::
min
(
pt1
.
x
,
pt2
.
x
);
y
=
std
::
min
(
pt1
.
y
,
pt2
.
y
);
width
=
std
::
max
(
pt1
.
x
,
pt2
.
x
)
-
x
;
height
=
std
::
max
(
pt1
.
y
,
pt2
.
y
)
-
y
;
}
template
<
typename
_Tp
>
inline
Rect_
<
_Tp
>&
Rect_
<
_Tp
>::
operator
=
(
const
Rect_
<
_Tp
>&
r
)
{
x
=
r
.
x
;
y
=
r
.
y
;
width
=
r
.
width
;
height
=
r
.
height
;
return
*
this
;
}
template
<
typename
_Tp
>
inline
Point_
<
_Tp
>
Rect_
<
_Tp
>::
tl
()
const
{
return
Point_
<
_Tp
>
(
x
,
y
);
}
template
<
typename
_Tp
>
inline
Point_
<
_Tp
>
Rect_
<
_Tp
>::
br
()
const
{
return
Point_
<
_Tp
>
(
x
+
width
,
y
+
height
);
}
template
<
typename
_Tp
>
inline
Size_
<
_Tp
>
Rect_
<
_Tp
>::
size
()
const
{
return
Size_
<
_Tp
>
(
width
,
height
);
}
template
<
typename
_Tp
>
inline
_Tp
Rect_
<
_Tp
>::
area
()
const
{
return
width
*
height
;
}
template
<
typename
_Tp
>
template
<
typename
_Tp2
>
inline
Rect_
<
_Tp
>::
operator
Rect_
<
_Tp2
>
()
const
{
return
Rect_
<
_Tp2
>
(
saturate_cast
<
_Tp2
>
(
x
),
saturate_cast
<
_Tp2
>
(
y
),
saturate_cast
<
_Tp2
>
(
width
),
saturate_cast
<
_Tp2
>
(
height
));
}
template
<
typename
_Tp
>
inline
bool
Rect_
<
_Tp
>::
contains
(
const
Point_
<
_Tp
>&
pt
)
const
{
return
x
<=
pt
.
x
&&
pt
.
x
<
x
+
width
&&
y
<=
pt
.
y
&&
pt
.
y
<
y
+
height
;
}
template
<
typename
_Tp
>
static
inline
Rect_
<
_Tp
>&
operator
+=
(
Rect_
<
_Tp
>&
a
,
const
Point_
<
_Tp
>&
b
)
{
a
.
x
+=
b
.
x
;
a
.
y
+=
b
.
y
;
return
a
;
}
template
<
typename
_Tp
>
static
inline
Rect_
<
_Tp
>&
operator
-=
(
Rect_
<
_Tp
>&
a
,
const
Point_
<
_Tp
>&
b
)
{
a
.
x
-=
b
.
x
;
a
.
y
-=
b
.
y
;
return
a
;
}
template
<
typename
_Tp
>
static
inline
Rect_
<
_Tp
>&
operator
+=
(
Rect_
<
_Tp
>&
a
,
const
Size_
<
_Tp
>&
b
)
{
a
.
width
+=
b
.
width
;
a
.
height
+=
b
.
height
;
return
a
;
}
template
<
typename
_Tp
>
static
inline
Rect_
<
_Tp
>&
operator
-=
(
Rect_
<
_Tp
>&
a
,
const
Size_
<
_Tp
>&
b
)
{
a
.
width
-=
b
.
width
;
a
.
height
-=
b
.
height
;
return
a
;
}
template
<
typename
_Tp
>
static
inline
Rect_
<
_Tp
>&
operator
&=
(
Rect_
<
_Tp
>&
a
,
const
Rect_
<
_Tp
>&
b
)
{
_Tp
x1
=
std
::
max
(
a
.
x
,
b
.
x
);
_Tp
y1
=
std
::
max
(
a
.
y
,
b
.
y
);
a
.
width
=
std
::
min
(
a
.
x
+
a
.
width
,
b
.
x
+
b
.
width
)
-
x1
;
a
.
height
=
std
::
min
(
a
.
y
+
a
.
height
,
b
.
y
+
b
.
height
)
-
y1
;
a
.
x
=
x1
;
a
.
y
=
y1
;
if
(
a
.
width
<=
0
||
a
.
height
<=
0
)
a
=
Rect
();
return
a
;
}
template
<
typename
_Tp
>
static
inline
Rect_
<
_Tp
>&
operator
|=
(
Rect_
<
_Tp
>&
a
,
const
Rect_
<
_Tp
>&
b
)
{
_Tp
x1
=
std
::
min
(
a
.
x
,
b
.
x
);
_Tp
y1
=
std
::
min
(
a
.
y
,
b
.
y
);
a
.
width
=
std
::
max
(
a
.
x
+
a
.
width
,
b
.
x
+
b
.
width
)
-
x1
;
a
.
height
=
std
::
max
(
a
.
y
+
a
.
height
,
b
.
y
+
b
.
height
)
-
y1
;
a
.
x
=
x1
;
a
.
y
=
y1
;
return
a
;
}
template
<
typename
_Tp
>
static
inline
bool
operator
==
(
const
Rect_
<
_Tp
>&
a
,
const
Rect_
<
_Tp
>&
b
)
{
return
a
.
x
==
b
.
x
&&
a
.
y
==
b
.
y
&&
a
.
width
==
b
.
width
&&
a
.
height
==
b
.
height
;
}
template
<
typename
_Tp
>
static
inline
bool
operator
!=
(
const
Rect_
<
_Tp
>&
a
,
const
Rect_
<
_Tp
>&
b
)
{
return
a
.
x
!=
b
.
x
||
a
.
y
!=
b
.
y
||
a
.
width
!=
b
.
width
||
a
.
height
!=
b
.
height
;
}
template
<
typename
_Tp
>
static
inline
Rect_
<
_Tp
>
operator
+
(
const
Rect_
<
_Tp
>&
a
,
const
Point_
<
_Tp
>&
b
)
{
return
Rect_
<
_Tp
>
(
a
.
x
+
b
.
x
,
a
.
y
+
b
.
y
,
a
.
width
,
a
.
height
);
}
template
<
typename
_Tp
>
static
inline
Rect_
<
_Tp
>
operator
-
(
const
Rect_
<
_Tp
>&
a
,
const
Point_
<
_Tp
>&
b
)
{
return
Rect_
<
_Tp
>
(
a
.
x
-
b
.
x
,
a
.
y
-
b
.
y
,
a
.
width
,
a
.
height
);
}
template
<
typename
_Tp
>
static
inline
Rect_
<
_Tp
>
operator
+
(
const
Rect_
<
_Tp
>&
a
,
const
Size_
<
_Tp
>&
b
)
{
return
Rect_
<
_Tp
>
(
a
.
x
,
a
.
y
,
a
.
width
+
b
.
width
,
a
.
height
+
b
.
height
);
}
template
<
typename
_Tp
>
static
inline
Rect_
<
_Tp
>
operator
&
(
const
Rect_
<
_Tp
>&
a
,
const
Rect_
<
_Tp
>&
b
)
{
Rect_
<
_Tp
>
c
=
a
;
return
c
&=
b
;
}
template
<
typename
_Tp
>
static
inline
Rect_
<
_Tp
>
operator
|
(
const
Rect_
<
_Tp
>&
a
,
const
Rect_
<
_Tp
>&
b
)
{
Rect_
<
_Tp
>
c
=
a
;
return
c
|=
b
;
}
////////////////////////////// RotatedRect //////////////////////////////
inline
RotatedRect
::
RotatedRect
()
:
center
(),
size
(),
angle
(
0
)
{}
inline
RotatedRect
::
RotatedRect
(
const
Point2f
&
_center
,
const
Size2f
&
_size
,
float
_angle
)
:
center
(
_center
),
size
(
_size
),
angle
(
_angle
)
{}
///////////////////////////////// Range /////////////////////////////////
inline
Range
::
Range
()
:
start
(
0
),
end
(
0
)
{}
inline
Range
::
Range
(
int
_start
,
int
_end
)
:
start
(
_start
),
end
(
_end
)
{}
inline
int
Range
::
size
()
const
{
return
end
-
start
;
}
inline
bool
Range
::
empty
()
const
{
return
start
==
end
;
}
inline
Range
Range
::
all
()
{
return
Range
(
INT_MIN
,
INT_MAX
);
}
static
inline
bool
operator
==
(
const
Range
&
r1
,
const
Range
&
r2
)
{
return
r1
.
start
==
r2
.
start
&&
r1
.
end
==
r2
.
end
;
}
static
inline
bool
operator
!=
(
const
Range
&
r1
,
const
Range
&
r2
)
{
return
!
(
r1
==
r2
);
}
static
inline
bool
operator
!
(
const
Range
&
r
)
{
return
r
.
start
==
r
.
end
;
}
static
inline
Range
operator
&
(
const
Range
&
r1
,
const
Range
&
r2
)
{
Range
r
(
std
::
max
(
r1
.
start
,
r2
.
start
),
std
::
min
(
r1
.
end
,
r2
.
end
));
r
.
end
=
std
::
max
(
r
.
end
,
r
.
start
);
return
r
;
}
static
inline
Range
&
operator
&=
(
Range
&
r1
,
const
Range
&
r2
)
{
r1
=
r1
&
r2
;
return
r1
;
}
static
inline
Range
operator
+
(
const
Range
&
r1
,
int
delta
)
{
return
Range
(
r1
.
start
+
delta
,
r1
.
end
+
delta
);
}
static
inline
Range
operator
+
(
int
delta
,
const
Range
&
r1
)
{
return
Range
(
r1
.
start
+
delta
,
r1
.
end
+
delta
);
}
static
inline
Range
operator
-
(
const
Range
&
r1
,
int
delta
)
{
return
r1
+
(
-
delta
);
}
///////////////////////////////// Scalar ////////////////////////////////
template
<
typename
_Tp
>
inline
Scalar_
<
_Tp
>::
Scalar_
()
{
this
->
val
[
0
]
=
this
->
val
[
1
]
=
this
->
val
[
2
]
=
this
->
val
[
3
]
=
0
;
}
template
<
typename
_Tp
>
inline
Scalar_
<
_Tp
>::
Scalar_
(
_Tp
v0
,
_Tp
v1
,
_Tp
v2
,
_Tp
v3
)
{
this
->
val
[
0
]
=
v0
;
this
->
val
[
1
]
=
v1
;
this
->
val
[
2
]
=
v2
;
this
->
val
[
3
]
=
v3
;
}
template
<
typename
_Tp
>
template
<
typename
_Tp2
,
int
cn
>
inline
Scalar_
<
_Tp
>::
Scalar_
(
const
Vec
<
_Tp2
,
cn
>&
v
)
{
int
i
;
for
(
i
=
0
;
i
<
(
cn
<
4
?
cn
:
4
);
i
++
)
this
->
val
[
i
]
=
cv
::
saturate_cast
<
_Tp
>
(
v
.
val
[
i
]);
for
(
;
i
<
4
;
i
++
)
this
->
val
[
i
]
=
0
;
}
template
<
typename
_Tp
>
inline
Scalar_
<
_Tp
>::
Scalar_
(
_Tp
v0
)
{
this
->
val
[
0
]
=
v0
;
this
->
val
[
1
]
=
this
->
val
[
2
]
=
this
->
val
[
3
]
=
0
;
}
template
<
typename
_Tp
>
inline
Scalar_
<
_Tp
>
Scalar_
<
_Tp
>::
all
(
_Tp
v0
)
{
return
Scalar_
<
_Tp
>
(
v0
,
v0
,
v0
,
v0
);
}
template
<
typename
_Tp
>
inline
Scalar_
<
_Tp
>
Scalar_
<
_Tp
>::
mul
(
const
Scalar_
<
_Tp
>&
t
,
double
scale
)
const
{
return
Scalar_
<
_Tp
>
(
saturate_cast
<
_Tp
>
(
this
->
val
[
0
]
*
t
.
val
[
0
]
*
scale
),
saturate_cast
<
_Tp
>
(
this
->
val
[
1
]
*
t
.
val
[
1
]
*
scale
),
saturate_cast
<
_Tp
>
(
this
->
val
[
2
]
*
t
.
val
[
2
]
*
scale
),
saturate_cast
<
_Tp
>
(
this
->
val
[
3
]
*
t
.
val
[
3
]
*
scale
));
}
template
<
typename
_Tp
>
inline
Scalar_
<
_Tp
>
Scalar_
<
_Tp
>::
conj
()
const
{
return
Scalar_
<
_Tp
>
(
saturate_cast
<
_Tp
>
(
this
->
val
[
0
]),
saturate_cast
<
_Tp
>
(
-
this
->
val
[
1
]),
saturate_cast
<
_Tp
>
(
-
this
->
val
[
2
]),
saturate_cast
<
_Tp
>
(
-
this
->
val
[
3
]));
}
template
<
typename
_Tp
>
inline
bool
Scalar_
<
_Tp
>::
isReal
()
const
{
return
this
->
val
[
1
]
==
0
&&
this
->
val
[
2
]
==
0
&&
this
->
val
[
3
]
==
0
;
}
template
<
typename
_Tp
>
template
<
typename
T2
>
inline
Scalar_
<
_Tp
>::
operator
Scalar_
<
T2
>
()
const
{
return
Scalar_
<
T2
>
(
saturate_cast
<
T2
>
(
this
->
val
[
0
]),
saturate_cast
<
T2
>
(
this
->
val
[
1
]),
saturate_cast
<
T2
>
(
this
->
val
[
2
]),
saturate_cast
<
T2
>
(
this
->
val
[
3
]));
}
template
<
typename
_Tp
>
static
inline
Scalar_
<
_Tp
>&
operator
+=
(
Scalar_
<
_Tp
>&
a
,
const
Scalar_
<
_Tp
>&
b
)
{
a
.
val
[
0
]
+=
b
.
val
[
0
];
a
.
val
[
1
]
+=
b
.
val
[
1
];
a
.
val
[
2
]
+=
b
.
val
[
2
];
a
.
val
[
3
]
+=
b
.
val
[
3
];
return
a
;
}
template
<
typename
_Tp
>
static
inline
Scalar_
<
_Tp
>&
operator
-=
(
Scalar_
<
_Tp
>&
a
,
const
Scalar_
<
_Tp
>&
b
)
{
a
.
val
[
0
]
-=
b
.
val
[
0
];
a
.
val
[
1
]
-=
b
.
val
[
1
];
a
.
val
[
2
]
-=
b
.
val
[
2
];
a
.
val
[
3
]
-=
b
.
val
[
3
];
return
a
;
}
template
<
typename
_Tp
>
static
inline
Scalar_
<
_Tp
>&
operator
*=
(
Scalar_
<
_Tp
>&
a
,
_Tp
v
)
{
a
.
val
[
0
]
*=
v
;
a
.
val
[
1
]
*=
v
;
a
.
val
[
2
]
*=
v
;
a
.
val
[
3
]
*=
v
;
return
a
;
}
template
<
typename
_Tp
>
static
inline
bool
operator
==
(
const
Scalar_
<
_Tp
>&
a
,
const
Scalar_
<
_Tp
>&
b
)
{
return
a
.
val
[
0
]
==
b
.
val
[
0
]
&&
a
.
val
[
1
]
==
b
.
val
[
1
]
&&
a
.
val
[
2
]
==
b
.
val
[
2
]
&&
a
.
val
[
3
]
==
b
.
val
[
3
];
}
template
<
typename
_Tp
>
static
inline
bool
operator
!=
(
const
Scalar_
<
_Tp
>&
a
,
const
Scalar_
<
_Tp
>&
b
)
{
return
a
.
val
[
0
]
!=
b
.
val
[
0
]
||
a
.
val
[
1
]
!=
b
.
val
[
1
]
||
a
.
val
[
2
]
!=
b
.
val
[
2
]
||
a
.
val
[
3
]
!=
b
.
val
[
3
];
}
template
<
typename
_Tp
>
static
inline
Scalar_
<
_Tp
>
operator
+
(
const
Scalar_
<
_Tp
>&
a
,
const
Scalar_
<
_Tp
>&
b
)
{
return
Scalar_
<
_Tp
>
(
a
.
val
[
0
]
+
b
.
val
[
0
],
a
.
val
[
1
]
+
b
.
val
[
1
],
a
.
val
[
2
]
+
b
.
val
[
2
],
a
.
val
[
3
]
+
b
.
val
[
3
]);
}
template
<
typename
_Tp
>
static
inline
Scalar_
<
_Tp
>
operator
-
(
const
Scalar_
<
_Tp
>&
a
,
const
Scalar_
<
_Tp
>&
b
)
{
return
Scalar_
<
_Tp
>
(
saturate_cast
<
_Tp
>
(
a
.
val
[
0
]
-
b
.
val
[
0
]),
saturate_cast
<
_Tp
>
(
a
.
val
[
1
]
-
b
.
val
[
1
]),
saturate_cast
<
_Tp
>
(
a
.
val
[
2
]
-
b
.
val
[
2
]),
saturate_cast
<
_Tp
>
(
a
.
val
[
3
]
-
b
.
val
[
3
]));
}
template
<
typename
_Tp
>
static
inline
Scalar_
<
_Tp
>
operator
*
(
const
Scalar_
<
_Tp
>&
a
,
_Tp
alpha
)
{
return
Scalar_
<
_Tp
>
(
a
.
val
[
0
]
*
alpha
,
a
.
val
[
1
]
*
alpha
,
a
.
val
[
2
]
*
alpha
,
a
.
val
[
3
]
*
alpha
);
}
template
<
typename
_Tp
>
static
inline
Scalar_
<
_Tp
>
operator
*
(
_Tp
alpha
,
const
Scalar_
<
_Tp
>&
a
)
{
return
a
*
alpha
;
}
template
<
typename
_Tp
>
static
inline
Scalar_
<
_Tp
>
operator
-
(
const
Scalar_
<
_Tp
>&
a
)
{
return
Scalar_
<
_Tp
>
(
saturate_cast
<
_Tp
>
(
-
a
.
val
[
0
]),
saturate_cast
<
_Tp
>
(
-
a
.
val
[
1
]),
saturate_cast
<
_Tp
>
(
-
a
.
val
[
2
]),
saturate_cast
<
_Tp
>
(
-
a
.
val
[
3
]));
}
template
<
typename
_Tp
>
static
inline
Scalar_
<
_Tp
>
operator
*
(
const
Scalar_
<
_Tp
>&
a
,
const
Scalar_
<
_Tp
>&
b
)
{
return
Scalar_
<
_Tp
>
(
saturate_cast
<
_Tp
>
(
a
[
0
]
*
b
[
0
]
-
a
[
1
]
*
b
[
1
]
-
a
[
2
]
*
b
[
2
]
-
a
[
3
]
*
b
[
3
]),
saturate_cast
<
_Tp
>
(
a
[
0
]
*
b
[
1
]
+
a
[
1
]
*
b
[
0
]
+
a
[
2
]
*
b
[
3
]
-
a
[
3
]
*
b
[
2
]),
saturate_cast
<
_Tp
>
(
a
[
0
]
*
b
[
2
]
-
a
[
1
]
*
b
[
3
]
+
a
[
2
]
*
b
[
0
]
+
a
[
3
]
*
b
[
1
]),
saturate_cast
<
_Tp
>
(
a
[
0
]
*
b
[
3
]
+
a
[
1
]
*
b
[
2
]
-
a
[
2
]
*
b
[
1
]
+
a
[
3
]
*
b
[
0
]));
}
template
<
typename
_Tp
>
static
inline
Scalar_
<
_Tp
>&
operator
*=
(
Scalar_
<
_Tp
>&
a
,
const
Scalar_
<
_Tp
>&
b
)
{
a
=
a
*
b
;
return
a
;
}
template
<
typename
_Tp
>
static
inline
Scalar_
<
_Tp
>
operator
/
(
const
Scalar_
<
_Tp
>&
a
,
_Tp
alpha
)
{
return
Scalar_
<
_Tp
>
(
a
.
val
[
0
]
/
alpha
,
a
.
val
[
1
]
/
alpha
,
a
.
val
[
2
]
/
alpha
,
a
.
val
[
3
]
/
alpha
);
}
template
<
typename
_Tp
>
static
inline
Scalar_
<
float
>
operator
/
(
const
Scalar_
<
float
>&
a
,
float
alpha
)
{
float
s
=
1
/
alpha
;
return
Scalar_
<
float
>
(
a
.
val
[
0
]
*
s
,
a
.
val
[
1
]
*
s
,
a
.
val
[
2
]
*
s
,
a
.
val
[
3
]
*
s
);
}
template
<
typename
_Tp
>
static
inline
Scalar_
<
double
>
operator
/
(
const
Scalar_
<
double
>&
a
,
double
alpha
)
{
double
s
=
1
/
alpha
;
return
Scalar_
<
double
>
(
a
.
val
[
0
]
*
s
,
a
.
val
[
1
]
*
s
,
a
.
val
[
2
]
*
s
,
a
.
val
[
3
]
*
s
);
}
template
<
typename
_Tp
>
static
inline
Scalar_
<
_Tp
>&
operator
/=
(
Scalar_
<
_Tp
>&
a
,
_Tp
alpha
)
{
a
=
a
/
alpha
;
return
a
;
}
template
<
typename
_Tp
>
static
inline
Scalar_
<
_Tp
>
operator
/
(
_Tp
a
,
const
Scalar_
<
_Tp
>&
b
)
{
_Tp
s
=
a
/
(
b
[
0
]
*
b
[
0
]
+
b
[
1
]
*
b
[
1
]
+
b
[
2
]
*
b
[
2
]
+
b
[
3
]
*
b
[
3
]);
return
b
.
conj
()
*
s
;
}
template
<
typename
_Tp
>
static
inline
Scalar_
<
_Tp
>
operator
/
(
const
Scalar_
<
_Tp
>&
a
,
const
Scalar_
<
_Tp
>&
b
)
{
return
a
*
((
_Tp
)
1
/
b
);
}
template
<
typename
_Tp
>
static
inline
Scalar_
<
_Tp
>&
operator
/=
(
Scalar_
<
_Tp
>&
a
,
const
Scalar_
<
_Tp
>&
b
)
{
a
=
a
/
b
;
return
a
;
}
template
<
typename
_Tp
>
static
inline
Scalar
operator
*
(
const
Matx
<
_Tp
,
4
,
4
>&
a
,
const
Scalar
&
b
)
{
Matx
<
double
,
4
,
1
>
c
((
Matx
<
double
,
4
,
4
>
)
a
,
b
,
Matx_MatMulOp
());
return
reinterpret_cast
<
const
Scalar
&>
(
c
);
}
template
<>
inline
Scalar
operator
*
(
const
Matx
<
double
,
4
,
4
>&
a
,
const
Scalar
&
b
)
{
Matx
<
double
,
4
,
1
>
c
(
a
,
b
,
Matx_MatMulOp
());
return
reinterpret_cast
<
const
Scalar
&>
(
c
);
}
//////////////////////////////// KeyPoint ///////////////////////////////
inline
KeyPoint
::
KeyPoint
()
:
pt
(
0
,
0
),
size
(
0
),
angle
(
-
1
),
response
(
0
),
octave
(
0
),
class_id
(
-
1
)
{}
inline
KeyPoint
::
KeyPoint
(
Point2f
_pt
,
float
_size
,
float
_angle
,
float
_response
,
int
_octave
,
int
_class_id
)
:
pt
(
_pt
),
size
(
_size
),
angle
(
_angle
),
response
(
_response
),
octave
(
_octave
),
class_id
(
_class_id
)
{}
inline
KeyPoint
::
KeyPoint
(
float
x
,
float
y
,
float
_size
,
float
_angle
,
float
_response
,
int
_octave
,
int
_class_id
)
:
pt
(
x
,
y
),
size
(
_size
),
angle
(
_angle
),
response
(
_response
),
octave
(
_octave
),
class_id
(
_class_id
)
{}
///////////////////////////////// DMatch ////////////////////////////////
inline
DMatch
::
DMatch
()
:
queryIdx
(
-
1
),
trainIdx
(
-
1
),
imgIdx
(
-
1
),
distance
(
FLT_MAX
)
{}
inline
DMatch
::
DMatch
(
int
_queryIdx
,
int
_trainIdx
,
float
_distance
)
:
queryIdx
(
_queryIdx
),
trainIdx
(
_trainIdx
),
imgIdx
(
-
1
),
distance
(
_distance
)
{}
inline
DMatch
::
DMatch
(
int
_queryIdx
,
int
_trainIdx
,
int
_imgIdx
,
float
_distance
)
inline
DMatch
::
DMatch
(
int
_queryIdx
,
int
_trainIdx
,
int
_imgIdx
,
float
_distance
)
:
queryIdx
(
_queryIdx
),
trainIdx
(
_trainIdx
),
imgIdx
(
_imgIdx
),
distance
(
_distance
)
{}
inline
bool
DMatch
::
operator
<
(
const
DMatch
&
m
)
const
{
return
distance
<
m
.
distance
;
}
inline
bool
DMatch
::
operator
<
(
const
DMatch
&
m
)
const
{
return
distance
<
m
.
distance
;
}
}
// cv
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment