From 606b83ac65911c384537044831f15ad7a90d9573 Mon Sep 17 00:00:00 2001 From: MediaPipe Team Date: Wed, 3 May 2023 13:30:08 -0700 Subject: [PATCH] Internal change PiperOrigin-RevId: 529180655 --- mediapipe/tasks/python/vision/__init__.py | 1 + .../tasks/python/vision/hand_landmarker.py | 59 +++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/mediapipe/tasks/python/vision/__init__.py b/mediapipe/tasks/python/vision/__init__.py index cea950ea..3c3f34db 100644 --- a/mediapipe/tasks/python/vision/__init__.py +++ b/mediapipe/tasks/python/vision/__init__.py @@ -42,6 +42,7 @@ GestureRecognizerResult = gesture_recognizer.GestureRecognizerResult HandLandmarker = hand_landmarker.HandLandmarker HandLandmarkerOptions = hand_landmarker.HandLandmarkerOptions HandLandmarkerResult = hand_landmarker.HandLandmarkerResult +HandLandmarksConnections = hand_landmarker.HandLandmarksConnections ImageClassifier = image_classifier.ImageClassifier ImageClassifierOptions = image_classifier.ImageClassifierOptions ImageClassifierResult = image_classifier.ImageClassifierResult diff --git a/mediapipe/tasks/python/vision/hand_landmarker.py b/mediapipe/tasks/python/vision/hand_landmarker.py index 1f2c629d..e781c888 100644 --- a/mediapipe/tasks/python/vision/hand_landmarker.py +++ b/mediapipe/tasks/python/vision/hand_landmarker.py @@ -82,6 +82,65 @@ class HandLandmark(enum.IntEnum): PINKY_TIP = 20 +class HandLandmarksConnections: + """The connections between hand landmarks.""" + + @dataclasses.dataclass + class Connection: + """The connection class for hand landmarks.""" + + start: int + end: int + + HAND_PALM_CONNECTIONS: List[Connection] = [ + Connection(0, 1), + Connection(1, 5), + Connection(9, 13), + Connection(13, 17), + Connection(5, 9), + Connection(0, 17), + ] + + HAND_THUMB_CONNECTIONS: List[Connection] = [ + Connection(1, 2), + Connection(2, 3), + Connection(3, 4), + ] + + HAND_INDEX_FINGER_CONNECTIONS: List[Connection] = [ + Connection(5, 6), + Connection(6, 7), + Connection(7, 8), + ] + + HAND_MIDDLE_FINGER_CONNECTIONS: List[Connection] = [ + Connection(9, 10), + Connection(10, 11), + Connection(11, 12), + ] + + HAND_RING_FINGER_CONNECTIONS: List[Connection] = [ + Connection(13, 14), + Connection(14, 15), + Connection(15, 16), + ] + + HAND_PINKY_FINGER_CONNECTIONS: List[Connection] = [ + Connection(17, 18), + Connection(18, 19), + Connection(19, 20), + ] + + HAND_CONNECTIONS: List[Connection] = ( + HAND_PALM_CONNECTIONS + + HAND_THUMB_CONNECTIONS + + HAND_INDEX_FINGER_CONNECTIONS + + HAND_MIDDLE_FINGER_CONNECTIONS + + HAND_RING_FINGER_CONNECTIONS + + HAND_PINKY_FINGER_CONNECTIONS + ) + + @dataclasses.dataclass class HandLandmarkerResult: """The hand landmarks result from HandLandmarker, where each vector element represents a single hand detected in the image.