Fixed a bug in the random_cropper where it might crash due to division by 0

if small images are given as input.
This commit is contained in:
Davis King 2017-09-17 15:16:41 -04:00
parent da968fa52c
commit cabad6d5fb
1 changed files with 3 additions and 2 deletions

View File

@ -276,11 +276,12 @@ namespace dlib
// lets this random box be either as big as it can be while still fitting in // lets this random box be either as big as it can be while still fitting in
// the image or as small as a 3x zoomed in box randomly somewhere in the image. // the image or as small as a 3x zoomed in box randomly somewhere in the image.
double mins = 1.0/3.0, maxs = std::min(img.nr()/(double)dims.rows, img.nc()/(double)dims.cols); double mins = 1.0/3.0, maxs = std::min(img.nr()/(double)dims.rows, img.nc()/(double)dims.cols);
mins = std::min(mins, maxs);
auto scale = rnd.get_double_in_range(mins, maxs); auto scale = rnd.get_double_in_range(mins, maxs);
rectangle rect(scale*dims.cols, scale*dims.rows); rectangle rect(scale*dims.cols, scale*dims.rows);
// randomly shift the box around // randomly shift the box around
point offset(rnd.get_random_32bit_number()%(img.nc()-rect.width()), point offset(rnd.get_random_32bit_number()%(1+img.nc()-rect.width()),
rnd.get_random_32bit_number()%(img.nr()-rect.height())); rnd.get_random_32bit_number()%(1+img.nr()-rect.height()));
return move_rect(rect, offset); return move_rect(rect, offset);
} }