From 04e034a70f9492113b20039aebda4ca49dc01a0d Mon Sep 17 00:00:00 2001 From: Davis King Date: Sat, 9 Sep 2017 09:23:24 -0400 Subject: [PATCH] Made object part annotations shown on the image_display scale relative to the size of their bounding box. --- dlib/gui_widgets/widgets.cpp | 19 +++++++++++-------- dlib/gui_widgets/widgets.h | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/dlib/gui_widgets/widgets.cpp b/dlib/gui_widgets/widgets.cpp index fa8d4b218..4059c85a6 100644 --- a/dlib/gui_widgets/widgets.cpp +++ b/dlib/gui_widgets/widgets.cpp @@ -6011,7 +6011,7 @@ namespace dlib selected_rect(0), default_rect_color(255,0,0,255), parts_menu(w), - part_width(15), // width part circles are drawn on the screen + part_width(100), // "parts" circles are drawn 1.0/part_width size on the screen relative to the size of the bounding rectangle. overlay_editing_enabled(true), highlight_timer(*this, &image_display::timer_event_unhighlight_rect), highlighted_rect(std::numeric_limits::max()), @@ -6331,16 +6331,17 @@ namespace dlib if (itr->second == OBJECT_PART_NOT_PRESENT) continue; - rectangle temp = centered_rect(get_rect_on_screen(centered_rect(itr->second,1,1)), part_width, part_width); + const long part_size = (long)std::max(1.0,std::round(std::sqrt(orect.area())/part_width)); + rectangle temp = centered_rect(get_rect_on_screen(centered_rect(itr->second,1,1)), part_size, part_size); if (rect_is_selected && selected_rect == i && selected_part_name.size() != 0 && selected_part_name == itr->first) { - draw_circle(c, center(temp), temp.width()/2, invert_pixel(color), area); + draw_circle(c, center(temp), temp.width(), invert_pixel(color), area); } else { - draw_circle(c, center(temp), temp.width()/2, color, area); + draw_circle(c, center(temp), temp.width(), color, area); } // make a rectangle that is at the spot we want to draw our string @@ -6551,11 +6552,12 @@ namespace dlib if (itr->second == OBJECT_PART_NOT_PRESENT) continue; - rectangle temp = centered_rect(get_rect_on_screen(centered_rect(itr->second,1,1)), part_width, part_width); + const long part_size = (long)std::max(1.0,std::round(std::sqrt(orect.area())/part_width)); + rectangle temp = centered_rect(get_rect_on_screen(centered_rect(itr->second,1,1)), part_size, part_size); point c = center(temp); // distance from edge of part circle - const long dist = static_cast(std::abs(length(c - point(x,y)) + 0.5 - temp.width()/2)); + const long dist = static_cast(std::abs(length(c - point(x,y)) + 0.5 - temp.width())); if (dist < best_dist) { best_idx = i; @@ -6698,11 +6700,12 @@ namespace dlib if (itr->second == OBJECT_PART_NOT_PRESENT) continue; - rectangle temp = centered_rect(get_rect_on_screen(centered_rect(itr->second,1,1)), part_width, part_width); + const long part_size = (long)std::max(1.0,std::round(std::sqrt(orect.area())/part_width)); + rectangle temp = centered_rect(get_rect_on_screen(centered_rect(itr->second,1,1)), part_size, part_size); point c = center(temp); // distance from edge of part circle - const long dist = static_cast(std::abs(length(c - point(x,y)) + 0.5 - temp.width()/2)); + const long dist = static_cast(std::abs(length(c - point(x,y)) + 0.5 - temp.width())); if (dist < best_dist) { best_idx = i; diff --git a/dlib/gui_widgets/widgets.h b/dlib/gui_widgets/widgets.h index 45b37f712..56dccd93f 100644 --- a/dlib/gui_widgets/widgets.h +++ b/dlib/gui_widgets/widgets.h @@ -3589,7 +3589,7 @@ namespace dlib any_function image_clicked_handler; popup_menu_region parts_menu; point last_right_click_pos; - const int part_width; + const double part_width; std::set part_names; bool overlay_editing_enabled; timer highlight_timer;