Added an overload of load_image_dataset() that outputs directly to mmod_rect

instead of rectangle.
This commit is contained in:
Davis King 2016-09-04 14:52:29 -04:00
parent eae0c2faa4
commit a280e48c0b
2 changed files with 73 additions and 0 deletions

View File

@ -14,6 +14,7 @@
#include <string>
#include <set>
#include "../image_processing/full_object_detection.h"
#include <utility>
namespace dlib
@ -141,6 +142,56 @@ namespace dlib
return ignored_rects;
}
// ----------------------------------------------------------------------------------------
template <
typename array_type
>
void load_image_dataset (
array_type& images,
std::vector<std::vector<mmod_rect> >& object_locations,
const image_dataset_file& source
)
{
images.clear();
object_locations.clear();
using namespace dlib::image_dataset_metadata;
dataset data;
load_image_dataset_metadata(data, source.get_filename());
// Set the current directory to be the one that contains the
// metadata file. We do this because the file might contain
// file paths which are relative to this folder.
locally_change_current_dir chdir(get_parent_directory(file(source.get_filename())));
typedef typename array_type::value_type image_type;
image_type img;
std::vector<mmod_rect> rects;
for (unsigned long i = 0; i < data.images.size(); ++i)
{
rects.clear();
for (unsigned long j = 0; j < data.images[i].boxes.size(); ++j)
{
if (source.should_load_box(data.images[i].boxes[j]))
{
if (data.images[i].boxes[j].ignore)
rects.push_back(ignored_mmod_rect(data.images[i].boxes[j].rect));
else
rects.push_back(mmod_rect(data.images[i].boxes[j].rect));
}
}
if (!source.should_skip_empty_images() || rects.size() != 0)
{
object_locations.push_back(std::move(rects));
load_image(img, data.images[i].filename);
images.push_back(std::move(img));
}
}
}
// ----------------------------------------------------------------------------------------
// ******* THIS FUNCTION IS DEPRECATED, you should use another version of load_image_dataset() *******

View File

@ -181,6 +181,28 @@ namespace dlib
(i.e. it ignores box labels and therefore loads all the boxes in the dataset)
!*/
template <
typename array_type
>
void load_image_dataset (
array_type& images,
std::vector<std::vector<mmod_rect> >& object_locations,
const image_dataset_file& source
);
/*!
requires
- array_type == An array of images. This is anything with an interface that
looks like std::vector<some generic image type> where a "generic image" is
anything that implements the generic image interface defined in
dlib/image_processing/generic_image.h.
ensures
- This function has essentially the same behavior as the above
load_image_dataset() routines, except here we out put to a vector of
mmod_rects instead of rectangles. In this case, both ignore and non-ignore
rectangles go into object_locations since mmod_rect has an ignore boolean
field that records the ignored/non-ignored state of each rectangle.
!*/
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------