From a128810564d27ee126a5bded65571018fc1825ee Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Thu, 16 Feb 2023 01:25:16 +0530 Subject: [PATCH 01/11] Updated MPPImageUtils with methods to create image frame --- mediapipe/tasks/ios/vision/core/utils/BUILD | 14 +- .../core/utils/sources/MPPImage+Utils.h | 22 ++- .../{MPPImage+Utils.m => MPPImage+Utils.mm} | 133 +++++++----------- 3 files changed, 70 insertions(+), 99 deletions(-) rename mediapipe/tasks/ios/vision/core/utils/sources/{MPPImage+Utils.m => MPPImage+Utils.mm} (73%) diff --git a/mediapipe/tasks/ios/vision/core/utils/BUILD b/mediapipe/tasks/ios/vision/core/utils/BUILD index 540c2753..c99055c7 100644 --- a/mediapipe/tasks/ios/vision/core/utils/BUILD +++ b/mediapipe/tasks/ios/vision/core/utils/BUILD @@ -4,23 +4,23 @@ licenses(["notice"]) objc_library( name = "MPPImageUtils", - srcs = ["sources/MPPImage+Utils.m"], + srcs = ["sources/MPPImage+Utils.mm"], hdrs = ["sources/MPPImage+Utils.h"], - copts = [ - "-ObjC++", - "-std=c++17", - ], module_name = "MPPImageUtils", sdk_frameworks = [ "Accelerate", "CoreGraphics", "CoreImage", "CoreVideo", - "UIKit", ], deps = [ "//mediapipe/tasks/ios/common/utils:MPPCommonUtils", "//mediapipe/tasks/ios/vision/core:MPPImage", - "//third_party/apple_frameworks:UIKit", + "//mediapipe/framework/formats:image_format_cc_proto", + "//mediapipe/framework/formats:image_frame", + ], + copts = [ + "-ObjC++", + "-std=c++17", ], ) diff --git a/mediapipe/tasks/ios/vision/core/utils/sources/MPPImage+Utils.h b/mediapipe/tasks/ios/vision/core/utils/sources/MPPImage+Utils.h index a9c371d5..724bccda 100644 --- a/mediapipe/tasks/ios/vision/core/utils/sources/MPPImage+Utils.h +++ b/mediapipe/tasks/ios/vision/core/utils/sources/MPPImage+Utils.h @@ -15,29 +15,25 @@ #import #import "mediapipe/tasks/ios/vision/core/sources/MPPImage.h" +#include "mediapipe/framework/formats/image_frame.h" NS_ASSUME_NONNULL_BEGIN -/** - * Helper utility for performing operations on MPPImage specific to the MediaPipe Vision library. +/** + * Helper utility for converting `MPPImage` into a `mediapipe::ImageFrame`. */ @interface MPPImage (Utils) - -/** Bitmap size of the image. */ -@property(nonatomic, readonly) CGSize bitmapSize; - /** - * Returns the underlying uint8 pixel buffer of an `MPPImage`. - * Irrespective of whether the underlying buffer is grayscale, RGB, RGBA, BGRA etc., the pixel - * data is converted to an RGB format. In case of grayscale images, the mono channel is duplicated + * Converts the `MPPImage` into a `mediapipe::ImageFrame`. + * Irrespective of whether the underlying buffer is grayscale, RGB, RGBA, BGRA etc., the MPPImage is converted to an RGB format. In case of grayscale images, the mono channel is duplicated * in the R, G, B channels. * - * @param error Pointer to the memory location where errors if any should be saved. If @c NULL, no - * error will be saved. + * @param error Pointer to the memory location where errors if any should be + * saved. If @c NULL, no error will be saved. * - * @return The underlying pixel buffer of the `MPPImage` or nil in case of errors. + * @return An std::unique_ptr or `nullptr` in case of errors. */ -- (nullable uint8_t *)rgbPixelDataWithError:(NSError **)error; +- (std::unique_ptr)imageFrameWithError:(NSError **)error; @end diff --git a/mediapipe/tasks/ios/vision/core/utils/sources/MPPImage+Utils.m b/mediapipe/tasks/ios/vision/core/utils/sources/MPPImage+Utils.mm similarity index 73% rename from mediapipe/tasks/ios/vision/core/utils/sources/MPPImage+Utils.m rename to mediapipe/tasks/ios/vision/core/utils/sources/MPPImage+Utils.mm index 01ac9912..8d6efe91 100644 --- a/mediapipe/tasks/ios/vision/core/utils/sources/MPPImage+Utils.m +++ b/mediapipe/tasks/ios/vision/core/utils/sources/MPPImage+Utils.mm @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#import "mediapipe/tasks/ios/vision/core/utils/sources/MPPImage+Utils.h" +#import "mediapipe/tasks/ios/vision/core/utils/sources/MPPImage+ImageFrameUtils.h" #import "mediapipe/tasks/ios/common/sources/MPPCommon.h" #import "mediapipe/tasks/ios/common/utils/sources/MPPCommonUtils.h" @@ -22,6 +22,12 @@ #import #import +#include "mediapipe/framework/formats/image_format.pb.h" + +namespace { + using ::mediapipe::ImageFrame; +} + @interface MPPPixelDataUtils : NSObject + (uint8_t *)rgbPixelDataFromPixelData:(uint8_t *)pixelData @@ -35,21 +41,19 @@ @interface MPPCVPixelBufferUtils : NSObject -+ (uint8_t *)pixelDataFromCVPixelBuffer:(CVPixelBufferRef)pixelBuffer error:(NSError **)error; ++ (std::unique_ptr)imageFrameFromCVPixelBuffer:(CVPixelBufferRef)pixelBuffer error:(NSError **)error; @end @interface MPPCGImageUtils : NSObject -+ (UInt8 *_Nullable)pixelDataFromCGImage:(CGImageRef)cgImage error:(NSError **)error; ++ (std::unique_ptr)imageFrameFromCGImage:(CGImageRef)cgImage error:(NSError **)error; @end -@interface UIImage (RawPixelDataUtils) +@interface UIImage (ImageFrameUtils) -@property(nonatomic, readonly) CGSize bitmapSize; - -- (uint8_t *)pixelDataWithError:(NSError **)error; +- (std::unique_ptr)imageFrameWithError:(NSError **)error; @end @@ -120,9 +124,15 @@ @implementation MPPCVPixelBufferUtils -+ (uint8_t *)rgbPixelDataFromCVPixelBuffer:(CVPixelBufferRef)pixelBuffer error:(NSError **)error { ++ (std::unique_ptr)rgbImageFrameFromCVPixelBuffer:(CVPixelBufferRef)pixelBuffer error:(NSError **)error { CVPixelBufferLockBaseAddress(pixelBuffer, 0); + size_t width = CVPixelBufferGetWidth(pixelBuffer); + size_t height = CVPixelBufferGetHeight(pixelBuffer); + size_t stride = CVPixelBufferGetBytesPerRow(pixelBuffer); + + + uint8_t *rgbPixelData = [MPPPixelDataUtils rgbPixelDataFromPixelData:(uint8_t *)CVPixelBufferGetBaseAddress(pixelBuffer) withWidth:CVPixelBufferGetWidth(pixelBuffer) @@ -133,10 +143,19 @@ CVPixelBufferUnlockBaseAddress(pixelBuffer, 0); - return rgbPixelData; + if (!rgbPixelData) { + return nullptr; + } + + std::unique_ptr imageFrame = absl::make_unique( + ::mediapipe::ImageFormat::SRGB, /*width=*/width, /*height=*/height, stride, + static_cast(rgbPixelData), + /*deleter=*/free); + + return imageFrame; } -+ (nullable uint8_t *)pixelDataFromCVPixelBuffer:(CVPixelBufferRef)pixelBuffer ++ (std::unique_ptr)imageFrameFromCVPixelBuffer:(CVPixelBufferRef)pixelBuffer error:(NSError **)error { uint8_t *pixelData = NULL; @@ -144,8 +163,7 @@ switch (pixelBufferFormat) { case kCVPixelFormatType_32BGRA: { - pixelData = [MPPCVPixelBufferUtils rgbPixelDataFromCVPixelBuffer:pixelBuffer error:error]; - break; + return [MPPCVPixelBufferUtils rgbImageFrameFromCVPixelBuffer:pixelBuffer error:error]; } default: { [MPPCommonUtils createCustomError:error @@ -155,20 +173,20 @@ } } - return pixelData; + return nullptr; } @end @implementation MPPCGImageUtils -+ (UInt8 *_Nullable)pixelDataFromCGImage:(CGImageRef)cgImage error:(NSError **)error { ++ (std::unique_ptr)imageFrameFromCGImage:(CGImageRef)cgImage error:(NSError **)error { size_t width = CGImageGetWidth(cgImage); size_t height = CGImageGetHeight(cgImage); NSInteger bitsPerComponent = 8; NSInteger channelCount = 4; - UInt8 *pixel_data_to_return = NULL; + UInt8 *pixelDataToReturn = NULL; CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); size_t bytesPerRow = channelCount * width; @@ -191,7 +209,7 @@ if (srcData) { // We have drawn the image as an RGBA image with 8 bitsPerComponent and hence can safely input // a pixel format of type kCVPixelFormatType_32RGBA for conversion by vImage. - pixel_data_to_return = [MPPPixelDataUtils rgbPixelDataFromPixelData:srcData + pixelDataToReturn = [MPPPixelDataUtils rgbPixelDataFromPixelData:srcData withWidth:width height:height stride:bytesPerRow @@ -204,38 +222,42 @@ CGColorSpaceRelease(colorSpace); - return pixel_data_to_return; + std::unique_ptr imageFrame = absl::make_unique( + mediapipe::ImageFormat::SRGB, /*width=*/(int)width, /*height=*/(int)height, (int)bytesPerRow, + static_cast(pixelDataToReturn), + /*deleter=*/free); + + return imageFrame; } @end -@implementation UIImage (RawPixelDataUtils) +@implementation UIImage (ImageFrameUtils) -- (uint8_t *)pixelDataFromCIImageWithError:(NSError **)error { - uint8_t *pixelData = NULL; +- (std::unique_ptr)imageFrameFromCIImageWithError:(NSError **)error { if (self.CIImage.pixelBuffer) { - pixelData = [MPPCVPixelBufferUtils pixelDataFromCVPixelBuffer:self.CIImage.pixelBuffer + return [MPPCVPixelBufferUtils imageFrameFromCVPixelBuffer:self.CIImage.pixelBuffer error:error]; } else if (self.CIImage.CGImage) { - pixelData = [MPPCGImageUtils pixelDataFromCGImage:self.CIImage.CGImage error:error]; + return [MPPCGImageUtils imageFrameFromCGImage:self.CIImage.CGImage error:error]; } else { [MPPCommonUtils createCustomError:error withCode:MPPTasksErrorCodeInvalidArgumentError description:@"CIImage should have CGImage or CVPixelBuffer info."]; } - return pixelData; + return nullptr; } -- (uint8_t *)pixelDataWithError:(NSError **)error { +- (std::unique_ptr)imageFrameWithError:(NSError **)error { uint8_t *pixelData = nil; if (self.CGImage) { - pixelData = [MPPCGImageUtils pixelDataFromCGImage:self.CGImage error:error]; + return [MPPCGImageUtils imageFrameFromCGImage:self.CGImage error:error]; } else if (self.CIImage) { - pixelData = [self pixelDataFromCIImageWithError:error]; + return [self imageFrameFromCIImageWithError:error]; } else { [MPPCommonUtils createCustomError:error withCode:MPPTasksErrorCodeInvalidArgumentError @@ -243,46 +265,27 @@ " CIImage or CGImage."]; } - return pixelData; + return nullptr; } -- (CGSize)bitmapSize { - CGFloat width = 0; - CGFloat height = 0; - - if (self.CGImage) { - width = CGImageGetWidth(self.CGImage); - height = CGImageGetHeight(self.CGImage); - } else if (self.CIImage.pixelBuffer) { - width = CVPixelBufferGetWidth(self.CIImage.pixelBuffer); - height = CVPixelBufferGetHeight(self.CIImage.pixelBuffer); - } else if (self.CIImage.CGImage) { - width = CGImageGetWidth(self.CIImage.CGImage); - height = CGImageGetHeight(self.CIImage.CGImage); - } - return CGSizeMake(width, height); -} @end @implementation MPPImage (Utils) -- (nullable uint8_t *)rgbPixelDataWithError:(NSError **)error { +- (std::unique_ptr)imageFrameWithError:(NSError **)error { uint8_t *pixelData = NULL; switch (self.imageSourceType) { case MPPImageSourceTypeSampleBuffer: { CVPixelBufferRef sampleImagePixelBuffer = CMSampleBufferGetImageBuffer(self.sampleBuffer); - pixelData = [MPPCVPixelBufferUtils pixelDataFromCVPixelBuffer:sampleImagePixelBuffer + return [MPPCVPixelBufferUtils imageFrameFromCVPixelBuffer:sampleImagePixelBuffer error:error]; - break; } case MPPImageSourceTypePixelBuffer: { - pixelData = [MPPCVPixelBufferUtils pixelDataFromCVPixelBuffer:self.pixelBuffer error:error]; - break; + return [MPPCVPixelBufferUtils imageFrameFromCVPixelBuffer:self.pixelBuffer error:error]; } case MPPImageSourceTypeImage: { - pixelData = [self.image pixelDataWithError:error]; - break; + return [self.image imageFrameWithError:error]; } default: [MPPCommonUtils createCustomError:error @@ -290,35 +293,7 @@ description:@"Invalid source type for MPPImage."]; } - return pixelData; -} - -- (CGSize)bitmapSize { - CGFloat width = 0; - CGFloat height = 0; - - switch (self.imageSourceType) { - case MPPImageSourceTypeSampleBuffer: { - CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(self.sampleBuffer); - width = CVPixelBufferGetWidth(pixelBuffer); - height = CVPixelBufferGetHeight(pixelBuffer); - break; - } - case MPPImageSourceTypePixelBuffer: { - width = CVPixelBufferGetWidth(self.pixelBuffer); - height = CVPixelBufferGetHeight(self.pixelBuffer); - break; - } - case MPPImageSourceTypeImage: { - width = self.image.bitmapSize.width; - height = self.image.bitmapSize.height; - break; - } - default: - break; - } - - return CGSizeMake(width, height); + return nullptr; } @end From 825b30bccdeae1c5982e65bd0b3bd9abbb85f780 Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Thu, 16 Feb 2023 01:25:57 +0530 Subject: [PATCH 02/11] Added MPPImageClassifierResult --- .../tasks/ios/vision/image_classifier/BUILD | 28 ++++++++++++ .../sources/MPPImageClassifierResult.h | 44 +++++++++++++++++++ .../sources/MPPImageClassifierResult.m | 28 ++++++++++++ 3 files changed, 100 insertions(+) create mode 100644 mediapipe/tasks/ios/vision/image_classifier/BUILD create mode 100644 mediapipe/tasks/ios/vision/image_classifier/sources/MPPImageClassifierResult.h create mode 100644 mediapipe/tasks/ios/vision/image_classifier/sources/MPPImageClassifierResult.m diff --git a/mediapipe/tasks/ios/vision/image_classifier/BUILD b/mediapipe/tasks/ios/vision/image_classifier/BUILD new file mode 100644 index 00000000..2ecfcab0 --- /dev/null +++ b/mediapipe/tasks/ios/vision/image_classifier/BUILD @@ -0,0 +1,28 @@ +# Copyright 2023 The MediaPipe Authors. All Rights Reserved. +# +# 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. + +package(default_visibility = ["//mediapipe/tasks:internal"]) + +licenses(["notice"]) + +objc_library( + name = "MPPImageClassifierResult", + srcs = ["sources/MPPImageClassifierResult.m"], + hdrs = ["sources/MPPImageClassifierResult.h"], + deps = [ + "//mediapipe/tasks/ios/components/containers:MPPClassificationResult", + "//mediapipe/tasks/ios/core:MPPTaskResult", + ], +) + diff --git a/mediapipe/tasks/ios/vision/image_classifier/sources/MPPImageClassifierResult.h b/mediapipe/tasks/ios/vision/image_classifier/sources/MPPImageClassifierResult.h new file mode 100644 index 00000000..92fdb13c --- /dev/null +++ b/mediapipe/tasks/ios/vision/image_classifier/sources/MPPImageClassifierResult.h @@ -0,0 +1,44 @@ +// 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 +#import "mediapipe/tasks/ios/components/containers/sources/MPPClassificationResult.h" +#import "mediapipe/tasks/ios/core/sources/MPPTaskResult.h" + +NS_ASSUME_NONNULL_BEGIN + +/** Represents the classification results generated by `MPPImageClassifier`. **/ +NS_SWIFT_NAME(ImageClassifierResult) +@interface MPPImageClassifierResult : MPPTaskResult + +/** The `MPPClassificationResult` instance containing one set of results per classifier head. **/ +@property(nonatomic, readonly) MPPClassificationResult *classificationResult; + +/** + * Initializes a new `MPPImageClassifierResult` with the given `MPPClassificationResult` and + * timestamp (in milliseconds). + * + * @param classificationResult The `MPPClassificationResult` instance containing one set of results + * per classifier head. + * @param timestampMs The timestamp for this result. + * + * @return An instance of `MPPImageClassifierResult` initialized with the given + * `MPPClassificationResult` and timestamp (in milliseconds). + */ +- (instancetype)initWithClassificationResult:(MPPClassificationResult *)classificationResult + timestampMs:(NSInteger)timestampMs; + +@end + +NS_ASSUME_NONNULL_END diff --git a/mediapipe/tasks/ios/vision/image_classifier/sources/MPPImageClassifierResult.m b/mediapipe/tasks/ios/vision/image_classifier/sources/MPPImageClassifierResult.m new file mode 100644 index 00000000..6dcd064e --- /dev/null +++ b/mediapipe/tasks/ios/vision/image_classifier/sources/MPPImageClassifierResult.m @@ -0,0 +1,28 @@ +// 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 "mediapipe/tasks/ios/vision/image_classifier/sources/MPPImageClassifierResult.h" + +@implementation MPPImageClassifierResult + +- (instancetype)initWithClassificationResult:(MPPClassificationResult *)classificationResult + timestampMs:(NSInteger)timestampMs { + self = [super initWithTimestampMs:timestampMs]; + if (self) { + _classificationResult = classificationResult; + } + return self; +} + +@end From 8c3e3456a3888a3d9a63cd8306ce743b6251731c Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Thu, 16 Feb 2023 01:26:10 +0530 Subject: [PATCH 03/11] Added MPPImageClassifierOptions --- .../tasks/ios/vision/image_classifier/BUILD | 10 +++ .../sources/MPPImageClassifierOptions.h | 70 +++++++++++++++++++ .../sources/MPPImageClassifierOptions.m | 41 +++++++++++ 3 files changed, 121 insertions(+) create mode 100644 mediapipe/tasks/ios/vision/image_classifier/sources/MPPImageClassifierOptions.h create mode 100644 mediapipe/tasks/ios/vision/image_classifier/sources/MPPImageClassifierOptions.m diff --git a/mediapipe/tasks/ios/vision/image_classifier/BUILD b/mediapipe/tasks/ios/vision/image_classifier/BUILD index 2ecfcab0..45e6e215 100644 --- a/mediapipe/tasks/ios/vision/image_classifier/BUILD +++ b/mediapipe/tasks/ios/vision/image_classifier/BUILD @@ -26,3 +26,13 @@ objc_library( ], ) +objc_library( + name = "MPPImageClassifierOptions", + srcs = ["sources/MPPImageClassifierOptions.m"], + hdrs = ["sources/MPPImageClassifierOptions.h"], + deps = [ + ":MPPImageClassifierResult", + "//mediapipe/tasks/ios/core:MPPTaskOptions", + "//mediapipe/tasks/ios/vision/core:MPPRunningMode", + ], +) diff --git a/mediapipe/tasks/ios/vision/image_classifier/sources/MPPImageClassifierOptions.h b/mediapipe/tasks/ios/vision/image_classifier/sources/MPPImageClassifierOptions.h new file mode 100644 index 00000000..2ca15811 --- /dev/null +++ b/mediapipe/tasks/ios/vision/image_classifier/sources/MPPImageClassifierOptions.h @@ -0,0 +1,70 @@ +// 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 + +#import "mediapipe/tasks/ios/core/sources/MPPTaskOptions.h" +#import "mediapipe/tasks/ios/vision/core/sources/MPPRunningMode.h" +#import "mediapipe/tasks/ios/vision/image_classifier/sources/MPPImageClassifierResult.h" + +NS_ASSUME_NONNULL_BEGIN + +/** + * Options for setting up a `MPPImageClassifier`. + */ +NS_SWIFT_NAME(ImageClassifierOptions) +@interface MPPImageClassifierOptions : MPPTaskOptions + +@property(nonatomic) MPPRunningMode runningMode; + +/** + * The user-defined result callback for processing live stream data. The result callback should only be specified when the running mode is set to the live stream mode. + */ +@property(nonatomic, copy) void (^completion)(MPPImageClassifierResult *result, NSError *error); + +/** + * The locale to use for display names specified through the TFLite Model Metadata, if any. Defaults + * to English. + */ +@property(nonatomic, copy) NSString *displayNamesLocale; + +/** + * The maximum number of top-scored classification results to return. If < 0, all available results + * will be returned. If 0, an invalid argument error is returned. + */ +@property(nonatomic) NSInteger maxResults; + +/** + * Score threshold to override the one provided in the model metadata (if any). Results below this + * value are rejected. + */ +@property(nonatomic) float scoreThreshold; + +/** + * The allowlist of category names. If non-empty, detection results whose category name is not in + * this set will be filtered out. Duplicate or unknown category names are ignored. Mutually + * exclusive with categoryDenylist. + */ +@property(nonatomic, copy) NSArray *categoryAllowlist; + +/** + * The denylist of category names. If non-empty, detection results whose category name is in this + * set will be filtered out. Duplicate or unknown category names are ignored. Mutually exclusive + * with categoryAllowlist. + */ +@property(nonatomic, copy) NSArray *categoryDenylist; + +@end + +NS_ASSUME_NONNULL_END diff --git a/mediapipe/tasks/ios/vision/image_classifier/sources/MPPImageClassifierOptions.m b/mediapipe/tasks/ios/vision/image_classifier/sources/MPPImageClassifierOptions.m new file mode 100644 index 00000000..e109dcc3 --- /dev/null +++ b/mediapipe/tasks/ios/vision/image_classifier/sources/MPPImageClassifierOptions.m @@ -0,0 +1,41 @@ +// 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 "mediapipe/tasks/ios/vision/image_classifier/sources/MPPImageClassifierOptions.h" + +@implementation MPPImageClassifierOptions + +- (instancetype)init { + self = [super init]; + if (self) { + _maxResults = -1; + _scoreThreshold = 0; + } + return self; +} + +- (id)copyWithZone:(NSZone *)zone { + MPPImageClassifierOptions *imageClassifierOptions = [super copyWithZone:zone]; + + imageClassifierOptions.scoreThreshold = self.scoreThreshold; + imageClassifierOptions.maxResults = self.maxResults; + imageClassifierOptions.categoryDenylist = self.categoryDenylist; + imageClassifierOptions.categoryAllowlist = self.categoryAllowlist; + imageClassifierOptions.displayNamesLocale = self.displayNamesLocale; + imageClassifierOptions.completion = self.completion; + + return imageClassifierOptions; +} + +@end From a0253274cc0b2e4139249989c443f28017ce44fb Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Thu, 16 Feb 2023 01:31:09 +0530 Subject: [PATCH 04/11] 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 91b9078a..360eb1cf 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 00000000..b7b777c9 --- /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 00000000..ff5e4103 --- /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 From a503fb53e0163dbe5ed9923c506a74252af5743f Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Thu, 16 Feb 2023 01:31:29 +0530 Subject: [PATCH 05/11] Updated MPPVisionTaskRunner --- mediapipe/tasks/ios/vision/core/BUILD | 6 ++++-- .../ios/vision/core/sources/MPPVisionTaskRunner.h | 10 ++-------- .../ios/vision/core/sources/MPPVisionTaskRunner.mm | 8 +++++--- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/mediapipe/tasks/ios/vision/core/BUILD b/mediapipe/tasks/ios/vision/core/BUILD index 360eb1cf..1364d967 100644 --- a/mediapipe/tasks/ios/vision/core/BUILD +++ b/mediapipe/tasks/ios/vision/core/BUILD @@ -38,9 +38,11 @@ objc_library( ], deps = [ ":MPPRunningMode", - "//mediapipe/tasks/ios/common:MPPCommon", - "//mediapipe/tasks/ios/common/utils:MPPCommonUtils", "//mediapipe/tasks/ios/core:MPPTaskRunner", + "//mediapipe/tasks/ios/core:MPPVisionPacketCreator", + ], +) + objc_library( name = "MPPVisionPacketCreator", srcs = ["sources/MPPVisionPacketCreator.mm"], diff --git a/mediapipe/tasks/ios/vision/core/sources/MPPVisionTaskRunner.h b/mediapipe/tasks/ios/vision/core/sources/MPPVisionTaskRunner.h index 84b65730..b33cd3c8 100644 --- a/mediapipe/tasks/ios/vision/core/sources/MPPVisionTaskRunner.h +++ b/mediapipe/tasks/ios/vision/core/sources/MPPVisionTaskRunner.h @@ -13,7 +13,6 @@ // limitations under the License. #import - #import "mediapipe/tasks/ios/core/sources/MPPTaskRunner.h" #import "mediapipe/tasks/ios/vision/core/sources/MPPRunningMode.h" @@ -42,8 +41,8 @@ NS_ASSUME_NONNULL_BEGIN * intended to deliver inference results must be provided. In case of image or video running mode, * packets callback must be set to nil. * - * @param error Pointer to the memory location where errors if any should be saved. If @c NULL, no - * error will be saved. + * @param error Pointer to the memory location where errors if any should be + * saved. If @c NULL, no error will be saved. * * @return An instance of `MPPVisionTaskRunner` initialized to the given MediaPipe calculator config * proto, running mode and packets callback. @@ -54,11 +53,6 @@ NS_ASSUME_NONNULL_BEGIN (mediapipe::tasks::core::PacketsCallback)packetsCallback error:(NSError **)error NS_DESIGNATED_INITIALIZER; -- (instancetype)initWithCalculatorGraphConfig:(mediapipe::CalculatorGraphConfig)graphConfig - packetsCallback: - (mediapipe::tasks::core::PacketsCallback)packetsCallback - error:(NSError **)error NS_UNAVAILABLE; - - (instancetype)init NS_UNAVAILABLE; + (instancetype)new NS_UNAVAILABLE; diff --git a/mediapipe/tasks/ios/vision/core/sources/MPPVisionTaskRunner.mm b/mediapipe/tasks/ios/vision/core/sources/MPPVisionTaskRunner.mm index bfa9e34e..7c39bf80 100644 --- a/mediapipe/tasks/ios/vision/core/sources/MPPVisionTaskRunner.mm +++ b/mediapipe/tasks/ios/vision/core/sources/MPPVisionTaskRunner.mm @@ -19,7 +19,8 @@ namespace { using ::mediapipe::CalculatorGraphConfig; -using ::mediapipe::tasks::core::PacketsCallback; +using ::mediapipe::Packet; +using ::mediapipe::tasks::core::PacketMap; } // namespace @interface MPPVisionTaskRunner () { @@ -29,9 +30,10 @@ using ::mediapipe::tasks::core::PacketsCallback; @implementation MPPVisionTaskRunner -- (nullable instancetype)initWithCalculatorGraphConfig:(CalculatorGraphConfig)graphConfig +- (nullable instancetype)initWithCalculatorGraphConfig:(mediapipe::CalculatorGraphConfig)graphConfig runningMode:(MPPRunningMode)runningMode - packetsCallback:(PacketsCallback)packetsCallback + packetsCallback: + (mediapipe::tasks::core::PacketsCallback)packetsCallback error:(NSError **)error { switch (runningMode) { case MPPRunningModeImage: From 42e35503d9c1071fceccd509a2e508ecd0ce5935 Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Thu, 16 Feb 2023 01:31:51 +0530 Subject: [PATCH 06/11] Removed unwanted declarations in namespace --- mediapipe/tasks/ios/vision/core/sources/MPPVisionTaskRunner.mm | 2 -- 1 file changed, 2 deletions(-) diff --git a/mediapipe/tasks/ios/vision/core/sources/MPPVisionTaskRunner.mm b/mediapipe/tasks/ios/vision/core/sources/MPPVisionTaskRunner.mm index 7c39bf80..fddad964 100644 --- a/mediapipe/tasks/ios/vision/core/sources/MPPVisionTaskRunner.mm +++ b/mediapipe/tasks/ios/vision/core/sources/MPPVisionTaskRunner.mm @@ -19,8 +19,6 @@ namespace { using ::mediapipe::CalculatorGraphConfig; -using ::mediapipe::Packet; -using ::mediapipe::tasks::core::PacketMap; } // namespace @interface MPPVisionTaskRunner () { From ae05c784437d1408c501aa998a7968b55fbc205c Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Thu, 16 Feb 2023 01:33:33 +0530 Subject: [PATCH 07/11] Updated formatting --- .../core/sources/MPPVisionPacketCreator.h | 2 +- .../core/sources/MPPVisionPacketCreator.mm | 7 ++-- .../core/utils/sources/MPPImage+Utils.h | 9 ++-- .../core/utils/sources/MPPImage+Utils.mm | 41 +++++++++---------- .../sources/MPPImageClassifierOptions.h | 5 ++- 5 files changed, 31 insertions(+), 33 deletions(-) diff --git a/mediapipe/tasks/ios/vision/core/sources/MPPVisionPacketCreator.h b/mediapipe/tasks/ios/vision/core/sources/MPPVisionPacketCreator.h index b7b777c9..3618d8de 100644 --- a/mediapipe/tasks/ios/vision/core/sources/MPPVisionPacketCreator.h +++ b/mediapipe/tasks/ios/vision/core/sources/MPPVisionPacketCreator.h @@ -16,7 +16,7 @@ #include "mediapipe/framework/packet.h" -/** +/** * This class helps create various kinds of packets for Mediapipe Vision Tasks. */ @interface MPPVisionPacketCreator : NSObject diff --git a/mediapipe/tasks/ios/vision/core/sources/MPPVisionPacketCreator.mm b/mediapipe/tasks/ios/vision/core/sources/MPPVisionPacketCreator.mm index ff5e4103..d0ee3f5d 100644 --- a/mediapipe/tasks/ios/vision/core/sources/MPPVisionPacketCreator.mm +++ b/mediapipe/tasks/ios/vision/core/sources/MPPVisionPacketCreator.mm @@ -1,4 +1,4 @@ -// Copyright 2019 The MediaPipe Authors. +// 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. @@ -19,19 +19,18 @@ #include "mediapipe/framework/formats/image.h" namespace { +using ::mediapipe::Image; using ::mediapipe::MakePacket; using ::mediapipe::Packet; -using ::mediapipe::Image; } // namespace struct freeDeleter { - void operator()(void* ptr) { free(ptr); } + void operator()(void *ptr) { free(ptr); } } @implementation MPPVisionPacketCreator + (Packet)createWithMPPImage:(MPPImage *)image error:(NSError **)error { - std::unique_ptr imageFrame = [image imageFrameWithError:error]; if (!imageFrame) { diff --git a/mediapipe/tasks/ios/vision/core/utils/sources/MPPImage+Utils.h b/mediapipe/tasks/ios/vision/core/utils/sources/MPPImage+Utils.h index 724bccda..ac304d6a 100644 --- a/mediapipe/tasks/ios/vision/core/utils/sources/MPPImage+Utils.h +++ b/mediapipe/tasks/ios/vision/core/utils/sources/MPPImage+Utils.h @@ -14,19 +14,20 @@ #import -#import "mediapipe/tasks/ios/vision/core/sources/MPPImage.h" #include "mediapipe/framework/formats/image_frame.h" +#import "mediapipe/tasks/ios/vision/core/sources/MPPImage.h" NS_ASSUME_NONNULL_BEGIN -/** +/** * Helper utility for converting `MPPImage` into a `mediapipe::ImageFrame`. */ @interface MPPImage (Utils) /** * Converts the `MPPImage` into a `mediapipe::ImageFrame`. - * Irrespective of whether the underlying buffer is grayscale, RGB, RGBA, BGRA etc., the MPPImage is converted to an RGB format. In case of grayscale images, the mono channel is duplicated - * in the R, G, B channels. + * Irrespective of whether the underlying buffer is grayscale, RGB, RGBA, BGRA etc., the MPPImage is + * converted to an RGB format. In case of grayscale images, the mono channel is duplicated in the R, + * G, B channels. * * @param error Pointer to the memory location where errors if any should be * saved. If @c NULL, no error will be saved. diff --git a/mediapipe/tasks/ios/vision/core/utils/sources/MPPImage+Utils.mm b/mediapipe/tasks/ios/vision/core/utils/sources/MPPImage+Utils.mm index 8d6efe91..e9f2540f 100644 --- a/mediapipe/tasks/ios/vision/core/utils/sources/MPPImage+Utils.mm +++ b/mediapipe/tasks/ios/vision/core/utils/sources/MPPImage+Utils.mm @@ -25,7 +25,7 @@ #include "mediapipe/framework/formats/image_format.pb.h" namespace { - using ::mediapipe::ImageFrame; +using ::mediapipe::ImageFrame; } @interface MPPPixelDataUtils : NSObject @@ -41,7 +41,8 @@ namespace { @interface MPPCVPixelBufferUtils : NSObject -+ (std::unique_ptr)imageFrameFromCVPixelBuffer:(CVPixelBufferRef)pixelBuffer error:(NSError **)error; ++ (std::unique_ptr)imageFrameFromCVPixelBuffer:(CVPixelBufferRef)pixelBuffer + error:(NSError **)error; @end @@ -124,15 +125,14 @@ namespace { @implementation MPPCVPixelBufferUtils -+ (std::unique_ptr)rgbImageFrameFromCVPixelBuffer:(CVPixelBufferRef)pixelBuffer error:(NSError **)error { ++ (std::unique_ptr)rgbImageFrameFromCVPixelBuffer:(CVPixelBufferRef)pixelBuffer + error:(NSError **)error { CVPixelBufferLockBaseAddress(pixelBuffer, 0); size_t width = CVPixelBufferGetWidth(pixelBuffer); size_t height = CVPixelBufferGetHeight(pixelBuffer); size_t stride = CVPixelBufferGetBytesPerRow(pixelBuffer); - - uint8_t *rgbPixelData = [MPPPixelDataUtils rgbPixelDataFromPixelData:(uint8_t *)CVPixelBufferGetBaseAddress(pixelBuffer) withWidth:CVPixelBufferGetWidth(pixelBuffer) @@ -146,17 +146,17 @@ namespace { if (!rgbPixelData) { return nullptr; } - - std::unique_ptr imageFrame = absl::make_unique( - ::mediapipe::ImageFormat::SRGB, /*width=*/width, /*height=*/height, stride, - static_cast(rgbPixelData), - /*deleter=*/free); + + std::unique_ptr imageFrame = + absl::make_unique(::mediapipe::ImageFormat::SRGB, /*width=*/width, + /*height=*/height, stride, static_cast(rgbPixelData), + /*deleter=*/free); return imageFrame; } + (std::unique_ptr)imageFrameFromCVPixelBuffer:(CVPixelBufferRef)pixelBuffer - error:(NSError **)error { + error:(NSError **)error { uint8_t *pixelData = NULL; OSType pixelBufferFormat = CVPixelBufferGetPixelFormatType(pixelBuffer); @@ -210,11 +210,11 @@ namespace { // We have drawn the image as an RGBA image with 8 bitsPerComponent and hence can safely input // a pixel format of type kCVPixelFormatType_32RGBA for conversion by vImage. pixelDataToReturn = [MPPPixelDataUtils rgbPixelDataFromPixelData:srcData - withWidth:width - height:height - stride:bytesPerRow - pixelBufferFormat:kCVPixelFormatType_32RGBA - error:error]; + withWidth:width + height:height + stride:bytesPerRow + pixelBufferFormat:kCVPixelFormatType_32RGBA + error:error]; } CGContextRelease(context); @@ -224,7 +224,7 @@ namespace { std::unique_ptr imageFrame = absl::make_unique( mediapipe::ImageFormat::SRGB, /*width=*/(int)width, /*height=*/(int)height, (int)bytesPerRow, - static_cast(pixelDataToReturn), + static_cast(pixelDataToReturn), /*deleter=*/free); return imageFrame; @@ -235,10 +235,8 @@ namespace { @implementation UIImage (ImageFrameUtils) - (std::unique_ptr)imageFrameFromCIImageWithError:(NSError **)error { - if (self.CIImage.pixelBuffer) { - return [MPPCVPixelBufferUtils imageFrameFromCVPixelBuffer:self.CIImage.pixelBuffer - error:error]; + return [MPPCVPixelBufferUtils imageFrameFromCVPixelBuffer:self.CIImage.pixelBuffer error:error]; } else if (self.CIImage.CGImage) { return [MPPCGImageUtils imageFrameFromCGImage:self.CIImage.CGImage error:error]; @@ -278,8 +276,7 @@ namespace { switch (self.imageSourceType) { case MPPImageSourceTypeSampleBuffer: { CVPixelBufferRef sampleImagePixelBuffer = CMSampleBufferGetImageBuffer(self.sampleBuffer); - return [MPPCVPixelBufferUtils imageFrameFromCVPixelBuffer:sampleImagePixelBuffer - error:error]; + return [MPPCVPixelBufferUtils imageFrameFromCVPixelBuffer:sampleImagePixelBuffer error:error]; } case MPPImageSourceTypePixelBuffer: { return [MPPCVPixelBufferUtils imageFrameFromCVPixelBuffer:self.pixelBuffer error:error]; diff --git a/mediapipe/tasks/ios/vision/image_classifier/sources/MPPImageClassifierOptions.h b/mediapipe/tasks/ios/vision/image_classifier/sources/MPPImageClassifierOptions.h index 2ca15811..f7e9a629 100644 --- a/mediapipe/tasks/ios/vision/image_classifier/sources/MPPImageClassifierOptions.h +++ b/mediapipe/tasks/ios/vision/image_classifier/sources/MPPImageClassifierOptions.h @@ -28,8 +28,9 @@ NS_SWIFT_NAME(ImageClassifierOptions) @property(nonatomic) MPPRunningMode runningMode; -/** - * The user-defined result callback for processing live stream data. The result callback should only be specified when the running mode is set to the live stream mode. +/** + * The user-defined result callback for processing live stream data. The result callback should only + * be specified when the running mode is set to the live stream mode. */ @property(nonatomic, copy) void (^completion)(MPPImageClassifierResult *result, NSError *error); From dce81342b6d622e51259c2d7364fca5f006ba29f Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Thu, 16 Feb 2023 01:35:27 +0530 Subject: [PATCH 08/11] Updated imports of MPPImageUtils --- mediapipe/tasks/ios/vision/core/BUILD | 2 +- .../tasks/ios/vision/core/sources/MPPVisionPacketCreator.mm | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mediapipe/tasks/ios/vision/core/BUILD b/mediapipe/tasks/ios/vision/core/BUILD index 1364d967..47e6ce22 100644 --- a/mediapipe/tasks/ios/vision/core/BUILD +++ b/mediapipe/tasks/ios/vision/core/BUILD @@ -54,6 +54,6 @@ objc_library( deps = [ "//mediapipe/framework:packet", "//mediapipe/framework/formats:image", - "//mediapipe/tasks/ios/vision/core/utils:MPPImageFrameUtils", + "//mediapipe/tasks/ios/vision/core/utils:MPPImageUtils", ], ) diff --git a/mediapipe/tasks/ios/vision/core/sources/MPPVisionPacketCreator.mm b/mediapipe/tasks/ios/vision/core/sources/MPPVisionPacketCreator.mm index d0ee3f5d..b0d3b142 100644 --- a/mediapipe/tasks/ios/vision/core/sources/MPPVisionPacketCreator.mm +++ b/mediapipe/tasks/ios/vision/core/sources/MPPVisionPacketCreator.mm @@ -14,7 +14,7 @@ #import "mediapipe/tasks/ios/vision/core/sources/MPPVisionPacketCreator.h" -#import "mediapipe/tasks/ios/vision/core/utils/sources/MPPImage+ImageFrameUtils.h" +#import "mediapipe/tasks/ios/vision/core/utils/sources/MPPImage+Utils.h" #include "mediapipe/framework/formats/image.h" From 5e5a1a733fc3619c7e0b1d4bc8d74f3060ee1f98 Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Thu, 16 Feb 2023 01:37:50 +0530 Subject: [PATCH 09/11] Updated imports --- mediapipe/tasks/ios/vision/core/utils/sources/MPPImage+Utils.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mediapipe/tasks/ios/vision/core/utils/sources/MPPImage+Utils.mm b/mediapipe/tasks/ios/vision/core/utils/sources/MPPImage+Utils.mm index e9f2540f..13cfd3be 100644 --- a/mediapipe/tasks/ios/vision/core/utils/sources/MPPImage+Utils.mm +++ b/mediapipe/tasks/ios/vision/core/utils/sources/MPPImage+Utils.mm @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#import "mediapipe/tasks/ios/vision/core/utils/sources/MPPImage+ImageFrameUtils.h" +#import "mediapipe/tasks/ios/vision/core/utils/sources/MPPImage+Utils.h" #import "mediapipe/tasks/ios/common/sources/MPPCommon.h" #import "mediapipe/tasks/ios/common/utils/sources/MPPCommonUtils.h" From 4d2dd50703c8165c0377f147f4465f613d411619 Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Mon, 20 Feb 2023 11:23:04 +0530 Subject: [PATCH 10/11] Updated method name in MPPVisionPacketCreator --- .../tasks/ios/vision/core/sources/MPPVisionPacketCreator.h | 2 +- .../tasks/ios/vision/core/sources/MPPVisionPacketCreator.mm | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mediapipe/tasks/ios/vision/core/sources/MPPVisionPacketCreator.h b/mediapipe/tasks/ios/vision/core/sources/MPPVisionPacketCreator.h index 3618d8de..e8a7e91a 100644 --- a/mediapipe/tasks/ios/vision/core/sources/MPPVisionPacketCreator.h +++ b/mediapipe/tasks/ios/vision/core/sources/MPPVisionPacketCreator.h @@ -21,6 +21,6 @@ */ @interface MPPVisionPacketCreator : NSObject -+ (Packet)createWithMPPImage:(MPPImage *)image error:(NSError **)error; ++ (Packet)createPacketWithMPPImage:(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 index b0d3b142..51dbc325 100644 --- a/mediapipe/tasks/ios/vision/core/sources/MPPVisionPacketCreator.mm +++ b/mediapipe/tasks/ios/vision/core/sources/MPPVisionPacketCreator.mm @@ -30,7 +30,7 @@ struct freeDeleter { @implementation MPPVisionPacketCreator -+ (Packet)createWithMPPImage:(MPPImage *)image error:(NSError **)error { ++ (Packet)createPacketWithMPPImage:(MPPImage *)image error:(NSError **)error { std::unique_ptr imageFrame = [image imageFrameWithError:error]; if (!imageFrame) { From 68fdf6b6cbb99a32d04044def4ff15c141c41cdc Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Mon, 20 Feb 2023 11:27:21 +0530 Subject: [PATCH 11/11] Updated comment arguments in MPPImageUtils --- .../tasks/ios/vision/core/utils/sources/MPPImage+Utils.mm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mediapipe/tasks/ios/vision/core/utils/sources/MPPImage+Utils.mm b/mediapipe/tasks/ios/vision/core/utils/sources/MPPImage+Utils.mm index 13cfd3be..c8b2b8a6 100644 --- a/mediapipe/tasks/ios/vision/core/utils/sources/MPPImage+Utils.mm +++ b/mediapipe/tasks/ios/vision/core/utils/sources/MPPImage+Utils.mm @@ -148,8 +148,8 @@ using ::mediapipe::ImageFrame; } std::unique_ptr imageFrame = - absl::make_unique(::mediapipe::ImageFormat::SRGB, /*width=*/width, - /*height=*/height, stride, static_cast(rgbPixelData), + absl::make_unique(::mediapipe::ImageFormat::SRGB, width, + height, stride, static_cast(rgbPixelData), /*deleter=*/free); return imageFrame; @@ -223,7 +223,7 @@ using ::mediapipe::ImageFrame; CGColorSpaceRelease(colorSpace); std::unique_ptr imageFrame = absl::make_unique( - mediapipe::ImageFormat::SRGB, /*width=*/(int)width, /*height=*/(int)height, (int)bytesPerRow, + mediapipe::ImageFormat::SRGB, (int)width, (int)height, (int)bytesPerRow, static_cast(pixelDataToReturn), /*deleter=*/free);