| 190 | typename image_type |
| 191 | > |
| 192 | void find_points_above_thresh ( |
| 193 | std::vector<std::pair<double, point> >& dets, |
| 194 | const image_type& img_, |
| 195 | const double thresh, |
| 196 | const unsigned long max_dets |
| 197 | ) |
| 198 | { |
| 199 | const_image_view<image_type> img(img_); |
| 200 | typedef typename image_traits<image_type>::pixel_type ptype; |
| 201 | |
| 202 | dets.clear(); |
| 203 | if (max_dets == 0) |
| 204 | return; |
| 205 | |
| 206 | unsigned long count = 0; |
| 207 | dlib::rand rnd; |
| 208 | for (long r = 0; r < img.nr(); ++r) |
| 209 | { |
| 210 | for (long c = 0; c < img.nc(); ++c) |
| 211 | { |
| 212 | const ptype val = img[r][c]; |
| 213 | if (val >= thresh) |
| 214 | { |
| 215 | ++count; |
| 216 | |
| 217 | if (dets.size() < max_dets) |
| 218 | { |
| 219 | dets.push_back(std::make_pair(val, point(c,r))); |
| 220 | } |
| 221 | else |
| 222 | { |
| 223 | // The idea here is to cause us to randomly sample possible detection |
| 224 | // locations throughout the image rather than just stopping the detection |
| 225 | // procedure once we hit the max_dets limit. So this method will result |
| 226 | // in a random subsample of all the detections >= thresh being in dets |
| 227 | // at the end of scan_image(). |
| 228 | const unsigned long random_index = rnd.get_random_32bit_number()%count; |
| 229 | if (random_index < dets.size()) |
| 230 | { |
| 231 | dets[random_index] = std::make_pair(val, point(c,r)); |
| 232 | } |
| 233 | } |
| 234 | } |
| 235 | } |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | // ---------------------------------------------------------------------------------------- |
| 240 | |