Added append() to random_cropper.

This commit is contained in:
Davis King 2016-11-26 15:48:00 -05:00
parent 8dece3ff88
commit 93f3a09f40
2 changed files with 53 additions and 3 deletions

View File

@ -110,13 +110,33 @@ namespace dlib
)
{
DLIB_CASSERT(images.size() == rects.size());
crops.resize(num_crops);
crop_rects.resize(num_crops);
parallel_for(0, num_crops, [&](long i) {
crops.clear();
crop_rects.clear();
append(num_crops, images, rects, crops, crop_rects);
}
template <
typename array_type
>
void append (
size_t num_crops,
const array_type& images,
const std::vector<std::vector<mmod_rect>>& rects,
array_type& crops,
std::vector<std::vector<mmod_rect>>& crop_rects
)
{
DLIB_CASSERT(images.size() == rects.size());
DLIB_CASSERT(crops.size() == crop_rects.size());
auto original_size = crops.size();
crops.resize(crops.size()+num_crops);
crop_rects.resize(crop_rects.size()+num_crops);
parallel_for(original_size, original_size+num_crops, [&](long i) {
(*this)(images, rects, crops[i], crop_rects[i]);
});
}
template <
typename array_type,
typename image_type

View File

@ -181,6 +181,36 @@ namespace dlib
- #get_max_object_height() == value
!*/
template <
typename array_type
>
void append (
size_t num_crops,
const array_type& images,
const std::vector<std::vector<mmod_rect>>& rects,
array_type& crops,
std::vector<std::vector<mmod_rect>>& crop_rects
);
/*!
requires
- images.size() == rects.size()
- crops.size() == crop_rects.size()
- for all valid i:
- images[i].size() != 0
- array_type is a type with an interface compatible with dlib::array or
std::vector and it must in turn contain image objects that implement the
interface defined in dlib/image_processing/generic_image.h
ensures
- Randomly extracts num_crops chips from images and appends them to the end
of crops. We also copy the object metadata for each extracted crop and
store it into #crop_rects. In particular, calling this function is the
same as making multiple calls to the version of operator() below that
outputs a single crop, except that append() will use multiple CPU cores
to do the processing and is therefore faster.
- #crops.size() == crops.size()+num_crops
- #crop_rects.size() == crop_rects.size()+num_crops
!*/
template <
typename array_type
>