Added validation of C++ image classification result packet in MPPImageClassifierResult+Helpers.mm
This commit is contained in:
parent
ab4b07646c
commit
e47bb16544
|
@ -18,6 +18,8 @@
|
|||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
static const int kMicroSecondsPerMilliSecond = 1000;
|
||||
|
||||
@interface MPPImageClassifierResult (Helpers)
|
||||
|
||||
/**
|
||||
|
@ -28,7 +30,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
*
|
||||
* @return An `MPPImageClassifierResult` object that contains a list of image classifications.
|
||||
*/
|
||||
+ (MPPImageClassifierResult *)imageClassifierResultWithClassificationsPacket:
|
||||
+ (nullable MPPImageClassifierResult *)imageClassifierResultWithClassificationsPacket:
|
||||
(const mediapipe::Packet &)packet;
|
||||
|
||||
@end
|
||||
|
|
|
@ -17,8 +17,6 @@
|
|||
|
||||
#include "mediapipe/tasks/cc/components/containers/proto/classifications.pb.h"
|
||||
|
||||
static const int kMicroSecondsPerMilliSecond = 1000;
|
||||
|
||||
namespace {
|
||||
using ClassificationResultProto =
|
||||
::mediapipe::tasks::components::containers::proto::ClassificationResult;
|
||||
|
@ -27,9 +25,16 @@ using ::mediapipe::Packet;
|
|||
|
||||
@implementation MPPImageClassifierResult (Helpers)
|
||||
|
||||
+ (MPPImageClassifierResult *)imageClassifierResultWithClassificationsPacket:
|
||||
+ (nullable MPPImageClassifierResult *)imageClassifierResultWithClassificationsPacket:
|
||||
(const Packet &)packet {
|
||||
MPPClassificationResult *classificationResult = [MPPClassificationResult
|
||||
MPPClassificationResult *classificationResult;
|
||||
MPPImageClassifierResult *imageClassifierResult;
|
||||
|
||||
if (!packet.ValidateAsType<ClassificationResultProto>().ok()) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
classificationResult = [MPPClassificationResult
|
||||
classificationResultWithProto:packet.Get<ClassificationResultProto>()];
|
||||
|
||||
return [[MPPImageClassifierResult alloc]
|
||||
|
|
Loading…
Reference in New Issue
Block a user