Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
dlib
Commits
fb44c7ba
Commit
fb44c7ba
authored
Aug 27, 2016
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added box_intersection_over_union() and also renamed the class members of
test_box_overlap so they are less confusing and vague.
parent
f0dff5fc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
107 additions
and
60 deletions
+107
-60
box_overlap_testing.h
dlib/image_processing/box_overlap_testing.h
+65
-41
box_overlap_testing_abstract.h
dlib/image_processing/box_overlap_testing_abstract.h
+42
-19
No files found.
dlib/image_processing/box_overlap_testing.h
View file @
fb44c7ba
...
...
@@ -10,27 +10,51 @@
namespace
dlib
{
// ----------------------------------------------------------------------------------------
inline
double
box_intersection_over_union
(
const
drectangle
&
a
,
const
drectangle
&
b
)
{
const
double
inner
=
a
.
intersect
(
b
).
area
();
if
(
inner
==
0
)
return
0
;
const
double
outer
=
(
a
+
b
).
area
();
return
inner
/
outer
;
}
// ----------------------------------------------------------------------------------------
inline
double
box_intersection_over_union
(
const
rectangle
&
a
,
const
rectangle
&
b
)
{
return
box_intersection_over_union
(
drectangle
(
a
),
drectangle
(
b
));
}
// ----------------------------------------------------------------------------------------
class
test_box_overlap
{
public
:
test_box_overlap
(
)
:
match_thresh
(
0
.
5
),
overlap
_thresh
(
1
.
0
)
)
:
iou_thresh
(
0
.
5
),
percent_covered
_thresh
(
1
.
0
)
{}
explicit
test_box_overlap
(
double
match
_thresh_
,
double
overlap
_thresh_
=
1
.
0
)
:
match_thresh
(
match_thresh_
),
overlap_thresh
(
overlap
_thresh_
)
double
iou
_thresh_
,
double
percent_covered
_thresh_
=
1
.
0
)
:
iou_thresh
(
iou_thresh_
),
percent_covered_thresh
(
percent_covered
_thresh_
)
{
// make sure requires clause is not broken
DLIB_ASSERT
(
0
<=
match_thresh
&&
match
_thresh
<=
1
&&
0
<=
overlap_thresh
&&
overlap
_thresh
<=
1
,
"
\t
test_box_overlap::test_box_overlap(
match_thresh, overlap
_thresh)"
DLIB_ASSERT
(
0
<=
iou_thresh
&&
iou
_thresh
<=
1
&&
0
<=
percent_covered_thresh
&&
percent_covered
_thresh
<=
1
,
"
\t
test_box_overlap::test_box_overlap(
iou_thresh, percent_covered
_thresh)"
<<
"
\n\t
Invalid inputs were given to this function "
<<
"
\n\t
match_thresh: "
<<
match
_thresh
<<
"
\n\t
overlap_thresh: "
<<
overlap
_thresh
<<
"
\n\t
iou_thresh: "
<<
iou
_thresh
<<
"
\n\t
percent_covered_thresh: "
<<
percent_covered
_thresh
<<
"
\n\t
this: "
<<
this
);
...
...
@@ -46,29 +70,29 @@ namespace dlib
return
false
;
const
double
outer
=
(
a
+
b
).
area
();
if
(
inner
/
outer
>
match
_thresh
||
inner
/
a
.
area
()
>
overlap
_thresh
||
inner
/
b
.
area
()
>
overlap
_thresh
)
if
(
inner
/
outer
>
iou
_thresh
||
inner
/
a
.
area
()
>
percent_covered
_thresh
||
inner
/
b
.
area
()
>
percent_covered
_thresh
)
return
true
;
else
return
false
;
}
double
get_
overlap
_thresh
(
double
get_
percent_covered
_thresh
(
)
const
{
return
overlap
_thresh
;
return
percent_covered
_thresh
;
}
double
get_
match
_thresh
(
double
get_
iou
_thresh
(
)
const
{
return
match
_thresh
;
return
iou
_thresh
;
}
private
:
double
match
_thresh
;
double
overlap
_thresh
;
double
iou
_thresh
;
double
percent_covered
_thresh
;
};
// ----------------------------------------------------------------------------------------
...
...
@@ -78,8 +102,8 @@ namespace dlib
std
::
ostream
&
out
)
{
serialize
(
item
.
get_
match
_thresh
(),
out
);
serialize
(
item
.
get_
overlap
_thresh
(),
out
);
serialize
(
item
.
get_
iou
_thresh
(),
out
);
serialize
(
item
.
get_
percent_covered
_thresh
(),
out
);
}
inline
void
deserialize
(
...
...
@@ -87,10 +111,10 @@ namespace dlib
std
::
istream
&
in
)
{
double
overlap_thresh
,
match
_thresh
;
deserialize
(
match
_thresh
,
in
);
deserialize
(
overlap
_thresh
,
in
);
item
=
test_box_overlap
(
match_thresh
,
overlap
_thresh
);
double
percent_covered_thresh
,
iou
_thresh
;
deserialize
(
iou
_thresh
,
in
);
deserialize
(
percent_covered
_thresh
,
in
);
item
=
test_box_overlap
(
iou_thresh
,
percent_covered
_thresh
);
}
// ----------------------------------------------------------------------------------------
...
...
@@ -99,8 +123,8 @@ namespace dlib
const
std
::
vector
<
std
::
vector
<
rectangle
>
>&
rects
)
{
double
max_
overlap
=
0
;
double
max_
match
_score
=
0
;
double
max_
pcov
=
0
;
double
max_
iou
_score
=
0
;
for
(
unsigned
long
i
=
0
;
i
<
rects
.
size
();
++
i
)
{
for
(
unsigned
long
j
=
0
;
j
<
rects
[
i
].
size
();
++
j
)
...
...
@@ -109,29 +133,29 @@ namespace dlib
{
const
rectangle
a
=
rects
[
i
][
j
];
const
rectangle
b
=
rects
[
i
][
k
];
const
double
match
_score
=
(
a
.
intersect
(
b
)).
area
()
/
(
double
)(
a
+
b
).
area
();
const
double
overlap
_a
=
(
a
.
intersect
(
b
)).
area
()
/
(
double
)(
a
).
area
();
const
double
overlap
_b
=
(
a
.
intersect
(
b
)).
area
()
/
(
double
)(
b
).
area
();
const
double
iou
_score
=
(
a
.
intersect
(
b
)).
area
()
/
(
double
)(
a
+
b
).
area
();
const
double
pcov
_a
=
(
a
.
intersect
(
b
)).
area
()
/
(
double
)(
a
).
area
();
const
double
pcov
_b
=
(
a
.
intersect
(
b
)).
area
()
/
(
double
)(
b
).
area
();
if
(
match_score
>
max_match
_score
)
max_
match_score
=
match
_score
;
if
(
iou_score
>
max_iou
_score
)
max_
iou_score
=
iou
_score
;
if
(
overlap_a
>
max_overlap
)
max_
overlap
=
overlap
_a
;
if
(
overlap_b
>
max_overlap
)
max_
overlap
=
overlap
_b
;
if
(
pcov_a
>
max_pcov
)
max_
pcov
=
pcov
_a
;
if
(
pcov_b
>
max_pcov
)
max_
pcov
=
pcov
_b
;
}
}
}
// Relax these thresholds very slightly. We do this because on some systems the
// boxes that generated the max values erroneously trigger a box overlap
match
//
even though their overlap and match values are *equal* to the thresholds but no
t
// greater. That is, sometimes when double values get moved around they change
// boxes that generated the max values erroneously trigger a box overlap
iou even
//
though their percent covered and iou values are *equal* to the thresholds bu
t
//
not
greater. That is, sometimes when double values get moved around they change
// their values slightly, so this avoids the problems that can create.
max_
match_score
=
std
::
min
(
1
.
0000001
*
max_match
_score
,
1
.
0
);
max_
overlap
=
std
::
min
(
1
.
0000001
*
max_overlap
,
1
.
0
);
return
test_box_overlap
(
max_
match_score
,
max_overlap
);
max_
iou_score
=
std
::
min
(
1
.
0000001
*
max_iou
_score
,
1
.
0
);
max_
pcov
=
std
::
min
(
1
.
0000001
*
max_pcov
,
1
.
0
);
return
test_box_overlap
(
max_
iou_score
,
max_pcov
);
}
// ----------------------------------------------------------------------------------------
...
...
dlib/image_processing/box_overlap_testing_abstract.h
View file @
fb44c7ba
...
...
@@ -8,6 +8,30 @@
namespace
dlib
{
// ----------------------------------------------------------------------------------------
inline
double
box_intersection_over_union
(
const
drectangle
&
a
,
const
drectangle
&
b
);
/*!
ensures
- returns area of the intersection of a and b divided by (a+b).area(). If both
boxes are empty then returns 0.
!*/
// ----------------------------------------------------------------------------------------
inline
double
box_intersection_over_union
(
const
rectangle
&
a
,
const
rectangle
&
b
);
/*!
ensures
- returns area of the intersection of a and b divided by (a+b).area(). If both
boxes are empty then returns 0.
!*/
// ----------------------------------------------------------------------------------------
class
test_box_overlap
...
...
@@ -28,21 +52,21 @@ namespace dlib
);
/*!
ensures
- #get_
match
_thresh() == 0.5
- #get_
overlap
_thresh() == 1.0
- #get_
iou
_thresh() == 0.5
- #get_
percent_covered
_thresh() == 1.0
!*/
explicit
test_box_overlap
(
double
match
_thresh
,
double
overlap
_thresh
=
1
.
0
double
iou
_thresh
,
double
percent_covered
_thresh
=
1
.
0
);
/*!
requires
- 0 <=
match
_thresh <= 1
- 0 <=
overlap
_thresh <= 1
- 0 <=
iou
_thresh <= 1
- 0 <=
percent_covered
_thresh <= 1
ensures
- #get_
match_thresh() == match
_thresh
- #get_
overlap_thresh() == overlap
_thresh
- #get_
iou_thresh() == iou
_thresh
- #get_
percent_covered_thresh() == percent_covered
_thresh
!*/
bool
operator
()
(
...
...
@@ -52,31 +76,30 @@ namespace dlib
/*!
ensures
- returns true if a and b overlap "enough". This is defined precisely below.
- if (a.intersect(b).area()/(a+b).area() > get_
match
_thresh() ||
a.intersect(b).area()/a.area() > get_
overlap
_thresh() ||
a.intersect(b).area()/b.area() > get_
overlap
_thresh() ) then
- if (a.intersect(b).area()/(a+b).area() > get_
iou
_thresh() ||
a.intersect(b).area()/a.area() > get_
percent_covered
_thresh() ||
a.intersect(b).area()/b.area() > get_
percent_covered
_thresh() ) then
- returns true
- else
- returns false
!*/
double
get_
match
_thresh
(
double
get_
iou
_thresh
(
)
const
;
/*!
ensures
- returns the threshold used to determine if two rectangle
s match.
Note that the match score varies from 0 to 1 and only becomes 1
when two rectangles are identical.
- returns the threshold used to determine if two rectangle
's intersection
over union value is big enough to be considered a match. Note that the
iou score varies from 0 to 1 and only becomes 1 when two rectangles are
identical.
!*/
double
get_
overlap
_thresh
(
double
get_
percent_covered
_thresh
(
)
const
;
/*!
ensures
- returns the threshold used to determine if two rectangles overlap. This
value is the percent of a rectangle's area covered by another rectangle.
!*/
};
...
...
@@ -110,7 +133,7 @@ namespace dlib
that is consistent with the given set of sets of rectangles.
- To be precise, this function finds and returns a test_box_overlap object
TBO such that:
- TBO.get_
match_thresh() and TBO.get_overlap
_thresh() are as small
- TBO.get_
iou_thresh() and TBO.get_percent_covered
_thresh() are as small
as possible such that the following conditions are satisfied.
- for all valid i:
- for all distinct rectangles A and B in rects[i]:
...
...
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