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
2f6419cd
"git@developer.sourcefind.cn:OpenDAS/deepspeed.git" did not exist on "4acf0e01963c43e177d7f64a8ab8be011fd4c85c"
Commit
2f6419cd
authored
Aug 18, 2013
by
Davis King
Browse files
Added remove_unobtainable_rectangles() for the scan_image_custom scanner.
parent
7da29fb9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
151 additions
and
65 deletions
+151
-65
dlib/image_processing/remove_unobtainable_rectangles.h
dlib/image_processing/remove_unobtainable_rectangles.h
+119
-65
dlib/image_processing/remove_unobtainable_rectangles_abstract.h
...mage_processing/remove_unobtainable_rectangles_abstract.h
+32
-0
No files found.
dlib/image_processing/remove_unobtainable_rectangles.h
View file @
2f6419cd
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
#include "remove_unobtainable_rectangles_abstract.h"
#include "remove_unobtainable_rectangles_abstract.h"
#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 "../svm/structural_object_detection_trainer.h"
#include "../svm/structural_object_detection_trainer.h"
#include "../geometry.h"
#include "../geometry.h"
...
@@ -137,90 +138,143 @@ namespace dlib
...
@@ -137,90 +138,143 @@ namespace dlib
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template
<
namespace
impl
typename
image_array_type
,
typename
feature_extractor
,
typename
box_generator
>
std
::
vector
<
std
::
vector
<
rectangle
>
>
remove_unobtainable_rectangles
(
const
structural_object_detection_trainer
<
scan_image_boxes
<
feature_extractor
,
box_generator
>
>&
trainer
,
const
image_array_type
&
images
,
std
::
vector
<
std
::
vector
<
rectangle
>
>&
object_locations
)
{
{
using
namespace
dlib
::
impl
;
template
<
// make sure requires clause is not broken
typename
image_array_type
,
DLIB_ASSERT
(
images
.
size
()
==
object_locations
.
size
(),
typename
scanner_type
,
"
\t
std::vector<std::vector<rectangle>> remove_unobtainable_rectangles()"
typename
get_boxes_functor
<<
"
\n\t
Invalid inputs were given to this function."
>
std
::
vector
<
std
::
vector
<
rectangle
>
>
remove_unobtainable_rectangles
(
get_boxes_functor
&
bg
,
const
structural_object_detection_trainer
<
scanner_type
>&
trainer
,
const
image_array_type
&
images
,
std
::
vector
<
std
::
vector
<
rectangle
>
>&
object_locations
)
{
using
namespace
dlib
::
impl
;
// make sure requires clause is not broken
DLIB_ASSERT
(
images
.
size
()
==
object_locations
.
size
(),
"
\t
std::vector<std::vector<rectangle>> remove_unobtainable_rectangles()"
<<
"
\n\t
Invalid inputs were given to this function."
);
);
box_generator
bg
=
trainer
.
get_scanner
().
get_box_generator
();
std
::
vector
<
rectangle
>
rects
;
std
::
vector
<
rectangle
>
rects
;
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
// 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
// we should use the loosest possible overlap tester here. Otherwise we should use
// the tester the trainer will use.
// the tester the trainer will use.
test_box_overlap
boxes_overlap
(
0.9999999
,
1
);
test_box_overlap
boxes_overlap
(
0.9999999
,
1
);
if
(
!
trainer
.
auto_set_overlap_tester
())
if
(
!
trainer
.
auto_set_overlap_tester
())
boxes_overlap
=
trainer
.
get_overlap_tester
();
boxes_overlap
=
trainer
.
get_overlap_tester
();
for
(
unsigned
long
k
=
0
;
k
<
images
.
size
();
++
k
)
for
(
unsigned
long
k
=
0
;
k
<
images
.
size
();
++
k
)
{
{
std
::
vector
<
rectangle
>
objs
=
object_locations
[
k
];
std
::
vector
<
rectangle
>
objs
=
object_locations
[
k
];
// Don't even bother computing the candidate rectangles if there aren't any
// Don't even bother computing the candidate rectangles if there aren't any
// object locations for this image since there isn't anything to do anyway.
// object locations for this image since there isn't anything to do anyway.
if
(
objs
.
size
()
==
0
)
if
(
objs
.
size
()
==
0
)
continue
;
continue
;
bg
(
images
[
k
],
rects
);
bg
(
images
[
k
],
rects
);
// First remove things that don't have any matches with the candidate object
// First remove things that don't have any matches with the candidate object
// locations.
// locations.
std
::
vector
<
rectangle
>
good_rects
;
std
::
vector
<
rectangle
>
good_rects
;
for
(
unsigned
long
j
=
0
;
j
<
objs
.
size
();
++
j
)
for
(
unsigned
long
j
=
0
;
j
<
objs
.
size
();
++
j
)
{
{
if
(
matches_rect
(
rects
,
objs
[
j
],
trainer
.
get_match_eps
()))
if
(
matches_rect
(
rects
,
objs
[
j
],
trainer
.
get_match_eps
()))
good_rects
.
push_back
(
objs
[
j
]);
good_rects
.
push_back
(
objs
[
j
]);
else
else
rejects
[
k
].
push_back
(
objs
[
j
]);
rejects
[
k
].
push_back
(
objs
[
j
]);
}
}
object_locations
[
k
]
=
good_rects
;
object_locations
[
k
]
=
good_rects
;
// Remap these rectangles to the ones that can come out of the scanner. That
// 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
// 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.
// any distinct truth rectangles get mapped to overlapping boxes.
objs
.
resize
(
good_rects
.
size
());
objs
.
resize
(
good_rects
.
size
());
for
(
unsigned
long
i
=
0
;
i
<
good_rects
.
size
();
++
i
)
for
(
unsigned
long
i
=
0
;
i
<
good_rects
.
size
();
++
i
)
objs
[
i
]
=
get_best_matching_rect
(
rects
,
good_rects
[
i
]);
objs
[
i
]
=
get_best_matching_rect
(
rects
,
good_rects
[
i
]);
good_rects
.
clear
();
good_rects
.
clear
();
// now check for truth rects that are too close together.
// now check for truth rects that are too close together.
for
(
unsigned
long
i
=
0
;
i
<
objs
.
size
();
++
i
)
for
(
unsigned
long
i
=
0
;
i
<
objs
.
size
();
++
i
)
{
// check if objs[i] hits another box
bool
hit_box
=
false
;
for
(
unsigned
long
j
=
i
+
1
;
j
<
objs
.
size
();
++
j
)
{
{
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
T
>
struct
load_to_functor
{
load_to_functor
(
T
&
obj_
)
:
obj
(
obj_
)
{}
T
&
obj
;
template
<
typename
U
,
typename
V
>
void
operator
()(
const
U
&
u
,
V
&
v
)
{
obj
.
load
(
u
,
v
);
}
};
}
// ----------------------------------------------------------------------------------------
template
<
typename
image_array_type
,
typename
feature_extractor
,
typename
box_generator
>
std
::
vector
<
std
::
vector
<
rectangle
>
>
remove_unobtainable_rectangles
(
const
structural_object_detection_trainer
<
scan_image_boxes
<
feature_extractor
,
box_generator
>
>&
trainer
,
const
image_array_type
&
images
,
std
::
vector
<
std
::
vector
<
rectangle
>
>&
object_locations
)
{
box_generator
bg
=
trainer
.
get_scanner
().
get_box_generator
();
return
impl
::
remove_unobtainable_rectangles
(
bg
,
trainer
,
images
,
object_locations
);
}
// ----------------------------------------------------------------------------------------
template
<
typename
image_array_type
,
typename
feature_extractor
>
std
::
vector
<
std
::
vector
<
rectangle
>
>
remove_unobtainable_rectangles
(
const
structural_object_detection_trainer
<
scan_image_custom
<
feature_extractor
>
>&
trainer
,
const
image_array_type
&
images
,
std
::
vector
<
std
::
vector
<
rectangle
>
>&
object_locations
)
{
feature_extractor
fe
;
fe
.
copy_configuration
(
trainer
.
get_scanner
().
get_feature_extractor
());
impl
::
load_to_functor
<
feature_extractor
>
bg
(
fe
);
return
impl
::
remove_unobtainable_rectangles
(
bg
,
trainer
,
images
,
object_locations
);
}
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
...
...
dlib/image_processing/remove_unobtainable_rectangles_abstract.h
View file @
2f6419cd
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
#include "scan_image_pyramid_abstract.h"
#include "scan_image_pyramid_abstract.h"
#include "scan_image_boxes_abstract.h"
#include "scan_image_boxes_abstract.h"
#include "scan_image_custom_abstract.h"
#include "../svm/structural_object_detection_trainer_abstract.h"
#include "../svm/structural_object_detection_trainer_abstract.h"
#include "../geometry.h"
#include "../geometry.h"
...
@@ -76,6 +77,37 @@ namespace dlib
...
@@ -76,6 +77,37 @@ namespace dlib
- V[i] == the set of rectangles removed from object_locations[i]
- V[i] == the set of rectangles removed from object_locations[i]
!*/
!*/
// ----------------------------------------------------------------------------------------
template
<
typename
image_array_type
,
typename
feature_extractor
>
std
::
vector
<
std
::
vector
<
rectangle
>
>
remove_unobtainable_rectangles
(
const
structural_object_detection_trainer
<
scan_image_custom
<
feature_extractor
>
>&
trainer
,
const
image_array_type
&
images
,
std
::
vector
<
std
::
vector
<
rectangle
>
>&
object_locations
);
/*!
requires
- images.size() == object_locations.size()
ensures
- Recall that the scan_image_custom object can't produce all possible rectangles
as object detections since it only considers a limited subset of all possible
object positions. Moreover, the structural_object_detection_trainer requires
its input training data to not contain any object positions which are unobtainable
by its scanner object. Therefore, remove_unobtainable_rectangles() is a tool
to filter out these unobtainable rectangles from the training data before giving
it to a structural_object_detection_trainer.
- This function interprets object_locations[i] as the set of object positions for
image[i], for all valid i.
- In particular, this function removes unobtainable rectangles from object_locations
and also returns a vector V such that:
- V.size() == object_locations.size()
- for all valid i:
- V[i] == the set of rectangles removed from object_locations[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