Added methods to MPPVisionPacketCreator
This commit is contained in:
parent
dc393b0bd4
commit
c625d6afdc
|
@ -14,9 +14,11 @@
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
#include "mediapipe/framework/packet.h"
|
|
||||||
#import "mediapipe/tasks/ios/vision/core/sources/MPPImage.h"
|
#import "mediapipe/tasks/ios/vision/core/sources/MPPImage.h"
|
||||||
|
|
||||||
|
#include "mediapipe/framework/packet.h"
|
||||||
|
#include "mediapipe/framework/formats/rect.pb.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class helps create various kinds of packets for Mediapipe Vision Tasks.
|
* This class helps create various kinds of packets for Mediapipe Vision Tasks.
|
||||||
*/
|
*/
|
||||||
|
@ -24,4 +26,13 @@
|
||||||
|
|
||||||
+ (mediapipe::Packet)createPacketWithMPPImage:(MPPImage *)image error:(NSError **)error;
|
+ (mediapipe::Packet)createPacketWithMPPImage:(MPPImage *)image error:(NSError **)error;
|
||||||
|
|
||||||
|
+ (mediapipe::Packet)createPacketWithMPPImage:(MPPImage *)image
|
||||||
|
timestampMs:(NSInteger)timestampMs
|
||||||
|
error:(NSError **)error;
|
||||||
|
|
||||||
|
+ (mediapipe::Packet)createPacketWithNormalizedRect:(mediapipe::NormalizedRect &)normalizedRect;
|
||||||
|
|
||||||
|
+ (mediapipe::Packet)createPacketWithNormalizedRect:(mediapipe::NormalizedRect &)normalizedRect
|
||||||
|
timestampMs:(NSInteger)timestampMs;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -16,18 +16,19 @@
|
||||||
#import "mediapipe/tasks/ios/vision/core/utils/sources/MPPImage+Utils.h"
|
#import "mediapipe/tasks/ios/vision/core/utils/sources/MPPImage+Utils.h"
|
||||||
|
|
||||||
#include "mediapipe/framework/formats/image.h"
|
#include "mediapipe/framework/formats/image.h"
|
||||||
|
#include "mediapipe/framework/timestamp.h"
|
||||||
|
|
||||||
|
static const NSUInteger kMicroSecondsPerMilliSecond = 1000;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
using ::mediapipe::Image;
|
using ::mediapipe::Image;
|
||||||
using ::mediapipe::ImageFrame;
|
using ::mediapipe::ImageFrame;
|
||||||
using ::mediapipe::MakePacket;
|
using ::mediapipe::MakePacket;
|
||||||
|
using ::mediapipe::NormalizedRect;
|
||||||
using ::mediapipe::Packet;
|
using ::mediapipe::Packet;
|
||||||
|
using ::mediapipe::Timestamp;
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
struct freeDeleter {
|
|
||||||
void operator()(void *ptr) { free(ptr); }
|
|
||||||
};
|
|
||||||
|
|
||||||
@implementation MPPVisionPacketCreator
|
@implementation MPPVisionPacketCreator
|
||||||
|
|
||||||
+ (Packet)createPacketWithMPPImage:(MPPImage *)image error:(NSError **)error {
|
+ (Packet)createPacketWithMPPImage:(MPPImage *)image error:(NSError **)error {
|
||||||
|
@ -40,4 +41,27 @@ struct freeDeleter {
|
||||||
return MakePacket<Image>(std::move(imageFrame));
|
return MakePacket<Image>(std::move(imageFrame));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
+ (Packet)createPacketWithMPPImage:(MPPImage *)image
|
||||||
|
timestampMs:(NSInteger)timestampMs
|
||||||
|
error:(NSError **)error {
|
||||||
|
std::unique_ptr<ImageFrame> imageFrame = [image imageFrameWithError:error];
|
||||||
|
|
||||||
|
if (!imageFrame) {
|
||||||
|
return Packet();
|
||||||
|
}
|
||||||
|
|
||||||
|
return MakePacket<Image>(std::move(imageFrame))
|
||||||
|
.At(Timestamp(int64(timestampMs * kMicroSecondsPerMilliSecond)));
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (Packet)createPacketWithNormalizedRect:(NormalizedRect &)normalizedRect {
|
||||||
|
return MakePacket<NormalizedRect>(std::move(normalizedRect));
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (Packet)createPacketWithNormalizedRect:(NormalizedRect &)normalizedRect
|
||||||
|
timestampMs:(NSInteger)timestampMs {
|
||||||
|
return MakePacket<NormalizedRect>(std::move(normalizedRect))
|
||||||
|
.At(Timestamp(int64(timestampMs * kMicroSecondsPerMilliSecond)));
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user