Gave load_image_dataset() the ability to skip images that don't have

any ground truth boxes.
This commit is contained in:
Davis King 2013-03-28 19:21:52 -04:00
parent d1493c1a50
commit 1e1f4efbaf
2 changed files with 24 additions and 14 deletions

View File

@ -28,7 +28,8 @@ namespace dlib
array<image_type,MM>& images,
std::vector<std::vector<rectangle> >& object_locations,
const std::string& filename,
const std::string& label
const std::string& label,
bool skip_empty_images = false
)
{
images.clear();
@ -47,11 +48,10 @@ namespace dlib
dataset data;
load_image_dataset_metadata(data, filename);
images.resize(data.images.size());
image_type img;
std::vector<rectangle> rects;
for (unsigned long i = 0; i < data.images.size(); ++i)
{
load_image(images[i], data.images[i].filename);
rects.clear();
for (unsigned long j = 0; j < data.images[i].boxes.size(); ++j)
{
@ -60,7 +60,13 @@ namespace dlib
rects.push_back(data.images[i].boxes[j].rect);
}
}
object_locations.push_back(rects);
if (!skip_empty_images || rects.size() != 0)
{
object_locations.push_back(rects);
load_image(img, data.images[i].filename);
images.push_back(img);
}
}
set_current_dir(old_working_dir);

View File

@ -23,25 +23,29 @@ namespace dlib
array<image_type,MM>& images,
std::vector<std::vector<rectangle> >& object_locations,
const std::string& filename,
const std::string& label
const std::string& label,
bool skip_empty_images = false
);
/*!
requires
- image_type == is an implementation of array2d/array2d_kernel_abstract.h
- pixel_traits<typename image_type::type> is defined
ensures
- This routine loads the images and their associated object boxes from
the image metadata file indicated by filename. This metadata file
should be in the XML format used by the save_image_dataset_metadata()
routine.
- #images.size() == the number of images in the metadata file
- This routine loads the images and their associated object boxes from the
image metadata file indicated by filename. This metadata file should be in
the XML format used by the save_image_dataset_metadata() routine.
- #images.size() == The number of images loaded from the metadata file. This
is all the images listed in the file unless skip_empty_images is set to true.
- #images.size() == #object_locations.size()
- This routine is capable of loading any image format which can be read
by the load_image() routine.
- This routine is capable of loading any image format which can be read by the
load_image() routine.
- for all valid i:
- #images[i] == a copy of the ith image from the dataset
- #images[i] == a copy of the i-th image from the dataset
- #object_locations[i] == a vector of all the rectangles associated with
#images[i].
#images[i].
- if (skip_empty_images == true) then
- #object_locations[i].size() != 0
(i.e. only images with detection boxes in them will be loaded.)
- if (labels != "") then
- only boxes with the given label will be loaded into object_locations.
- else