Added method to initialize iOS categories with default indices
This commit is contained in:
parent
0debe7848b
commit
9ac4ed5020
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user