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
0ffdc782
Commit
0ffdc782
authored
Nov 11, 2013
by
Davis King
Browse files
Made remove_unobtainable_rectangles() work on scan_fhog_pyramid.
parent
791e9cda
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
95 additions
and
64 deletions
+95
-64
dlib/image_processing/remove_unobtainable_rectangles.h
dlib/image_processing/remove_unobtainable_rectangles.h
+95
-64
No files found.
dlib/image_processing/remove_unobtainable_rectangles.h
View file @
0ffdc782
...
@@ -7,6 +7,7 @@
...
@@ -7,6 +7,7 @@
#include "scan_image_pyramid.h"
#include "scan_image_pyramid.h"
#include "scan_image_boxes.h"
#include "scan_image_boxes.h"
#include "scan_image_custom.h"
#include "scan_image_custom.h"
#include "scan_fhog_pyramid.h"
#include "../svm/structural_object_detection_trainer.h"
#include "../svm/structural_object_detection_trainer.h"
#include "../geometry.h"
#include "../geometry.h"
...
@@ -53,87 +54,117 @@ namespace dlib
...
@@ -53,87 +54,117 @@ namespace dlib
return
best_rect
;
return
best_rect
;
}
}
}
// ------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template
<
template
<
typename
image_array_type
,
typename
image_array_type
,
typename
Pyramid_type
,
typename
image_scanner_type
typename
Feature_extractor_type
>
>
std
::
vector
<
std
::
vector
<
rectangle
>
>
pyramid_remove_unobtainable_rectangles
(
std
::
vector
<
std
::
vector
<
rectangle
>
>
remove_unobtainable_rectangles
(
const
structural_object_detection_trainer
<
image_scanner_type
>&
trainer
,
const
structural_object_detection_trainer
<
scan_image_pyramid
<
Pyramid_type
,
Feature_extractor_type
>
>&
trainer
,
const
image_array_type
&
images
,
const
image_array_type
&
images
,
std
::
vector
<
std
::
vector
<
rectangle
>
>&
object_locations
std
::
vector
<
std
::
vector
<
rectangle
>
>&
object_locations
)
)
{
{
using
namespace
dlib
::
impl
;
using
namespace
dlib
::
impl
;
// make sure requires clause is not broken
// make sure requires clause is not broken
DLIB_ASSERT
(
images
.
size
()
==
object_locations
.
size
(),
DLIB_ASSERT
(
images
.
size
()
==
object_locations
.
size
(),
"
\t
std::vector<std::vector<rectangle>> remove_unobtainable_rectangles()"
"
\t
std::vector<std::vector<rectangle>> remove_unobtainable_rectangles()"
<<
"
\n\t
Invalid inputs were given to this function."
<<
"
\n\t
Invalid inputs were given to this function."
);
);
std
::
vector
<
std
::
vector
<
rectangle
>
>
rejects
(
images
.
size
());
std
::
vector
<
std
::
vector
<
rectangle
>
>
rejects
(
images
.
size
());
// If the trainer is setup to automatically fit the overlap tester to the data then
// we should use the loosest possible overlap tester here. Otherwise we should use
// the tester the trainer will use.
test_box_overlap
boxes_overlap
(
0.9999999
,
1
);
if
(
!
trainer
.
auto_set_overlap_tester
())
boxes_overlap
=
trainer
.
get_overlap_tester
();
for
(
unsigned
long
k
=
0
;
k
<
images
.
size
();
++
k
)
// If the trainer is setup to automatically fit the overlap tester to the data then
{
// we should use the loosest possible overlap tester here. Otherwise we should use
std
::
vector
<
rectangle
>
objs
=
object_locations
[
k
];
// the tester the trainer will use.
test_box_overlap
boxes_overlap
(
0.9999999
,
1
);
if
(
!
trainer
.
auto_set_overlap_tester
())
boxes_overlap
=
trainer
.
get_overlap_tester
();
// First remove things that don't have any matches with the candidate object
for
(
unsigned
long
k
=
0
;
k
<
images
.
size
();
++
k
)
// locations.
std
::
vector
<
rectangle
>
good_rects
;
for
(
unsigned
long
j
=
0
;
j
<
objs
.
size
();
++
j
)
{
{
const
rectangle
rect
=
trainer
.
get_scanner
().
get_best_matching_rect
(
objs
[
j
]);
std
::
vector
<
rectangle
>
objs
=
object_locations
[
k
];
const
double
score
=
(
objs
[
j
].
intersect
(
rect
)).
area
()
/
(
double
)(
objs
[
j
]
+
rect
).
area
();
if
(
score
>
trainer
.
get_match_eps
())
good_rects
.
push_back
(
objs
[
j
]);
else
rejects
[
k
].
push_back
(
objs
[
j
]);
}
object_locations
[
k
]
=
good_rects
;
// First remove things that don't have any matches with the candidate object
// locations.
std
::
vector
<
rectangle
>
good_rects
;
for
(
unsigned
long
j
=
0
;
j
<
objs
.
size
();
++
j
)
{
const
rectangle
rect
=
trainer
.
get_scanner
().
get_best_matching_rect
(
objs
[
j
]);
const
double
score
=
(
objs
[
j
].
intersect
(
rect
)).
area
()
/
(
double
)(
objs
[
j
]
+
rect
).
area
();
if
(
score
>
trainer
.
get_match_eps
())
good_rects
.
push_back
(
objs
[
j
]);
else
rejects
[
k
].
push_back
(
objs
[
j
]);
}
object_locations
[
k
]
=
good_rects
;
// Remap these rectangles to the ones that can come out of the scanner. That
// way when we compare them to each other in the following loop we will know if
// any distinct truth rectangles get mapped to overlapping boxes.
objs
.
resize
(
good_rects
.
size
());
for
(
unsigned
long
i
=
0
;
i
<
good_rects
.
size
();
++
i
)
objs
[
i
]
=
trainer
.
get_scanner
().
get_best_matching_rect
(
good_rects
[
i
]);
good_rects
.
clear
();
// Remap these rectangles to the ones that can come out of the scanner. That
// now check for truth rects that are too close together.
// way when we compare them to each other in the following loop we will know if
for
(
unsigned
long
i
=
0
;
i
<
objs
.
size
();
++
i
)
// any distinct truth rectangles get mapped to overlapping boxes.
{
objs
.
resize
(
good_rects
.
size
());
// check if objs[i] hits another box
for
(
unsigned
long
i
=
0
;
i
<
good_rects
.
size
();
++
i
)
bool
hit_box
=
false
;
objs
[
i
]
=
trainer
.
get_scanner
().
get_best_matching_rect
(
good_rects
[
i
]);
for
(
unsigned
long
j
=
i
+
1
;
j
<
objs
.
size
();
++
j
)
good_rects
.
clear
();
// now check for truth rects that are too close together.
for
(
unsigned
long
i
=
0
;
i
<
objs
.
size
();
++
i
)
{
{
if
(
boxes_overlap
(
objs
[
i
],
objs
[
j
]))
// check if objs[i] hits another box
bool
hit_box
=
false
;
for
(
unsigned
long
j
=
i
+
1
;
j
<
objs
.
size
();
++
j
)
{
{
hit_box
=
true
;
if
(
boxes_overlap
(
objs
[
i
],
objs
[
j
]))
break
;
{
hit_box
=
true
;
break
;
}
}
}
if
(
hit_box
)
rejects
[
k
].
push_back
(
object_locations
[
k
][
i
]);
else
good_rects
.
push_back
(
object_locations
[
k
][
i
]);
}
}
if
(
hit_box
)
object_locations
[
k
]
=
good_rects
;
rejects
[
k
].
push_back
(
object_locations
[
k
][
i
]);
else
good_rects
.
push_back
(
object_locations
[
k
][
i
]);
}
}
object_locations
[
k
]
=
good_rects
;
return
rejects
;
}
}
return
rejects
;
}
// ----------------------------------------------------------------------------------------
template
<
typename
image_array_type
,
typename
Pyramid_type
,
typename
Feature_extractor_type
>
std
::
vector
<
std
::
vector
<
rectangle
>
>
remove_unobtainable_rectangles
(
const
structural_object_detection_trainer
<
scan_image_pyramid
<
Pyramid_type
,
Feature_extractor_type
>
>&
trainer
,
const
image_array_type
&
images
,
std
::
vector
<
std
::
vector
<
rectangle
>
>&
object_locations
)
{
return
impl
::
pyramid_remove_unobtainable_rectangles
(
trainer
,
images
,
object_locations
);
}
// ----------------------------------------------------------------------------------------
template
<
typename
image_array_type
,
typename
Pyramid_type
>
std
::
vector
<
std
::
vector
<
rectangle
>
>
remove_unobtainable_rectangles
(
const
structural_object_detection_trainer
<
scan_fhog_pyramid
<
Pyramid_type
>
>&
trainer
,
const
image_array_type
&
images
,
std
::
vector
<
std
::
vector
<
rectangle
>
>&
object_locations
)
{
return
impl
::
pyramid_remove_unobtainable_rectangles
(
trainer
,
images
,
object_locations
);
}
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
...
...
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