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
dc4d0398
Commit
dc4d0398
authored
Jan 22, 2013
by
Vadim Pisarevsky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
converted few more comp. geometry functions to C++
parent
c2241dcc
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
48 additions
and
238 deletions
+48
-238
_geom.h
modules/imgproc/src/_geom.h
+0
-10
contours.cpp
modules/imgproc/src/contours.cpp
+0
-81
geometry.cpp
modules/imgproc/src/geometry.cpp
+32
-94
matchcontours.cpp
modules/imgproc/src/matchcontours.cpp
+15
-52
rotcalipers.cpp
modules/imgproc/src/rotcalipers.cpp
+0
-0
shapedescr.cpp
modules/imgproc/src/shapedescr.cpp
+0
-0
minarea.cpp
samples/cpp/minarea.cpp
+1
-1
No files found.
modules/imgproc/src/_geom.h
View file @
dc4d0398
...
...
@@ -52,16 +52,6 @@ CV_INLINE float icvDistanceL2_32f( CvPoint2D32f pt1, CvPoint2D32f pt2 )
}
int
icvIntersectLines
(
double
x1
,
double
dx1
,
double
y1
,
double
dy1
,
double
x2
,
double
dx2
,
double
y2
,
double
dy2
,
double
*
t2
);
void
icvIntersectLines3
(
double
*
a0
,
double
*
b0
,
double
*
c0
,
double
*
a1
,
double
*
b1
,
double
*
c1
,
CvPoint2D32f
*
point
);
/* curvature: 0 - 1-curvature, 1 - k-cosine curvature. */
CvSeq
*
icvApproximateChainTC89
(
CvChain
*
chain
,
int
header_size
,
CvMemStorage
*
storage
,
int
method
);
...
...
modules/imgproc/src/contours.cpp
View file @
dc4d0398
...
...
@@ -1753,85 +1753,4 @@ void cv::findContours( InputOutputArray _image, OutputArrayOfArrays _contours,
findContours
(
_image
,
_contours
,
noArray
(),
mode
,
method
,
offset
);
}
double
cv
::
arcLength
(
InputArray
_curve
,
bool
closed
)
{
Mat
curve
=
_curve
.
getMat
();
CV_Assert
(
curve
.
checkVector
(
2
)
>=
0
&&
(
curve
.
depth
()
==
CV_32F
||
curve
.
depth
()
==
CV_32S
));
CvMat
_ccurve
=
curve
;
return
cvArcLength
(
&
_ccurve
,
CV_WHOLE_SEQ
,
closed
);
}
cv
::
Rect
cv
::
boundingRect
(
InputArray
_points
)
{
Mat
points
=
_points
.
getMat
();
CV_Assert
(
points
.
checkVector
(
2
)
>=
0
&&
(
points
.
depth
()
==
CV_32F
||
points
.
depth
()
==
CV_32S
));
CvMat
_cpoints
=
points
;
return
cvBoundingRect
(
&
_cpoints
,
0
);
}
double
cv
::
contourArea
(
InputArray
_contour
,
bool
oriented
)
{
Mat
contour
=
_contour
.
getMat
();
CV_Assert
(
contour
.
checkVector
(
2
)
>=
0
&&
(
contour
.
depth
()
==
CV_32F
||
contour
.
depth
()
==
CV_32S
));
CvMat
_ccontour
=
contour
;
return
cvContourArea
(
&
_ccontour
,
CV_WHOLE_SEQ
,
oriented
);
}
cv
::
RotatedRect
cv
::
minAreaRect
(
InputArray
_points
)
{
Mat
points
=
_points
.
getMat
();
CV_Assert
(
points
.
checkVector
(
2
)
>=
0
&&
(
points
.
depth
()
==
CV_32F
||
points
.
depth
()
==
CV_32S
));
CvMat
_cpoints
=
points
;
return
cvMinAreaRect2
(
&
_cpoints
,
0
);
}
void
cv
::
minEnclosingCircle
(
InputArray
_points
,
Point2f
&
center
,
float
&
radius
)
{
Mat
points
=
_points
.
getMat
();
CV_Assert
(
points
.
checkVector
(
2
)
>=
0
&&
(
points
.
depth
()
==
CV_32F
||
points
.
depth
()
==
CV_32S
));
CvMat
_cpoints
=
points
;
cvMinEnclosingCircle
(
&
_cpoints
,
(
CvPoint2D32f
*
)
&
center
,
&
radius
);
}
double
cv
::
matchShapes
(
InputArray
_contour1
,
InputArray
_contour2
,
int
method
,
double
parameter
)
{
Mat
contour1
=
_contour1
.
getMat
(),
contour2
=
_contour2
.
getMat
();
CV_Assert
(
contour1
.
checkVector
(
2
)
>=
0
&&
contour2
.
checkVector
(
2
)
>=
0
&&
(
contour1
.
depth
()
==
CV_32F
||
contour1
.
depth
()
==
CV_32S
)
&&
contour1
.
depth
()
==
contour2
.
depth
());
CvMat
c1
=
Mat
(
contour1
),
c2
=
Mat
(
contour2
);
return
cvMatchShapes
(
&
c1
,
&
c2
,
method
,
parameter
);
}
cv
::
RotatedRect
cv
::
fitEllipse
(
InputArray
_points
)
{
Mat
points
=
_points
.
getMat
();
CV_Assert
(
points
.
checkVector
(
2
)
>=
0
&&
(
points
.
depth
()
==
CV_32F
||
points
.
depth
()
==
CV_32S
));
CvMat
_cpoints
=
points
;
return
cvFitEllipse2
(
&
_cpoints
);
}
double
cv
::
pointPolygonTest
(
InputArray
_contour
,
Point2f
pt
,
bool
measureDist
)
{
Mat
contour
=
_contour
.
getMat
();
CV_Assert
(
contour
.
checkVector
(
2
)
>=
0
&&
(
contour
.
depth
()
==
CV_32F
||
contour
.
depth
()
==
CV_32S
));
CvMat
c
=
Mat
(
contour
);
return
cvPointPolygonTest
(
&
c
,
pt
,
measureDist
);
}
/* End of file. */
modules/imgproc/src/geometry.cpp
View file @
dc4d0398
...
...
@@ -92,93 +92,34 @@ cvBoxPoints( CvBox2D box, CvPoint2D32f pt[4] )
}
int
icvIntersectLines
(
double
x1
,
double
dx1
,
double
y1
,
double
dy1
,
double
x2
,
double
dx2
,
double
y2
,
double
dy2
,
double
*
t2
)
{
double
d
=
dx1
*
dy2
-
dx2
*
dy1
;
int
result
=
-
1
;
if
(
d
!=
0
)
{
*
t2
=
((
x2
-
x1
)
*
dy1
-
(
y2
-
y1
)
*
dx1
)
/
d
;
result
=
0
;
}
return
result
;
}
void
icvIntersectLines3
(
double
*
a0
,
double
*
b0
,
double
*
c0
,
double
*
a1
,
double
*
b1
,
double
*
c1
,
CvPoint2D32f
*
point
)
{
double
det
=
a0
[
0
]
*
b1
[
0
]
-
a1
[
0
]
*
b0
[
0
];
if
(
det
!=
0
)
{
det
=
1.
/
det
;
point
->
x
=
(
float
)
((
b0
[
0
]
*
c1
[
0
]
-
b1
[
0
]
*
c0
[
0
])
*
det
);
point
->
y
=
(
float
)
((
a1
[
0
]
*
c0
[
0
]
-
a0
[
0
]
*
c1
[
0
])
*
det
);
}
else
{
point
->
x
=
point
->
y
=
FLT_MAX
;
}
}
CV_IMPL
double
cvPointPolygonTest
(
const
CvArr
*
_contour
,
CvPoint2D32f
pt
,
int
measure_dist
)
double
cv
::
pointPolygonTest
(
InputArray
_contour
,
Point2f
pt
,
bool
measureDist
)
{
double
result
=
0
;
Mat
contour
=
_contour
.
getMat
();
int
i
,
total
=
contour
.
checkVector
(
2
),
counter
=
0
;
int
depth
=
contour
.
depth
();
CV_Assert
(
total
>=
0
&&
(
depth
==
CV_32S
||
depth
==
CV_32F
));
CvSeqBlock
block
;
CvContour
header
;
CvSeq
*
contour
=
(
CvSeq
*
)
_contour
;
CvSeqReader
reader
;
int
i
,
total
,
counter
=
0
;
int
is_float
;
bool
is_float
=
depth
==
CV_32F
;
double
min_dist_num
=
FLT_MAX
,
min_dist_denom
=
1
;
CvPoint
ip
=
{
0
,
0
}
;
Point
ip
(
cvRound
(
pt
.
x
),
cvRound
(
pt
.
y
))
;
if
(
!
CV_IS_SEQ
(
contour
)
)
{
contour
=
cvPointSeqFromMat
(
CV_SEQ_KIND_CURVE
+
CV_SEQ_FLAG_CLOSED
,
_contour
,
&
header
,
&
block
);
}
else
if
(
CV_IS_SEQ_POINT_SET
(
contour
)
)
{
if
(
contour
->
header_size
==
sizeof
(
CvContour
)
&&
!
measure_dist
)
{
CvRect
r
=
((
CvContour
*
)
contour
)
->
rect
;
if
(
pt
.
x
<
r
.
x
||
pt
.
y
<
r
.
y
||
pt
.
x
>=
r
.
x
+
r
.
width
||
pt
.
y
>=
r
.
y
+
r
.
height
)
return
-
1
;
}
}
else
if
(
CV_IS_SEQ_CHAIN
(
contour
)
)
{
CV_Error
(
CV_StsBadArg
,
"Chains are not supported. Convert them to polygonal representation using cvApproxChains()"
);
}
else
CV_Error
(
CV_StsBadArg
,
"Input contour is neither a valid sequence nor a matrix"
);
if
(
total
==
0
)
return
measureDist
?
-
DBL_MAX
:
-
1
;
total
=
contour
->
total
;
is_float
=
CV_SEQ_ELTYPE
(
contour
)
==
CV_32FC2
;
cvStartReadSeq
(
contour
,
&
reader
,
-
1
);
const
Point
*
cnt
=
(
const
Point
*
)
contour
.
data
;
const
Point2f
*
cntf
=
(
const
Point2f
*
)
cnt
;
if
(
!
is_float
&&
!
measure
_dist
&&
(
ip
.
x
=
cvRound
(
pt
.
x
))
==
pt
.
x
&&
(
ip
.
y
=
cvRound
(
pt
.
y
))
==
pt
.
y
)
if
(
!
is_float
&&
!
measure
Dist
&&
ip
.
x
==
pt
.
x
&&
ip
.
y
==
pt
.
y
)
{
// the fastest "pure integer" branch
CvPoint
v0
,
v
;
CV_READ_SEQ_ELEM
(
v
,
reader
);
// the fastest "purely integer" branch
Point
v0
,
v
=
cnt
[
total
-
1
];
for
(
i
=
0
;
i
<
total
;
i
++
)
{
int
dist
;
v0
=
v
;
CV_READ_SEQ_ELEM
(
v
,
reader
)
;
v
=
cnt
[
i
]
;
if
(
(
v0
.
y
<=
ip
.
y
&&
v
.
y
<=
ip
.
y
)
||
(
v0
.
y
>
ip
.
y
&&
v
.
y
>
ip
.
y
)
||
...
...
@@ -202,34 +143,28 @@ cvPointPolygonTest( const CvArr* _contour, CvPoint2D32f pt, int measure_dist )
}
else
{
CvPoint2D3
2f
v0
,
v
;
Cv
Point
iv
;
Point
2f
v0
,
v
;
Point
iv
;
if
(
is_float
)
{
CV_READ_SEQ_ELEM
(
v
,
reader
)
;
v
=
cntf
[
total
-
1
]
;
}
else
{
CV_READ_SEQ_ELEM
(
iv
,
reader
);
v
=
cvPointTo32f
(
iv
);
v
=
cnt
[
total
-
1
];
}
if
(
!
measure
_d
ist
)
if
(
!
measure
D
ist
)
{
for
(
i
=
0
;
i
<
total
;
i
++
)
{
double
dist
;
v0
=
v
;
if
(
is_float
)
{
CV_READ_SEQ_ELEM
(
v
,
reader
);
}
v
=
cntf
[
i
];
else
{
CV_READ_SEQ_ELEM
(
iv
,
reader
);
v
=
cvPointTo32f
(
iv
);
}
v
=
cnt
[
i
];
if
(
(
v0
.
y
<=
pt
.
y
&&
v
.
y
<=
pt
.
y
)
||
(
v0
.
y
>
pt
.
y
&&
v
.
y
>
pt
.
y
)
||
...
...
@@ -259,14 +194,9 @@ cvPointPolygonTest( const CvArr* _contour, CvPoint2D32f pt, int measure_dist )
v0
=
v
;
if
(
is_float
)
{
CV_READ_SEQ_ELEM
(
v
,
reader
);
}
v
=
cntf
[
i
];
else
{
CV_READ_SEQ_ELEM
(
iv
,
reader
);
v
=
cvPointTo32f
(
iv
);
}
v
=
cnt
[
i
];
dx
=
v
.
x
-
v0
.
x
;
dy
=
v
.
y
-
v0
.
y
;
dx1
=
pt
.
x
-
v0
.
x
;
dy1
=
pt
.
y
-
v0
.
y
;
...
...
@@ -312,6 +242,14 @@ cvPointPolygonTest( const CvArr* _contour, CvPoint2D32f pt, int measure_dist )
}
CV_IMPL
double
cvPointPolygonTest
(
const
CvArr
*
_contour
,
CvPoint2D32f
pt
,
int
measure_dist
)
{
cv
::
AutoBuffer
<
double
>
abuf
;
cv
::
Mat
contour
=
cv
::
cvarrToMat
(
_contour
,
false
,
false
,
0
,
&
abuf
);
return
cv
::
pointPolygonTest
(
contour
,
pt
,
measure_dist
!=
0
);
}
/*
This code is described in "Computational Geometry in C" (Second Edition),
Chapter 7. It is not written to be comprehensible without the
...
...
modules/imgproc/src/matchcontours.cpp
View file @
dc4d0398
...
...
@@ -40,64 +40,21 @@
//M*/
#include "precomp.hpp"
/*F///////////////////////////////////////////////////////////////////////////////////////
// Name: cvMatchContours
// Purpose:
// Calculates matching of the two contours
// Context:
// Parameters:
// contour_1 - pointer to the first input contour object.
// contour_2 - pointer to the second input contour object.
// method - method for the matching calculation
// (now CV_IPPI_CONTOURS_MATCH_I1, CV_CONTOURS_MATCH_I2 or
// CV_CONTOURS_MATCH_I3 only )
// rezult - output calculated measure
//
//F*/
CV_IMPL
double
cvMatchShapes
(
const
void
*
contour1
,
const
void
*
contour2
,
int
method
,
double
/*parameter*/
)
double
cv
::
matchShapes
(
InputArray
contour1
,
InputArray
contour2
,
int
method
,
double
)
{
CvMoments
moments
;
CvHuMoments
huMoments
;
double
ma
[
7
],
mb
[
7
];
int
i
,
sma
,
smb
;
double
eps
=
1.e-5
;
double
mmm
;
double
result
=
0
;
if
(
!
contour1
||
!
contour2
)
CV_Error
(
CV_StsNullPtr
,
""
);
// calculate moments of the first shape
cvMoments
(
contour1
,
&
moments
);
cvGetHuMoments
(
&
moments
,
&
huMoments
);
ma
[
0
]
=
huMoments
.
hu1
;
ma
[
1
]
=
huMoments
.
hu2
;
ma
[
2
]
=
huMoments
.
hu3
;
ma
[
3
]
=
huMoments
.
hu4
;
ma
[
4
]
=
huMoments
.
hu5
;
ma
[
5
]
=
huMoments
.
hu6
;
ma
[
6
]
=
huMoments
.
hu7
;
// calculate moments of the second shape
cvMoments
(
contour2
,
&
moments
);
cvGetHuMoments
(
&
moments
,
&
huMoments
);
mb
[
0
]
=
huMoments
.
hu1
;
mb
[
1
]
=
huMoments
.
hu2
;
mb
[
2
]
=
huMoments
.
hu3
;
mb
[
3
]
=
huMoments
.
hu4
;
mb
[
4
]
=
huMoments
.
hu5
;
mb
[
5
]
=
huMoments
.
hu6
;
mb
[
6
]
=
huMoments
.
hu7
;
HuMoments
(
moments
(
contour1
),
ma
);
HuMoments
(
moments
(
contour2
),
mb
);
switch
(
method
)
{
case
1
:
{
for
(
i
=
0
;
i
<
7
;
i
++
)
{
double
ama
=
fabs
(
ma
[
i
]
);
...
...
@@ -124,10 +81,8 @@ cvMatchShapes( const void* contour1, const void* contour2,
}
}
break
;
}
case
2
:
{
for
(
i
=
0
;
i
<
7
;
i
++
)
{
double
ama
=
fabs
(
ma
[
i
]
);
...
...
@@ -154,10 +109,8 @@ cvMatchShapes( const void* contour1, const void* contour2,
}
}
break
;
}
case
3
:
{
for
(
i
=
0
;
i
<
7
;
i
++
)
{
double
ama
=
fabs
(
ma
[
i
]
);
...
...
@@ -186,7 +139,6 @@ cvMatchShapes( const void* contour1, const void* contour2,
}
}
break
;
}
default
:
CV_Error
(
CV_StsBadArg
,
"Unknown comparison method"
);
}
...
...
@@ -195,4 +147,15 @@ cvMatchShapes( const void* contour1, const void* contour2,
}
CV_IMPL
double
cvMatchShapes
(
const
void
*
_contour1
,
const
void
*
_contour2
,
int
method
,
double
parameter
)
{
cv
::
AutoBuffer
<
double
>
abuf1
,
abuf2
;
cv
::
Mat
contour1
=
cv
::
cvarrToMat
(
_contour1
,
false
,
false
,
0
,
&
abuf1
);
cv
::
Mat
contour2
=
cv
::
cvarrToMat
(
_contour2
,
false
,
false
,
0
,
&
abuf2
);
return
cv
::
matchShapes
(
contour1
,
contour2
,
method
,
parameter
);
}
/* End of file. */
modules/imgproc/src/rotcalipers.cpp
View file @
dc4d0398
This diff is collapsed.
Click to expand it.
modules/imgproc/src/shapedescr.cpp
View file @
dc4d0398
This diff is collapsed.
Click to expand it.
samples/cpp/minarea.cpp
View file @
dc4d0398
...
...
@@ -13,7 +13,7 @@ static void help()
"Random points are generated and then enclosed.
\n
"
"Call:
\n
"
"./minarea
\n
"
"Using OpenCV v
ersion %s
\n
"
<<
CV_VERSION
<<
"
\n
"
<<
endl
;
"Using OpenCV v"
<<
CV_VERSION
<<
"
\n
"
<<
endl
;
}
int
main
(
int
/*argc*/
,
char
**
/*argv*/
)
...
...
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