From 43e51c1094158f548650171c84f4b1f0bcabba20 Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Wed, 14 Jun 2023 15:34:32 +0530 Subject: [PATCH 1/4] Added live stream mode tests for iOS Hand Landmarker --- .../hand_landmarker/MPPHandLandmarkerTests.m | 290 +++++++++++++++++- 1 file changed, 287 insertions(+), 3 deletions(-) diff --git a/mediapipe/tasks/ios/test/vision/hand_landmarker/MPPHandLandmarkerTests.m b/mediapipe/tasks/ios/test/vision/hand_landmarker/MPPHandLandmarkerTests.m index f9bdeb150..779bfde1f 100644 --- a/mediapipe/tasks/ios/test/vision/hand_landmarker/MPPHandLandmarkerTests.m +++ b/mediapipe/tasks/ios/test/vision/hand_landmarker/MPPHandLandmarkerTests.m @@ -58,7 +58,10 @@ static const float kLandmarksErrorTolerance = 0.03f; XCTAssertTrue(handLandmarkerResult.landmarks.count == 0); \ XCTAssertTrue(handLandmarkerResult.worldLandmarks.count == 0); -@interface MPPHandLandmarkerTests : XCTestCase +@interface MPPHandLandmarkerTests : XCTestCase { + NSDictionary *_liveStreamSucceedsTestDict; + NSDictionary *_outOfOrderTimestampTestDict; +} @end @implementation MPPHandLandmarkerTests @@ -153,7 +156,7 @@ static const float kLandmarksErrorTolerance = 0.03f; return filePath; } -#pragma mark Gesture Recognizer Initializers +#pragma mark Hand Landmarker Initializers - (MPPHandLandmarkerOptions *)handLandmarkerOptionsWithModelFileInfo: (ResourceFileInfo *)modelFileInfo { @@ -185,7 +188,7 @@ static const float kLandmarksErrorTolerance = 0.03f; AssertEqualErrors(error, expectedError); } -#pragma mark Assert Gesture Recognizer Results +#pragma mark Assert Hand Landmarker Results - (MPPImage *)imageWithFileInfo:(ResourceFileInfo *)fileInfo { MPPImage *image = [MPPImage imageFromBundleWithClass:[MPPHandLandmarkerTests class] @@ -289,4 +292,285 @@ static const float kLandmarksErrorTolerance = 0.03f; } +#pragma mark Running Mode Tests + +- (void)testCreateHandLandmarkerFailsWithDelegateInNonLiveStreamMode { + MPPRunningMode runningModesToTest[] = {MPPRunningModeImage, MPPRunningModeVideo}; + for (int i = 0; i < sizeof(runningModesToTest) / sizeof(runningModesToTest[0]); i++) { + MPPHandLandmarkerOptions *options = + [self handLandmarkerOptionsWithModelFileInfo:kHandLandmarkerBundleAssetFile]; + + options.runningMode = runningModesToTest[i]; + options.handLandmarkerLiveStreamDelegate = self; + + [self assertCreateHandLandmarkerWithOptions:options + failsWithExpectedError: + [NSError + errorWithDomain:kExpectedErrorDomain + code:MPPTasksErrorCodeInvalidArgumentError + userInfo:@{ + NSLocalizedDescriptionKey : + @"The vision task is in image or video mode. The " + @"delegate must not be set in the task's options." + }]]; + } +} + +- (void)testCreateHandLandmarkerFailsWithMissingDelegateInLiveStreamMode { + MPPHandLandmarkerOptions *options = + [self handLandmarkerOptionsWithModelFileInfo:kHandLandmarkerBundleAssetFile]; + + options.runningMode = MPPRunningModeLiveStream; + + [self + assertCreateHandLandmarkerWithOptions:options + failsWithExpectedError: + [NSError errorWithDomain:kExpectedErrorDomain + code:MPPTasksErrorCodeInvalidArgumentError + userInfo:@{ + NSLocalizedDescriptionKey : + @"The vision task is in live stream mode. An " + @"object must be set as the delegate of the task " + @"in its options to ensure asynchronous delivery " + @"of results." + }]]; +} + +- (void)testDetectFailsWithCallingWrongApiInImageMode { + MPPHandLandmarkerOptions *options = + [self handLandmarkerOptionsWithModelFileInfo:kHandLandmarkerBundleAssetFile]; + + MPPHandLandmarker *handLandmarker = + [self createHandLandmarkerWithOptionsSucceeds:options]; + + MPPImage *image = [self imageWithFileInfo:kFistImage]; + + NSError *liveStreamApiCallError; + XCTAssertFalse([handLandmarker detectAsyncInImage:image + timestampInMilliseconds:0 + error:&liveStreamApiCallError]); + + NSError *expectedLiveStreamApiCallError = + [NSError errorWithDomain:kExpectedErrorDomain + code:MPPTasksErrorCodeInvalidArgumentError + userInfo:@{ + NSLocalizedDescriptionKey : @"The vision task is not initialized with live " + @"stream mode. Current Running Mode: Image" + }]; + + AssertEqualErrors(liveStreamApiCallError, expectedLiveStreamApiCallError); + + NSError *videoApiCallError; + XCTAssertFalse([handLandmarker detectInVideoFrame:image + timestampInMilliseconds:0 + error:&videoApiCallError]); + + NSError *expectedVideoApiCallError = + [NSError errorWithDomain:kExpectedErrorDomain + code:MPPTasksErrorCodeInvalidArgumentError + userInfo:@{ + NSLocalizedDescriptionKey : @"The vision task is not initialized with " + @"video mode. Current Running Mode: Image" + }]; + AssertEqualErrors(videoApiCallError, expectedVideoApiCallError); +} + +- (void)testDetectFailsWithCallingWrongApiInVideoMode { + MPPHandLandmarkerOptions *options = + [self handLandmarkerOptionsWithModelFileInfo:kHandLandmarkerBundleAssetFile]; + options.runningMode = MPPRunningModeVideo; + + MPPHandLandmarker *handLandmarker = + [self createHandLandmarkerWithOptionsSucceeds:options]; + + MPPImage *image = [self imageWithFileInfo:kFistImage]; + + NSError *liveStreamApiCallError; + XCTAssertFalse([handLandmarker detectAsyncInImage:image + timestampInMilliseconds:0 + error:&liveStreamApiCallError]); + + NSError *expectedLiveStreamApiCallError = + [NSError errorWithDomain:kExpectedErrorDomain + code:MPPTasksErrorCodeInvalidArgumentError + userInfo:@{ + NSLocalizedDescriptionKey : @"The vision task is not initialized with live " + @"stream mode. Current Running Mode: Video" + }]; + + AssertEqualErrors(liveStreamApiCallError, expectedLiveStreamApiCallError); + + NSError *imageApiCallError; + XCTAssertFalse([handLandmarker detectInImage:image error:&imageApiCallError]); + + NSError *expectedImageApiCallError = + [NSError errorWithDomain:kExpectedErrorDomain + code:MPPTasksErrorCodeInvalidArgumentError + userInfo:@{ + NSLocalizedDescriptionKey : @"The vision task is not initialized with " + @"image mode. Current Running Mode: Video" + }]; + AssertEqualErrors(imageApiCallError, expectedImageApiCallError); +} + +- (void)testDetectFailsWithCallingWrongApiInLiveStreamMode { + MPPHandLandmarkerOptions *options = + [self handLandmarkerOptionsWithModelFileInfo:kHandLandmarkerBundleAssetFile]; + options.runningMode = MPPRunningModeLiveStream; + options.handLandmarkerLiveStreamDelegate = self; + + MPPHandLandmarker *handLandmarker = + [self createHandLandmarkerWithOptionsSucceeds:options]; + + MPPImage *image = [self imageWithFileInfo:kFistImage]; + + NSError *imageApiCallError; + XCTAssertFalse([handLandmarker detectInImage:image error:&imageApiCallError]); + + NSError *expectedImageApiCallError = + [NSError errorWithDomain:kExpectedErrorDomain + code:MPPTasksErrorCodeInvalidArgumentError + userInfo:@{ + NSLocalizedDescriptionKey : @"The vision task is not initialized with " + @"image mode. Current Running Mode: Live Stream" + }]; + AssertEqualErrors(imageApiCallError, expectedImageApiCallError); + + NSError *videoApiCallError; + XCTAssertFalse([handLandmarker detectInVideoFrame:image + timestampInMilliseconds:0 + error:&videoApiCallError]); + + NSError *expectedVideoApiCallError = + [NSError errorWithDomain:kExpectedErrorDomain + code:MPPTasksErrorCodeInvalidArgumentError + userInfo:@{ + NSLocalizedDescriptionKey : @"The vision task is not initialized with " + @"video mode. Current Running Mode: Live Stream" + }]; + AssertEqualErrors(videoApiCallError, expectedVideoApiCallError); +} + +- (void)testDetectWithVideoModeSucceeds { + MPPHandLandmarkerOptions *options = + [self handLandmarkerOptionsWithModelFileInfo:kHandLandmarkerBundleAssetFile]; + options.runningMode = MPPRunningModeVideo; + + MPPHandLandmarker *handLandmarker = + [self createHandLandmarkerWithOptionsSucceeds:options]; + + MPPImage *image = [self imageWithFileInfo:kThumbUpImage]; + + for (int i = 0; i < 3; i++) { + MPPHandLandmarkerResult *handLandmarkerResult = + [handLandmarker detectInVideoFrame:image timestampInMilliseconds:i error:nil]; + [self assertHandLandmarkerResult:handLandmarkerResult + isApproximatelyEqualToExpectedResult:[MPPHandLandmarkerTests + thumbUpHandLandmarkerResult]]; + } +} + +- (void)testDetectWithOutOfOrderTimestampsAndLiveStreamModeFails { + MPPHandLandmarkerOptions *options = + [self handLandmarkerOptionsWithModelFileInfo:kHandLandmarkerBundleAssetFile]; + options.runningMode = MPPRunningModeLiveStream; + options.handLandmarkerLiveStreamDelegate = self; + + XCTestExpectation *expectation = [[XCTestExpectation alloc] + initWithDescription:@"detectWiththOutOfOrderTimestampsAndLiveStream"]; + + expectation.expectedFulfillmentCount = 1; + + MPPHandLandmarker *handLandmarker = + [self createHandLandmarkerWithOptionsSucceeds:options]; + + _outOfOrderTimestampTestDict = @{ + kLiveStreamTestsDictHandLandmarkerKey : handLandmarker, + kLiveStreamTestsDictExpectationKey : expectation + }; + + MPPImage *image = [self imageWithFileInfo:kThumbUpImage]; + + XCTAssertTrue([handLandmarker detectAsyncInImage:image timestampInMilliseconds:1 error:nil]); + + NSError *error; + XCTAssertFalse([handLandmarker detectAsyncInImage:image + timestampInMilliseconds:0 + error:&error]); + + NSError *expectedError = + [NSError errorWithDomain:kExpectedErrorDomain + code:MPPTasksErrorCodeInvalidArgumentError + userInfo:@{ + NSLocalizedDescriptionKey : + @"INVALID_ARGUMENT: Input timestamp must be monotonically increasing." + }]; + AssertEqualErrors(error, expectedError); + + NSTimeInterval timeout = 0.5f; + [self waitForExpectations:@[ expectation ] timeout:timeout]; +} + +- (void)testDetectWithLiveStreamModeSucceeds { + MPPHandLandmarkerOptions *options = + [self handLandmarkerOptionsWithModelFileInfo:kHandLandmarkerBundleAssetFile]; + options.runningMode = MPPRunningModeLiveStream; + options.handLandmarkerLiveStreamDelegate = self; + + NSInteger iterationCount = 100; + + // Because of flow limiting, we cannot ensure that the callback will be invoked `iterationCount` + // times. An normal expectation will fail if expectation.fulfill() is not called + // `expectation.expectedFulfillmentCount` times. If `expectation.isInverted = true`, the test will + // only succeed if expectation is not fulfilled for the specified `expectedFulfillmentCount`. + // Since in our case we cannot predict how many times the expectation is supposed to be fullfilled + // setting, `expectation.expectedFulfillmentCount` = `iterationCount` + 1 and + // `expectation.isInverted = true` ensures that test succeeds ifexpectation is fullfilled <= + // `iterationCount` times. + XCTestExpectation *expectation = + [[XCTestExpectation alloc] initWithDescription:@"detectWithLiveStream"]; + + expectation.expectedFulfillmentCount = iterationCount + 1; + expectation.inverted = YES; + + MPPHandLandmarker *handLandmarker = + [self createHandLandmarkerWithOptionsSucceeds:options]; + + _liveStreamSucceedsTestDict = @{ + kLiveStreamTestsDictHandLandmarkerKey : handLandmarker, + kLiveStreamTestsDictExpectationKey : expectation + }; + + // TODO: Mimic initialization from CMSampleBuffer as live stream mode is most likely to be used + // with the iOS camera. AVCaptureVideoDataOutput sample buffer delegates provide frames of type + // `CMSampleBuffer`. + MPPImage *image = [self imageWithFileInfo:kThumbUpImage]; + + for (int i = 0; i < iterationCount; i++) { + XCTAssertTrue([handLandmarker detectAsyncInImage:image + timestampInMilliseconds:i + error:nil]); + } + + NSTimeInterval timeout = 0.5f; + [self waitForExpectations:@[ expectation ] timeout:timeout]; +} + +- (void)handLandmarker:(MPPHandLandmarker *)handLandmarker + didFinishRecognitionWithResult:(MPPHandLandmarkerResult *)handLandmarkerResult + timestampInMilliseconds:(NSInteger)timestampInMilliseconds + error:(NSError *)error { + [self assertHandLandmarkerResult:handLandmarkerResult + isApproximatelyEqualToExpectedResult:[MPPHandLandmarkerTests + thumbUpHandLandmarkerResult]]; + + if (handLandmarker == _outOfOrderTimestampTestDict[kLiveStreamTestsDictHandLandmarkerKey]) { + [_outOfOrderTimestampTestDict[kLiveStreamTestsDictExpectationKey] fulfill]; + } else if (handLandmarker == + _liveStreamSucceedsTestDict[kLiveStreamTestsDictHandLandmarkerKey]) { + [_liveStreamSucceedsTestDict[kLiveStreamTestsDictExpectationKey] fulfill]; + } + +} + @end From dffca9e3b54ebba127b870f1ee472925c107c3ee Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Wed, 14 Jun 2023 15:51:06 +0530 Subject: [PATCH 2/4] Updated protobuf helper method name in iOS Gesture Recognizer Helpers --- .../gesture_recognizer/MPPGestureRecognizerTests.m | 13 ++++++------- .../MPPGestureRecognizerResult+ProtobufHelpers.h | 8 ++++---- .../MPPGestureRecognizerResult+ProtobufHelpers.mm | 8 ++++---- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/mediapipe/tasks/ios/test/vision/gesture_recognizer/MPPGestureRecognizerTests.m b/mediapipe/tasks/ios/test/vision/gesture_recognizer/MPPGestureRecognizerTests.m index dcd5683f7..6bbcf9b10 100644 --- a/mediapipe/tasks/ios/test/vision/gesture_recognizer/MPPGestureRecognizerTests.m +++ b/mediapipe/tasks/ios/test/vision/gesture_recognizer/MPPGestureRecognizerTests.m @@ -98,18 +98,17 @@ static NSString *const kLiveStreamTestsDictExpectationKey = @"expectation"; [MPPGestureRecognizerTests filePathWithFileInfo:kExpectedThumbUpLandmarksFile]; return [MPPGestureRecognizerResult - gestureRecognizerResultsFromTextEncodedProtobufFileWithName:filePath - gestureLabel:kExpectedThumbUpLabel - shouldRemoveZPosition:YES]; + gestureRecognizerResultsFromProtobufFileWithName:filePath + gestureLabel:kExpectedThumbUpLabel + shouldRemoveZPosition:YES]; } + (MPPGestureRecognizerResult *)fistGestureRecognizerResultWithLabel:(NSString *)gestureLabel { NSString *filePath = [MPPGestureRecognizerTests filePathWithFileInfo:kExpectedFistLandmarksFile]; - return [MPPGestureRecognizerResult - gestureRecognizerResultsFromTextEncodedProtobufFileWithName:filePath - gestureLabel:gestureLabel - shouldRemoveZPosition:YES]; + return [MPPGestureRecognizerResult gestureRecognizerResultsFromProtobufFileWithName:filePath + gestureLabel:gestureLabel + shouldRemoveZPosition:YES]; } #pragma mark Assert Gesture Recognizer Results diff --git a/mediapipe/tasks/ios/test/vision/gesture_recognizer/utils/sources/MPPGestureRecognizerResult+ProtobufHelpers.h b/mediapipe/tasks/ios/test/vision/gesture_recognizer/utils/sources/MPPGestureRecognizerResult+ProtobufHelpers.h index cfa0a5e53..069b90b99 100644 --- a/mediapipe/tasks/ios/test/vision/gesture_recognizer/utils/sources/MPPGestureRecognizerResult+ProtobufHelpers.h +++ b/mediapipe/tasks/ios/test/vision/gesture_recognizer/utils/sources/MPPGestureRecognizerResult+ProtobufHelpers.h @@ -1,4 +1,4 @@ -// Copyright 2022 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,9 +19,9 @@ NS_ASSUME_NONNULL_BEGIN @interface MPPGestureRecognizerResult (ProtobufHelpers) + (MPPGestureRecognizerResult *) - gestureRecognizerResultsFromTextEncodedProtobufFileWithName:(NSString *)fileName - gestureLabel:(NSString *)gestureLabel - shouldRemoveZPosition:(BOOL)removeZPosition; + gestureRecognizerResultsFromProtobufFileWithName:(NSString *)fileName + gestureLabel:(NSString *)gestureLabel + shouldRemoveZPosition:(BOOL)removeZPosition; @end diff --git a/mediapipe/tasks/ios/test/vision/gesture_recognizer/utils/sources/MPPGestureRecognizerResult+ProtobufHelpers.mm b/mediapipe/tasks/ios/test/vision/gesture_recognizer/utils/sources/MPPGestureRecognizerResult+ProtobufHelpers.mm index f628499d5..28e5628ff 100644 --- a/mediapipe/tasks/ios/test/vision/gesture_recognizer/utils/sources/MPPGestureRecognizerResult+ProtobufHelpers.mm +++ b/mediapipe/tasks/ios/test/vision/gesture_recognizer/utils/sources/MPPGestureRecognizerResult+ProtobufHelpers.mm @@ -31,10 +31,10 @@ using ::mediapipe::tasks::ios::test::vision::utils::get_proto_from_pbtxt; @implementation MPPGestureRecognizerResult (ProtobufHelpers) -+ (MPPGestureRecognizerResult *) - gestureRecognizerResultsFromTextEncodedProtobufFileWithName:(NSString *)fileName - gestureLabel:(NSString *)gestureLabel - shouldRemoveZPosition:(BOOL)removeZPosition { ++ (MPPGestureRecognizerResult *)gestureRecognizerResultsProtobufFileWithName:(NSString *)fileName + gestureLabel: + (NSString *)gestureLabel + shouldRemoveZPosition:(BOOL)removeZPosition { LandmarksDetectionResultProto landmarkDetectionResultProto; if (!get_proto_from_pbtxt(fileName.cppString, landmarkDetectionResultProto).ok()) { From 0ae27fad373edff0e5602fc0204e50aba65d436a Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Wed, 14 Jun 2023 15:51:41 +0530 Subject: [PATCH 3/4] Updated iOS hand landmarker tests --- .../vision/hand_landmarker/MPPHandLandmarkerTests.m | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/mediapipe/tasks/ios/test/vision/hand_landmarker/MPPHandLandmarkerTests.m b/mediapipe/tasks/ios/test/vision/hand_landmarker/MPPHandLandmarkerTests.m index 9f605411b..eec13d450 100644 --- a/mediapipe/tasks/ios/test/vision/hand_landmarker/MPPHandLandmarkerTests.m +++ b/mediapipe/tasks/ios/test/vision/hand_landmarker/MPPHandLandmarkerTests.m @@ -40,6 +40,9 @@ static ResourceFileInfo *const kExpectedPointingUpRotatedLandmarksFile = static NSString *const kExpectedErrorDomain = @"com.google.mediapipe.tasks"; static const float kLandmarksErrorTolerance = 0.03f; +static NSString *const kLiveStreamTestsDictHandLandmarkerKey = @"gesture_recognizer"; +static NSString *const kLiveStreamTestsDictExpectationKey = @"expectation"; + #define AssertEqualErrors(error, expectedError) \ XCTAssertNotNil(error); \ XCTAssertEqualObjects(error.domain, expectedError.domain); \ @@ -57,7 +60,7 @@ static const float kLandmarksErrorTolerance = 0.03f; XCTAssertTrue(handLandmarkerResult.landmarks.count == 0); \ XCTAssertTrue(handLandmarkerResult.worldLandmarks.count == 0); -@interface MPPHandLandmarkerTests : XCTestCase { +@interface MPPHandLandmarkerTests : XCTestCase { NSDictionary *_liveStreamSucceedsTestDict; NSDictionary *_outOfOrderTimestampTestDict; } @@ -335,7 +338,7 @@ static const float kLandmarksErrorTolerance = 0.03f; MPPHandLandmarker *handLandmarker = [self createHandLandmarkerWithOptionsSucceeds:options]; - MPPImage *image = [self imageWithFileInfo:kFistImage]; + MPPImage *image = [self imageWithFileInfo:kThumbUpImage]; NSError *liveStreamApiCallError; XCTAssertFalse([handLandmarker detectAsyncInImage:image @@ -375,7 +378,7 @@ static const float kLandmarksErrorTolerance = 0.03f; MPPHandLandmarker *handLandmarker = [self createHandLandmarkerWithOptionsSucceeds:options]; - MPPImage *image = [self imageWithFileInfo:kFistImage]; + MPPImage *image = [self imageWithFileInfo:kThumbUpImage]; NSError *liveStreamApiCallError; XCTAssertFalse([handLandmarker detectAsyncInImage:image @@ -414,7 +417,7 @@ static const float kLandmarksErrorTolerance = 0.03f; MPPHandLandmarker *handLandmarker = [self createHandLandmarkerWithOptionsSucceeds:options]; - MPPImage *image = [self imageWithFileInfo:kFistImage]; + MPPImage *image = [self imageWithFileInfo:kThumbUpImage]; NSError *imageApiCallError; XCTAssertFalse([handLandmarker detectInImage:image error:&imageApiCallError]); @@ -549,7 +552,7 @@ static const float kLandmarksErrorTolerance = 0.03f; } - (void)handLandmarker:(MPPHandLandmarker *)handLandmarker - didFinishRecognitionWithResult:(MPPHandLandmarkerResult *)handLandmarkerResult + didFinishDetectionWithResult:(MPPHandLandmarkerResult *)handLandmarkerResult timestampInMilliseconds:(NSInteger)timestampInMilliseconds error:(NSError *)error { [self assertHandLandmarkerResult:handLandmarkerResult From 94a9464750caba0a18f1d75818068d20bebaa602 Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Wed, 14 Jun 2023 15:52:26 +0530 Subject: [PATCH 4/4] Fixed formatting in MPPHandLandmarkerTests.m --- .../hand_landmarker/MPPHandLandmarkerTests.m | 94 ++++++++----------- 1 file changed, 40 insertions(+), 54 deletions(-) diff --git a/mediapipe/tasks/ios/test/vision/hand_landmarker/MPPHandLandmarkerTests.m b/mediapipe/tasks/ios/test/vision/hand_landmarker/MPPHandLandmarkerTests.m index eec13d450..36ad2ba9d 100644 --- a/mediapipe/tasks/ios/test/vision/hand_landmarker/MPPHandLandmarkerTests.m +++ b/mediapipe/tasks/ios/test/vision/hand_landmarker/MPPHandLandmarkerTests.m @@ -167,7 +167,7 @@ static NSString *const kLiveStreamTestsDictExpectationKey = @"expectation"; - (MPPHandLandmarker *)createHandLandmarkerWithOptionsSucceeds: (MPPHandLandmarkerOptions *)handLandmarkerOptions { - NSError* error; + NSError *error; MPPHandLandmarker *handLandmarker = [[MPPHandLandmarker alloc] initWithOptions:handLandmarkerOptions error:&error]; XCTAssertNotNil(handLandmarker); @@ -298,10 +298,10 @@ static NSString *const kLiveStreamTestsDictExpectationKey = @"expectation"; options.runningMode = runningModesToTest[i]; options.handLandmarkerLiveStreamDelegate = self; - [self assertCreateHandLandmarkerWithOptions:options - failsWithExpectedError: - [NSError - errorWithDomain:kExpectedErrorDomain + [self + assertCreateHandLandmarkerWithOptions:options + failsWithExpectedError: + [NSError errorWithDomain:kExpectedErrorDomain code:MPPTasksErrorCodeInvalidArgumentError userInfo:@{ NSLocalizedDescriptionKey : @@ -317,33 +317,31 @@ static NSString *const kLiveStreamTestsDictExpectationKey = @"expectation"; options.runningMode = MPPRunningModeLiveStream; - [self - assertCreateHandLandmarkerWithOptions:options - failsWithExpectedError: - [NSError errorWithDomain:kExpectedErrorDomain - code:MPPTasksErrorCodeInvalidArgumentError - userInfo:@{ - NSLocalizedDescriptionKey : - @"The vision task is in live stream mode. An " - @"object must be set as the delegate of the task " - @"in its options to ensure asynchronous delivery " - @"of results." - }]]; + [self assertCreateHandLandmarkerWithOptions:options + failsWithExpectedError: + [NSError errorWithDomain:kExpectedErrorDomain + code:MPPTasksErrorCodeInvalidArgumentError + userInfo:@{ + NSLocalizedDescriptionKey : + @"The vision task is in live stream mode. An " + @"object must be set as the delegate of the task " + @"in its options to ensure asynchronous delivery " + @"of results." + }]]; } - (void)testDetectFailsWithCallingWrongApiInImageMode { MPPHandLandmarkerOptions *options = [self handLandmarkerOptionsWithModelFileInfo:kHandLandmarkerBundleAssetFile]; - MPPHandLandmarker *handLandmarker = - [self createHandLandmarkerWithOptionsSucceeds:options]; + MPPHandLandmarker *handLandmarker = [self createHandLandmarkerWithOptionsSucceeds:options]; MPPImage *image = [self imageWithFileInfo:kThumbUpImage]; NSError *liveStreamApiCallError; XCTAssertFalse([handLandmarker detectAsyncInImage:image - timestampInMilliseconds:0 - error:&liveStreamApiCallError]); + timestampInMilliseconds:0 + error:&liveStreamApiCallError]); NSError *expectedLiveStreamApiCallError = [NSError errorWithDomain:kExpectedErrorDomain @@ -357,8 +355,8 @@ static NSString *const kLiveStreamTestsDictExpectationKey = @"expectation"; NSError *videoApiCallError; XCTAssertFalse([handLandmarker detectInVideoFrame:image - timestampInMilliseconds:0 - error:&videoApiCallError]); + timestampInMilliseconds:0 + error:&videoApiCallError]); NSError *expectedVideoApiCallError = [NSError errorWithDomain:kExpectedErrorDomain @@ -375,15 +373,14 @@ static NSString *const kLiveStreamTestsDictExpectationKey = @"expectation"; [self handLandmarkerOptionsWithModelFileInfo:kHandLandmarkerBundleAssetFile]; options.runningMode = MPPRunningModeVideo; - MPPHandLandmarker *handLandmarker = - [self createHandLandmarkerWithOptionsSucceeds:options]; + MPPHandLandmarker *handLandmarker = [self createHandLandmarkerWithOptionsSucceeds:options]; MPPImage *image = [self imageWithFileInfo:kThumbUpImage]; NSError *liveStreamApiCallError; XCTAssertFalse([handLandmarker detectAsyncInImage:image - timestampInMilliseconds:0 - error:&liveStreamApiCallError]); + timestampInMilliseconds:0 + error:&liveStreamApiCallError]); NSError *expectedLiveStreamApiCallError = [NSError errorWithDomain:kExpectedErrorDomain @@ -414,8 +411,7 @@ static NSString *const kLiveStreamTestsDictExpectationKey = @"expectation"; options.runningMode = MPPRunningModeLiveStream; options.handLandmarkerLiveStreamDelegate = self; - MPPHandLandmarker *handLandmarker = - [self createHandLandmarkerWithOptionsSucceeds:options]; + MPPHandLandmarker *handLandmarker = [self createHandLandmarkerWithOptionsSucceeds:options]; MPPImage *image = [self imageWithFileInfo:kThumbUpImage]; @@ -433,8 +429,8 @@ static NSString *const kLiveStreamTestsDictExpectationKey = @"expectation"; NSError *videoApiCallError; XCTAssertFalse([handLandmarker detectInVideoFrame:image - timestampInMilliseconds:0 - error:&videoApiCallError]); + timestampInMilliseconds:0 + error:&videoApiCallError]); NSError *expectedVideoApiCallError = [NSError errorWithDomain:kExpectedErrorDomain @@ -451,17 +447,16 @@ static NSString *const kLiveStreamTestsDictExpectationKey = @"expectation"; [self handLandmarkerOptionsWithModelFileInfo:kHandLandmarkerBundleAssetFile]; options.runningMode = MPPRunningModeVideo; - MPPHandLandmarker *handLandmarker = - [self createHandLandmarkerWithOptionsSucceeds:options]; + MPPHandLandmarker *handLandmarker = [self createHandLandmarkerWithOptionsSucceeds:options]; MPPImage *image = [self imageWithFileInfo:kThumbUpImage]; for (int i = 0; i < 3; i++) { - MPPHandLandmarkerResult *handLandmarkerResult = - [handLandmarker detectInVideoFrame:image timestampInMilliseconds:i error:nil]; + MPPHandLandmarkerResult *handLandmarkerResult = [handLandmarker detectInVideoFrame:image + timestampInMilliseconds:i + error:nil]; [self assertHandLandmarkerResult:handLandmarkerResult - isApproximatelyEqualToExpectedResult:[MPPHandLandmarkerTests - thumbUpHandLandmarkerResult]]; + isApproximatelyEqualToExpectedResult:[MPPHandLandmarkerTests thumbUpHandLandmarkerResult]]; } } @@ -476,8 +471,7 @@ static NSString *const kLiveStreamTestsDictExpectationKey = @"expectation"; expectation.expectedFulfillmentCount = 1; - MPPHandLandmarker *handLandmarker = - [self createHandLandmarkerWithOptionsSucceeds:options]; + MPPHandLandmarker *handLandmarker = [self createHandLandmarkerWithOptionsSucceeds:options]; _outOfOrderTimestampTestDict = @{ kLiveStreamTestsDictHandLandmarkerKey : handLandmarker, @@ -489,9 +483,7 @@ static NSString *const kLiveStreamTestsDictExpectationKey = @"expectation"; XCTAssertTrue([handLandmarker detectAsyncInImage:image timestampInMilliseconds:1 error:nil]); NSError *error; - XCTAssertFalse([handLandmarker detectAsyncInImage:image - timestampInMilliseconds:0 - error:&error]); + XCTAssertFalse([handLandmarker detectAsyncInImage:image timestampInMilliseconds:0 error:&error]); NSError *expectedError = [NSError errorWithDomain:kExpectedErrorDomain @@ -528,8 +520,7 @@ static NSString *const kLiveStreamTestsDictExpectationKey = @"expectation"; expectation.expectedFulfillmentCount = iterationCount + 1; expectation.inverted = YES; - MPPHandLandmarker *handLandmarker = - [self createHandLandmarkerWithOptionsSucceeds:options]; + MPPHandLandmarker *handLandmarker = [self createHandLandmarkerWithOptionsSucceeds:options]; _liveStreamSucceedsTestDict = @{ kLiveStreamTestsDictHandLandmarkerKey : handLandmarker, @@ -542,9 +533,7 @@ static NSString *const kLiveStreamTestsDictExpectationKey = @"expectation"; MPPImage *image = [self imageWithFileInfo:kThumbUpImage]; for (int i = 0; i < iterationCount; i++) { - XCTAssertTrue([handLandmarker detectAsyncInImage:image - timestampInMilliseconds:i - error:nil]); + XCTAssertTrue([handLandmarker detectAsyncInImage:image timestampInMilliseconds:i error:nil]); } NSTimeInterval timeout = 0.5f; @@ -553,19 +542,16 @@ static NSString *const kLiveStreamTestsDictExpectationKey = @"expectation"; - (void)handLandmarker:(MPPHandLandmarker *)handLandmarker didFinishDetectionWithResult:(MPPHandLandmarkerResult *)handLandmarkerResult - timestampInMilliseconds:(NSInteger)timestampInMilliseconds - error:(NSError *)error { + timestampInMilliseconds:(NSInteger)timestampInMilliseconds + error:(NSError *)error { [self assertHandLandmarkerResult:handLandmarkerResult - isApproximatelyEqualToExpectedResult:[MPPHandLandmarkerTests - thumbUpHandLandmarkerResult]]; + isApproximatelyEqualToExpectedResult:[MPPHandLandmarkerTests thumbUpHandLandmarkerResult]]; if (handLandmarker == _outOfOrderTimestampTestDict[kLiveStreamTestsDictHandLandmarkerKey]) { [_outOfOrderTimestampTestDict[kLiveStreamTestsDictExpectationKey] fulfill]; - } else if (handLandmarker == - _liveStreamSucceedsTestDict[kLiveStreamTestsDictHandLandmarkerKey]) { + } else if (handLandmarker == _liveStreamSucceedsTestDict[kLiveStreamTestsDictHandLandmarkerKey]) { [_liveStreamSucceedsTestDict[kLiveStreamTestsDictExpectationKey] fulfill]; } - } @end