Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
ac83daec
Commit
ac83daec
authored
Dec 24, 2011
by
Davis King
Browse files
Made the test_box_overlap a little more flexible. This change breaks
backwards compatibility with the previous version though.
parent
8268c2fe
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
98 additions
and
11 deletions
+98
-11
dlib/image_processing/box_overlap_testing.h
dlib/image_processing/box_overlap_testing.h
+57
-8
dlib/image_processing/box_overlap_testing_abstract.h
dlib/image_processing/box_overlap_testing_abstract.h
+41
-3
No files found.
dlib/image_processing/box_overlap_testing.h
View file @
ac83daec
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
#include "box_overlap_testing_abstract.h"
#include "box_overlap_testing_abstract.h"
#include "../geometry.h"
#include "../geometry.h"
#include <vector>
namespace
dlib
namespace
dlib
{
{
...
@@ -15,18 +16,21 @@ namespace dlib
...
@@ -15,18 +16,21 @@ namespace dlib
{
{
public:
public:
test_box_overlap
(
test_box_overlap
(
)
:
overlap_thresh
(
0.5
)
)
:
match_thresh
(
0.5
),
overlap_thresh
(
0.5
)
{}
{}
test_box_overlap
(
test_box_overlap
(
double
match_thresh_
,
double
overlap_thresh_
double
overlap_thresh_
)
:
overlap_thresh
(
overlap_thresh_
)
)
:
match_thresh
(
match_thresh_
),
overlap_thresh
(
overlap_thresh_
)
{
{
// make sure requires clause is not broken
// make sure requires clause is not broken
DLIB_ASSERT
(
0
<=
overlap_thresh
&&
overlap_thresh
<=
1
,
DLIB_ASSERT
(
0
<=
match_thresh
&&
match_thresh
<=
1
&&
"
\t
test_box_overlap::test_box_overlap(overlap_thresh)"
0
<=
overlap_thresh
&&
overlap_thresh
<=
1
,
"
\t
test_box_overlap::test_box_overlap(match_thresh, overlap_thresh)"
<<
"
\n\t
Invalid inputs were given to this function "
<<
"
\n\t
Invalid inputs were given to this function "
<<
"
\n\t
overlap_thresh: "
<<
overlap_thresh
<<
"
\n\t
match_thresh: "
<<
match_thresh
<<
"
\n\t
overlap_thresh: "
<<
overlap_thresh
<<
"
\n\t
this: "
<<
this
<<
"
\n\t
this: "
<<
this
);
);
...
@@ -39,7 +43,9 @@ namespace dlib
...
@@ -39,7 +43,9 @@ namespace dlib
{
{
const
double
inner
=
a
.
intersect
(
b
).
area
();
const
double
inner
=
a
.
intersect
(
b
).
area
();
const
double
outer
=
(
a
+
b
).
area
();
const
double
outer
=
(
a
+
b
).
area
();
if
(
inner
/
outer
>
overlap_thresh
)
if
(
inner
/
outer
>
match_thresh
||
inner
/
a
.
area
()
>
overlap_thresh
||
inner
/
b
.
area
()
>
overlap_thresh
)
return
true
;
return
true
;
else
else
return
false
;
return
false
;
...
@@ -51,7 +57,14 @@ namespace dlib
...
@@ -51,7 +57,14 @@ namespace dlib
return
overlap_thresh
;
return
overlap_thresh
;
}
}
double
get_match_thresh
(
)
const
{
return
match_thresh
;
}
private:
private:
double
match_thresh
;
double
overlap_thresh
;
double
overlap_thresh
;
};
};
...
@@ -62,6 +75,7 @@ namespace dlib
...
@@ -62,6 +75,7 @@ namespace dlib
std
::
ostream
&
out
std
::
ostream
&
out
)
)
{
{
serialize
(
item
.
get_match_thresh
(),
out
);
serialize
(
item
.
get_overlap_thresh
(),
out
);
serialize
(
item
.
get_overlap_thresh
(),
out
);
}
}
...
@@ -70,9 +84,44 @@ namespace dlib
...
@@ -70,9 +84,44 @@ namespace dlib
std
::
istream
&
in
std
::
istream
&
in
)
)
{
{
double
overlap_thresh
;
double
overlap_thresh
,
match_thresh
;
deserialize
(
match_thresh
,
in
);
deserialize
(
overlap_thresh
,
in
);
deserialize
(
overlap_thresh
,
in
);
item
=
test_box_overlap
(
overlap_thresh
);
item
=
test_box_overlap
(
match_thresh
,
overlap_thresh
);
}
// ----------------------------------------------------------------------------------------
inline
test_box_overlap
find_tight_overlap_tester
(
const
std
::
vector
<
std
::
vector
<
rectangle
>
>&
rects
)
{
double
max_overlap
=
0
;
double
max_match_score
=
0
;
for
(
unsigned
long
i
=
0
;
i
<
rects
.
size
();
++
i
)
{
for
(
unsigned
long
j
=
0
;
j
<
rects
[
i
].
size
();
++
j
)
{
for
(
unsigned
long
k
=
j
+
1
;
k
<
rects
[
i
].
size
();
++
k
)
{
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
();
if
(
match_score
>
max_match_score
)
max_match_score
=
match_score
;
if
(
overlap_a
>
max_overlap
)
max_overlap
=
overlap_a
;
if
(
overlap_b
>
max_overlap
)
max_overlap
=
overlap_b
;
}
}
}
return
test_box_overlap
(
max_match_score
,
max_overlap
);
}
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
...
...
dlib/image_processing/box_overlap_testing_abstract.h
View file @
ac83daec
...
@@ -29,15 +29,19 @@ namespace dlib
...
@@ -29,15 +29,19 @@ namespace dlib
/*!
/*!
ensures
ensures
- #get_overlap_thresh() == 0.5
- #get_overlap_thresh() == 0.5
- #get_match_thresh() == 0.5
!*/
!*/
test_box_overlap
(
test_box_overlap
(
double
match_thresh
,
double
overlap_thresh
double
overlap_thresh
);
);
/*!
/*!
requires
requires
- 0 <= match_thresh <= 1
- 0 <= overlap_thresh <= 1
- 0 <= overlap_thresh <= 1
ensures
ensures
- #get_match_thresh() == match_thresh
- #get_overlap_thresh() == overlap_thresh
- #get_overlap_thresh() == overlap_thresh
!*/
!*/
...
@@ -47,15 +51,31 @@ namespace dlib
...
@@ -47,15 +51,31 @@ namespace dlib
)
const
;
)
const
;
/*!
/*!
ensures
ensures
- returns true if a.intersect(b).area()/(a+b).area > get_overlap_thresh()
- returns true if a and b overlap "enough". This is defined precisely below.
and false otherwise. (i.e. returns true if a and b overlap enough)
- if (a.intersect(b).area()/(a+b).area() > get_match_thresh() ||
a.intersect(b).area()/a.area() > get_overlap_thresh() ||
a.intersect(b).area()/a.area() > get_overlap_thresh() ) then
- returns true
- else
- returns false
!*/
!*/
double
get_overlap_thresh
(
double
get_overlap_thresh
(
)
const
;
)
const
;
/*!
/*!
ensures
ensures
- returns the threshold used to determine if two rectangles overlap.
- returns the threshold used to determine if two rectangles overlap. This
value is the percent of a rectangle's area covered by another rectangle.
!*/
double
get_match_thresh
(
)
const
;
/*!
ensures
- returns the threshold used to determine if two rectangles match.
Note that the match score varies from 0 to 1 and only becomes 1
when two rectangles are identical.
!*/
!*/
...
@@ -79,6 +99,24 @@ namespace dlib
...
@@ -79,6 +99,24 @@ namespace dlib
provides deserialization support
provides deserialization support
!*/
!*/
// ----------------------------------------------------------------------------------------
test_box_overlap
find_tight_overlap_tester
(
const
std
::
vector
<
std
::
vector
<
rectangle
>
>&
rects
);
/*!
ensures
- This function finds the most restrictive test_box_overlap object possible
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
as possible such that the following conditions are satisfied.
- for all valid i:
- for all distinct rectangles A and B in rects[i]:
- TBO(A,B) == false
!*/
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
}
}
...
...
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