From cabad6d5fba85ea8095e2942868535903aaffd95 Mon Sep 17 00:00:00 2001 From: Davis King Date: Sun, 17 Sep 2017 15:16:41 -0400 Subject: [PATCH] Fixed a bug in the random_cropper where it might crash due to division by 0 if small images are given as input. --- dlib/image_transforms/random_cropper.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dlib/image_transforms/random_cropper.h b/dlib/image_transforms/random_cropper.h index 24d4640cf..3a2378575 100644 --- a/dlib/image_transforms/random_cropper.h +++ b/dlib/image_transforms/random_cropper.h @@ -276,11 +276,12 @@ namespace dlib // 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. 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); rectangle rect(scale*dims.cols, scale*dims.rows); // randomly shift the box around - point offset(rnd.get_random_32bit_number()%(img.nc()-rect.width()), - rnd.get_random_32bit_number()%(img.nr()-rect.height())); + point offset(rnd.get_random_32bit_number()%(1+img.nc()-rect.width()), + rnd.get_random_32bit_number()%(1+img.nr()-rect.height())); return move_rect(rect, offset); }