Commit 2f6419cd authored by Davis King's avatar Davis King

Added remove_unobtainable_rectangles() for the scan_image_custom scanner.

parent 7da29fb9
...@@ -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,13 +138,16 @@ namespace dlib ...@@ -137,13 +138,16 @@ namespace dlib
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
namespace impl
{
template < template <
typename image_array_type, typename image_array_type,
typename feature_extractor, typename scanner_type,
typename box_generator typename get_boxes_functor
> >
std::vector<std::vector<rectangle> > remove_unobtainable_rectangles ( std::vector<std::vector<rectangle> > remove_unobtainable_rectangles (
const structural_object_detection_trainer<scan_image_boxes<feature_extractor, box_generator> >& trainer, get_boxes_functor& bg,
const structural_object_detection_trainer<scanner_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
) )
...@@ -155,7 +159,6 @@ namespace dlib ...@@ -155,7 +159,6 @@ namespace dlib
<< "\n\t Invalid inputs were given to this function." << "\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());
...@@ -223,6 +226,57 @@ namespace dlib ...@@ -223,6 +226,57 @@ namespace dlib
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);
}
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
} }
......
...@@ -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]
!*/
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment