From c560032a9198e90f9045d2296942bbf16dcada21 Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Tue, 3 Oct 2023 19:18:06 +0530 Subject: [PATCH] Added iOS pose landmarker options --- .../tasks/ios/vision/pose_landmarker/BUILD | 10 ++ .../sources/MPPPoseLandmarkerOptions.h | 107 ++++++++++++++++++ .../sources/MPPPoseLandmarkerOptions.m | 45 ++++++++ 3 files changed, 162 insertions(+) create mode 100644 mediapipe/tasks/ios/vision/pose_landmarker/sources/MPPPoseLandmarkerOptions.h create mode 100644 mediapipe/tasks/ios/vision/pose_landmarker/sources/MPPPoseLandmarkerOptions.m diff --git a/mediapipe/tasks/ios/vision/pose_landmarker/BUILD b/mediapipe/tasks/ios/vision/pose_landmarker/BUILD index 8aa0068cc..e45113758 100644 --- a/mediapipe/tasks/ios/vision/pose_landmarker/BUILD +++ b/mediapipe/tasks/ios/vision/pose_landmarker/BUILD @@ -27,3 +27,13 @@ objc_library( ], ) +objc_library( + name = "MPPPoseLandmarkerOptions", + srcs = ["sources/MPPPoseLandmarkerOptions.m"], + hdrs = ["sources/MPPPoseLandmarkerOptions.h"], + deps = [ + ":MPPPoseLandmarkerResult", + "//mediapipe/tasks/ios/core:MPPTaskOptions", + "//mediapipe/tasks/ios/vision/core:MPPRunningMode", + ], +) diff --git a/mediapipe/tasks/ios/vision/pose_landmarker/sources/MPPPoseLandmarkerOptions.h b/mediapipe/tasks/ios/vision/pose_landmarker/sources/MPPPoseLandmarkerOptions.h new file mode 100644 index 000000000..e0cb4d7bf --- /dev/null +++ b/mediapipe/tasks/ios/vision/pose_landmarker/sources/MPPPoseLandmarkerOptions.h @@ -0,0 +1,107 @@ +// 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 + +#import "mediapipe/tasks/ios/core/sources/MPPTaskOptions.h" +#import "mediapipe/tasks/ios/vision/core/sources/MPPRunningMode.h" +#import "mediapipe/tasks/ios/vision/pose_landmarker/sources/MPPPoseLandmarkerResult.h" + +NS_ASSUME_NONNULL_BEGIN + +@class MPPPoseLandmarker; + +/** + * This protocol defines an interface for the delegates of `PoseLandmarker` to receive + * results of performing asynchronous pose landmark detection on images (i.e, when `runningMode` = + * `.liveStream`). + * + * The delegate of `PoseLandmarker` must adopt `PoseLandmarkerLiveStreamDelegate` protocol. + * The methods in this protocol are optional. + */ +NS_SWIFT_NAME(PoseLandmarkerLiveStreamDelegate) +@protocol MPPPoseLandmarkerLiveStreamDelegate + +/** + * This method notifies a delegate that the results of asynchronous pose landmark detection of an + * image submitted to the `PoseLandmarker` is available. + * + * This method is called on a private serial dispatch queue created by the `PoseLandmarker` + * for performing the asynchronous delegates calls. + * + * @param poseLandmarker The pose landmarker which performed the pose landmark detection. + * This is useful to test equality when there are multiple instances of `PoseLandmarker`. + * @param result The `PoseLandmarkerResult` object that contains a list of landmark. + * @param timestampInMilliseconds The timestamp (in milliseconds) which indicates when the input + * image was sent to the pose landmarker. + * @param error An optional error parameter populated when there is an error in performing pose + * landmark detection on the input live stream image data. + */ +- (void)poseLandmarker:(MPPPoseLandmarker *)poseLandmarker + didFinishDetectionWithResult:(nullable MPPPoseLandmarkerResult *)result + timestampInMilliseconds:(NSInteger)timestampInMilliseconds + error:(nullable NSError *)error + NS_SWIFT_NAME(poseLandmarker(_:didFinishDetection:timestampInMilliseconds:error:)); +@end + +/** Options for setting up a `PoseLandmarker`. */ +NS_SWIFT_NAME(PoseLandmarkerOptions) +@interface MPPPoseLandmarkerOptions : MPPTaskOptions + +/** + * Running mode of the pose landmark dection task. Defaults to `.image`. `PoseLandmarker` can be + * created with one of the following running modes: + * 1. `.image`: The mode for performing pose landmark detection on single image inputs. + * 2. `.video`: The mode for performing pose landmark detection on the decoded frames of a video. + * 3. `.liveStream`: The mode for performing pose landmark detection on a live stream of input + * data, such as from the camera. + */ +@property(nonatomic) MPPRunningMode runningMode; + +/** + * An object that confirms to `PoseLandmarkerLiveStreamDelegate` protocol. This object must + * implement `poseLandmarker(_:didFinishDetectionWithResult:timestampInMilliseconds:error:)` to + * receive the results of performing asynchronous pose landmark detection on images (i.e, when + * `runningMode` = `.liveStream`). + */ +@property(nonatomic, weak, nullable) id + poseLandmarkerLiveStreamDelegate; + +/** The maximum number of poses that can be detected by the `PoseLandmarker`. Defaults to 1. */ +@property(nonatomic) NSInteger numPoses; + +/** + * The minimum confidence score for pose detection to be considered successful. Defaults to 0.5. + */ +@property(nonatomic) float minPoseDetectionConfidence; + +/** + * The minimum confidence score of pose presence score in the pose landmark detection. Defaults to + * 0.5. + */ +@property(nonatomic) float minPosePresenceConfidence; + +/** + * The minimum confidence score for pose tracking to be considered successful. Defaults to 0.5. + */ +@property(nonatomic) float minTrackingConfidence; + +/** + * Whether to output segmentation masks. Defaults to `false`. + */ +@property(nonatomic) BOOL shouldOutputSegmentationMasks; + +@end + +NS_ASSUME_NONNULL_END diff --git a/mediapipe/tasks/ios/vision/pose_landmarker/sources/MPPPoseLandmarkerOptions.m b/mediapipe/tasks/ios/vision/pose_landmarker/sources/MPPPoseLandmarkerOptions.m new file mode 100644 index 000000000..0a838693c --- /dev/null +++ b/mediapipe/tasks/ios/vision/pose_landmarker/sources/MPPPoseLandmarkerOptions.m @@ -0,0 +1,45 @@ +// 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/pose_landmarker/sources/MPPPoseLandmarkerOptions.h" + +@implementation MPPPoseLandmarkerOptions + +- (instancetype)init { + self = [super init]; + if (self) { + _numPoses = 1; + _minPoseDetectionConfidence = 0.5f; + _minPosePresenceConfidence = 0.5f; + _minTrackingConfidence = 0.5f; + _shouldOutputSegmentationMasks = NO; + } + return self; +} + +- (id)copyWithZone:(NSZone *)zone { + MPPPoseLandmarkerOptions *poseLandmarkerOptions = [super copyWithZone:zone]; + + poseLandmarkerOptions.runningMode = self.runningMode; + poseLandmarkerOptions.numPoses = self.numPoses; + poseLandmarkerOptions.minPoseDetectionConfidence = self.minPoseDetectionConfidence; + poseLandmarkerOptions.minPosePresenceConfidence = self.minPosePresenceConfidence; + poseLandmarkerOptions.minTrackingConfidence = self.minTrackingConfidence; + poseLandmarkerOptions.shouldOutputSegmentationMasks = self.shouldOutputSegmentationMasks; + poseLandmarkerOptions.poseLandmarkerLiveStreamDelegate = self.poseLandmarkerLiveStreamDelegate; + + return poseLandmarkerOptions; +} + +@end