Updated iOS image classifier delegate name
This commit is contained in:
parent
7797aa932b
commit
244dcb727e
|
@ -166,7 +166,7 @@ NS_SWIFT_NAME(ImageClassifier)
|
||||||
* the provided `MPPImage`. Only use this method when the `MPPImageClassifier` is created with
|
* the provided `MPPImage`. Only use this method when the `MPPImageClassifier` is created with
|
||||||
* `MPPRunningModeLiveStream`.
|
* `MPPRunningModeLiveStream`.
|
||||||
* The object which needs to be continuously notified of the available results of image
|
* The object which needs to be continuously notified of the available results of image
|
||||||
* classification must confirm to `MPPImageClassifierDelegate` protocol and implement the
|
* classification must confirm to `MPPImageClassifierLiveStreamDelegate` protocol and implement the
|
||||||
* `imageClassifier:didFinishClassificationWithResult:timestampInMilliseconds:error:`
|
* `imageClassifier:didFinishClassificationWithResult:timestampInMilliseconds:error:`
|
||||||
* delegate method.
|
* delegate method.
|
||||||
*
|
*
|
||||||
|
@ -193,7 +193,7 @@ NS_SWIFT_NAME(ImageClassifier)
|
||||||
* of the provided `MPPImage`. Only use this method when the `MPPImageClassifier` is created with
|
* of the provided `MPPImage`. Only use this method when the `MPPImageClassifier` is created with
|
||||||
* `MPPRunningModeLiveStream`.
|
* `MPPRunningModeLiveStream`.
|
||||||
* The object which needs to be continuously notified of the available results of image
|
* The object which needs to be continuously notified of the available results of image
|
||||||
* classification must confirm to `MPPImageClassifierDelegate` protocol and implement the
|
* classification must confirm to `MPPImageClassifierLiveStreamDelegate` protocol and implement the
|
||||||
* `imageClassifier:didFinishClassificationWithResult:timestampInMilliseconds:error:` delegate
|
* `imageClassifier:didFinishClassificationWithResult:timestampInMilliseconds:error:` delegate
|
||||||
* method.
|
* method.
|
||||||
*
|
*
|
||||||
|
|
|
@ -54,14 +54,14 @@ static NSString *const kTaskName = @"imageClassifier";
|
||||||
/** iOS Vision Task Runner */
|
/** iOS Vision Task Runner */
|
||||||
MPPVisionTaskRunner *_visionTaskRunner;
|
MPPVisionTaskRunner *_visionTaskRunner;
|
||||||
}
|
}
|
||||||
@property(nonatomic, weak) id<MPPImageClassifierDelegate> imageClassifierDelegate;
|
@property(nonatomic, weak) id<MPPImageClassifierLiveStreamDelegate>
|
||||||
|
imageClassifierLiveStreamDelegate;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation MPPImageClassifier
|
@implementation MPPImageClassifier
|
||||||
|
|
||||||
- (instancetype)initWithOptions:(MPPImageClassifierOptions *)options error:(NSError **)error {
|
- (instancetype)initWithOptions:(MPPImageClassifierOptions *)options error:(NSError **)error {
|
||||||
self = [super init];
|
self = [super init];
|
||||||
NSLog(@"Image Classifier Initializing with dispatch queu and weak self");
|
|
||||||
if (self) {
|
if (self) {
|
||||||
MPPTaskInfo *taskInfo = [[MPPTaskInfo alloc]
|
MPPTaskInfo *taskInfo = [[MPPTaskInfo alloc]
|
||||||
initWithTaskGraphName:kTaskGraphName
|
initWithTaskGraphName:kTaskGraphName
|
||||||
|
@ -84,9 +84,8 @@ static NSString *const kTaskName = @"imageClassifier";
|
||||||
|
|
||||||
PacketsCallback packetsCallback = nullptr;
|
PacketsCallback packetsCallback = nullptr;
|
||||||
|
|
||||||
if (options.imageClassifierDelegate) {
|
if (options.imageClassifierLiveStreamDelegate) {
|
||||||
_imageClassifierDelegate = options.imageClassifierDelegate;
|
_imageClassifierLiveStreamDelegate = options.imageClassifierLiveStreamDelegate;
|
||||||
|
|
||||||
// Capturing `self` as weak in order to avoid `self` being kept in memory
|
// Capturing `self` as weak in order to avoid `self` being kept in memory
|
||||||
// and cause a retain cycle, after self is set to `nil`.
|
// and cause a retain cycle, after self is set to `nil`.
|
||||||
MPPImageClassifier *__weak weakSelf = self;
|
MPPImageClassifier *__weak weakSelf = self;
|
||||||
|
@ -95,13 +94,13 @@ static NSString *const kTaskName = @"imageClassifier";
|
||||||
// asynchronously. This is to ensure that if the client performs a long running operation in
|
// asynchronously. This is to ensure that if the client performs a long running operation in
|
||||||
// the delegate method, the queue on which the C++ callbacks is invoked is not blocked and is
|
// the delegate method, the queue on which the C++ callbacks is invoked is not blocked and is
|
||||||
// freed up to continue with its operations.
|
// freed up to continue with its operations.
|
||||||
const char *queueName = [MPPVisionTaskRunner uniqueQueueNameWithTaskName:kTaskName];
|
const char *queueName = [MPPVisionTaskRunner uniqueDispatchQueueNameWithSuffix:kTaskName];
|
||||||
dispatch_queue_t callbackQueue = dispatch_queue_create(queueName, NULL);
|
dispatch_queue_t callbackQueue = dispatch_queue_create(queueName, NULL);
|
||||||
packetsCallback = [=](absl::StatusOr<PacketMap> status_or_packets) {
|
packetsCallback = [=](absl::StatusOr<PacketMap> status_or_packets) {
|
||||||
if (!weakSelf) {
|
if (!weakSelf) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (![weakSelf.imageClassifierDelegate
|
if (![weakSelf.imageClassifierLiveStreamDelegate
|
||||||
respondsToSelector:@selector
|
respondsToSelector:@selector
|
||||||
(imageClassifier:
|
(imageClassifier:
|
||||||
didFinishClassificationWithResult:timestampInMilliseconds:error:)]) {
|
didFinishClassificationWithResult:timestampInMilliseconds:error:)]) {
|
||||||
|
@ -111,7 +110,7 @@ static NSString *const kTaskName = @"imageClassifier";
|
||||||
NSError *callbackError = nil;
|
NSError *callbackError = nil;
|
||||||
if (![MPPCommonUtils checkCppError:status_or_packets.status() toError:&callbackError]) {
|
if (![MPPCommonUtils checkCppError:status_or_packets.status() toError:&callbackError]) {
|
||||||
dispatch_async(callbackQueue, ^{
|
dispatch_async(callbackQueue, ^{
|
||||||
[weakSelf.imageClassifierDelegate imageClassifier:weakSelf
|
[weakSelf.imageClassifierLiveStreamDelegate imageClassifier:weakSelf
|
||||||
didFinishClassificationWithResult:nil
|
didFinishClassificationWithResult:nil
|
||||||
timestampInMilliseconds:Timestamp::Unset().Value()
|
timestampInMilliseconds:Timestamp::Unset().Value()
|
||||||
error:callbackError];
|
error:callbackError];
|
||||||
|
@ -132,7 +131,7 @@ static NSString *const kTaskName = @"imageClassifier";
|
||||||
outputPacketMap[kImageOutStreamName.cppString].Timestamp().Value() /
|
outputPacketMap[kImageOutStreamName.cppString].Timestamp().Value() /
|
||||||
kMicroSecondsPerMilliSecond;
|
kMicroSecondsPerMilliSecond;
|
||||||
dispatch_async(callbackQueue, ^{
|
dispatch_async(callbackQueue, ^{
|
||||||
[weakSelf.imageClassifierDelegate imageClassifier:weakSelf
|
[weakSelf.imageClassifierLiveStreamDelegate imageClassifier:weakSelf
|
||||||
didFinishClassificationWithResult:result
|
didFinishClassificationWithResult:result
|
||||||
timestampInMilliseconds:timeStampInMilliseconds
|
timestampInMilliseconds:timeStampInMilliseconds
|
||||||
error:callbackError];
|
error:callbackError];
|
||||||
|
|
|
@ -27,11 +27,11 @@ NS_ASSUME_NONNULL_BEGIN
|
||||||
* results of asynchronous classification of images
|
* results of asynchronous classification of images
|
||||||
* (i.e, when `runningMode = MPPRunningModeLiveStream`).
|
* (i.e, when `runningMode = MPPRunningModeLiveStream`).
|
||||||
*
|
*
|
||||||
* The delegate of `MPPImageClassifier` must adopt `MPPImageClassifierDelegate` protocol.
|
* The delegate of `MPPImageClassifier` must adopt `MPPImageClassifierLiveStreamDelegate` protocol.
|
||||||
* The methods in this protocol are optional.
|
* The methods in this protocol are optional.
|
||||||
*/
|
*/
|
||||||
NS_SWIFT_NAME(ImageClassifierDelegate)
|
NS_SWIFT_NAME(ImageClassifierLiveStreamDelegate)
|
||||||
@protocol MPPImageClassifierDelegate <NSObject>
|
@protocol MPPImageClassifierLiveStreamDelegate <NSObject>
|
||||||
|
|
||||||
@optional
|
@optional
|
||||||
/**
|
/**
|
||||||
|
@ -75,12 +75,13 @@ NS_SWIFT_NAME(ImageClassifierOptions)
|
||||||
@property(nonatomic) MPPRunningMode runningMode;
|
@property(nonatomic) MPPRunningMode runningMode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An object that confirms to `MPPImageClassifierDelegate` protocol. This object must implement
|
* An object that confirms to `MPPImageClassifierLiveStreamDelegate` protocol. This object must
|
||||||
* `objectDetector:didFinishDetectionWithResult:timestampInMilliseconds:error:`
|
* implement `objectDetector:didFinishDetectionWithResult:timestampInMilliseconds:error:` to receive
|
||||||
* to receive the results of asynchronous classification on images (i.e, when `runningMode =
|
* the results of asynchronous classification on images (i.e, when `runningMode =
|
||||||
* MPPRunningModeLiveStream`).
|
* MPPRunningModeLiveStream`).
|
||||||
*/
|
*/
|
||||||
@property(nonatomic, weak, nullable) id<MPPImageClassifierDelegate> imageClassifierDelegate;
|
@property(nonatomic, weak, nullable) id<MPPImageClassifierLiveStreamDelegate>
|
||||||
|
imageClassifierLiveStreamDelegate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The locale to use for display names specified through the TFLite Model Metadata, if any. Defaults
|
* The locale to use for display names specified through the TFLite Model Metadata, if any. Defaults
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
imageClassifierOptions.categoryDenylist = self.categoryDenylist;
|
imageClassifierOptions.categoryDenylist = self.categoryDenylist;
|
||||||
imageClassifierOptions.categoryAllowlist = self.categoryAllowlist;
|
imageClassifierOptions.categoryAllowlist = self.categoryAllowlist;
|
||||||
imageClassifierOptions.displayNamesLocale = self.displayNamesLocale;
|
imageClassifierOptions.displayNamesLocale = self.displayNamesLocale;
|
||||||
imageClassifierOptions.imageClassifierDelegate = self.imageClassifierDelegate;
|
imageClassifierOptions.imageClassifierLiveStreamDelegate = self.imageClassifierLiveStreamDelegate;
|
||||||
|
|
||||||
return imageClassifierOptions;
|
return imageClassifierOptions;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user