MCPcopy Create free account
hub / github.com/davisking/dlib / propagate_labels

Function propagate_labels

tools/imglab/src/metadata_editor.cpp:275–314  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

on_keydownMethod · 0.85

Calls 3

sizeMethod · 0.45
areaMethod · 0.45
intersectMethod · 0.45

Tested by

no test coverage detected