From 9ac4ed50200954b4bb45b7b716c495bfd99d2b94 Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Wed, 24 May 2023 19:30:28 +0530 Subject: [PATCH] Added method to initialize iOS categories with default indices --- .../utils/sources/MPPCategory+Helpers.h | 19 +++++++++++++++++++ .../utils/sources/MPPCategory+Helpers.mm | 9 +++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/mediapipe/tasks/ios/components/containers/utils/sources/MPPCategory+Helpers.h b/mediapipe/tasks/ios/components/containers/utils/sources/MPPCategory+Helpers.h index 9a11d1e29..b2417f4c6 100644 --- a/mediapipe/tasks/ios/components/containers/utils/sources/MPPCategory+Helpers.h +++ b/mediapipe/tasks/ios/components/containers/utils/sources/MPPCategory+Helpers.h @@ -19,8 +19,27 @@ NS_ASSUME_NONNULL_BEGIN @interface MPPCategory (Helpers) +/** + * Creates an `MPPCategory` with the given MediaPipe `Classification` proto. + * + * @param classificationProto A MediaPipe `Classification` proto. + * @return An `MPPCategory` object that with the given MediaPipe `Classification` proto. + */ + (MPPCategory *)categoryWithProto:(const ::mediapipe::Classification &)classificationProto; +/** + * Creates an `MPPCategory` with the given MediaPipe `Classification` proto and the given category index. + * The resulting `MPPCategory` is created with the given category index instead of the category index specified in the `Classification` proto. + * This method is useful for tasks like gesture recognizer which always returns a default index for the recognized gestures. + * + * @param classificationProto A MediaPipe `Classification` proto. + * @param index The index to be used for creating the `MPPCategory` instead of the category index specified in the `Classification` proto. + * + * @return An `MPPGestureRecognizerResult` object that contains the hand gesture recognition + * results. + */ ++ (MPPCategory *)categoryWithProto:(const ::mediapipe::Classification &)classificationProto andIndex:(NSInteger)index; + @end NS_ASSUME_NONNULL_END diff --git a/mediapipe/tasks/ios/components/containers/utils/sources/MPPCategory+Helpers.mm b/mediapipe/tasks/ios/components/containers/utils/sources/MPPCategory+Helpers.mm index 12cfa5627..ac7e02cca 100644 --- a/mediapipe/tasks/ios/components/containers/utils/sources/MPPCategory+Helpers.mm +++ b/mediapipe/tasks/ios/components/containers/utils/sources/MPPCategory+Helpers.mm @@ -21,7 +21,7 @@ using ClassificationProto = ::mediapipe::Classification; @implementation MPPCategory (Helpers) -+ (MPPCategory *)categoryWithProto:(const ClassificationProto &)classificationProto { ++ (MPPCategory *)categoryWithProto:(const ClassificationProto &)classificationProto andIndex:(NSInteger)index { NSString *categoryName; NSString *displayName; @@ -33,10 +33,15 @@ using ClassificationProto = ::mediapipe::Classification; displayName = [NSString stringWithCppString:classificationProto.display_name()]; } - return [[MPPCategory alloc] initWithIndex:classificationProto.index() + return [[MPPCategory alloc] initWithIndex:index score:classificationProto.score() categoryName:categoryName displayName:displayName]; } + ++ (MPPCategory *)categoryWithProto:(const ClassificationProto &)classificationProto { + return [MPPCategory categoryWithProto:classificationProto andIndex:classificationProto.index()]; +} + @end