From ddf4d3fbd3e612ed6beb8c4cb3a77565c7baa184 Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Fri, 26 May 2023 10:58:30 +0530 Subject: [PATCH] Added iOS hand landmarker options helpers --- .../ios/vision/hand_landmarker/utils/BUILD | 33 ++++++++++ .../MPPHandLandmarkerOptions+Helpers.h | 32 ++++++++++ .../MPPHandLandmarkerOptions+Helpers.mm | 60 +++++++++++++++++++ 3 files changed, 125 insertions(+) create mode 100644 mediapipe/tasks/ios/vision/hand_landmarker/utils/BUILD create mode 100644 mediapipe/tasks/ios/vision/hand_landmarker/utils/sources/MPPHandLandmarkerOptions+Helpers.h create mode 100644 mediapipe/tasks/ios/vision/hand_landmarker/utils/sources/MPPHandLandmarkerOptions+Helpers.mm diff --git a/mediapipe/tasks/ios/vision/hand_landmarker/utils/BUILD b/mediapipe/tasks/ios/vision/hand_landmarker/utils/BUILD new file mode 100644 index 00000000..dfb85a21 --- /dev/null +++ b/mediapipe/tasks/ios/vision/hand_landmarker/utils/BUILD @@ -0,0 +1,33 @@ +# Copyright 2023 The MediaPipe Authors. +# +# 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. + +package(default_visibility = ["//mediapipe/tasks:internal"]) + +licenses(["notice"]) + +objc_library( + name = "MPPHandLandmarkerOptionsHelpers", + srcs = ["sources/MPPHandLandmarkerOptions+Helpers.mm"], + hdrs = ["sources/MPPHandLandmarkerOptions+Helpers.h"], + deps = [ + "//mediapipe/framework:calculator_options_cc_proto", + "//mediapipe/tasks/cc/vision/hand_detector/proto:hand_detector_graph_options_cc_proto", + "//mediapipe/tasks/cc/vision/hand_landmarker/proto:hand_landmarker_graph_options_cc_proto", + "//mediapipe/tasks/cc/vision/hand_landmarker/proto:hand_landmarks_detector_graph_options_cc_proto", + "//mediapipe/tasks/ios/common/utils:NSStringHelpers", + "//mediapipe/tasks/ios/core:MPPTaskOptionsProtocol", + "//mediapipe/tasks/ios/core/utils:MPPBaseOptionsHelpers", + "//mediapipe/tasks/ios/vision/hand_landmarker:MPPHandLandmarkerOptions", + ], +) diff --git a/mediapipe/tasks/ios/vision/hand_landmarker/utils/sources/MPPHandLandmarkerOptions+Helpers.h b/mediapipe/tasks/ios/vision/hand_landmarker/utils/sources/MPPHandLandmarkerOptions+Helpers.h new file mode 100644 index 00000000..d93f4350 --- /dev/null +++ b/mediapipe/tasks/ios/vision/hand_landmarker/utils/sources/MPPHandLandmarkerOptions+Helpers.h @@ -0,0 +1,32 @@ +// Copyright 2023 The MediaPipe Authors. +// +// 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. + +#include "mediapipe/framework/calculator_options.pb.h" +#import "mediapipe/tasks/ios/core/sources/MPPTaskOptionsProtocol.h" +#import "mediapipe/tasks/ios/vision/hand_landmarker/sources/MPPHandLandmarkerOptions.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface MPPHandLandmarkerOptions (Helpers) + +/** + * Populates the provided `CalculatorOptions` proto container with the current settings. + * + * @param optionsProto The `CalculatorOptions` proto object to copy the settings to. + */ +- (void)copyToProto:(::mediapipe::CalculatorOptions *)optionsProto; + +@end + +NS_ASSUME_NONNULL_END diff --git a/mediapipe/tasks/ios/vision/hand_landmarker/utils/sources/MPPHandLandmarkerOptions+Helpers.mm b/mediapipe/tasks/ios/vision/hand_landmarker/utils/sources/MPPHandLandmarkerOptions+Helpers.mm new file mode 100644 index 00000000..f88a35bc --- /dev/null +++ b/mediapipe/tasks/ios/vision/hand_landmarker/utils/sources/MPPHandLandmarkerOptions+Helpers.mm @@ -0,0 +1,60 @@ +// Copyright 2023 The MediaPipe Authors. +// +// 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 "mediapipe/tasks/ios/vision/hand_landmarker/utils/sources/MPPHandLandmarkerOptions+Helpers.h" + +#import "mediapipe/tasks/ios/common/utils/sources/NSString+Helpers.h" +#import "mediapipe/tasks/ios/core/utils/sources/MPPBaseOptions+Helpers.h" + +#include "mediapipe/tasks/cc/vision/hand_detector/proto/hand_detector_graph_options.pb.h" +#include "mediapipe/tasks/cc/vision/hand_landmarker/proto/hand_landmarker_graph_options.pb.h" +#include "mediapipe/tasks/cc/vision/hand_landmarker/proto/hand_landmarks_detector_graph_options.pb.h" + +namespace { +using CalculatorOptionsProto = mediapipe::CalculatorOptions; +using HandLandmarkerGraphOptionsProto = + ::mediapipe::tasks::vision::hand_landmarker::proto::HandLandmarkerGraphOptions; +using HandDetectorGraphOptionsProto = + ::mediapipe::tasks::vision::hand_detector::proto::HandDetectorGraphOptions; +using HandLandmarksDetectorGraphOptionsProto = + ::mediapipe::tasks::vision::hand_landmarker::proto::HandLandmarksDetectorGraphOptions; +} // namespace + +@implementation MPPHandLandmarkerOptions (Helpers) + +- (void)copyToProto:(CalculatorOptionsProto *)optionsProto { + HandLandmarkerGraphOptionsProto *handLandmarkerGraphOptionsProto = + optionsProto + ->MutableExtension(HandLandmarkerGraphOptionsProto::ext) + handLandmarkerGraphOptionsProto->Clear(); + + [self.baseOptions copyToProto:gestureRecognizerGraphOptionsProto->mutable_base_options() + withUseStreamMode:self.runningMode != MPPRunningModeImage]; + + handLandmarkerGraphOptionsProto->set_min_tracking_confidence(self.minTrackingConfidence); + + HandDetectorGraphOptionsProto *handDetectorGraphOptionsProto = + handLandmarkerGraphOptionsProto->mutable_hand_detector_graph_options(); + handDetectorGraphOptionsProto->Clear(); + handDetectorGraphOptionsProto->set_num_hands(self.numberOfHands); + handDetectorGraphOptionsProto->set_min_detection_confidence(self.minHandDetectionConfidence); + + HandLandmarksDetectorGraphOptionsProto *handLandmarksDetectorGraphOptionsProto = + handLandmarkerGraphOptionsProto->mutable_hand_landmarks_detector_graph_options(); + handLandmarksDetectorGraphOptionsProto->Clear(); + handLandmarksDetectorGraphOptionsProto->set_min_detection_confidence( + self.minHandPresenceConfidence); +} + +@end