Skip to content

Add ColorPalette and ColorLookup support to keypoint annotators#2343

Open
SkalskiP wants to merge 4 commits into
developfrom
feature/keypoint-annotators-color-lookup-support
Open

Add ColorPalette and ColorLookup support to keypoint annotators#2343
SkalskiP wants to merge 4 commits into
developfrom
feature/keypoint-annotators-color-lookup-support

Conversation

@SkalskiP

@SkalskiP SkalskiP commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

Summary

Brings the same color-mapping system used by detection annotators (ColorPalette + ColorLookup) to VertexAnnotator, EdgeAnnotator, and VertexLabelAnnotator. This lets users color keypoints by detection index, class, or track — and introduces a new ColorLookup.KEYPOINT strategy for per-keypoint-index coloring.

  • EdgeAnnotator (sv.ColorLookup.CLASS, sv.ColorLookup.INDEX, sv.ColorLookup.KEYPOINT)
IMG_8709_crop_edge_color_lookup
  • VertexAnnotator (sv.ColorLookup.CLASS, sv.ColorLookup.INDEX, sv.ColorLookup.KEYPOINT)
IMG_8709_crop_vertex_color_lookup
  • VertexLabelAnnotator (sv.ColorLookup.CLASS, sv.ColorLookup.INDEX, sv.ColorLookup.KEYPOINT)
IMG_8709_crop_label_color_lookup

@codecov

codecov Bot commented Jun 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.75000% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 81%. Comparing base (07d182b) to head (720f29b).

Additional details and impacted files
@@           Coverage Diff           @@
##           develop   #2343   +/-   ##
=======================================
- Coverage       81%     81%   -0%     
=======================================
  Files           66      66           
  Lines         9077    9108   +31     
=======================================
+ Hits          7377    7398   +21     
- Misses        1700    1710   +10     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

Pull request overview

This PR extends the ColorPalette + ColorLookup color-mapping approach (used by detection annotators) to keypoint annotators, enabling palette-driven coloring and introducing a new ColorLookup.KEYPOINT strategy for per-keypoint-index coloring.

Changes:

  • Added shared color-resolution helpers to support ColorLookup.KEYPOINT and reuse logic between detection and keypoint annotators.
  • Updated VertexAnnotator, EdgeAnnotator, and VertexLabelAnnotator to accept ColorPalette and use ColorLookup to resolve per-annotation colors.
  • Refactored detection annotators to use newly introduced internal helpers, and updated keypoint annotator tests to match the new internal API.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
tests/key_points/test_annotators.py Updates unit tests for VertexLabelAnnotator color resolution to align with the new single-color resolution logic.
src/supervision/key_points/annotators.py Adds palette/lookup support to keypoint annotators and introduces shared keypoint color resolution.
src/supervision/annotators/utils.py Adds ColorLookup.KEYPOINT and refactors/extends internal color index + color resolution helpers (with deprecation wrappers).
src/supervision/annotators/core.py Switches detection annotators to use the new internal _resolve_detection_color helper.

Comment on lines +83 to +88
if tracker_id is None:
raise ValueError(
"Could not resolve color by track because "
"tracker_id is not available. Make sure that the "
"Detections object contains tracker_id data."
)
Comment on lines +78 to 82
color_lookup: Strategy for mapping colors to annotations.
Options are `INDEX` (per-skeleton index), `CLASS`
(per class_id), and `KEYPOINT` (per keypoint index within
each skeleton).
"""
Comment on lines +30 to +36
def _resolve_keypoint_color(
color: Color | ColorPalette,
color_lookup: ColorLookup,
key_points: KeyPoints,
instance_idx: int,
keypoint_idx: int = 0,
) -> Color:
Comment thread src/supervision/key_points/annotators.py Outdated
@SkalskiP SkalskiP marked this pull request as ready for review June 19, 2026 22:45
@SkalskiP

Copy link
Copy Markdown
Collaborator Author

@Borda this is ready for review. I believe this makes VertexAnnotator, EdgeAnnotator, and VertexLabelAnnotator a lot more useful in real life scenarios.

@Borda Borda self-requested a review June 20, 2026 07:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants