| 100 | } |
| 101 | |
| 102 | rectangle make_random_cropping_rect( |
| 103 | const matrix<rgb_pixel>& image, |
| 104 | dlib::rand& rnd |
| 105 | ) |
| 106 | { |
| 107 | const auto scale = rnd.get_double_in_range(0.5, 1.0); |
| 108 | const auto ratio = exp(rnd.get_double_in_range(log(3.0 / 4.0), log(4.0 / 3.0))); |
| 109 | const auto size = scale * min(image.nr(), image.nc()); |
| 110 | const auto rect = move_rect(set_aspect_ratio(rectangle(size, size), ratio), 0, 0); |
| 111 | const point offset(rnd.get_integer(max(0, static_cast<int>(image.nc() - rect.width()))), |
| 112 | rnd.get_integer(max(0, static_cast<int>(image.nr() - rect.height())))); |
| 113 | return move_rect(rect, offset); |
| 114 | } |
| 115 | |
| 116 | // A helper function to generate different kinds of augmentations. |
| 117 | matrix<rgb_pixel> augment( |
no test coverage detected