Made the random translation amount user settable.

This commit is contained in:
Davis King 2016-11-26 08:26:59 -05:00
parent 3fca40f189
commit 8dece3ff88
2 changed files with 34 additions and 2 deletions

View File

@ -21,6 +21,7 @@ namespace dlib
double min_object_height = 0.25; // cropped object will be at least this fraction of the height of the image.
double max_object_height = 0.7; // cropped object will be at most this fraction of the height of the image.
double background_crops_fraction = 0.5;
double translate_amount = 0.10;
std::mutex rnd_mutex;
dlib::rand rnd;
@ -30,6 +31,17 @@ namespace dlib
time_t seed
) { rnd = dlib::rand(seed); }
double get_translate_amount (
) const { return translate_amount; }
void set_translate_amount (
double value
)
{
DLIB_CASSERT(0 <= value);
translate_amount = value;
}
double get_background_crops_fraction (
) const { return background_crops_fraction; }
@ -191,8 +203,8 @@ namespace dlib
{
auto rect = rects[randomly_pick_rect(rects)].rect;
// perturb the location of the crop by a small fraction of the object's size.
const point rand_translate = dpoint(rnd.get_double_in_range(-0.1,0.1)*rect.width(),
rnd.get_double_in_range(-0.1,0.1)*rect.height());
const point rand_translate = dpoint(rnd.get_double_in_range(-translate_amount,translate_amount)*rect.width(),
rnd.get_double_in_range(-translate_amount,translate_amount)*rect.height());
// perturb the scale of the crop by a fraction of the object's size
const double rand_scale_perturb = rnd.get_double_in_range(min_object_height, max_object_height);

View File

@ -38,6 +38,7 @@ namespace dlib
- #get_min_object_height() == 0.25
- #get_max_object_height() == 0.7
- #get_background_crops_fraction() == 0.5
- #get_translate_amount() == 0.1
!*/
void set_seed (
@ -48,6 +49,25 @@ namespace dlib
- Seeds the internal random number generator with the given seed.
!*/
double get_translate_amount (
) const;
/*!
ensures
- When a box is cropped out, it will be randomly translated prior to
cropping by #get_translate_amount()*(the box's height) up or down and
#get_translate_amount()*(the box's width) left or right.
!*/
void set_translate_amount (
double value
);
/*!
requires
- value >= 0
ensures
- #get_translate_amount() == value
!*/
double get_background_crops_fraction (
) const;
/*!