From 87f525c76b1b133c3caa0b033a097bb268c37b06 Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Mon, 22 May 2023 19:59:19 -0700 Subject: [PATCH] Internal change PiperOrigin-RevId: 534264040 --- mediapipe/tasks/ios/BUILD | 4 +- .../object_detector/MPPObjectDetectorTests.m | 127 +++++++++--------- .../tasks/ios/vision/object_detector/BUILD | 12 +- .../sources/MPPObjectDetector.h | 17 ++- .../sources/MPPObjectDetector.mm | 34 ++--- .../sources/MPPObjectDetectorOptions.h | 6 +- ...tionResult.h => MPPObjectDetectorResult.h} | 8 +- ...tionResult.m => MPPObjectDetectorResult.m} | 4 +- .../ios/vision/object_detector/utils/BUILD | 8 +- ...rs.h => MPPObjectDetectorResult+Helpers.h} | 10 +- ....mm => MPPObjectDetectorResult+Helpers.mm} | 14 +- 11 files changed, 121 insertions(+), 123 deletions(-) rename mediapipe/tasks/ios/vision/object_detector/sources/{MPPObjectDetectionResult.h => MPPObjectDetectorResult.h} (86%) rename mediapipe/tasks/ios/vision/object_detector/sources/{MPPObjectDetectionResult.m => MPPObjectDetectorResult.m} (93%) rename mediapipe/tasks/ios/vision/object_detector/utils/sources/{MPPObjectDetectionResult+Helpers.h => MPPObjectDetectorResult+Helpers.h} (75%) rename mediapipe/tasks/ios/vision/object_detector/utils/sources/{MPPObjectDetectionResult+Helpers.mm => MPPObjectDetectorResult+Helpers.mm} (75%) diff --git a/mediapipe/tasks/ios/BUILD b/mediapipe/tasks/ios/BUILD index fb3d57dd..d9be847f 100644 --- a/mediapipe/tasks/ios/BUILD +++ b/mediapipe/tasks/ios/BUILD @@ -81,7 +81,7 @@ strip_api_include_path_prefix( "//mediapipe/tasks/ios/vision/image_classifier:sources/MPPImageClassifierResult.h", "//mediapipe/tasks/ios/vision/object_detector:sources/MPPObjectDetector.h", "//mediapipe/tasks/ios/vision/object_detector:sources/MPPObjectDetectorOptions.h", - "//mediapipe/tasks/ios/vision/object_detector:sources/MPPObjectDetectionResult.h", + "//mediapipe/tasks/ios/vision/object_detector:sources/MPPObjectDetectorResult.h", ], ) @@ -162,7 +162,7 @@ apple_static_xcframework( ":MPPImageClassifierResult.h", ":MPPObjectDetector.h", ":MPPObjectDetectorOptions.h", - ":MPPObjectDetectionResult.h", + ":MPPObjectDetectorResult.h", ], deps = [ "//mediapipe/tasks/ios/vision/image_classifier:MPPImageClassifier", diff --git a/mediapipe/tasks/ios/test/vision/object_detector/MPPObjectDetectorTests.m b/mediapipe/tasks/ios/test/vision/object_detector/MPPObjectDetectorTests.m index 700df65a..164159ed 100644 --- a/mediapipe/tasks/ios/test/vision/object_detector/MPPObjectDetectorTests.m +++ b/mediapipe/tasks/ios/test/vision/object_detector/MPPObjectDetectorTests.m @@ -70,7 +70,7 @@ static NSString *const kLiveStreamTestsDictExpectationKey = @"expectation"; #pragma mark Results -+ (MPPObjectDetectionResult *)expectedDetectionResultForCatsAndDogsImageWithTimestampInMilliseconds: ++ (MPPObjectDetectorResult *)expectedDetectionResultForCatsAndDogsImageWithTimestampInMilliseconds: (NSInteger)timestampInMilliseconds { NSArray *detections = @[ [[MPPDetection alloc] initWithCategories:@[ @@ -95,8 +95,8 @@ static NSString *const kLiveStreamTestsDictExpectationKey = @"expectation"; keypoints:nil], ]; - return [[MPPObjectDetectionResult alloc] initWithDetections:detections - timestampInMilliseconds:timestampInMilliseconds]; + return [[MPPObjectDetectorResult alloc] initWithDetections:detections + timestampInMilliseconds:timestampInMilliseconds]; } - (void)assertDetections:(NSArray *)detections @@ -112,25 +112,25 @@ static NSString *const kLiveStreamTestsDictExpectationKey = @"expectation"; } } -- (void)assertObjectDetectionResult:(MPPObjectDetectionResult *)objectDetectionResult - isEqualToExpectedResult:(MPPObjectDetectionResult *)expectedObjectDetectionResult - expectedDetectionsCount:(NSInteger)expectedDetectionsCount { - XCTAssertNotNil(objectDetectionResult); +- (void)assertObjectDetectorResult:(MPPObjectDetectorResult *)objectDetectorResult + isEqualToExpectedResult:(MPPObjectDetectorResult *)expectedObjectDetectorResult + expectedDetectionsCount:(NSInteger)expectedDetectionsCount { + XCTAssertNotNil(objectDetectorResult); NSArray *detectionsSubsetToCompare; - XCTAssertEqual(objectDetectionResult.detections.count, expectedDetectionsCount); - if (objectDetectionResult.detections.count > expectedObjectDetectionResult.detections.count) { - detectionsSubsetToCompare = [objectDetectionResult.detections - subarrayWithRange:NSMakeRange(0, expectedObjectDetectionResult.detections.count)]; + XCTAssertEqual(objectDetectorResult.detections.count, expectedDetectionsCount); + if (objectDetectorResult.detections.count > expectedObjectDetectorResult.detections.count) { + detectionsSubsetToCompare = [objectDetectorResult.detections + subarrayWithRange:NSMakeRange(0, expectedObjectDetectorResult.detections.count)]; } else { - detectionsSubsetToCompare = objectDetectionResult.detections; + detectionsSubsetToCompare = objectDetectorResult.detections; } [self assertDetections:detectionsSubsetToCompare - isEqualToExpectedDetections:expectedObjectDetectionResult.detections]; + isEqualToExpectedDetections:expectedObjectDetectorResult.detections]; - XCTAssertEqual(objectDetectionResult.timestampInMilliseconds, - expectedObjectDetectionResult.timestampInMilliseconds); + XCTAssertEqual(objectDetectorResult.timestampInMilliseconds, + expectedObjectDetectorResult.timestampInMilliseconds); } #pragma mark File @@ -195,28 +195,27 @@ static NSString *const kLiveStreamTestsDictExpectationKey = @"expectation"; - (void)assertResultsOfDetectInImage:(MPPImage *)mppImage usingObjectDetector:(MPPObjectDetector *)objectDetector maxResults:(NSInteger)maxResults - equalsObjectDetectionResult:(MPPObjectDetectionResult *)expectedObjectDetectionResult { - MPPObjectDetectionResult *objectDetectionResult = [objectDetector detectInImage:mppImage - error:nil]; + equalsObjectDetectorResult:(MPPObjectDetectorResult *)expectedObjectDetectorResult { + MPPObjectDetectorResult *ObjectDetectorResult = [objectDetector detectInImage:mppImage error:nil]; - [self assertObjectDetectionResult:objectDetectionResult - isEqualToExpectedResult:expectedObjectDetectionResult - expectedDetectionsCount:maxResults > 0 ? maxResults - : objectDetectionResult.detections.count]; + [self assertObjectDetectorResult:ObjectDetectorResult + isEqualToExpectedResult:expectedObjectDetectorResult + expectedDetectionsCount:maxResults > 0 ? maxResults + : ObjectDetectorResult.detections.count]; } - (void)assertResultsOfDetectInImageWithFileInfo:(NSDictionary *)fileInfo usingObjectDetector:(MPPObjectDetector *)objectDetector maxResults:(NSInteger)maxResults - equalsObjectDetectionResult: - (MPPObjectDetectionResult *)expectedObjectDetectionResult { + equalsObjectDetectorResult: + (MPPObjectDetectorResult *)expectedObjectDetectorResult { MPPImage *mppImage = [self imageWithFileInfo:fileInfo]; [self assertResultsOfDetectInImage:mppImage usingObjectDetector:objectDetector maxResults:maxResults - equalsObjectDetectionResult:expectedObjectDetectionResult]; + equalsObjectDetectorResult:expectedObjectDetectorResult]; } #pragma mark General Tests @@ -266,10 +265,10 @@ static NSString *const kLiveStreamTestsDictExpectationKey = @"expectation"; [self assertResultsOfDetectInImageWithFileInfo:kCatsAndDogsImage usingObjectDetector:objectDetector maxResults:-1 - equalsObjectDetectionResult: - [MPPObjectDetectorTests - expectedDetectionResultForCatsAndDogsImageWithTimestampInMilliseconds: - 0]]; + equalsObjectDetectorResult: + [MPPObjectDetectorTests + expectedDetectionResultForCatsAndDogsImageWithTimestampInMilliseconds: + 0]]; } - (void)testDetectWithOptionsSucceeds { @@ -280,10 +279,10 @@ static NSString *const kLiveStreamTestsDictExpectationKey = @"expectation"; [self assertResultsOfDetectInImageWithFileInfo:kCatsAndDogsImage usingObjectDetector:objectDetector maxResults:-1 - equalsObjectDetectionResult: - [MPPObjectDetectorTests - expectedDetectionResultForCatsAndDogsImageWithTimestampInMilliseconds: - 0]]; + equalsObjectDetectorResult: + [MPPObjectDetectorTests + expectedDetectionResultForCatsAndDogsImageWithTimestampInMilliseconds: + 0]]; } - (void)testDetectWithMaxResultsSucceeds { @@ -297,10 +296,10 @@ static NSString *const kLiveStreamTestsDictExpectationKey = @"expectation"; [self assertResultsOfDetectInImageWithFileInfo:kCatsAndDogsImage usingObjectDetector:objectDetector maxResults:maxResults - equalsObjectDetectionResult: - [MPPObjectDetectorTests - expectedDetectionResultForCatsAndDogsImageWithTimestampInMilliseconds: - 0]]; + equalsObjectDetectorResult: + [MPPObjectDetectorTests + expectedDetectionResultForCatsAndDogsImageWithTimestampInMilliseconds: + 0]]; } - (void)testDetectWithScoreThresholdSucceeds { @@ -316,13 +315,13 @@ static NSString *const kLiveStreamTestsDictExpectationKey = @"expectation"; boundingBox:CGRectMake(608, 161, 381, 439) keypoints:nil], ]; - MPPObjectDetectionResult *expectedObjectDetectionResult = - [[MPPObjectDetectionResult alloc] initWithDetections:detections timestampInMilliseconds:0]; + MPPObjectDetectorResult *expectedObjectDetectorResult = + [[MPPObjectDetectorResult alloc] initWithDetections:detections timestampInMilliseconds:0]; [self assertResultsOfDetectInImageWithFileInfo:kCatsAndDogsImage usingObjectDetector:objectDetector maxResults:-1 - equalsObjectDetectionResult:expectedObjectDetectionResult]; + equalsObjectDetectorResult:expectedObjectDetectorResult]; } - (void)testDetectWithCategoryAllowlistSucceeds { @@ -359,13 +358,13 @@ static NSString *const kLiveStreamTestsDictExpectationKey = @"expectation"; keypoints:nil], ]; - MPPObjectDetectionResult *expectedDetectionResult = - [[MPPObjectDetectionResult alloc] initWithDetections:detections timestampInMilliseconds:0]; + MPPObjectDetectorResult *expectedDetectionResult = + [[MPPObjectDetectorResult alloc] initWithDetections:detections timestampInMilliseconds:0]; [self assertResultsOfDetectInImageWithFileInfo:kCatsAndDogsImage usingObjectDetector:objectDetector maxResults:-1 - equalsObjectDetectionResult:expectedDetectionResult]; + equalsObjectDetectorResult:expectedDetectionResult]; } - (void)testDetectWithCategoryDenylistSucceeds { @@ -414,13 +413,13 @@ static NSString *const kLiveStreamTestsDictExpectationKey = @"expectation"; keypoints:nil], ]; - MPPObjectDetectionResult *expectedDetectionResult = - [[MPPObjectDetectionResult alloc] initWithDetections:detections timestampInMilliseconds:0]; + MPPObjectDetectorResult *expectedDetectionResult = + [[MPPObjectDetectorResult alloc] initWithDetections:detections timestampInMilliseconds:0]; [self assertResultsOfDetectInImageWithFileInfo:kCatsAndDogsImage usingObjectDetector:objectDetector maxResults:-1 - equalsObjectDetectionResult:expectedDetectionResult]; + equalsObjectDetectorResult:expectedDetectionResult]; } - (void)testDetectWithOrientationSucceeds { @@ -437,8 +436,8 @@ static NSString *const kLiveStreamTestsDictExpectationKey = @"expectation"; keypoints:nil], ]; - MPPObjectDetectionResult *expectedDetectionResult = - [[MPPObjectDetectionResult alloc] initWithDetections:detections timestampInMilliseconds:0]; + MPPObjectDetectorResult *expectedDetectionResult = + [[MPPObjectDetectorResult alloc] initWithDetections:detections timestampInMilliseconds:0]; MPPImage *image = [self imageWithFileInfo:kCatsAndDogsRotatedImage orientation:UIImageOrientationRight]; @@ -446,7 +445,7 @@ static NSString *const kLiveStreamTestsDictExpectationKey = @"expectation"; [self assertResultsOfDetectInImage:image usingObjectDetector:objectDetector maxResults:1 - equalsObjectDetectionResult:expectedDetectionResult]; + equalsObjectDetectorResult:expectedDetectionResult]; } #pragma mark Running Mode Tests @@ -613,15 +612,15 @@ static NSString *const kLiveStreamTestsDictExpectationKey = @"expectation"; MPPImage *image = [self imageWithFileInfo:kCatsAndDogsImage]; for (int i = 0; i < 3; i++) { - MPPObjectDetectionResult *objectDetectionResult = [objectDetector detectInVideoFrame:image - timestampInMilliseconds:i - error:nil]; + MPPObjectDetectorResult *ObjectDetectorResult = [objectDetector detectInVideoFrame:image + timestampInMilliseconds:i + error:nil]; - [self assertObjectDetectionResult:objectDetectionResult - isEqualToExpectedResult: - [MPPObjectDetectorTests - expectedDetectionResultForCatsAndDogsImageWithTimestampInMilliseconds:i] - expectedDetectionsCount:maxResults]; + [self assertObjectDetectorResult:ObjectDetectorResult + isEqualToExpectedResult: + [MPPObjectDetectorTests + expectedDetectionResultForCatsAndDogsImageWithTimestampInMilliseconds:i] + expectedDetectionsCount:maxResults]; } } @@ -714,16 +713,16 @@ static NSString *const kLiveStreamTestsDictExpectationKey = @"expectation"; #pragma mark MPPObjectDetectorLiveStreamDelegate Methods - (void)objectDetector:(MPPObjectDetector *)objectDetector - didFinishDetectionWithResult:(MPPObjectDetectionResult *)objectDetectionResult + didFinishDetectionWithResult:(MPPObjectDetectorResult *)ObjectDetectorResult timestampInMilliseconds:(NSInteger)timestampInMilliseconds error:(NSError *)error { NSInteger maxResults = 4; - [self assertObjectDetectionResult:objectDetectionResult - isEqualToExpectedResult: - [MPPObjectDetectorTests - expectedDetectionResultForCatsAndDogsImageWithTimestampInMilliseconds: - timestampInMilliseconds] - expectedDetectionsCount:maxResults]; + [self assertObjectDetectorResult:ObjectDetectorResult + isEqualToExpectedResult: + [MPPObjectDetectorTests + expectedDetectionResultForCatsAndDogsImageWithTimestampInMilliseconds: + timestampInMilliseconds] + expectedDetectionsCount:maxResults]; if (objectDetector == outOfOrderTimestampTestDict[kLiveStreamTestsDictObjectDetectorKey]) { [outOfOrderTimestampTestDict[kLiveStreamTestsDictExpectationKey] fulfill]; diff --git a/mediapipe/tasks/ios/vision/object_detector/BUILD b/mediapipe/tasks/ios/vision/object_detector/BUILD index 81c97c89..002a5992 100644 --- a/mediapipe/tasks/ios/vision/object_detector/BUILD +++ b/mediapipe/tasks/ios/vision/object_detector/BUILD @@ -17,9 +17,9 @@ package(default_visibility = ["//mediapipe/tasks:internal"]) licenses(["notice"]) objc_library( - name = "MPPObjectDetectionResult", - srcs = ["sources/MPPObjectDetectionResult.m"], - hdrs = ["sources/MPPObjectDetectionResult.h"], + name = "MPPObjectDetectorResult", + srcs = ["sources/MPPObjectDetectorResult.m"], + hdrs = ["sources/MPPObjectDetectorResult.h"], deps = [ "//mediapipe/tasks/ios/components/containers:MPPDetection", "//mediapipe/tasks/ios/core:MPPTaskResult", @@ -31,7 +31,7 @@ objc_library( srcs = ["sources/MPPObjectDetectorOptions.m"], hdrs = ["sources/MPPObjectDetectorOptions.h"], deps = [ - ":MPPObjectDetectionResult", + ":MPPObjectDetectorResult", "//mediapipe/tasks/ios/core:MPPTaskOptions", "//mediapipe/tasks/ios/vision/core:MPPRunningMode", ], @@ -47,8 +47,8 @@ objc_library( "-x objective-c++", ], deps = [ - ":MPPObjectDetectionResult", ":MPPObjectDetectorOptions", + ":MPPObjectDetectorResult", "//mediapipe/tasks/cc/vision/object_detector:object_detector_graph", "//mediapipe/tasks/ios/common/utils:MPPCommonUtils", "//mediapipe/tasks/ios/common/utils:NSStringHelpers", @@ -56,7 +56,7 @@ objc_library( "//mediapipe/tasks/ios/vision/core:MPPImage", "//mediapipe/tasks/ios/vision/core:MPPVisionPacketCreator", "//mediapipe/tasks/ios/vision/core:MPPVisionTaskRunner", - "//mediapipe/tasks/ios/vision/object_detector/utils:MPPObjectDetectionResultHelpers", "//mediapipe/tasks/ios/vision/object_detector/utils:MPPObjectDetectorOptionsHelpers", + "//mediapipe/tasks/ios/vision/object_detector/utils:MPPObjectDetectorResultHelpers", ], ) diff --git a/mediapipe/tasks/ios/vision/object_detector/sources/MPPObjectDetector.h b/mediapipe/tasks/ios/vision/object_detector/sources/MPPObjectDetector.h index ae18bf58..d3f946bb 100644 --- a/mediapipe/tasks/ios/vision/object_detector/sources/MPPObjectDetector.h +++ b/mediapipe/tasks/ios/vision/object_detector/sources/MPPObjectDetector.h @@ -15,8 +15,8 @@ #import #import "mediapipe/tasks/ios/vision/core/sources/MPPImage.h" -#import "mediapipe/tasks/ios/vision/object_detector/sources/MPPObjectDetectionResult.h" #import "mediapipe/tasks/ios/vision/object_detector/sources/MPPObjectDetectorOptions.h" +#import "mediapipe/tasks/ios/vision/object_detector/sources/MPPObjectDetectorResult.h" NS_ASSUME_NONNULL_BEGIN @@ -109,14 +109,13 @@ NS_SWIFT_NAME(ObjectDetector) * @param error An optional error parameter populated when there is an error in performing object * detection on the input image. * - * @return An `MPPObjectDetectionResult` object that contains a list of detections, each detection + * @return An `MPPObjectDetectorResult` object that contains a list of detections, each detection * has a bounding box that is expressed in the unrotated input frame of reference coordinates * system, i.e. in `[0,image_width) x [0,image_height)`, which are the dimensions of the underlying * image data. */ -- (nullable MPPObjectDetectionResult *)detectInImage:(MPPImage *)image - error:(NSError **)error - NS_SWIFT_NAME(detect(image:)); +- (nullable MPPObjectDetectorResult *)detectInImage:(MPPImage *)image + error:(NSError **)error NS_SWIFT_NAME(detect(image:)); /** * Performs object detection on the provided video frame of type `MPPImage` using the whole @@ -139,14 +138,14 @@ NS_SWIFT_NAME(ObjectDetector) * @param error An optional error parameter populated when there is an error in performing object * detection on the input image. * - * @return An `MPPObjectDetectionResult` object that contains a list of detections, each detection + * @return An `MPPObjectDetectorResult` object that contains a list of detections, each detection * has a bounding box that is expressed in the unrotated input frame of reference coordinates * system, i.e. in `[0,image_width) x [0,image_height)`, which are the dimensions of the underlying * image data. */ -- (nullable MPPObjectDetectionResult *)detectInVideoFrame:(MPPImage *)image - timestampInMilliseconds:(NSInteger)timestampInMilliseconds - error:(NSError **)error +- (nullable MPPObjectDetectorResult *)detectInVideoFrame:(MPPImage *)image + timestampInMilliseconds:(NSInteger)timestampInMilliseconds + error:(NSError **)error NS_SWIFT_NAME(detect(videoFrame:timestampInMilliseconds:)); /** diff --git a/mediapipe/tasks/ios/vision/object_detector/sources/MPPObjectDetector.mm b/mediapipe/tasks/ios/vision/object_detector/sources/MPPObjectDetector.mm index a5b4077b..27b196d7 100644 --- a/mediapipe/tasks/ios/vision/object_detector/sources/MPPObjectDetector.mm +++ b/mediapipe/tasks/ios/vision/object_detector/sources/MPPObjectDetector.mm @@ -19,8 +19,8 @@ #import "mediapipe/tasks/ios/core/sources/MPPTaskInfo.h" #import "mediapipe/tasks/ios/vision/core/sources/MPPVisionPacketCreator.h" #import "mediapipe/tasks/ios/vision/core/sources/MPPVisionTaskRunner.h" -#import "mediapipe/tasks/ios/vision/object_detector/utils/sources/MPPObjectDetectionResult+Helpers.h" #import "mediapipe/tasks/ios/vision/object_detector/utils/sources/MPPObjectDetectorOptions+Helpers.h" +#import "mediapipe/tasks/ios/vision/object_detector/utils/sources/MPPObjectDetectorResult+Helpers.h" namespace { using ::mediapipe::NormalizedRect; @@ -118,9 +118,9 @@ static NSString *const kTaskName = @"objectDetector"; return; } - MPPObjectDetectionResult *result = [MPPObjectDetectionResult - objectDetectionResultWithDetectionsPacket:statusOrPackets.value()[kDetectionsStreamName - .cppString]]; + MPPObjectDetectorResult *result = [MPPObjectDetectorResult + objectDetectorResultWithDetectionsPacket:statusOrPackets + .value()[kDetectionsStreamName.cppString]]; NSInteger timeStampInMilliseconds = outputPacketMap[kImageOutStreamName.cppString].Timestamp().Value() / @@ -184,9 +184,9 @@ static NSString *const kTaskName = @"objectDetector"; return inputPacketMap; } -- (nullable MPPObjectDetectionResult *)detectInImage:(MPPImage *)image - regionOfInterest:(CGRect)roi - error:(NSError **)error { +- (nullable MPPObjectDetectorResult *)detectInImage:(MPPImage *)image + regionOfInterest:(CGRect)roi + error:(NSError **)error { std::optional rect = [_visionTaskRunner normalizedRectFromRegionOfInterest:roi imageSize:CGSizeMake(image.width, image.height) @@ -213,18 +213,18 @@ static NSString *const kTaskName = @"objectDetector"; return nil; } - return [MPPObjectDetectionResult - objectDetectionResultWithDetectionsPacket:outputPacketMap - .value()[kDetectionsStreamName.cppString]]; + return [MPPObjectDetectorResult + objectDetectorResultWithDetectionsPacket:outputPacketMap + .value()[kDetectionsStreamName.cppString]]; } -- (nullable MPPObjectDetectionResult *)detectInImage:(MPPImage *)image error:(NSError **)error { +- (nullable MPPObjectDetectorResult *)detectInImage:(MPPImage *)image error:(NSError **)error { return [self detectInImage:image regionOfInterest:CGRectZero error:error]; } -- (nullable MPPObjectDetectionResult *)detectInVideoFrame:(MPPImage *)image - timestampInMilliseconds:(NSInteger)timestampInMilliseconds - error:(NSError **)error { +- (nullable MPPObjectDetectorResult *)detectInVideoFrame:(MPPImage *)image + timestampInMilliseconds:(NSInteger)timestampInMilliseconds + error:(NSError **)error { std::optional inputPacketMap = [self inputPacketMapWithMPPImage:image timestampInMilliseconds:timestampInMilliseconds error:error]; @@ -239,9 +239,9 @@ static NSString *const kTaskName = @"objectDetector"; return nil; } - return [MPPObjectDetectionResult - objectDetectionResultWithDetectionsPacket:outputPacketMap - .value()[kDetectionsStreamName.cppString]]; + return [MPPObjectDetectorResult + objectDetectorResultWithDetectionsPacket:outputPacketMap + .value()[kDetectionsStreamName.cppString]]; } - (BOOL)detectAsyncInImage:(MPPImage *)image diff --git a/mediapipe/tasks/ios/vision/object_detector/sources/MPPObjectDetectorOptions.h b/mediapipe/tasks/ios/vision/object_detector/sources/MPPObjectDetectorOptions.h index 182714c0..33d7bdbb 100644 --- a/mediapipe/tasks/ios/vision/object_detector/sources/MPPObjectDetectorOptions.h +++ b/mediapipe/tasks/ios/vision/object_detector/sources/MPPObjectDetectorOptions.h @@ -16,7 +16,7 @@ #import "mediapipe/tasks/ios/core/sources/MPPTaskOptions.h" #import "mediapipe/tasks/ios/vision/core/sources/MPPRunningMode.h" -#import "mediapipe/tasks/ios/vision/object_detector/sources/MPPObjectDetectionResult.h" +#import "mediapipe/tasks/ios/vision/object_detector/sources/MPPObjectDetectorResult.h" NS_ASSUME_NONNULL_BEGIN @@ -44,7 +44,7 @@ NS_SWIFT_NAME(ObjectDetectorLiveStreamDelegate) * * @param objectDetector The object detector which performed the object detection. * This is useful to test equality when there are multiple instances of `MPPObjectDetector`. - * @param result The `MPPObjectDetectionResult` object that contains a list of detections, each + * @param result The `MPPObjectDetectorResult` object that contains a list of detections, each * detection has a bounding box that is expressed in the unrotated input frame of reference * coordinates system, i.e. in `[0,image_width) x [0,image_height)`, which are the dimensions of the * underlying image data. @@ -54,7 +54,7 @@ NS_SWIFT_NAME(ObjectDetectorLiveStreamDelegate) * detection on the input live stream image data. */ - (void)objectDetector:(MPPObjectDetector *)objectDetector - didFinishDetectionWithResult:(nullable MPPObjectDetectionResult *)result + didFinishDetectionWithResult:(nullable MPPObjectDetectorResult *)result timestampInMilliseconds:(NSInteger)timestampInMilliseconds error:(nullable NSError *)error NS_SWIFT_NAME(objectDetector(_:didFinishDetection:timestampInMilliseconds:error:)); diff --git a/mediapipe/tasks/ios/vision/object_detector/sources/MPPObjectDetectionResult.h b/mediapipe/tasks/ios/vision/object_detector/sources/MPPObjectDetectorResult.h similarity index 86% rename from mediapipe/tasks/ios/vision/object_detector/sources/MPPObjectDetectionResult.h rename to mediapipe/tasks/ios/vision/object_detector/sources/MPPObjectDetectorResult.h index da9899d4..2641b6b4 100644 --- a/mediapipe/tasks/ios/vision/object_detector/sources/MPPObjectDetectionResult.h +++ b/mediapipe/tasks/ios/vision/object_detector/sources/MPPObjectDetectorResult.h @@ -19,8 +19,8 @@ NS_ASSUME_NONNULL_BEGIN /** Represents the detection results generated by `MPPObjectDetector`. */ -NS_SWIFT_NAME(ObjectDetectionResult) -@interface MPPObjectDetectionResult : MPPTaskResult +NS_SWIFT_NAME(ObjectDetectorResult) +@interface MPPObjectDetectorResult : MPPTaskResult /** * The array of `MPPDetection` objects each of which has a bounding box that is expressed in the @@ -30,7 +30,7 @@ NS_SWIFT_NAME(ObjectDetectionResult) @property(nonatomic, readonly) NSArray *detections; /** - * Initializes a new `MPPObjectDetectionResult` with the given array of detections and timestamp (in + * Initializes a new `MPPObjectDetectorResult` with the given array of detections and timestamp (in * milliseconds). * * @param detections An array of `MPPDetection` objects each of which has a bounding box that is @@ -38,7 +38,7 @@ NS_SWIFT_NAME(ObjectDetectionResult) * x [0,image_height)`, which are the dimensions of the underlying image data. * @param timestampInMilliseconds The timestamp (in milliseconds) for this result. * - * @return An instance of `MPPObjectDetectionResult` initialized with the given array of detections + * @return An instance of `MPPObjectDetectorResult` initialized with the given array of detections * and timestamp (in milliseconds). */ - (instancetype)initWithDetections:(NSArray *)detections diff --git a/mediapipe/tasks/ios/vision/object_detector/sources/MPPObjectDetectionResult.m b/mediapipe/tasks/ios/vision/object_detector/sources/MPPObjectDetectorResult.m similarity index 93% rename from mediapipe/tasks/ios/vision/object_detector/sources/MPPObjectDetectionResult.m rename to mediapipe/tasks/ios/vision/object_detector/sources/MPPObjectDetectorResult.m index 47902bba..568fbcff 100644 --- a/mediapipe/tasks/ios/vision/object_detector/sources/MPPObjectDetectionResult.m +++ b/mediapipe/tasks/ios/vision/object_detector/sources/MPPObjectDetectorResult.m @@ -12,9 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -#import "mediapipe/tasks/ios/vision/object_detector/sources/MPPObjectDetectionResult.h" +#import "mediapipe/tasks/ios/vision/object_detector/sources/MPPObjectDetectorResult.h" -@implementation MPPObjectDetectionResult +@implementation MPPObjectDetectorResult - (instancetype)initWithDetections:(NSArray *)detections timestampInMilliseconds:(NSInteger)timestampInMilliseconds { diff --git a/mediapipe/tasks/ios/vision/object_detector/utils/BUILD b/mediapipe/tasks/ios/vision/object_detector/utils/BUILD index d4597b23..63ddbd0b 100644 --- a/mediapipe/tasks/ios/vision/object_detector/utils/BUILD +++ b/mediapipe/tasks/ios/vision/object_detector/utils/BUILD @@ -31,12 +31,12 @@ objc_library( ) objc_library( - name = "MPPObjectDetectionResultHelpers", - srcs = ["sources/MPPObjectDetectionResult+Helpers.mm"], - hdrs = ["sources/MPPObjectDetectionResult+Helpers.h"], + name = "MPPObjectDetectorResultHelpers", + srcs = ["sources/MPPObjectDetectorResult+Helpers.mm"], + hdrs = ["sources/MPPObjectDetectorResult+Helpers.h"], deps = [ "//mediapipe/framework:packet", "//mediapipe/tasks/ios/components/containers/utils:MPPDetectionHelpers", - "//mediapipe/tasks/ios/vision/object_detector:MPPObjectDetectionResult", + "//mediapipe/tasks/ios/vision/object_detector:MPPObjectDetectorResult", ], ) diff --git a/mediapipe/tasks/ios/vision/object_detector/utils/sources/MPPObjectDetectionResult+Helpers.h b/mediapipe/tasks/ios/vision/object_detector/utils/sources/MPPObjectDetectorResult+Helpers.h similarity index 75% rename from mediapipe/tasks/ios/vision/object_detector/utils/sources/MPPObjectDetectionResult+Helpers.h rename to mediapipe/tasks/ios/vision/object_detector/utils/sources/MPPObjectDetectorResult+Helpers.h index 645f5c56..377e6e32 100644 --- a/mediapipe/tasks/ios/vision/object_detector/utils/sources/MPPObjectDetectionResult+Helpers.h +++ b/mediapipe/tasks/ios/vision/object_detector/utils/sources/MPPObjectDetectorResult+Helpers.h @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#import "mediapipe/tasks/ios/vision/object_detector/sources/MPPObjectDetectionResult.h" +#import "mediapipe/tasks/ios/vision/object_detector/sources/MPPObjectDetectorResult.h" #include "mediapipe/framework/packet.h" @@ -20,17 +20,17 @@ NS_ASSUME_NONNULL_BEGIN static const int kMicroSecondsPerMilliSecond = 1000; -@interface MPPObjectDetectionResult (Helpers) +@interface MPPObjectDetectorResult (Helpers) /** - * Creates an `MPPObjectDetectionResult` from a MediaPipe packet containing a + * Creates an `MPPObjectDetectorResult` from a MediaPipe packet containing a * `std::vector`. * * @param packet a MediaPipe packet wrapping a `std::vector`. * - * @return An `MPPObjectDetectionResult` object that contains a list of detections. + * @return An `MPPObjectDetectorResult` object that contains a list of detections. */ -+ (nullable MPPObjectDetectionResult *)objectDetectionResultWithDetectionsPacket: ++ (nullable MPPObjectDetectorResult *)objectDetectorResultWithDetectionsPacket: (const mediapipe::Packet &)packet; @end diff --git a/mediapipe/tasks/ios/vision/object_detector/utils/sources/MPPObjectDetectionResult+Helpers.mm b/mediapipe/tasks/ios/vision/object_detector/utils/sources/MPPObjectDetectorResult+Helpers.mm similarity index 75% rename from mediapipe/tasks/ios/vision/object_detector/utils/sources/MPPObjectDetectionResult+Helpers.mm rename to mediapipe/tasks/ios/vision/object_detector/utils/sources/MPPObjectDetectorResult+Helpers.mm index 225a6993..b2f9cfc0 100644 --- a/mediapipe/tasks/ios/vision/object_detector/utils/sources/MPPObjectDetectionResult+Helpers.mm +++ b/mediapipe/tasks/ios/vision/object_detector/utils/sources/MPPObjectDetectorResult+Helpers.mm @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#import "mediapipe/tasks/ios/vision/object_detector/utils/sources/MPPObjectDetectionResult+Helpers.h" +#import "mediapipe/tasks/ios/vision/object_detector/utils/sources/MPPObjectDetectorResult+Helpers.h" #import "mediapipe/tasks/ios/components/containers/utils/sources/MPPDetection+Helpers.h" @@ -21,9 +21,9 @@ using DetectionProto = ::mediapipe::Detection; using ::mediapipe::Packet; } // namespace -@implementation MPPObjectDetectionResult (Helpers) +@implementation MPPObjectDetectorResult (Helpers) -+ (nullable MPPObjectDetectionResult *)objectDetectionResultWithDetectionsPacket: ++ (nullable MPPObjectDetectorResult *)objectDetectorResultWithDetectionsPacket: (const Packet &)packet { if (!packet.ValidateAsType>().ok()) { return nil; @@ -37,10 +37,10 @@ using ::mediapipe::Packet; [detections addObject:[MPPDetection detectionWithProto:detectionProto]]; } - return [[MPPObjectDetectionResult alloc] - initWithDetections:detections - timestampInMilliseconds:(NSInteger)(packet.Timestamp().Value() / - kMicroSecondsPerMilliSecond)]; + return + [[MPPObjectDetectorResult alloc] initWithDetections:detections + timestampInMilliseconds:(NSInteger)(packet.Timestamp().Value() / + kMicroSecondsPerMilliSecond)]; } @end