diff --git a/mediapipe/tasks/ios/components/containers/BUILD b/mediapipe/tasks/ios/components/containers/BUILD index 0477d288a..4effb74b2 100644 --- a/mediapipe/tasks/ios/components/containers/BUILD +++ b/mediapipe/tasks/ios/components/containers/BUILD @@ -66,3 +66,10 @@ objc_library( srcs = ["sources/MPPConnection.m"], hdrs = ["sources/MPPConnection.h"], ) + +objc_library( + name = "MPPRegionOfInterest", + srcs = ["sources/MPPRegionOfInterest.m"], + hdrs = ["sources/MPPRegionOfInterest.h"], + deps = [":MPPDetection"], +) diff --git a/mediapipe/tasks/ios/components/containers/sources/MPPRegionOfInterest.h b/mediapipe/tasks/ios/components/containers/sources/MPPRegionOfInterest.h new file mode 100644 index 000000000..a6b30269d --- /dev/null +++ b/mediapipe/tasks/ios/components/containers/sources/MPPRegionOfInterest.h @@ -0,0 +1,67 @@ +// 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/components/containers/sources/MPPDetection.h" + +NS_ASSUME_NONNULL_BEGIN + +/** The Region-Of-Interest (ROI) to interact with in an interactive segmentation inference. */ +/** An instance can contain erither a single normalized point pointing to the object that the user + * wants to segment or array of normalized key points that make up scribbles over the object that + * the user wants to segment.*/ +NS_SWIFT_NAME(RegionOfInterest) +@interface MPPRegionOfInterest : NSObject + +/** The normalized point pointing to the object that the user wants to segment. `nil if `scribbles` + * is not `nil` */ +@property(nonatomic, readonly, nullable) MPPNormalizedKeypoint *keypoint; + +/** The array of normalized key points that make up scribbles over the object that the user wants to + * segment. `nil if `keypoint` is not `nil` */ +@property(nonatomic, readonly, nullable) NSArray *scribbles; + +/** + * Initializes a new `RegionOfInterest` that represents a single normalized point pointing to the + * object that the user wants to segment. + * + * @param normalizedKeypoint The normalized key point pointing to the object that the user wants to + * segment. + * + * @return An instance of `RegionOfInterest` initialized with the given normalized key point + * pointing to the object that the user wants to segment. + */ +- (instancetype)initWithNormalizedKeyPoint:(MPPNormalizedKeypoint *)normalizedKeypoint + NS_DESIGNATED_INITIALIZER; + +/** + * Initializes a new `RegionOfInterest` that represents scribbles over the object that the user + * wants to segment. + * + * @param scribbles The array of normalized key points that make up scribbles over the object that + * the user wants to segment. + * + * @return An instance of `RegionOfInterest` initialized with the given normalized key points that + * make up scribbles over the object that the user wants to segment. + */ +- (instancetype)initWitScribbles:(NSArray *)scribbles + NS_DESIGNATED_INITIALIZER; + +- (instancetype)init NS_UNAVAILABLE; + ++ (instancetype)new NS_UNAVAILABLE; + +@end + +NS_ASSUME_NONNULL_END diff --git a/mediapipe/tasks/ios/components/containers/sources/MPPRegionOfInterest.m b/mediapipe/tasks/ios/components/containers/sources/MPPRegionOfInterest.m new file mode 100644 index 000000000..0dfa0e5b4 --- /dev/null +++ b/mediapipe/tasks/ios/components/containers/sources/MPPRegionOfInterest.m @@ -0,0 +1,35 @@ +// 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/components/containers/sources/MPPRegionOfInterest.h" + +@implementation MPPRegionOfInterest + +- (instancetype)initWithNormalizedKeyPoint:(MPPNormalizedKeypoint *)normalizedKeypoint { + self = [super init]; + if (self) { + _keypoint = normalizedKeypoint; + } + return self; +} + +- (instancetype)initWitScribbles:(NSArray *)scribbles { + self = [super init]; + if (self) { + _scribbles = scribbles; + } + return self; +} + +@end