Added MPPVisionPacketCreator

This commit is contained in:
Prianka Liz Kariat 2023-02-16 01:31:09 +05:30
parent 8c3e3456a3
commit a0253274cc
3 changed files with 82 additions and 3 deletions

View File

@ -19,9 +19,6 @@ objc_library(
deps = [
"//mediapipe/tasks/ios/common:MPPCommon",
"//mediapipe/tasks/ios/common/utils:MPPCommonUtils",
"//third_party/apple_frameworks:CoreMedia",
"//third_party/apple_frameworks:CoreVideo",
"//third_party/apple_frameworks:UIKit",
],
)
@ -44,5 +41,17 @@ objc_library(
"//mediapipe/tasks/ios/common:MPPCommon",
"//mediapipe/tasks/ios/common/utils:MPPCommonUtils",
"//mediapipe/tasks/ios/core:MPPTaskRunner",
objc_library(
name = "MPPVisionPacketCreator",
srcs = ["sources/MPPVisionPacketCreator.mm"],
hdrs = ["sources/MPPVisionPacketCreator.h"],
copts = [
"-ObjC++",
"-std=c++17",
],
deps = [
"//mediapipe/framework:packet",
"//mediapipe/framework/formats:image",
"//mediapipe/tasks/ios/vision/core/utils:MPPImageFrameUtils",
],
)

View File

@ -0,0 +1,26 @@
// Copyright 2023 The MediaPipe Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#import <Foundation/Foundation.h>
#include "mediapipe/framework/packet.h"
/**
* This class helps create various kinds of packets for Mediapipe Vision Tasks.
*/
@interface MPPVisionPacketCreator : NSObject
+ (Packet)createWithMPPImage:(MPPImage *)image error:(NSError **)error;
@end

View File

@ -0,0 +1,44 @@
// Copyright 2019 The MediaPipe Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#import "mediapipe/tasks/ios/vision/core/sources/MPPVisionPacketCreator.h"
#import "mediapipe/tasks/ios/vision/core/utils/sources/MPPImage+ImageFrameUtils.h"
#include "mediapipe/framework/formats/image.h"
namespace {
using ::mediapipe::MakePacket;
using ::mediapipe::Packet;
using ::mediapipe::Image;
} // namespace
struct freeDeleter {
void operator()(void* ptr) { free(ptr); }
}
@implementation MPPVisionPacketCreator
+ (Packet)createWithMPPImage:(MPPImage *)image error:(NSError **)error {
std::unique_ptr<ImageFrame> imageFrame = [image imageFrameWithError:error];
if (!imageFrame) {
return nullptr;
}
return MakePacket<Image>(std::move(imageFrame));
}
@end