Added condition check for delegates
This commit is contained in:
parent
c9b00b07e0
commit
82a238a0c8
|
@ -188,13 +188,14 @@ NS_SWIFT_NAME(ImageClassifier)
|
|||
NS_SWIFT_NAME(classifyAsync(image:timestampInMilliseconds:));
|
||||
|
||||
/**
|
||||
* Sends live stream image data of type `MPPImage` to perform image classification, cropped to the
|
||||
* Sends live stream image data of type ``MPPImage`` to perform image classification, cropped to the
|
||||
* specified region of interest.. Rotation will be applied according to the `orientation` property
|
||||
* of the provided `MPPImage`. Only use this method when the `MPPImageClassifier` is created with
|
||||
* `MPPRunningModeLiveStream`.
|
||||
* The object which needs to be continuously notified of the available results of image
|
||||
* classification must confirm to `MPPImageClassifierDelegate` protocol and implement the
|
||||
* `imageClassifier:didFinishClassificationWithResult:timestampInMilliseconds:error:` delegate method.
|
||||
* `imageClassifier:didFinishClassificationWithResult:timestampInMilliseconds:error:` delegate
|
||||
* method.
|
||||
*
|
||||
* It's required to provide a timestamp (in milliseconds) to indicate when the input image is sent
|
||||
* to the image classifier. The input timestamps must be monotonically increasing.
|
||||
|
|
|
@ -88,10 +88,15 @@ static NSString *const kTaskGraphName =
|
|||
packetsCallback = [=](absl::StatusOr<PacketMap> status_or_packets) {
|
||||
NSError *callbackError = nil;
|
||||
if (![MPPCommonUtils checkCppError:status_or_packets.status() toError:&callbackError]) {
|
||||
if ([_imageClassifierDelegate
|
||||
respondsToSelector:@selector
|
||||
(imageClassifier:
|
||||
didFinishClassificationWithResult:timestampInMilliseconds:error:)]) {
|
||||
[_imageClassifierDelegate imageClassifier:self
|
||||
didFinishClassificationWithResult:nil
|
||||
timestampInMilliseconds:Timestamp::Unset().Value()
|
||||
error:callbackError];
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -104,6 +109,10 @@ static NSString *const kTaskGraphName =
|
|||
[MPPImageClassifierResult imageClassifierResultWithClassificationsPacket:
|
||||
outputPacketMap[kClassificationsStreamName.cppString]];
|
||||
|
||||
if ([_imageClassifierDelegate
|
||||
respondsToSelector:@selector
|
||||
(imageClassifier:
|
||||
didFinishClassificationWithResult:timestampInMilliseconds:error:)]) {
|
||||
[_imageClassifierDelegate imageClassifier:self
|
||||
didFinishClassificationWithResult:result
|
||||
timestampInMilliseconds:outputPacketMap[kImageOutStreamName.cppString]
|
||||
|
@ -111,6 +120,7 @@ static NSString *const kTaskGraphName =
|
|||
.Value() /
|
||||
kMicroSecondsPerMilliSecond
|
||||
error:callbackError];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -84,10 +84,14 @@ static NSString *const kTaskGraphName = @"mediapipe.tasks.vision.ObjectDetectorG
|
|||
packetsCallback = [=](absl::StatusOr<PacketMap> statusOrPackets) {
|
||||
NSError *callbackError = nil;
|
||||
if (![MPPCommonUtils checkCppError:statusOrPackets.status() toError:&callbackError]) {
|
||||
if ([_objectDetectorDelegate
|
||||
respondsToSelector:@selector
|
||||
(objectDetector:didFinishDetectionWithResult:timestampInMilliseconds:error:)]) {
|
||||
[_objectDetectorDelegate objectDetector:self
|
||||
didFinishDetectionWithResult:nil
|
||||
timestampInMilliseconds:Timestamp::Unset().Value()
|
||||
error:callbackError];
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -99,7 +103,9 @@ static NSString *const kTaskGraphName = @"mediapipe.tasks.vision.ObjectDetectorG
|
|||
MPPObjectDetectionResult *result = [MPPObjectDetectionResult
|
||||
objectDetectionResultWithDetectionsPacket:statusOrPackets.value()[kDetectionsStreamName
|
||||
.cppString]];
|
||||
|
||||
if ([_objectDetectorDelegate
|
||||
respondsToSelector:@selector
|
||||
(objectDetector:didFinishDetectionWithResult:timestampInMilliseconds:error:)]) {
|
||||
[_objectDetectorDelegate objectDetector:self
|
||||
didFinishDetectionWithResult:result
|
||||
timestampInMilliseconds:outputPacketMap[kImageOutStreamName.cppString]
|
||||
|
@ -121,6 +127,7 @@ static NSString *const kTaskGraphName = @"mediapipe.tasks.vision.ObjectDetectorG
|
|||
return nil;
|
||||
}
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user