diff --git a/mediapipe/tasks/ios/vision/core/sources/MPPRunningMode.h b/mediapipe/tasks/ios/vision/core/sources/MPPRunningMode.h index 5cc57b88a..8818d9b15 100644 --- a/mediapipe/tasks/ios/vision/core/sources/MPPRunningMode.h +++ b/mediapipe/tasks/ios/vision/core/sources/MPPRunningMode.h @@ -38,4 +38,23 @@ typedef NS_ENUM(NSUInteger, MPPRunningMode) { } NS_SWIFT_NAME(RunningMode); +NS_INLINE NSString *MPPRunningModeDisplayName(MPPRunningMode runningMode) { + + if (runningMode > MPPRunningModeLiveStream) { + return nil; + } + + #define MPPRunningModeDisplayNameMap(mode) [mode] = @#mode + + NSString *displayNameMap[MPPRunningModeLiveStream + 1] = { + MPPRunningModeDisplayNameMap(MPPRunningModeImage), + MPPRunningModeDisplayNameMap(MPPRunningModeVideo), + MPPRunningModeDisplayNameMap(MPPRunningModeLiveStream), + }; + + #undef MPPRunningModeDisplayNameMap + + return displayNameMap[runningMode]; +} + NS_ASSUME_NONNULL_END diff --git a/mediapipe/tasks/ios/vision/core/sources/MPPVisionTaskRunner.mm b/mediapipe/tasks/ios/vision/core/sources/MPPVisionTaskRunner.mm index fff14a978..43ef8ce9b 100644 --- a/mediapipe/tasks/ios/vision/core/sources/MPPVisionTaskRunner.mm +++ b/mediapipe/tasks/ios/vision/core/sources/MPPVisionTaskRunner.mm @@ -116,10 +116,11 @@ using ::mediapipe::tasks::core::PacketsCallback; [MPPCommonUtils createCustomError:error withCode:MPPTasksErrorCodeInvalidArgumentError - description:@"Unsupported UIImageOrientation. `imageOrientation` cannot be equal to " - @"any of the mirrored orientations " - @"(`UIImageOrientationUpMirrored`,`UIImageOrientationDownMirrored`,`" - @"UIImageOrientationLeftMirrored`,`UIImageOrientationRightMirrored`)"]; + description: + @"Unsupported UIImageOrientation. `imageOrientation` cannot be equal to " + @"any of the mirrored orientations " + @"(`UIImageOrientationUpMirrored`,`UIImageOrientationDownMirrored`,`" + @"UIImageOrientationLeftMirrored`,`UIImageOrientationRightMirrored`)"]; } normalizedRect.set_rotation(-rotationDegrees * M_PI / 180.0); @@ -132,8 +133,9 @@ using ::mediapipe::tasks::core::PacketsCallback; [MPPCommonUtils createCustomError:error withCode:MPPTasksErrorCodeInvalidArgumentError - description: - @"The vision task is not initialized with image mode. Current Running Mode:"]; + description:[NSString stringWithFormat:@"The vision task is not initialized with " + @"image mode. Current Running Mode: %@", + MPPRunningModeDisplayName(_runningMode)]]; return std::nullopt; } @@ -146,8 +148,9 @@ using ::mediapipe::tasks::core::PacketsCallback; [MPPCommonUtils createCustomError:error withCode:MPPTasksErrorCodeInvalidArgumentError - description: - @"The vision task is not initialized with image mode. Current Running Mode:"]; + description:[NSString stringWithFormat:@"The vision task is not initialized with " + @"video mode. Current Running Mode: %@", + MPPRunningModeDisplayName(_runningMode)]]; return std::nullopt; } @@ -159,8 +162,9 @@ using ::mediapipe::tasks::core::PacketsCallback; [MPPCommonUtils createCustomError:error withCode:MPPTasksErrorCodeInvalidArgumentError - description: - @"The vision task is not initialized with image mode. Current Running Mode:"]; + description:[NSString stringWithFormat:@"The vision task is not initialized with " + @"live stream mode. Current Running Mode: %@", + MPPRunningModeDisplayName(_runningMode)]]; return NO; }