| 265 | // ---------------------------------------------------------------------------------------- |
| 266 | |
| 267 | void propagate_labels( |
| 268 | const std::string& label, |
| 269 | dlib::image_dataset_metadata::dataset& data, |
| 270 | unsigned long prev, |
| 271 | unsigned long next |
| 272 | ) |
| 273 | { |
| 274 | if (prev == next || next >= data.images.size()) |
| 275 | return; |
| 276 | |
| 277 | |
| 278 | for (unsigned long i = 0; i < data.images[prev].boxes.size(); ++i) |
| 279 | { |
| 280 | if (data.images[prev].boxes[i].label != label) |
| 281 | continue; |
| 282 | |
| 283 | // figure out which box in the next image matches the current one the best |
| 284 | const rectangle cur = data.images[prev].boxes[i].rect; |
| 285 | double best_overlap = 0; |
| 286 | unsigned long best_idx = 0; |
| 287 | for (unsigned long j = 0; j < data.images[next].boxes.size(); ++j) |
| 288 | { |
| 289 | const rectangle next_box = data.images[next].boxes[j].rect; |
| 290 | const double overlap = cur.intersect(next_box).area()/(double)(cur+next_box).area(); |
| 291 | if (overlap > best_overlap) |
| 292 | { |
| 293 | best_overlap = overlap; |
| 294 | best_idx = j; |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | // If we found a matching rectangle in the next image and the best match doesn't |
| 299 | // already have a label. |
| 300 | if (best_overlap > 0.5 && data.images[next].boxes[best_idx].label == "") |
| 301 | { |
| 302 | data.images[next].boxes[best_idx].label = label; |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | } |
| 307 | |
| 308 | // ---------------------------------------------------------------------------------------- |
| 309 |
no test coverage detected