Both rounded-rectangle helpers (LabelAnnotator.draw_rounded_rectangle and the public draw_rounded_rectangle in draw/utils) always drew two rectangles plus four corner circles, even when border_radius is 0, which is the default for LabelAnnotator and VertexLabelAnnotator. With a zero radius that is six cv2 calls per label per frame (the four circles are zero-radius no-ops) where one fill rectangle does the same thing. Add a square-corner fast path to both helpers. Output is pixel identical; only the redundant calls go away. On a 1080p frame with 100 labels LabelAnnotator drops from ~2.1 ms to ~1.3 ms (about 1.6x), and the rounded-rectangle call itself is ~2.8x faster at radius 0. The radius > 0 path is unchanged. Adds tests pinning square output to a plain rectangle for both helpers (the public draw/utils function had no tests before). - Rename LabelAnnotator.draw_rounded_rectangle to _draw_rounded_rectangle (accidentally public static method — now signals internal) - Expand draw/utils.py border_radius docstring: document <= 0 and clamp-to-zero fast-path behaviour - Add crash-era comment to both test files: border_radius < 0 previously raised cv2.error; fast path silently draws square corners instead - Add clamped-to-zero test in both test files: positive radius on a 1px-wide box clamps to 0 and triggers the fast path - Strengthen positive-radius assertion: full center-row check + all four corners unpainted (replaces two-pixel spot check) - Add pytest.param(id=) slugs to all parametrize decorators per CONTRIBUTING.md convention - Add Google-style docstring with Args, Returns, Example to `LabelAnnotator.draw_rounded_rectangle` (was undocumented @staticmethod) - Rename `testdraw_*` → `test_draw_*` in `TestLabelAnnotator` to restore consistent test naming broken by the earlier private-rename commit - Expand `draw/utils.draw_rounded_rectangle` border_radius docstring: note that negative values previously raised `cv2.error` and now draw square corners silently; drop "as a fast path" implementation detail - Add `Example:` block to `draw/utils.draw_rounded_rectangle` --------- Co-authored-by: jirka <6035284+Borda@users.noreply.github.com> Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> |
||
|---|---|---|
| .. | ||
| __init__.py | ||
| test_color.py | ||
| test_utils.py | ||