Added condition check for delegates

This commit is contained in:
Prianka Liz Kariat 2023-05-02 08:45:08 +05:30
parent c9b00b07e0
commit 82a238a0c8
4 changed files with 63 additions and 45 deletions

View File

@ -188,13 +188,14 @@ NS_SWIFT_NAME(ImageClassifier)
NS_SWIFT_NAME(classifyAsync(image:timestampInMilliseconds:)); 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 * 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 * 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 `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 * 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. * to the image classifier. The input timestamps must be monotonically increasing.

View File

@ -88,10 +88,15 @@ static NSString *const kTaskGraphName =
packetsCallback = [=](absl::StatusOr<PacketMap> status_or_packets) { packetsCallback = [=](absl::StatusOr<PacketMap> status_or_packets) {
NSError *callbackError = nil; NSError *callbackError = nil;
if (![MPPCommonUtils checkCppError:status_or_packets.status() toError:&callbackError]) { if (![MPPCommonUtils checkCppError:status_or_packets.status() toError:&callbackError]) {
if ([_imageClassifierDelegate
respondsToSelector:@selector
(imageClassifier:
didFinishClassificationWithResult:timestampInMilliseconds:error:)]) {
[_imageClassifierDelegate imageClassifier:self [_imageClassifierDelegate imageClassifier:self
didFinishClassificationWithResult:nil didFinishClassificationWithResult:nil
timestampInMilliseconds:Timestamp::Unset().Value() timestampInMilliseconds:Timestamp::Unset().Value()
error:callbackError]; error:callbackError];
}
return; return;
} }
@ -104,6 +109,10 @@ static NSString *const kTaskGraphName =
[MPPImageClassifierResult imageClassifierResultWithClassificationsPacket: [MPPImageClassifierResult imageClassifierResultWithClassificationsPacket:
outputPacketMap[kClassificationsStreamName.cppString]]; outputPacketMap[kClassificationsStreamName.cppString]];
if ([_imageClassifierDelegate
respondsToSelector:@selector
(imageClassifier:
didFinishClassificationWithResult:timestampInMilliseconds:error:)]) {
[_imageClassifierDelegate imageClassifier:self [_imageClassifierDelegate imageClassifier:self
didFinishClassificationWithResult:result didFinishClassificationWithResult:result
timestampInMilliseconds:outputPacketMap[kImageOutStreamName.cppString] timestampInMilliseconds:outputPacketMap[kImageOutStreamName.cppString]
@ -111,6 +120,7 @@ static NSString *const kTaskGraphName =
.Value() / .Value() /
kMicroSecondsPerMilliSecond kMicroSecondsPerMilliSecond
error:callbackError]; error:callbackError];
}
}; };
} }

View File

@ -84,10 +84,14 @@ static NSString *const kTaskGraphName = @"mediapipe.tasks.vision.ObjectDetectorG
packetsCallback = [=](absl::StatusOr<PacketMap> statusOrPackets) { packetsCallback = [=](absl::StatusOr<PacketMap> statusOrPackets) {
NSError *callbackError = nil; NSError *callbackError = nil;
if (![MPPCommonUtils checkCppError:statusOrPackets.status() toError:&callbackError]) { if (![MPPCommonUtils checkCppError:statusOrPackets.status() toError:&callbackError]) {
if ([_objectDetectorDelegate
respondsToSelector:@selector
(objectDetector:didFinishDetectionWithResult:timestampInMilliseconds:error:)]) {
[_objectDetectorDelegate objectDetector:self [_objectDetectorDelegate objectDetector:self
didFinishDetectionWithResult:nil didFinishDetectionWithResult:nil
timestampInMilliseconds:Timestamp::Unset().Value() timestampInMilliseconds:Timestamp::Unset().Value()
error:callbackError]; error:callbackError];
}
return; return;
} }
@ -99,7 +103,9 @@ static NSString *const kTaskGraphName = @"mediapipe.tasks.vision.ObjectDetectorG
MPPObjectDetectionResult *result = [MPPObjectDetectionResult MPPObjectDetectionResult *result = [MPPObjectDetectionResult
objectDetectionResultWithDetectionsPacket:statusOrPackets.value()[kDetectionsStreamName objectDetectionResultWithDetectionsPacket:statusOrPackets.value()[kDetectionsStreamName
.cppString]]; .cppString]];
if ([_objectDetectorDelegate
respondsToSelector:@selector
(objectDetector:didFinishDetectionWithResult:timestampInMilliseconds:error:)]) {
[_objectDetectorDelegate objectDetector:self [_objectDetectorDelegate objectDetector:self
didFinishDetectionWithResult:result didFinishDetectionWithResult:result
timestampInMilliseconds:outputPacketMap[kImageOutStreamName.cppString] timestampInMilliseconds:outputPacketMap[kImageOutStreamName.cppString]
@ -121,6 +127,7 @@ static NSString *const kTaskGraphName = @"mediapipe.tasks.vision.ObjectDetectorG
return nil; return nil;
} }
} }
return self; return self;
} }