Skip to content

fix(key_points): render three-coordinate points using x and y - #2759

Merged
Borda merged 6 commits into
roboflow:developfrom
aswanth-07:fix/three-coordinate-keypoint-rendering
Oct 20, 2026
Merged

Borda merged 6 commits into
roboflow:developfrom
aswanth-07:fix/three-coordinate-keypoint-rendering

Conversation

@aswanth-07

@aswanth-07 aswanth-07 commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Description

KeyPoints accepts (N, K, 3) coordinates, but VertexAnnotator and the shared covariance-ellipse renderer unpack every point into two values. They raise ValueError: too many values to unpack (expected 2) for this accepted representation.

I use the first two coordinate columns for image-space drawing. This fixes vertex, ellipse area, ellipse outline and ellipse halo annotation. Edge and label annotators also use only x/y for missing-point and finiteness checks, so a third coordinate does not change visibility. Existing two-coordinate rendering and covariance handling stay unchanged.

import numpy as np
import supervision as sv

points = sv.KeyPoints(xy=np.array([[[25.0, 30.0, 0.2]]], dtype=np.float32))
scene = np.zeros((64, 64, 3), dtype=np.uint8)
sv.VertexAnnotator().annotate(scene, points)

Motivation and Context

The coordinate validator accepts both two and three channels. Image annotators place pixels using x and y, while callers retain the extra coordinate in the original container. Selection already preserves that coordinate depth.

Changes Made

  • Limit unpacking and edge/label visibility checks to x/y.
  • Add 16 vertex/ellipse cases and 48 edge/label cases for float32/float64, missing points, non-finite depth and explicit visibility. Compare images with two-coordinate input and check input preservation.
  • Add an Unreleased changelog entry.

Testing

I ran these checks on Windows, Python 3.13.3, NumPy 2.2.6 and OpenCV 4.12.0, with the source checkout first on PYTHONPATH:

  • The original 16 cases fail on pristine source. Of the new depth-check cases plus the two updated behavior tests, 32 fail on the prior PR head and 18 already pass. The complete annotator module now has 143 passes.

  • Current develop sync, pytest -q -p pytest_cov.plugin --cov=supervision: the prior PR head has 6,132 passes; the fix has 6,180 passes. Both have seven skips, 42 warnings and the same four reference drawing failures in tests/cv2/test_drawing.py:

    • TestFallbackThickLine::test_line_matches_opencv[clipped-at-canvas-edges]
    • TestFallbackThickLine::test_random_lines_match_opencv
    • TestFallbackEllipse::test_ellipse_matches_opencv[thin-full]
    • TestFallbackEllipse::test_random_ellipses_match_opencv
  • Both full runs include doctests and report 94% rounded coverage. The blocked-OpenCV integration suite passes on both.

  • All-file pre-commit, final changed-file hooks and git diff --check pass.

  • Added/updated tests, and the full suite passes locally (tests added; four failures reproduce on pristine upstream)

  • Updated relevant docstrings

  • Added an Unreleased changelog entry

Additional Notes

The fix preserves input coordinate data, visibility and covariance arrays. I did not run Linux/macOS or the supported-Python matrix locally.

AI assistance disclosure: AI-assisted development tools were used during investigation and implementation. The reported tests were run against the final diff.

@codecov

codecov Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94%. Comparing base (c944ecb) to head (bd20c66).

Additional details and impacted files
@@           Coverage Diff           @@
##           develop   #2759   +/-   ##
=======================================
  Coverage       94%     94%           
=======================================
  Files           83      83           
  Lines        13644   13644           
=======================================
+ Hits         12839   12841    +2     
+ Misses         805     803    -2     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@aswanth-07
aswanth-07 marked this pull request as ready for review October 17, 2026 17:59
@aswanth-07
aswanth-07 requested a review from SkalskiP as a code owner October 17, 2026 17:59
@Borda Borda added the bug Something isn't working label Oct 19, 2026
@Borda
Borda requested a balanced review from Copilot October 19, 2026 11:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The localized fix preserves existing two-coordinate behavior and includes focused regression coverage, with no identified blocking issues.

No open issues 🎉

What changed in this PR

Fixes rendering of accepted three-coordinate keypoints by using only x/y for pixel positions.

Changes:

  • Updates vertex and shared ellipse rendering without modifying input coordinates.
  • Adds 16 regression cases covering rendering, visibility, and input preservation.
  • Clarifies docstrings and adds an Unreleased changelog entry.
File Description
tests/​key_points/​test_annotators.py Adds regression coverage for all four affected annotators.
src/​supervision/​key_points/​annotators.py Restricts point unpacking to x/y coordinates.
docs/​changelog.md Documents the rendering fix.

Review effort: Balanced

@Borda

Borda commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

Thanks for fixing three-coordinate rendering in the vertex and ellipse annotators. Two related paths still need the same treatment:

  • EdgeAnnotator checks the full endpoint vector for zero and nonfinite values.
  • VertexLabelAnnotator checks the full vector before placing labels at x/y.

This makes (0, 0, z) behave differently from the (0, 0) missing-point sentinel, and a nonfinite depth value suppresses drawing even when x/y are valid.

Could you restrict these checks to x/y and add regression coverage for origin sentinels, nonfinite depth, explicit visibility, and input preservation?
The resulting rendering should match equivalent two-coordinate input.


Not sure why, but your fork does not allow me to push changes to this PR

@aswanth-07

Copy link
Copy Markdown
Contributor Author

Updated in c1079fa. EdgeAnnotator and VertexLabelAnnotator now check only x/y, so (0, 0, z) and nonfinite depth follow the same drawing rules as equivalent two-coordinate input.

The 48 added cases cover float32/float64, finite/NaN/infinite depth, default and explicit visibility, origin sentinels, and input preservation. All 143 annotator tests pass. The full suite has 6,180 passes and seven skips, with the same four Windows fallback-drawing failures as the prior head. All-file pre-commit passes.

I also checked the PR setting: maintainer edits are already enabled. I haven't established why GitHub prevented your push.

@Borda
Borda merged commit cebbc5f into roboflow:develop Oct 20, 2026
36 checks passed
Borda added a commit that referenced this pull request Oct 20, 2026
* fix(key_points): Render three-coordinate points
* fix(key_points): Check x/y for edges and labels

---------

Co-authored-by: Jirka Borovec <6035284+Borda@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants