Repository navigation
fix(annotators): keep labels wider than the frame at its left edge - #2940
Merged
Borda merged 5 commits intoNov 11, 2026
Merged
Conversation
snap_boxes shifts an overflowing label box back into the frame, and the shift for a box crossing the right or bottom edge ignored that the box could be larger than the frame, so a label starting inside it ended up past the left edge and lost its first characters. A box that cannot fit now stops at the top-left edge, as boxes starting outside it already did.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #2940 +/- ##
=======================================
Coverage 95% 95%
=======================================
Files 83 83
Lines 14440 14443 +3
=======================================
+ Hits 13685 13688 +3
Misses 755 755 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the oversized-label placement fix.
No open issues 🎉
What changed in this PR
Fixes smart label placement in Supervision so labels wider or taller than the frame remain anchored at the left or top edge, rather than shifting beyond it.
Changes:
- Caps rightward-overflow and bottom-overflow corrections in
snap_boxes, preserving box dimensions. - Adds regression tests for oversized boxes alongside existing edge-shifting behavior.
- Documents the fix for
LabelAnnotatorandRichLabelAnnotatorwithsmart_position=True.
| File | Description |
|---|---|
tests/annotators/test_utils.py |
Adds five parametrized cases covering edge shifts and oversized boxes. |
src/supervision/annotators/utils.py |
Limits overflow shifts to keep left and top coordinates nonnegative. |
docs/changelog.md |
Adds an Unreleased entry describing the label-placement fix. |
Review effort: Balanced
Changes: - Integrate the target branch's OpenCV fallback arithmetic and CSV column validation changes with their tests. - Preserve the label-positioning and target changelog entries when resolving their collision. Impact: - The PR branch includes current target fixes while retaining its label-positioning change and release notes. Verification: - Focused annotator utility tests: 88 passed. - Reviewed the complete staged merge and git diff --cached --check passed. Residual limits: - Review findings for RTL labels and changelog wording remain to be selected and addressed. --- Co-authored-by: Codex <[email protected]>
Changes: - Align shaped right-to-left text to the visible frame edge when smart-positioned label boxes are oversized. - Add Arabic, Hebrew and mixed-direction rendering regressions and correct the changelog description. Impact: - Oversized right-to-left labels keep their leading text visible while left-to-right box placement remains unchanged. Verification: - Full pytest coverage gate: 6,665 passed, 281 skipped. - Selected-file pre-commit checks, type check and diff check passed. - Independent source challenge found no remaining concrete defect. Residual limits: - Extreme padding and fonts or platforms beyond the tested configuration were not exhaustively checked. --- Co-authored-by: Codex <[email protected]>
…er-than-frame # Conflicts: # docs/changelog.md
Contributor
Author
|
Thanks for the RTL fix, @Borda. I merged |
Borda
approved these changes
Nov 11, 2026
Borda
added a commit
that referenced
this pull request
Nov 11, 2026
…2940) snap_boxes shifts an overflowing label box back into the frame, and the shift for a box crossing the right or bottom edge ignored that the box could be larger than the frame, so a label starting inside it ended up past the left edge and lost its first characters. A box that cannot fit now stops at the top-left edge, as boxes starting outside it already did. * docs(changelog): link the PR number * fix(annotators): preserve leading text in oversized RTL labels --------- Co-authored-by: Jirka Borovec <[email protected]> Co-authored-by: Codex <[email protected]>
3 tasks done
avanish-garg
added a commit
to avanish-garg/supervision
that referenced
this pull request
Nov 16, 2026
…nchor jump The smart_position entry for roboflow#2940 already ships under 0.31.7; remove its copy from Unreleased. Document that an empty mask's box-center anchor can differ from the centroid in neighbouring frames.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
LabelAnnotator(smart_position=True)andRichLabelAnnotator(smart_position=True)move each label box into the frame withsnap_boxes, which promises to prioritize the top and left edges. A label box that starts outside the frame is moved to x=0 even when it is wider than the frame, but one that starts inside it and runs past the right edge was shifted left by the whole overflow, so a box wider than the frame ended up with a negative x1 and lost the first characters of its text. The same happened for tall boxes at the bottom edge.With this change the shift for a box crossing the right or bottom edge stops at the left or top edge, so a box that cannot fit keeps its left (top) edge visible and only its end is cut.
Motivation and Context
On a small frame (thumbnail, crop) a long label with
smart_position=Trueshowed its tail instead of its beginning. Boxes that fit the frame, and boxes starting outside it, are unchanged.Changes Made
snap_boxes: limit the right and bottom shifts so x1 and y1 stay at or above 0.TestSnapBoxescovers the existing shifts and the two new cases (wider and taller than the frame, starting inside it).snap_boxeshad no unit test intests/, only its doctest.Unreleased.Testing
New tests on
develop:2 failed, 3 passed(assert Falseon the two boxes starting inside the frame). With this change:5 passed.pytest tests/annotators tests/key_points src/supervision/annotators:855 passed, 1 skipped.pre-commit run --files <changed files>: ruff, ruff-format, docformatter, mdformat, mypy and codespell pass.Full suite on the branch:
pytest tests src-> 7301 passed, 35 skipped.Added/updated tests, and the full suite passes locally
Updated docs (docstrings / mkdocs entry) for new or changed public API
Added a changelog entry in
docs/changelog.mdunderUnreleased(skip for lint/type/format-only or pure doc changes)Additional Notes
snap_boxesis only called from_adjust_labels_in_frame; the keypointVertexLabelAnnotatordoes not use it.Arabic and Hebrew lines in
RichLabelAnnotatorare right-aligned in their box, so for those a label wider than the frame now shows its end, as it already did when the box started left of the frame; keeping their start would need per-label alignment insnap_boxes, left out here.