From 47e55fcf2f5f6ef588088a828289138862a2f627 Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Mon, 17 Apr 2023 14:29:18 -0700 Subject: [PATCH] Add HAND_CONNECTIONS to HandLandmarker and GestureRecognizer PiperOrigin-RevId: 524951052 --- .../face_landmarks_connections.ts | 2 +- .../tasks/web/vision/gesture_recognizer/BUILD | 1 + .../gesture_recognizer/gesture_recognizer.ts | 7 +++++ .../tasks/web/vision/hand_landmarker/BUILD | 7 +++++ .../vision/hand_landmarker/hand_landmarker.ts | 7 +++++ .../hand_landmarks_connections.ts | 31 +++++++++++++++++++ 6 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 mediapipe/tasks/web/vision/hand_landmarker/hand_landmarks_connections.ts diff --git a/mediapipe/tasks/web/vision/face_landmarker/face_landmarks_connections.ts b/mediapipe/tasks/web/vision/face_landmarker/face_landmarks_connections.ts index 97832475..337f663e 100644 --- a/mediapipe/tasks/web/vision/face_landmarker/face_landmarks_connections.ts +++ b/mediapipe/tasks/web/vision/face_landmarker/face_landmarks_connections.ts @@ -19,7 +19,7 @@ import {Connection} from '../../../../tasks/web/vision/core/types'; // tslint:disable:class-as-namespace Using for easier import by 3P users /** - * A class containing the Pairs of landmark indices to be rendered with + * A class containing the pairs of landmark indices to be rendered with * connections. */ export class FaceLandmarksConnections { diff --git a/mediapipe/tasks/web/vision/gesture_recognizer/BUILD b/mediapipe/tasks/web/vision/gesture_recognizer/BUILD index 9156e89b..a3a630e9 100644 --- a/mediapipe/tasks/web/vision/gesture_recognizer/BUILD +++ b/mediapipe/tasks/web/vision/gesture_recognizer/BUILD @@ -34,6 +34,7 @@ mediapipe_ts_library( "//mediapipe/tasks/web/core:classifier_options", "//mediapipe/tasks/web/vision/core:image_processing_options", "//mediapipe/tasks/web/vision/core:vision_task_runner", + "//mediapipe/tasks/web/vision/hand_landmarker:hand_landmarks_connections", "//mediapipe/web/graph_runner:graph_runner_ts", ], ) diff --git a/mediapipe/tasks/web/vision/gesture_recognizer/gesture_recognizer.ts b/mediapipe/tasks/web/vision/gesture_recognizer/gesture_recognizer.ts index 74d37cb6..df9c9128 100644 --- a/mediapipe/tasks/web/vision/gesture_recognizer/gesture_recognizer.ts +++ b/mediapipe/tasks/web/vision/gesture_recognizer/gesture_recognizer.ts @@ -31,6 +31,7 @@ import {convertClassifierOptionsToProto} from '../../../../tasks/web/components/ import {WasmFileset} from '../../../../tasks/web/core/wasm_fileset'; import {ImageProcessingOptions} from '../../../../tasks/web/vision/core/image_processing_options'; import {VisionGraphRunner, VisionTaskRunner} from '../../../../tasks/web/vision/core/vision_task_runner'; +import {HAND_CONNECTIONS} from '../../../../tasks/web/vision/hand_landmarker/hand_landmarks_connections'; import {ImageSource, WasmModule} from '../../../../web/graph_runner/graph_runner'; // Placeholder for internal dependency on trusted resource url @@ -72,6 +73,12 @@ export class GestureRecognizer extends VisionTaskRunner { private readonly handGestureRecognizerGraphOptions: HandGestureRecognizerGraphOptions; + /** + * An array containing the pairs of hand landmark indices to be rendered with + * connections. + */ + static HAND_CONNECTIONS = HAND_CONNECTIONS; + /** * Initializes the Wasm runtime and creates a new gesture recognizer from the * provided options. diff --git a/mediapipe/tasks/web/vision/hand_landmarker/BUILD b/mediapipe/tasks/web/vision/hand_landmarker/BUILD index c5687ee2..948d5692 100644 --- a/mediapipe/tasks/web/vision/hand_landmarker/BUILD +++ b/mediapipe/tasks/web/vision/hand_landmarker/BUILD @@ -16,6 +16,7 @@ mediapipe_ts_library( visibility = ["//visibility:public"], deps = [ ":hand_landmarker_types", + ":hand_landmarks_connections", "//mediapipe/framework:calculator_jspb_proto", "//mediapipe/framework:calculator_options_jspb_proto", "//mediapipe/framework/formats:classification_jspb_proto", @@ -72,3 +73,9 @@ jasmine_node_test( tags = ["nomsan"], deps = [":hand_landmarker_test_lib"], ) + +mediapipe_ts_library( + name = "hand_landmarks_connections", + srcs = ["hand_landmarks_connections.ts"], + deps = ["//mediapipe/tasks/web/vision/core:types"], +) diff --git a/mediapipe/tasks/web/vision/hand_landmarker/hand_landmarker.ts b/mediapipe/tasks/web/vision/hand_landmarker/hand_landmarker.ts index 1978bb06..62928536 100644 --- a/mediapipe/tasks/web/vision/hand_landmarker/hand_landmarker.ts +++ b/mediapipe/tasks/web/vision/hand_landmarker/hand_landmarker.ts @@ -27,6 +27,7 @@ import {Landmark, NormalizedLandmark} from '../../../../tasks/web/components/con import {WasmFileset} from '../../../../tasks/web/core/wasm_fileset'; import {ImageProcessingOptions} from '../../../../tasks/web/vision/core/image_processing_options'; import {VisionGraphRunner, VisionTaskRunner} from '../../../../tasks/web/vision/core/vision_task_runner'; +import {HAND_CONNECTIONS} from '../../../../tasks/web/vision/hand_landmarker/hand_landmarks_connections'; import {ImageSource, WasmModule} from '../../../../web/graph_runner/graph_runner'; // Placeholder for internal dependency on trusted resource url @@ -63,6 +64,12 @@ export class HandLandmarker extends VisionTaskRunner { HandLandmarksDetectorGraphOptions; private readonly handDetectorGraphOptions: HandDetectorGraphOptions; + /** + * An array containing the pairs of hand landmark indices to be rendered with + * connections. + */ + static HAND_CONNECTIONS = HAND_CONNECTIONS; + /** * Initializes the Wasm runtime and creates a new `HandLandmarker` from the * provided options. diff --git a/mediapipe/tasks/web/vision/hand_landmarker/hand_landmarks_connections.ts b/mediapipe/tasks/web/vision/hand_landmarker/hand_landmarks_connections.ts new file mode 100644 index 00000000..edb789c8 --- /dev/null +++ b/mediapipe/tasks/web/vision/hand_landmarker/hand_landmarks_connections.ts @@ -0,0 +1,31 @@ +/** + * Copyright 2023 The MediaPipe Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import {Connection} from '../../../../tasks/web/vision/core/types'; + +/** + * An array containing the pairs of hand landmark indices to be rendered with + * connections. + */ +export const HAND_CONNECTIONS: Connection[] = [ + {start: 0, end: 1}, {start: 1, end: 2}, {start: 2, end: 3}, + {start: 3, end: 4}, {start: 0, end: 5}, {start: 5, end: 6}, + {start: 6, end: 7}, {start: 7, end: 8}, {start: 5, end: 9}, + {start: 9, end: 10}, {start: 10, end: 11}, {start: 11, end: 12}, + {start: 9, end: 13}, {start: 13, end: 14}, {start: 14, end: 15}, + {start: 15, end: 16}, {start: 13, end: 17}, {start: 0, end: 17}, + {start: 17, end: 18}, {start: 18, end: 19}, {start: 19, end: 20} +];