From a0253274cc0b2e4139249989c443f28017ce44fb Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Thu, 16 Feb 2023 01:31:09 +0530 Subject: [PATCH] Added MPPVisionPacketCreator --- mediapipe/tasks/ios/vision/core/BUILD | 15 +++++-- .../core/sources/MPPVisionPacketCreator.h | 26 +++++++++++ .../core/sources/MPPVisionPacketCreator.mm | 44 +++++++++++++++++++ 3 files changed, 82 insertions(+), 3 deletions(-) create mode 100644 mediapipe/tasks/ios/vision/core/sources/MPPVisionPacketCreator.h create mode 100644 mediapipe/tasks/ios/vision/core/sources/MPPVisionPacketCreator.mm diff --git a/mediapipe/tasks/ios/vision/core/BUILD b/mediapipe/tasks/ios/vision/core/BUILD index 91b9078a5..360eb1cfc 100644 --- a/mediapipe/tasks/ios/vision/core/BUILD +++ b/mediapipe/tasks/ios/vision/core/BUILD @@ -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", ], ) diff --git a/mediapipe/tasks/ios/vision/core/sources/MPPVisionPacketCreator.h b/mediapipe/tasks/ios/vision/core/sources/MPPVisionPacketCreator.h new file mode 100644 index 000000000..b7b777c97 --- /dev/null +++ b/mediapipe/tasks/ios/vision/core/sources/MPPVisionPacketCreator.h @@ -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 + +#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 diff --git a/mediapipe/tasks/ios/vision/core/sources/MPPVisionPacketCreator.mm b/mediapipe/tasks/ios/vision/core/sources/MPPVisionPacketCreator.mm new file mode 100644 index 000000000..ff5e41030 --- /dev/null +++ b/mediapipe/tasks/ios/vision/core/sources/MPPVisionPacketCreator.mm @@ -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 = [image imageFrameWithError:error]; + + if (!imageFrame) { + return nullptr; + } + + return MakePacket(std::move(imageFrame)); +} + +@end