Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move label placement when overlapping small boxes #15310

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions frigate/util/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,16 +222,25 @@ def draw_box_with_label(
# set the text start position
if position == "ul":
text_offset_x = x_min
text_offset_y = 0 if y_min < line_height else y_min - (line_height + 8)
text_offset_y = max(0, y_min - (line_height + 8))
elif position == "ur":
text_offset_x = x_max - (text_width + 8)
text_offset_y = 0 if y_min < line_height else y_min - (line_height + 8)
text_offset_x = max(0, x_max - (text_width + 8))
text_offset_y = max(0, y_min - (line_height + 8))
elif position == "bl":
text_offset_x = x_min
text_offset_y = y_max
elif position == "br":
text_offset_x = x_max - (text_width + 8)
text_offset_x = max(0, x_max - (text_width + 8))
text_offset_y = y_max

# Adjust position if it overlaps with the box
if position in {"ul", "ur"} and text_offset_y < y_min + thickness:
# Move the text below the box
text_offset_y = y_max
elif position in {"bl", "br"} and text_offset_y + line_height > y_max:
# Move the text above the box
text_offset_y = max(0, y_min - (line_height + 8))

# make the coords of the box with a small padding of two pixels
textbox_coords = (
(text_offset_x, text_offset_y),
Expand Down
Loading