Skip to content

Add ColorPalette and ColorLookup support to keypoint annotators#2343

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

Add ColorPalette and ColorLookup support to keypoint annotators#2343
SkalskiP wants to merge 9 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 86.58537% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 82%. Comparing base (14f6f24) to head (779de03).
⚠️ Report is 8 commits behind head on develop.

❌ Your project check has failed because the head coverage (82%) is below the target coverage (95%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@           Coverage Diff           @@
##           develop   #2343   +/-   ##
=======================================
- Coverage       82%     82%   -0%     
=======================================
  Files           66      66           
  Lines         9082    9113   +31     
=======================================
+ Hits          7412    7436   +24     
- Misses        1670    1677    +7     
🚀 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 thread src/supervision/annotators/utils.py
Comment thread src/supervision/key_points/annotators.py
Comment thread src/supervision/key_points/annotators.py
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
Comment thread src/supervision/annotators/utils.py Outdated
Comment thread src/supervision/annotators/utils.py
calculate_dynamic_pixel_size,
get_labels_text,
hex_to_rgba,
resolve_color,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe check this issue and consider also deprecating it?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

adding back in sugegstion #2343 (comment)

Comment thread src/supervision/key_points/annotators.py
Borda
Borda previously approved these changes Jun 23, 2026
- Generalize TRACK error msg in _resolve_color_idx to not reference
  "Detections object" (function now shared with keypoint annotators)
- Consolidate multi-line error strings to full line width
- Add Raises section to _resolve_color_idx docstring
- Add TRACK-not-supported note to VertexAnnotator, EdgeAnnotator,
  VertexLabelAnnotator color_lookup docs
- Add ColorPalette+ColorLookup tests: INDEX/CLASS/KEYPOINT for all
  three keypoint annotators + CLASS-without-class_id error case
- Fix _resolve_color_idx signature: NDArray[np.generic] (linter)

[resolve items 1,2,3,5,6] PR #2343 review by @Copilot and @Borda
Challenge: evidence=VALID suggestion=VALID resolution=as-suggested

---
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
@Borda

Borda commented Jun 23, 2026

Copy link
Copy Markdown
Member

There seems to be some timeout for one of the links, but it shall be fine...

Comment thread src/supervision/annotators/utils.py Outdated
calculate_dynamic_kernel_size,
calculate_dynamic_pixel_size,
get_labels_text,
hex_to_rgba,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
hex_to_rgba,
hex_to_rgba,
resolve_color,

Borda
Borda previously approved these changes Jun 24, 2026
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants