Commit cabad6d5 authored by Davis King's avatar Davis King

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

if small images are given as input.
parent da968fa5
...@@ -276,11 +276,12 @@ namespace dlib ...@@ -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);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment