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
b4734976
Commit
b4734976
authored
Dec 26, 2011
by
Davis King
Browse files
Added determine_object_boxes()
parent
849fd0c2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
159 additions
and
0 deletions
+159
-0
dlib/image_processing/scan_image_pyramid_tools.h
dlib/image_processing/scan_image_pyramid_tools.h
+114
-0
dlib/image_processing/scan_image_pyramid_tools_abstract.h
dlib/image_processing/scan_image_pyramid_tools_abstract.h
+45
-0
No files found.
dlib/image_processing/scan_image_pyramid_tools.h
View file @
b4734976
...
...
@@ -8,6 +8,8 @@
#include "../lsh.h"
#include "../statistics.h"
#include "../image_keypoint.h"
#include <list>
#include "../geometry.h"
namespace
dlib
{
...
...
@@ -89,6 +91,118 @@ namespace dlib
setup_hashed_features
(
scanner
,
images
,
feature_extractor
(),
bits
,
num_samples
);
}
// ----------------------------------------------------------------------------------------
namespace
impl
{
bool
compare_first
(
const
std
::
pair
<
unsigned
long
,
rectangle
>&
a
,
const
std
::
pair
<
unsigned
long
,
rectangle
>&
b
)
{
return
a
.
first
<
b
.
first
;
}
}
template
<
typename
image_scanner_type
>
std
::
vector
<
rectangle
>
determine_object_boxes
(
const
image_scanner_type
&
scanner
,
const
std
::
vector
<
rectangle
>&
rects
,
double
min_match_score
)
/*!
requires
- 0 < min_match_score <= 1
- image_scanner_type == an implementation of the scan_image_pyramid
object defined in dlib/image_processing/scan_image_pyramid_tools_abstract.h
ensures
- returns a set of object boxes which, when used as detection
templates with the given scanner, can attain at least
min_match_score alignment with every element of rects. Note that
the alignment between two rectangles A and B is defined as
(A.intersect(B).area())/(double)(A+B).area()
!*/
{
// make sure requires clause is not broken
DLIB_ASSERT
(
0
<
min_match_score
&&
min_match_score
<=
1
,
"
\t
std::vector<rectangle> determine_object_boxes()"
<<
"
\n\t
Invalid inputs were given to this function. "
<<
"
\n\t
min_match_score: "
<<
min_match_score
);
typename
image_scanner_type
::
pyramid_type
pyr
;
typedef
std
::
list
<
std
::
pair
<
unsigned
long
,
rectangle
>
>
list_type
;
// copy rects into sorted_rects and sort them in order of increasing area
list_type
sorted_rects
;
for
(
unsigned
long
i
=
0
;
i
<
rects
.
size
();
++
i
)
sorted_rects
.
push_back
(
std
::
make_pair
(
rects
[
i
].
area
(),
rects
[
i
]));
sorted_rects
.
sort
(
dlib
::
impl
::
compare_first
);
std
::
vector
<
rectangle
>
object_boxes
;
while
(
sorted_rects
.
size
()
!=
0
)
{
rectangle
cur
=
sorted_rects
.
front
().
second
;
sorted_rects
.
pop_front
();
object_boxes
.
push_back
(
centered_rect
(
point
(
0
,
0
),
cur
.
width
(),
cur
.
height
()));
// remove all the rectangles which match cur
for
(
unsigned
long
itr
=
0
;
itr
<
scanner
.
get_max_pyramid_levels
();
++
itr
)
{
list_type
::
iterator
i
=
sorted_rects
.
begin
();
while
(
i
!=
sorted_rects
.
end
())
{
const
rectangle
temp
=
move_rect
(
i
->
second
,
cur
.
tl_corner
());
const
double
match_score
=
(
cur
.
intersect
(
temp
).
area
())
/
(
double
)(
cur
+
temp
).
area
();
if
(
match_score
>
min_match_score
)
{
i
=
sorted_rects
.
erase
(
i
);
}
else
{
++
i
;
}
}
cur
=
pyr
.
rect_up
(
cur
);
}
}
return
object_boxes
;
}
// ----------------------------------------------------------------------------------------
template
<
typename
image_scanner_type
>
std
::
vector
<
rectangle
>
determine_object_boxes
(
const
image_scanner_type
&
scanner
,
const
std
::
vector
<
std
::
vector
<
rectangle
>
>&
rects
,
double
min_match_score
)
{
// make sure requires clause is not broken
DLIB_ASSERT
(
0
<
min_match_score
&&
min_match_score
<=
1
,
"
\t
std::vector<rectangle> determine_object_boxes()"
<<
"
\n\t
Invalid inputs were given to this function. "
<<
"
\n\t
min_match_score: "
<<
min_match_score
);
std
::
vector
<
rectangle
>
temp
;
for
(
unsigned
long
i
=
0
;
i
<
rects
.
size
();
++
i
)
{
for
(
unsigned
long
j
=
0
;
j
<
rects
[
i
].
size
();
++
j
)
{
temp
.
push_back
(
rects
[
i
][
j
]);
}
}
return
determine_object_boxes
(
scanner
,
temp
,
min_match_score
);
}
// ----------------------------------------------------------------------------------------
}
...
...
dlib/image_processing/scan_image_pyramid_tools_abstract.h
View file @
b4734976
...
...
@@ -84,6 +84,51 @@ namespace dlib
feature vectors.
!*/
// ----------------------------------------------------------------------------------------
template
<
typename
image_scanner_type
>
std
::
vector
<
rectangle
>
determine_object_boxes
(
const
image_scanner_type
&
scanner
,
const
std
::
vector
<
rectangle
>&
rects
,
double
min_match_score
);
/*!
requires
- 0 < min_match_score <= 1
- image_scanner_type == an implementation of the scan_image_pyramid
object defined in dlib/image_processing/scan_image_pyramid_tools_abstract.h
ensures
- returns a set of object boxes which, when used as detection
templates with the given scanner, can attain at least
min_match_score alignment with every element of rects. Note that
the alignment between two rectangles A and B is defined as
(A.intersect(B).area())/(double)(A+B).area()
!*/
// ----------------------------------------------------------------------------------------
template
<
typename
image_scanner_type
>
std
::
vector
<
rectangle
>
determine_object_boxes
(
const
image_scanner_type
&
scanner
,
const
std
::
vector
<
std
::
vector
<
rectangle
>
>&
rects
,
double
min_match_score
);
/*!
requires
- 0 < min_match_score <= 1
- image_scanner_type == an implementation of the scan_image_pyramid
object defined in dlib/image_processing/scan_image_pyramid_tools_abstract.h
ensures
- copies all rectangles in rects into a std::vector<rectangle> object, call it
R. Then this function returns determine_object_boxes(scanner,R,min_match_score).
That is, it just called the version of determine_object_boxes() defined above
and returns the results.
!*/
// ----------------------------------------------------------------------------------------
}
...
...
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