Added methods to iOS MPPImage test utils

This commit is contained in:
Prianka Liz Kariat 2023-09-06 18:40:59 +05:30
parent b547c4ae0d
commit 17c316a890
2 changed files with 54 additions and 0 deletions

View File

@ -14,6 +14,7 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import "mediapipe/tasks/ios/test/utils/sources/MPPFileInfo.h"
#import "mediapipe/tasks/ios/vision/core/sources/MPPImage.h" #import "mediapipe/tasks/ios/vision/core/sources/MPPImage.h"
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@ -23,6 +24,34 @@ NS_ASSUME_NONNULL_BEGIN
*/ */
@interface MPPImage (TestUtils) @interface MPPImage (TestUtils)
/**
* Loads an image from a file in an app bundle into a `MPPImage` object.
*
* @param fileInfo The file info specifying the name and extension of the image
* file in the bundle.
*
* @return The `MPPImage` object contains the loaded image. This method returns
* nil if it cannot load the image.
*/
+ (MPPImage *)imageWithFileInfo:(MPPFileInfo *)fileInfo;
NS_SWIFT_NAME(image(withFileInfo:));
/**
* Loads an image from a file in an app bundle into a `MPPImage` object with the specified
* orientation.
*
* @param fileInfo The file info specifying the name and extension of the image
* file in the bundle.
*
* @return The `MPPImage` object contains the loaded image. This method returns
* nil if it cannot load the image.
*/
+ (MPPImage *)imageWithFileInfo:(MPPFileInfo *)fileInfo
orientation:(UIImageOrientation)orientation
NS_SWIFT_NAME(image(withFileInfo:orientation:));
// TODO: Remove after all tests are migrated
/** /**
* Loads an image from a file in an app bundle into a `MPPImage` object. * Loads an image from a file in an app bundle into a `MPPImage` object.
* *
@ -39,6 +68,7 @@ NS_ASSUME_NONNULL_BEGIN
ofType:(NSString *)type ofType:(NSString *)type
NS_SWIFT_NAME(imageFromBundle(class:filename:type:)); NS_SWIFT_NAME(imageFromBundle(class:filename:type:));
// TODO: Remove after all tests are migrated
/** /**
* Loads an image from a file in an app bundle into a `MPPImage` object with the specified * Loads an image from a file in an app bundle into a `MPPImage` object with the specified
* orientation. * orientation.

View File

@ -14,6 +14,7 @@
#import "mediapipe/tasks/ios/test/vision/utils/sources/MPPImage+TestUtils.h" #import "mediapipe/tasks/ios/test/vision/utils/sources/MPPImage+TestUtils.h"
// TODO: Remove this category after all tests are migrated to the new methods.
@interface UIImage (FileUtils) @interface UIImage (FileUtils)
+ (nullable UIImage *)imageFromBundleWithClass:(Class)classObject + (nullable UIImage *)imageFromBundleWithClass:(Class)classObject
@ -37,6 +38,28 @@
@implementation MPPImage (TestUtils) @implementation MPPImage (TestUtils)
+ (MPPImage *)imageWithFileInfo:(MPPFileInfo *)fileInfo {
if (!fileInfo.path) return nil;
UIImage *image = [[UIImage alloc] initWithContentsOfFile:fileInfo.path];
if (!image) return nil;
return [[MPPImage alloc] initWithUIImage:image error:nil];
}
+ (MPPImage *)imageWithFileInfo:(MPPFileInfo *)fileInfo
orientation:(UIImageOrientation)orientation {
if (!fileInfo.path) return nil;
UIImage *image = [[UIImage alloc] initWithContentsOfFile:fileInfo.path];
if (!image) return nil;
return [[MPPImage alloc] initWithUIImage:image orientation:orientation error:nil];
}
// TODO: Remove after all tests are migrated
+ (nullable MPPImage *)imageFromBundleWithClass:(Class)classObject + (nullable MPPImage *)imageFromBundleWithClass:(Class)classObject
fileName:(NSString *)name fileName:(NSString *)name
ofType:(NSString *)type { ofType:(NSString *)type {
@ -45,6 +68,7 @@
return [[MPPImage alloc] initWithUIImage:image error:nil]; return [[MPPImage alloc] initWithUIImage:image error:nil];
} }
// TODO: Remove after all tests are migrated
+ (nullable MPPImage *)imageFromBundleWithClass:(Class)classObject + (nullable MPPImage *)imageFromBundleWithClass:(Class)classObject
fileName:(NSString *)name fileName:(NSString *)name
ofType:(NSString *)type ofType:(NSString *)type