Made object part annotations shown on the image_display scale relative to the size of their bounding box.

This commit is contained in:
Davis King 2017-09-09 09:23:24 -04:00
parent 85c94dc1e4
commit 04e034a70f
2 changed files with 12 additions and 9 deletions

View File

@ -6011,7 +6011,7 @@ namespace dlib
selected_rect(0), selected_rect(0),
default_rect_color(255,0,0,255), default_rect_color(255,0,0,255),
parts_menu(w), 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), overlay_editing_enabled(true),
highlight_timer(*this, &image_display::timer_event_unhighlight_rect), highlight_timer(*this, &image_display::timer_event_unhighlight_rect),
highlighted_rect(std::numeric_limits<unsigned long>::max()), highlighted_rect(std::numeric_limits<unsigned long>::max()),
@ -6331,16 +6331,17 @@ namespace dlib
if (itr->second == OBJECT_PART_NOT_PRESENT) if (itr->second == OBJECT_PART_NOT_PRESENT)
continue; 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 && if (rect_is_selected && selected_rect == i &&
selected_part_name.size() != 0 && selected_part_name == itr->first) 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 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 // 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) if (itr->second == OBJECT_PART_NOT_PRESENT)
continue; 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); point c = center(temp);
// distance from edge of part circle // distance from edge of part circle
const long dist = static_cast<long>(std::abs(length(c - point(x,y)) + 0.5 - temp.width()/2)); const long dist = static_cast<long>(std::abs(length(c - point(x,y)) + 0.5 - temp.width()));
if (dist < best_dist) if (dist < best_dist)
{ {
best_idx = i; best_idx = i;
@ -6698,11 +6700,12 @@ namespace dlib
if (itr->second == OBJECT_PART_NOT_PRESENT) if (itr->second == OBJECT_PART_NOT_PRESENT)
continue; 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); point c = center(temp);
// distance from edge of part circle // distance from edge of part circle
const long dist = static_cast<long>(std::abs(length(c - point(x,y)) + 0.5 - temp.width()/2)); const long dist = static_cast<long>(std::abs(length(c - point(x,y)) + 0.5 - temp.width()));
if (dist < best_dist) if (dist < best_dist)
{ {
best_idx = i; best_idx = i;

View File

@ -3589,7 +3589,7 @@ namespace dlib
any_function<void(const point& p, bool is_double_click, unsigned long btn)> image_clicked_handler; any_function<void(const point& p, bool is_double_click, unsigned long btn)> image_clicked_handler;
popup_menu_region parts_menu; popup_menu_region parts_menu;
point last_right_click_pos; point last_right_click_pos;
const int part_width; const double part_width;
std::set<std::string> part_names; std::set<std::string> part_names;
bool overlay_editing_enabled; bool overlay_editing_enabled;
timer<image_display> highlight_timer; timer<image_display> highlight_timer;