Internal change
PiperOrigin-RevId: 534264040
This commit is contained in:
		
							parent
							
								
									51730ec25c
								
							
						
					
					
						commit
						87f525c76b
					
				| 
						 | 
				
			
			@ -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",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -70,7 +70,7 @@ static NSString *const kLiveStreamTestsDictExpectationKey = @"expectation";
 | 
			
		|||
 | 
			
		||||
#pragma mark Results
 | 
			
		||||
 | 
			
		||||
+ (MPPObjectDetectionResult *)expectedDetectionResultForCatsAndDogsImageWithTimestampInMilliseconds:
 | 
			
		||||
+ (MPPObjectDetectorResult *)expectedDetectionResultForCatsAndDogsImageWithTimestampInMilliseconds:
 | 
			
		||||
    (NSInteger)timestampInMilliseconds {
 | 
			
		||||
  NSArray<MPPDetection *> *detections = @[
 | 
			
		||||
    [[MPPDetection alloc] initWithCategories:@[
 | 
			
		||||
| 
						 | 
				
			
			@ -95,7 +95,7 @@ static NSString *const kLiveStreamTestsDictExpectationKey = @"expectation";
 | 
			
		|||
                                   keypoints:nil],
 | 
			
		||||
  ];
 | 
			
		||||
 | 
			
		||||
  return [[MPPObjectDetectionResult alloc] initWithDetections:detections
 | 
			
		||||
  return [[MPPObjectDetectorResult alloc] initWithDetections:detections
 | 
			
		||||
                                     timestampInMilliseconds:timestampInMilliseconds];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -112,25 +112,25 @@ static NSString *const kLiveStreamTestsDictExpectationKey = @"expectation";
 | 
			
		|||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (void)assertObjectDetectionResult:(MPPObjectDetectionResult *)objectDetectionResult
 | 
			
		||||
            isEqualToExpectedResult:(MPPObjectDetectionResult *)expectedObjectDetectionResult
 | 
			
		||||
- (void)assertObjectDetectorResult:(MPPObjectDetectorResult *)objectDetectorResult
 | 
			
		||||
           isEqualToExpectedResult:(MPPObjectDetectorResult *)expectedObjectDetectorResult
 | 
			
		||||
           expectedDetectionsCount:(NSInteger)expectedDetectionsCount {
 | 
			
		||||
  XCTAssertNotNil(objectDetectionResult);
 | 
			
		||||
  XCTAssertNotNil(objectDetectorResult);
 | 
			
		||||
 | 
			
		||||
  NSArray<MPPDetection *> *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
 | 
			
		||||
  [self assertObjectDetectorResult:ObjectDetectorResult
 | 
			
		||||
           isEqualToExpectedResult:expectedObjectDetectorResult
 | 
			
		||||
           expectedDetectionsCount:maxResults > 0 ? maxResults
 | 
			
		||||
                                                   : objectDetectionResult.detections.count];
 | 
			
		||||
                                                  : 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,7 +265,7 @@ static NSString *const kLiveStreamTestsDictExpectationKey = @"expectation";
 | 
			
		|||
  [self assertResultsOfDetectInImageWithFileInfo:kCatsAndDogsImage
 | 
			
		||||
                             usingObjectDetector:objectDetector
 | 
			
		||||
                                      maxResults:-1
 | 
			
		||||
                     equalsObjectDetectionResult:
 | 
			
		||||
                      equalsObjectDetectorResult:
 | 
			
		||||
                          [MPPObjectDetectorTests
 | 
			
		||||
                              expectedDetectionResultForCatsAndDogsImageWithTimestampInMilliseconds:
 | 
			
		||||
                                  0]];
 | 
			
		||||
| 
						 | 
				
			
			@ -280,7 +279,7 @@ static NSString *const kLiveStreamTestsDictExpectationKey = @"expectation";
 | 
			
		|||
  [self assertResultsOfDetectInImageWithFileInfo:kCatsAndDogsImage
 | 
			
		||||
                             usingObjectDetector:objectDetector
 | 
			
		||||
                                      maxResults:-1
 | 
			
		||||
                     equalsObjectDetectionResult:
 | 
			
		||||
                      equalsObjectDetectorResult:
 | 
			
		||||
                          [MPPObjectDetectorTests
 | 
			
		||||
                              expectedDetectionResultForCatsAndDogsImageWithTimestampInMilliseconds:
 | 
			
		||||
                                  0]];
 | 
			
		||||
| 
						 | 
				
			
			@ -297,7 +296,7 @@ static NSString *const kLiveStreamTestsDictExpectationKey = @"expectation";
 | 
			
		|||
  [self assertResultsOfDetectInImageWithFileInfo:kCatsAndDogsImage
 | 
			
		||||
                             usingObjectDetector:objectDetector
 | 
			
		||||
                                      maxResults:maxResults
 | 
			
		||||
                     equalsObjectDetectionResult:
 | 
			
		||||
                      equalsObjectDetectorResult:
 | 
			
		||||
                          [MPPObjectDetectorTests
 | 
			
		||||
                              expectedDetectionResultForCatsAndDogsImageWithTimestampInMilliseconds:
 | 
			
		||||
                                  0]];
 | 
			
		||||
| 
						 | 
				
			
			@ -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,11 +612,11 @@ static NSString *const kLiveStreamTestsDictExpectationKey = @"expectation";
 | 
			
		|||
  MPPImage *image = [self imageWithFileInfo:kCatsAndDogsImage];
 | 
			
		||||
 | 
			
		||||
  for (int i = 0; i < 3; i++) {
 | 
			
		||||
    MPPObjectDetectionResult *objectDetectionResult = [objectDetector detectInVideoFrame:image
 | 
			
		||||
    MPPObjectDetectorResult *ObjectDetectorResult = [objectDetector detectInVideoFrame:image
 | 
			
		||||
                                                               timestampInMilliseconds:i
 | 
			
		||||
                                                                                 error:nil];
 | 
			
		||||
 | 
			
		||||
    [self assertObjectDetectionResult:objectDetectionResult
 | 
			
		||||
    [self assertObjectDetectorResult:ObjectDetectorResult
 | 
			
		||||
             isEqualToExpectedResult:
 | 
			
		||||
                 [MPPObjectDetectorTests
 | 
			
		||||
                     expectedDetectionResultForCatsAndDogsImageWithTimestampInMilliseconds:i]
 | 
			
		||||
| 
						 | 
				
			
			@ -714,11 +713,11 @@ 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
 | 
			
		||||
  [self assertObjectDetectorResult:ObjectDetectorResult
 | 
			
		||||
           isEqualToExpectedResult:
 | 
			
		||||
               [MPPObjectDetectorTests
 | 
			
		||||
                   expectedDetectionResultForCatsAndDogsImageWithTimestampInMilliseconds:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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",
 | 
			
		||||
    ],
 | 
			
		||||
)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -15,8 +15,8 @@
 | 
			
		|||
#import <Foundation/Foundation.h>
 | 
			
		||||
 | 
			
		||||
#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,12 +138,12 @@ 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
 | 
			
		||||
- (nullable MPPObjectDetectorResult *)detectInVideoFrame:(MPPImage *)image
 | 
			
		||||
                                 timestampInMilliseconds:(NSInteger)timestampInMilliseconds
 | 
			
		||||
                                                   error:(NSError **)error
 | 
			
		||||
    NS_SWIFT_NAME(detect(videoFrame:timestampInMilliseconds:));
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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,7 +184,7 @@ static NSString *const kTaskName = @"objectDetector";
 | 
			
		|||
  return inputPacketMap;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (nullable MPPObjectDetectionResult *)detectInImage:(MPPImage *)image
 | 
			
		||||
- (nullable MPPObjectDetectorResult *)detectInImage:(MPPImage *)image
 | 
			
		||||
                                   regionOfInterest:(CGRect)roi
 | 
			
		||||
                                              error:(NSError **)error {
 | 
			
		||||
  std::optional<NormalizedRect> rect =
 | 
			
		||||
| 
						 | 
				
			
			@ -213,16 +213,16 @@ static NSString *const kTaskName = @"objectDetector";
 | 
			
		|||
    return nil;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return [MPPObjectDetectionResult
 | 
			
		||||
      objectDetectionResultWithDetectionsPacket:outputPacketMap
 | 
			
		||||
  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
 | 
			
		||||
- (nullable MPPObjectDetectorResult *)detectInVideoFrame:(MPPImage *)image
 | 
			
		||||
                                 timestampInMilliseconds:(NSInteger)timestampInMilliseconds
 | 
			
		||||
                                                   error:(NSError **)error {
 | 
			
		||||
  std::optional<PacketMap> inputPacketMap = [self inputPacketMapWithMPPImage:image
 | 
			
		||||
| 
						 | 
				
			
			@ -239,8 +239,8 @@ static NSString *const kTaskName = @"objectDetector";
 | 
			
		|||
    return nil;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return [MPPObjectDetectionResult
 | 
			
		||||
      objectDetectionResultWithDetectionsPacket:outputPacketMap
 | 
			
		||||
  return [MPPObjectDetectorResult
 | 
			
		||||
      objectDetectorResultWithDetectionsPacket:outputPacketMap
 | 
			
		||||
                                                   .value()[kDetectionsStreamName.cppString]];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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:));
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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<MPPDetection *> *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<MPPDetection *> *)detections
 | 
			
		||||
| 
						 | 
				
			
			@ -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<MPPDetection *> *)detections
 | 
			
		||||
           timestampInMilliseconds:(NSInteger)timestampInMilliseconds {
 | 
			
		||||
| 
						 | 
				
			
			@ -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",
 | 
			
		||||
    ],
 | 
			
		||||
)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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<DetectionProto>`.
 | 
			
		||||
 *
 | 
			
		||||
 * @param packet a MediaPipe packet wrapping a `std::vector<DetectionProto>`.
 | 
			
		||||
 *
 | 
			
		||||
 * @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
 | 
			
		||||
| 
						 | 
				
			
			@ -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<std::vector<DetectionProto>>().ok()) {
 | 
			
		||||
    return nil;
 | 
			
		||||
| 
						 | 
				
			
			@ -37,8 +37,8 @@ using ::mediapipe::Packet;
 | 
			
		|||
    [detections addObject:[MPPDetection detectionWithProto:detectionProto]];
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return [[MPPObjectDetectionResult alloc]
 | 
			
		||||
           initWithDetections:detections
 | 
			
		||||
  return
 | 
			
		||||
      [[MPPObjectDetectorResult alloc] initWithDetections:detections
 | 
			
		||||
                                  timestampInMilliseconds:(NSInteger)(packet.Timestamp().Value() /
 | 
			
		||||
                                                                      kMicroSecondsPerMilliSecond)];
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user