Updated MPPObjectDetectorResult Helpers to return empty result instead of nil

This commit is contained in:
Prianka Liz Kariat 2023-05-24 19:57:38 +05:30
parent 3eb97ae1ff
commit 69017381af

View File

@ -25,8 +25,12 @@ using ::mediapipe::Packet;
+ (nullable MPPObjectDetectorResult *)objectDetectorResultWithDetectionsPacket: + (nullable MPPObjectDetectorResult *)objectDetectorResultWithDetectionsPacket:
(const Packet &)packet { (const Packet &)packet {
NSInteger timestampInMilliseconds = (NSInteger)(packet.Timestamp().Value() /
kMicroSecondsPerMilliSecond);
if (!packet.ValidateAsType<std::vector<DetectionProto>>().ok()) { if (!packet.ValidateAsType<std::vector<DetectionProto>>().ok()) {
return nil; return [[MPPObjectDetectorResult alloc] initWithDetections:@[]
timestampInMilliseconds:timestampInMilliseconds];
} }
const std::vector<DetectionProto> &detectionProtos = packet.Get<std::vector<DetectionProto>>(); const std::vector<DetectionProto> &detectionProtos = packet.Get<std::vector<DetectionProto>>();
@ -39,8 +43,7 @@ using ::mediapipe::Packet;
return return
[[MPPObjectDetectorResult alloc] initWithDetections:detections [[MPPObjectDetectorResult alloc] initWithDetections:detections
timestampInMilliseconds:(NSInteger)(packet.Timestamp().Value() / timestampInMilliseconds:timestampInMilliseconds];
kMicroSecondsPerMilliSecond)];
} }
@end @end