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
e36ad508
Commit
e36ad508
authored
Mar 29, 2012
by
Vadim Pisarevsky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added cv::convexityDefects (ticket #796)
parent
959c37fc
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
1 deletion
+42
-1
imgproc.hpp
modules/imgproc/include/opencv2/imgproc/imgproc.hpp
+2
-0
contours.cpp
modules/imgproc/src/contours.cpp
+40
-1
No files found.
modules/imgproc/include/opencv2/imgproc/imgproc.hpp
View file @
e36ad508
...
@@ -1029,6 +1029,8 @@ CV_EXPORTS_W double matchShapes( InputArray contour1, InputArray contour2,
...
@@ -1029,6 +1029,8 @@ CV_EXPORTS_W double matchShapes( InputArray contour1, InputArray contour2,
//! computes convex hull for a set of 2D points.
//! computes convex hull for a set of 2D points.
CV_EXPORTS_W
void
convexHull
(
InputArray
points
,
OutputArray
hull
,
CV_EXPORTS_W
void
convexHull
(
InputArray
points
,
OutputArray
hull
,
bool
clockwise
=
false
,
bool
returnPoints
=
true
);
bool
clockwise
=
false
,
bool
returnPoints
=
true
);
//! computes the contour convexity defects
CV_EXPORTS_W
void
convexityDefects
(
InputArray
points
,
InputArray
hull
,
OutputArray
defects
);
//! returns true iff the contour is convex. Does not support contours with self-intersection
//! returns true iff the contour is convex. Does not support contours with self-intersection
CV_EXPORTS_W
bool
isContourConvex
(
InputArray
contour
);
CV_EXPORTS_W
bool
isContourConvex
(
InputArray
contour
);
...
...
modules/imgproc/src/contours.cpp
View file @
e36ad508
...
@@ -1961,6 +1961,46 @@ void cv::convexHull( InputArray _points, OutputArray _hull, bool clockwise, bool
...
@@ -1961,6 +1961,46 @@ void cv::convexHull( InputArray _points, OutputArray _hull, bool clockwise, bool
shull
.
copyTo
(
dhull
);
shull
.
copyTo
(
dhull
);
}
}
void
cv
::
convexityDefects
(
InputArray
_points
,
InputArray
_hull
,
OutputArray
_defects
)
{
Mat
points
=
_points
.
getMat
();
CV_Assert
(
points
.
isContinuous
()
&&
points
.
type
()
==
CV_32SC2
);
Mat
hull
=
_hull
.
getMat
();
Ptr
<
CvMemStorage
>
storage
=
cvCreateMemStorage
();
CvMat
c_points
=
points
,
c_hull
=
hull
;
CvSeq
*
seq
=
cvConvexityDefects
(
&
c_points
,
&
c_hull
);
int
i
,
n
=
seq
->
total
;
if
(
n
==
0
)
{
_defects
.
release
();
return
;
}
_defects
.
create
(
n
,
1
,
CV_32SC4
);
Mat
defects
=
_defects
.
getMat
();
SeqIterator
<
CvConvexityDefect
>
it
=
Seq
<
CvConvexityDefect
>
(
seq
).
begin
();
CvPoint
*
ptorg
=
(
CvPoint
*
)
points
.
data
;
for
(
i
=
0
;
i
<
n
;
i
++
,
++
it
)
{
CvConvexityDefect
&
d
=
*
it
;
int
idx0
=
(
int
)(
d
.
start
-
ptorg
);
int
idx1
=
(
int
)(
d
.
end
-
ptorg
);
int
idx2
=
(
int
)(
d
.
depth_point
-
ptorg
);
CV_Assert
(
0
<=
idx0
&&
idx0
<
n
);
CV_Assert
(
0
<=
idx1
&&
idx1
<
n
);
CV_Assert
(
0
<=
idx2
&&
idx2
<
n
);
CV_Assert
(
d
.
depth
>=
0
);
int
idepth
=
cvRound
(
d
.
depth
*
256
);
defects
.
at
<
Vec4i
>
(
i
)
=
Vec4i
(
idx0
,
idx1
,
idx2
,
idepth
);
}
}
bool
cv
::
isContourConvex
(
InputArray
_contour
)
bool
cv
::
isContourConvex
(
InputArray
_contour
)
{
{
Mat
contour
=
_contour
.
getMat
();
Mat
contour
=
_contour
.
getMat
();
...
@@ -1993,7 +2033,6 @@ void cv::fitLine( InputArray _points, OutputArray _line, int distType,
...
@@ -1993,7 +2033,6 @@ void cv::fitLine( InputArray _points, OutputArray _line, int distType,
float
line
[
6
];
float
line
[
6
];
cvFitLine
(
&
_cpoints
,
distType
,
param
,
reps
,
aeps
,
&
line
[
0
]);
cvFitLine
(
&
_cpoints
,
distType
,
param
,
reps
,
aeps
,
&
line
[
0
]);
int
out_size
=
(
is2d
)
?
(
(
is3d
)
?
(
points
.
channels
()
*
points
.
rows
*
2
)
:
4
)
:
6
;
int
out_size
=
(
is2d
)
?
(
(
is3d
)
?
(
points
.
channels
()
*
points
.
rows
*
2
)
:
4
)
:
6
;
_line
.
create
(
out_size
,
1
,
CV_32F
,
-
1
,
true
);
_line
.
create
(
out_size
,
1
,
CV_32F
,
-
1
,
true
);
...
...
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