Commit a20f401e authored by Davis King's avatar Davis King

Gave imglab the ability to propagate rectangle labels between images.

parent 885a19e6
......@@ -208,6 +208,47 @@ on_window_resized(
// ----------------------------------------------------------------------------------------
void propagate_labels(
const std::string& label,
dlib::image_dataset_metadata::dataset& data,
unsigned long prev,
unsigned long next
)
{
if (prev == next || next >= data.images.size())
return;
for (unsigned long i = 0; i < data.images[prev].boxes.size(); ++i)
{
if (data.images[prev].boxes[i].label != label)
continue;
// figure out which box in the next image matches the current one the best
const rectangle cur = data.images[prev].boxes[i].rect;
double best_overlap = 0;
unsigned long best_idx = 0;
for (unsigned long j = 0; j < data.images[next].boxes.size(); ++j)
{
const rectangle next_box = data.images[next].boxes[j].rect;
const double overlap = cur.intersect(next_box).area()/(double)(cur+next_box).area();
if (overlap > best_overlap)
{
best_overlap = overlap;
best_idx = j;
}
}
// If we found a matching rectangle in the next image and the best match doesn't
// already have a label.
if (best_overlap > 0.5 && data.images[next].boxes[best_idx].label == "")
{
data.images[next].boxes[best_idx].label = label;
}
}
}
void metadata_editor::
on_keydown (
unsigned long key,
......@@ -230,10 +271,14 @@ on_keydown (
if (key == base_window::KEY_UP)
{
if (state&base_window::KBD_MOD_CONTROL)
propagate_labels(display.get_default_overlay_rect_label(), metadata, image_pos, image_pos-1);
select_image(image_pos-1);
}
else if (key == base_window::KEY_DOWN)
{
if (state&base_window::KBD_MOD_CONTROL)
propagate_labels(display.get_default_overlay_rect_label(), metadata, image_pos, image_pos+1);
select_image(image_pos+1);
}
}
......@@ -441,8 +486,10 @@ display_about(
,0,0) << endl << endl;
sout << wrap_string("Additionally, you can hold ctrl and then scroll the mouse wheel to zoom. A normal left click "
"and drag allows you to navigate around the image. Finally, holding ctrl and "
"left clicking a rectangle will give it the label from the Next Label field.",0,0) << endl;
"and drag allows you to navigate around the image. Holding ctrl and "
"left clicking a rectangle will give it the label from the Next Label field. "
"Finally, holding ctrl and pressing the up or down keyboard keys will propagate "
"rectangle labels from one image to the next.",0,0) << endl;
message_box("About Image Labeler",sout.str());
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment