feat: add MediaPipe hand landmark support#2283
Conversation
Codecov Report❌ Patch coverage is ❌ Your patch check has failed because the patch coverage (75%) is below the target coverage (95%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## develop #2283 +/- ##
=======================================
Coverage 82% 82%
=======================================
Files 66 66
Lines 9082 9084 +2
=======================================
+ Hits 7412 7418 +6
+ Misses 1670 1666 -4 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Adds MediaPipe hand-landmark support to the key_points module by introducing a dedicated hand skeleton and extending MediaPipe result parsing to handle both current and legacy hand outputs.
Changes:
- Added
Skeleton.HAND(21 vertices / 20 edges) and ensured it is discoverable via existing vertex/edge-count lookup maps. - Extended
KeyPoints.from_mediapipe()to parsehand_landmarksandmulti_hand_landmarks, and to default missing per-landmark visibility to1.0. - Updated test helpers and expanded unit tests to cover the new hand skeleton and MediaPipe hand parsing.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/supervision/key_points/skeletons.py |
Adds the new Skeleton.HAND edge definition and relies on existing lookup-map construction. |
src/supervision/key_points/core.py |
Extends from_mediapipe() to support hand landmarks and makes confidence extraction more robust. |
tests/helpers.py |
Adds a fake landmark type without visibility and extends fake MediaPipe results to include hand-related fields. |
tests/key_points/test_core.py |
Adds MediaPipe hand-landmark parsing test cases. |
tests/key_points/test_skeletons.py |
Adds tests validating the hand skeleton definition and exact edge list. |
| Creates a `sv.KeyPoints` instance from a | ||
| [MediaPipe](https://github.com/google-ai-edge/mediapipe) | ||
| pose landmark detection inference result. |
| ( | ||
| _FakeMediapipeResults( | ||
| multi_hand_landmarks=[ | ||
| _FakeMediapipePose( | ||
| landmarks=[ | ||
| _FakeMediapipeLandmarkWithoutVisibility(0.1, 0.2), | ||
| _FakeMediapipeLandmarkWithoutVisibility(0.3, 0.4), | ||
| ] | ||
| ) | ||
| ] | ||
| ), | ||
| (100, 200), | ||
| _create_key_points( | ||
| xy=[[[10.0, 40.0], [30.0, 80.0]]], | ||
| confidence=[[1.0, 1.0]], | ||
| class_id=None, | ||
| ), | ||
| ), | ||
| ], | ||
| ) |
Before submitting
Description
Adds support for MediaPipe hand landmarks in the key points module.
This PR adds a new
Skeleton.HANDdefinition for MediaPipe's 21 hand landmarks and extendsKeyPoints.from_mediapipe()to parse hand landmark outputs from both current and legacy MediaPipe result formats.Type of Change
Motivation and Context
MediaPipe hand landmarks contain 21 keypoints per hand. The existing
Skeletonenum supported COCO, GHUM, and FaceMesh skeletons, but did not include a hand skeleton. This meantEdgeAnnotatorcould not automatically draw hand landmark connections.KeyPoints.from_mediapipe()also handled pose and face landmarks, but did not handle hand landmarks. This PR adds support for bothhand_landmarksandmulti_hand_landmarks.Closes #2170
Changes Made
Added
Skeleton.HANDwith 21 vertices and 20 MediaPipe hand landmark edgesAdded automatic lookup support through existing
SKELETONS_BY_VERTEX_COUNTandSKELETONS_BY_EDGE_COUNTExtended
KeyPoints.from_mediapipe()to support:hand_landmarksmulti_hand_landmarksUpdated MediaPipe fake test helpers to support hand landmark test cases
Added tests for the hand skeleton definition and MediaPipe hand landmark parsing
Made MediaPipe confidence extraction robust by defaulting missing
visibilityvalues to1.0Testing
Commands run:
Result:
Google Colab (optional)
Not applicable.
Screenshots/Videos (optional)
Not applicable.
Additional Notes
The skeleton edges use 1-based indexing to match the existing
EdgeAnnotatorbehavior, which subtracts1before indexing into keypoint arrays.