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/image_classifier:sources/MPPImageClassifierResult.h",
|
||||||
"//mediapipe/tasks/ios/vision/object_detector:sources/MPPObjectDetector.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/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",
|
":MPPImageClassifierResult.h",
|
||||||
":MPPObjectDetector.h",
|
":MPPObjectDetector.h",
|
||||||
":MPPObjectDetectorOptions.h",
|
":MPPObjectDetectorOptions.h",
|
||||||
":MPPObjectDetectionResult.h",
|
":MPPObjectDetectorResult.h",
|
||||||
],
|
],
|
||||||
deps = [
|
deps = [
|
||||||
"//mediapipe/tasks/ios/vision/image_classifier:MPPImageClassifier",
|
"//mediapipe/tasks/ios/vision/image_classifier:MPPImageClassifier",
|
||||||
|
|
|
@ -70,7 +70,7 @@ static NSString *const kLiveStreamTestsDictExpectationKey = @"expectation";
|
||||||
|
|
||||||
#pragma mark Results
|
#pragma mark Results
|
||||||
|
|
||||||
+ (MPPObjectDetectionResult *)expectedDetectionResultForCatsAndDogsImageWithTimestampInMilliseconds:
|
+ (MPPObjectDetectorResult *)expectedDetectionResultForCatsAndDogsImageWithTimestampInMilliseconds:
|
||||||
(NSInteger)timestampInMilliseconds {
|
(NSInteger)timestampInMilliseconds {
|
||||||
NSArray<MPPDetection *> *detections = @[
|
NSArray<MPPDetection *> *detections = @[
|
||||||
[[MPPDetection alloc] initWithCategories:@[
|
[[MPPDetection alloc] initWithCategories:@[
|
||||||
|
@ -95,8 +95,8 @@ static NSString *const kLiveStreamTestsDictExpectationKey = @"expectation";
|
||||||
keypoints:nil],
|
keypoints:nil],
|
||||||
];
|
];
|
||||||
|
|
||||||
return [[MPPObjectDetectionResult alloc] initWithDetections:detections
|
return [[MPPObjectDetectorResult alloc] initWithDetections:detections
|
||||||
timestampInMilliseconds:timestampInMilliseconds];
|
timestampInMilliseconds:timestampInMilliseconds];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)assertDetections:(NSArray<MPPDetection *> *)detections
|
- (void)assertDetections:(NSArray<MPPDetection *> *)detections
|
||||||
|
@ -112,25 +112,25 @@ static NSString *const kLiveStreamTestsDictExpectationKey = @"expectation";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)assertObjectDetectionResult:(MPPObjectDetectionResult *)objectDetectionResult
|
- (void)assertObjectDetectorResult:(MPPObjectDetectorResult *)objectDetectorResult
|
||||||
isEqualToExpectedResult:(MPPObjectDetectionResult *)expectedObjectDetectionResult
|
isEqualToExpectedResult:(MPPObjectDetectorResult *)expectedObjectDetectorResult
|
||||||
expectedDetectionsCount:(NSInteger)expectedDetectionsCount {
|
expectedDetectionsCount:(NSInteger)expectedDetectionsCount {
|
||||||
XCTAssertNotNil(objectDetectionResult);
|
XCTAssertNotNil(objectDetectorResult);
|
||||||
|
|
||||||
NSArray<MPPDetection *> *detectionsSubsetToCompare;
|
NSArray<MPPDetection *> *detectionsSubsetToCompare;
|
||||||
XCTAssertEqual(objectDetectionResult.detections.count, expectedDetectionsCount);
|
XCTAssertEqual(objectDetectorResult.detections.count, expectedDetectionsCount);
|
||||||
if (objectDetectionResult.detections.count > expectedObjectDetectionResult.detections.count) {
|
if (objectDetectorResult.detections.count > expectedObjectDetectorResult.detections.count) {
|
||||||
detectionsSubsetToCompare = [objectDetectionResult.detections
|
detectionsSubsetToCompare = [objectDetectorResult.detections
|
||||||
subarrayWithRange:NSMakeRange(0, expectedObjectDetectionResult.detections.count)];
|
subarrayWithRange:NSMakeRange(0, expectedObjectDetectorResult.detections.count)];
|
||||||
} else {
|
} else {
|
||||||
detectionsSubsetToCompare = objectDetectionResult.detections;
|
detectionsSubsetToCompare = objectDetectorResult.detections;
|
||||||
}
|
}
|
||||||
|
|
||||||
[self assertDetections:detectionsSubsetToCompare
|
[self assertDetections:detectionsSubsetToCompare
|
||||||
isEqualToExpectedDetections:expectedObjectDetectionResult.detections];
|
isEqualToExpectedDetections:expectedObjectDetectorResult.detections];
|
||||||
|
|
||||||
XCTAssertEqual(objectDetectionResult.timestampInMilliseconds,
|
XCTAssertEqual(objectDetectorResult.timestampInMilliseconds,
|
||||||
expectedObjectDetectionResult.timestampInMilliseconds);
|
expectedObjectDetectorResult.timestampInMilliseconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark File
|
#pragma mark File
|
||||||
|
@ -195,28 +195,27 @@ static NSString *const kLiveStreamTestsDictExpectationKey = @"expectation";
|
||||||
- (void)assertResultsOfDetectInImage:(MPPImage *)mppImage
|
- (void)assertResultsOfDetectInImage:(MPPImage *)mppImage
|
||||||
usingObjectDetector:(MPPObjectDetector *)objectDetector
|
usingObjectDetector:(MPPObjectDetector *)objectDetector
|
||||||
maxResults:(NSInteger)maxResults
|
maxResults:(NSInteger)maxResults
|
||||||
equalsObjectDetectionResult:(MPPObjectDetectionResult *)expectedObjectDetectionResult {
|
equalsObjectDetectorResult:(MPPObjectDetectorResult *)expectedObjectDetectorResult {
|
||||||
MPPObjectDetectionResult *objectDetectionResult = [objectDetector detectInImage:mppImage
|
MPPObjectDetectorResult *ObjectDetectorResult = [objectDetector detectInImage:mppImage error:nil];
|
||||||
error:nil];
|
|
||||||
|
|
||||||
[self assertObjectDetectionResult:objectDetectionResult
|
[self assertObjectDetectorResult:ObjectDetectorResult
|
||||||
isEqualToExpectedResult:expectedObjectDetectionResult
|
isEqualToExpectedResult:expectedObjectDetectorResult
|
||||||
expectedDetectionsCount:maxResults > 0 ? maxResults
|
expectedDetectionsCount:maxResults > 0 ? maxResults
|
||||||
: objectDetectionResult.detections.count];
|
: ObjectDetectorResult.detections.count];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)assertResultsOfDetectInImageWithFileInfo:(NSDictionary *)fileInfo
|
- (void)assertResultsOfDetectInImageWithFileInfo:(NSDictionary *)fileInfo
|
||||||
usingObjectDetector:(MPPObjectDetector *)objectDetector
|
usingObjectDetector:(MPPObjectDetector *)objectDetector
|
||||||
maxResults:(NSInteger)maxResults
|
maxResults:(NSInteger)maxResults
|
||||||
|
|
||||||
equalsObjectDetectionResult:
|
equalsObjectDetectorResult:
|
||||||
(MPPObjectDetectionResult *)expectedObjectDetectionResult {
|
(MPPObjectDetectorResult *)expectedObjectDetectorResult {
|
||||||
MPPImage *mppImage = [self imageWithFileInfo:fileInfo];
|
MPPImage *mppImage = [self imageWithFileInfo:fileInfo];
|
||||||
|
|
||||||
[self assertResultsOfDetectInImage:mppImage
|
[self assertResultsOfDetectInImage:mppImage
|
||||||
usingObjectDetector:objectDetector
|
usingObjectDetector:objectDetector
|
||||||
maxResults:maxResults
|
maxResults:maxResults
|
||||||
equalsObjectDetectionResult:expectedObjectDetectionResult];
|
equalsObjectDetectorResult:expectedObjectDetectorResult];
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark General Tests
|
#pragma mark General Tests
|
||||||
|
@ -266,10 +265,10 @@ static NSString *const kLiveStreamTestsDictExpectationKey = @"expectation";
|
||||||
[self assertResultsOfDetectInImageWithFileInfo:kCatsAndDogsImage
|
[self assertResultsOfDetectInImageWithFileInfo:kCatsAndDogsImage
|
||||||
usingObjectDetector:objectDetector
|
usingObjectDetector:objectDetector
|
||||||
maxResults:-1
|
maxResults:-1
|
||||||
equalsObjectDetectionResult:
|
equalsObjectDetectorResult:
|
||||||
[MPPObjectDetectorTests
|
[MPPObjectDetectorTests
|
||||||
expectedDetectionResultForCatsAndDogsImageWithTimestampInMilliseconds:
|
expectedDetectionResultForCatsAndDogsImageWithTimestampInMilliseconds:
|
||||||
0]];
|
0]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)testDetectWithOptionsSucceeds {
|
- (void)testDetectWithOptionsSucceeds {
|
||||||
|
@ -280,10 +279,10 @@ static NSString *const kLiveStreamTestsDictExpectationKey = @"expectation";
|
||||||
[self assertResultsOfDetectInImageWithFileInfo:kCatsAndDogsImage
|
[self assertResultsOfDetectInImageWithFileInfo:kCatsAndDogsImage
|
||||||
usingObjectDetector:objectDetector
|
usingObjectDetector:objectDetector
|
||||||
maxResults:-1
|
maxResults:-1
|
||||||
equalsObjectDetectionResult:
|
equalsObjectDetectorResult:
|
||||||
[MPPObjectDetectorTests
|
[MPPObjectDetectorTests
|
||||||
expectedDetectionResultForCatsAndDogsImageWithTimestampInMilliseconds:
|
expectedDetectionResultForCatsAndDogsImageWithTimestampInMilliseconds:
|
||||||
0]];
|
0]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)testDetectWithMaxResultsSucceeds {
|
- (void)testDetectWithMaxResultsSucceeds {
|
||||||
|
@ -297,10 +296,10 @@ static NSString *const kLiveStreamTestsDictExpectationKey = @"expectation";
|
||||||
[self assertResultsOfDetectInImageWithFileInfo:kCatsAndDogsImage
|
[self assertResultsOfDetectInImageWithFileInfo:kCatsAndDogsImage
|
||||||
usingObjectDetector:objectDetector
|
usingObjectDetector:objectDetector
|
||||||
maxResults:maxResults
|
maxResults:maxResults
|
||||||
equalsObjectDetectionResult:
|
equalsObjectDetectorResult:
|
||||||
[MPPObjectDetectorTests
|
[MPPObjectDetectorTests
|
||||||
expectedDetectionResultForCatsAndDogsImageWithTimestampInMilliseconds:
|
expectedDetectionResultForCatsAndDogsImageWithTimestampInMilliseconds:
|
||||||
0]];
|
0]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)testDetectWithScoreThresholdSucceeds {
|
- (void)testDetectWithScoreThresholdSucceeds {
|
||||||
|
@ -316,13 +315,13 @@ static NSString *const kLiveStreamTestsDictExpectationKey = @"expectation";
|
||||||
boundingBox:CGRectMake(608, 161, 381, 439)
|
boundingBox:CGRectMake(608, 161, 381, 439)
|
||||||
keypoints:nil],
|
keypoints:nil],
|
||||||
];
|
];
|
||||||
MPPObjectDetectionResult *expectedObjectDetectionResult =
|
MPPObjectDetectorResult *expectedObjectDetectorResult =
|
||||||
[[MPPObjectDetectionResult alloc] initWithDetections:detections timestampInMilliseconds:0];
|
[[MPPObjectDetectorResult alloc] initWithDetections:detections timestampInMilliseconds:0];
|
||||||
|
|
||||||
[self assertResultsOfDetectInImageWithFileInfo:kCatsAndDogsImage
|
[self assertResultsOfDetectInImageWithFileInfo:kCatsAndDogsImage
|
||||||
usingObjectDetector:objectDetector
|
usingObjectDetector:objectDetector
|
||||||
maxResults:-1
|
maxResults:-1
|
||||||
equalsObjectDetectionResult:expectedObjectDetectionResult];
|
equalsObjectDetectorResult:expectedObjectDetectorResult];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)testDetectWithCategoryAllowlistSucceeds {
|
- (void)testDetectWithCategoryAllowlistSucceeds {
|
||||||
|
@ -359,13 +358,13 @@ static NSString *const kLiveStreamTestsDictExpectationKey = @"expectation";
|
||||||
keypoints:nil],
|
keypoints:nil],
|
||||||
];
|
];
|
||||||
|
|
||||||
MPPObjectDetectionResult *expectedDetectionResult =
|
MPPObjectDetectorResult *expectedDetectionResult =
|
||||||
[[MPPObjectDetectionResult alloc] initWithDetections:detections timestampInMilliseconds:0];
|
[[MPPObjectDetectorResult alloc] initWithDetections:detections timestampInMilliseconds:0];
|
||||||
|
|
||||||
[self assertResultsOfDetectInImageWithFileInfo:kCatsAndDogsImage
|
[self assertResultsOfDetectInImageWithFileInfo:kCatsAndDogsImage
|
||||||
usingObjectDetector:objectDetector
|
usingObjectDetector:objectDetector
|
||||||
maxResults:-1
|
maxResults:-1
|
||||||
equalsObjectDetectionResult:expectedDetectionResult];
|
equalsObjectDetectorResult:expectedDetectionResult];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)testDetectWithCategoryDenylistSucceeds {
|
- (void)testDetectWithCategoryDenylistSucceeds {
|
||||||
|
@ -414,13 +413,13 @@ static NSString *const kLiveStreamTestsDictExpectationKey = @"expectation";
|
||||||
keypoints:nil],
|
keypoints:nil],
|
||||||
];
|
];
|
||||||
|
|
||||||
MPPObjectDetectionResult *expectedDetectionResult =
|
MPPObjectDetectorResult *expectedDetectionResult =
|
||||||
[[MPPObjectDetectionResult alloc] initWithDetections:detections timestampInMilliseconds:0];
|
[[MPPObjectDetectorResult alloc] initWithDetections:detections timestampInMilliseconds:0];
|
||||||
|
|
||||||
[self assertResultsOfDetectInImageWithFileInfo:kCatsAndDogsImage
|
[self assertResultsOfDetectInImageWithFileInfo:kCatsAndDogsImage
|
||||||
usingObjectDetector:objectDetector
|
usingObjectDetector:objectDetector
|
||||||
maxResults:-1
|
maxResults:-1
|
||||||
equalsObjectDetectionResult:expectedDetectionResult];
|
equalsObjectDetectorResult:expectedDetectionResult];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)testDetectWithOrientationSucceeds {
|
- (void)testDetectWithOrientationSucceeds {
|
||||||
|
@ -437,8 +436,8 @@ static NSString *const kLiveStreamTestsDictExpectationKey = @"expectation";
|
||||||
keypoints:nil],
|
keypoints:nil],
|
||||||
];
|
];
|
||||||
|
|
||||||
MPPObjectDetectionResult *expectedDetectionResult =
|
MPPObjectDetectorResult *expectedDetectionResult =
|
||||||
[[MPPObjectDetectionResult alloc] initWithDetections:detections timestampInMilliseconds:0];
|
[[MPPObjectDetectorResult alloc] initWithDetections:detections timestampInMilliseconds:0];
|
||||||
|
|
||||||
MPPImage *image = [self imageWithFileInfo:kCatsAndDogsRotatedImage
|
MPPImage *image = [self imageWithFileInfo:kCatsAndDogsRotatedImage
|
||||||
orientation:UIImageOrientationRight];
|
orientation:UIImageOrientationRight];
|
||||||
|
@ -446,7 +445,7 @@ static NSString *const kLiveStreamTestsDictExpectationKey = @"expectation";
|
||||||
[self assertResultsOfDetectInImage:image
|
[self assertResultsOfDetectInImage:image
|
||||||
usingObjectDetector:objectDetector
|
usingObjectDetector:objectDetector
|
||||||
maxResults:1
|
maxResults:1
|
||||||
equalsObjectDetectionResult:expectedDetectionResult];
|
equalsObjectDetectorResult:expectedDetectionResult];
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark Running Mode Tests
|
#pragma mark Running Mode Tests
|
||||||
|
@ -613,15 +612,15 @@ static NSString *const kLiveStreamTestsDictExpectationKey = @"expectation";
|
||||||
MPPImage *image = [self imageWithFileInfo:kCatsAndDogsImage];
|
MPPImage *image = [self imageWithFileInfo:kCatsAndDogsImage];
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
MPPObjectDetectionResult *objectDetectionResult = [objectDetector detectInVideoFrame:image
|
MPPObjectDetectorResult *ObjectDetectorResult = [objectDetector detectInVideoFrame:image
|
||||||
timestampInMilliseconds:i
|
timestampInMilliseconds:i
|
||||||
error:nil];
|
error:nil];
|
||||||
|
|
||||||
[self assertObjectDetectionResult:objectDetectionResult
|
[self assertObjectDetectorResult:ObjectDetectorResult
|
||||||
isEqualToExpectedResult:
|
isEqualToExpectedResult:
|
||||||
[MPPObjectDetectorTests
|
[MPPObjectDetectorTests
|
||||||
expectedDetectionResultForCatsAndDogsImageWithTimestampInMilliseconds:i]
|
expectedDetectionResultForCatsAndDogsImageWithTimestampInMilliseconds:i]
|
||||||
expectedDetectionsCount:maxResults];
|
expectedDetectionsCount:maxResults];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -714,16 +713,16 @@ static NSString *const kLiveStreamTestsDictExpectationKey = @"expectation";
|
||||||
|
|
||||||
#pragma mark MPPObjectDetectorLiveStreamDelegate Methods
|
#pragma mark MPPObjectDetectorLiveStreamDelegate Methods
|
||||||
- (void)objectDetector:(MPPObjectDetector *)objectDetector
|
- (void)objectDetector:(MPPObjectDetector *)objectDetector
|
||||||
didFinishDetectionWithResult:(MPPObjectDetectionResult *)objectDetectionResult
|
didFinishDetectionWithResult:(MPPObjectDetectorResult *)ObjectDetectorResult
|
||||||
timestampInMilliseconds:(NSInteger)timestampInMilliseconds
|
timestampInMilliseconds:(NSInteger)timestampInMilliseconds
|
||||||
error:(NSError *)error {
|
error:(NSError *)error {
|
||||||
NSInteger maxResults = 4;
|
NSInteger maxResults = 4;
|
||||||
[self assertObjectDetectionResult:objectDetectionResult
|
[self assertObjectDetectorResult:ObjectDetectorResult
|
||||||
isEqualToExpectedResult:
|
isEqualToExpectedResult:
|
||||||
[MPPObjectDetectorTests
|
[MPPObjectDetectorTests
|
||||||
expectedDetectionResultForCatsAndDogsImageWithTimestampInMilliseconds:
|
expectedDetectionResultForCatsAndDogsImageWithTimestampInMilliseconds:
|
||||||
timestampInMilliseconds]
|
timestampInMilliseconds]
|
||||||
expectedDetectionsCount:maxResults];
|
expectedDetectionsCount:maxResults];
|
||||||
|
|
||||||
if (objectDetector == outOfOrderTimestampTestDict[kLiveStreamTestsDictObjectDetectorKey]) {
|
if (objectDetector == outOfOrderTimestampTestDict[kLiveStreamTestsDictObjectDetectorKey]) {
|
||||||
[outOfOrderTimestampTestDict[kLiveStreamTestsDictExpectationKey] fulfill];
|
[outOfOrderTimestampTestDict[kLiveStreamTestsDictExpectationKey] fulfill];
|
||||||
|
|
|
@ -17,9 +17,9 @@ package(default_visibility = ["//mediapipe/tasks:internal"])
|
||||||
licenses(["notice"])
|
licenses(["notice"])
|
||||||
|
|
||||||
objc_library(
|
objc_library(
|
||||||
name = "MPPObjectDetectionResult",
|
name = "MPPObjectDetectorResult",
|
||||||
srcs = ["sources/MPPObjectDetectionResult.m"],
|
srcs = ["sources/MPPObjectDetectorResult.m"],
|
||||||
hdrs = ["sources/MPPObjectDetectionResult.h"],
|
hdrs = ["sources/MPPObjectDetectorResult.h"],
|
||||||
deps = [
|
deps = [
|
||||||
"//mediapipe/tasks/ios/components/containers:MPPDetection",
|
"//mediapipe/tasks/ios/components/containers:MPPDetection",
|
||||||
"//mediapipe/tasks/ios/core:MPPTaskResult",
|
"//mediapipe/tasks/ios/core:MPPTaskResult",
|
||||||
|
@ -31,7 +31,7 @@ objc_library(
|
||||||
srcs = ["sources/MPPObjectDetectorOptions.m"],
|
srcs = ["sources/MPPObjectDetectorOptions.m"],
|
||||||
hdrs = ["sources/MPPObjectDetectorOptions.h"],
|
hdrs = ["sources/MPPObjectDetectorOptions.h"],
|
||||||
deps = [
|
deps = [
|
||||||
":MPPObjectDetectionResult",
|
":MPPObjectDetectorResult",
|
||||||
"//mediapipe/tasks/ios/core:MPPTaskOptions",
|
"//mediapipe/tasks/ios/core:MPPTaskOptions",
|
||||||
"//mediapipe/tasks/ios/vision/core:MPPRunningMode",
|
"//mediapipe/tasks/ios/vision/core:MPPRunningMode",
|
||||||
],
|
],
|
||||||
|
@ -47,8 +47,8 @@ objc_library(
|
||||||
"-x objective-c++",
|
"-x objective-c++",
|
||||||
],
|
],
|
||||||
deps = [
|
deps = [
|
||||||
":MPPObjectDetectionResult",
|
|
||||||
":MPPObjectDetectorOptions",
|
":MPPObjectDetectorOptions",
|
||||||
|
":MPPObjectDetectorResult",
|
||||||
"//mediapipe/tasks/cc/vision/object_detector:object_detector_graph",
|
"//mediapipe/tasks/cc/vision/object_detector:object_detector_graph",
|
||||||
"//mediapipe/tasks/ios/common/utils:MPPCommonUtils",
|
"//mediapipe/tasks/ios/common/utils:MPPCommonUtils",
|
||||||
"//mediapipe/tasks/ios/common/utils:NSStringHelpers",
|
"//mediapipe/tasks/ios/common/utils:NSStringHelpers",
|
||||||
|
@ -56,7 +56,7 @@ objc_library(
|
||||||
"//mediapipe/tasks/ios/vision/core:MPPImage",
|
"//mediapipe/tasks/ios/vision/core:MPPImage",
|
||||||
"//mediapipe/tasks/ios/vision/core:MPPVisionPacketCreator",
|
"//mediapipe/tasks/ios/vision/core:MPPVisionPacketCreator",
|
||||||
"//mediapipe/tasks/ios/vision/core:MPPVisionTaskRunner",
|
"//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:MPPObjectDetectorOptionsHelpers",
|
||||||
|
"//mediapipe/tasks/ios/vision/object_detector/utils:MPPObjectDetectorResultHelpers",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
|
@ -15,8 +15,8 @@
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
#import "mediapipe/tasks/ios/vision/core/sources/MPPImage.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/MPPObjectDetectorOptions.h"
|
||||||
|
#import "mediapipe/tasks/ios/vision/object_detector/sources/MPPObjectDetectorResult.h"
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_BEGIN
|
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
|
* @param error An optional error parameter populated when there is an error in performing object
|
||||||
* detection on the input image.
|
* 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
|
* 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
|
* system, i.e. in `[0,image_width) x [0,image_height)`, which are the dimensions of the underlying
|
||||||
* image data.
|
* image data.
|
||||||
*/
|
*/
|
||||||
- (nullable MPPObjectDetectionResult *)detectInImage:(MPPImage *)image
|
- (nullable MPPObjectDetectorResult *)detectInImage:(MPPImage *)image
|
||||||
error:(NSError **)error
|
error:(NSError **)error NS_SWIFT_NAME(detect(image:));
|
||||||
NS_SWIFT_NAME(detect(image:));
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs object detection on the provided video frame of type `MPPImage` using the whole
|
* 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
|
* @param error An optional error parameter populated when there is an error in performing object
|
||||||
* detection on the input image.
|
* 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
|
* 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
|
* system, i.e. in `[0,image_width) x [0,image_height)`, which are the dimensions of the underlying
|
||||||
* image data.
|
* image data.
|
||||||
*/
|
*/
|
||||||
- (nullable MPPObjectDetectionResult *)detectInVideoFrame:(MPPImage *)image
|
- (nullable MPPObjectDetectorResult *)detectInVideoFrame:(MPPImage *)image
|
||||||
timestampInMilliseconds:(NSInteger)timestampInMilliseconds
|
timestampInMilliseconds:(NSInteger)timestampInMilliseconds
|
||||||
error:(NSError **)error
|
error:(NSError **)error
|
||||||
NS_SWIFT_NAME(detect(videoFrame:timestampInMilliseconds:));
|
NS_SWIFT_NAME(detect(videoFrame:timestampInMilliseconds:));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -19,8 +19,8 @@
|
||||||
#import "mediapipe/tasks/ios/core/sources/MPPTaskInfo.h"
|
#import "mediapipe/tasks/ios/core/sources/MPPTaskInfo.h"
|
||||||
#import "mediapipe/tasks/ios/vision/core/sources/MPPVisionPacketCreator.h"
|
#import "mediapipe/tasks/ios/vision/core/sources/MPPVisionPacketCreator.h"
|
||||||
#import "mediapipe/tasks/ios/vision/core/sources/MPPVisionTaskRunner.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/MPPObjectDetectorOptions+Helpers.h"
|
||||||
|
#import "mediapipe/tasks/ios/vision/object_detector/utils/sources/MPPObjectDetectorResult+Helpers.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
using ::mediapipe::NormalizedRect;
|
using ::mediapipe::NormalizedRect;
|
||||||
|
@ -118,9 +118,9 @@ static NSString *const kTaskName = @"objectDetector";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
MPPObjectDetectionResult *result = [MPPObjectDetectionResult
|
MPPObjectDetectorResult *result = [MPPObjectDetectorResult
|
||||||
objectDetectionResultWithDetectionsPacket:statusOrPackets.value()[kDetectionsStreamName
|
objectDetectorResultWithDetectionsPacket:statusOrPackets
|
||||||
.cppString]];
|
.value()[kDetectionsStreamName.cppString]];
|
||||||
|
|
||||||
NSInteger timeStampInMilliseconds =
|
NSInteger timeStampInMilliseconds =
|
||||||
outputPacketMap[kImageOutStreamName.cppString].Timestamp().Value() /
|
outputPacketMap[kImageOutStreamName.cppString].Timestamp().Value() /
|
||||||
|
@ -184,9 +184,9 @@ static NSString *const kTaskName = @"objectDetector";
|
||||||
return inputPacketMap;
|
return inputPacketMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (nullable MPPObjectDetectionResult *)detectInImage:(MPPImage *)image
|
- (nullable MPPObjectDetectorResult *)detectInImage:(MPPImage *)image
|
||||||
regionOfInterest:(CGRect)roi
|
regionOfInterest:(CGRect)roi
|
||||||
error:(NSError **)error {
|
error:(NSError **)error {
|
||||||
std::optional<NormalizedRect> rect =
|
std::optional<NormalizedRect> rect =
|
||||||
[_visionTaskRunner normalizedRectFromRegionOfInterest:roi
|
[_visionTaskRunner normalizedRectFromRegionOfInterest:roi
|
||||||
imageSize:CGSizeMake(image.width, image.height)
|
imageSize:CGSizeMake(image.width, image.height)
|
||||||
|
@ -213,18 +213,18 @@ static NSString *const kTaskName = @"objectDetector";
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
return [MPPObjectDetectionResult
|
return [MPPObjectDetectorResult
|
||||||
objectDetectionResultWithDetectionsPacket:outputPacketMap
|
objectDetectorResultWithDetectionsPacket:outputPacketMap
|
||||||
.value()[kDetectionsStreamName.cppString]];
|
.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];
|
return [self detectInImage:image regionOfInterest:CGRectZero error:error];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (nullable MPPObjectDetectionResult *)detectInVideoFrame:(MPPImage *)image
|
- (nullable MPPObjectDetectorResult *)detectInVideoFrame:(MPPImage *)image
|
||||||
timestampInMilliseconds:(NSInteger)timestampInMilliseconds
|
timestampInMilliseconds:(NSInteger)timestampInMilliseconds
|
||||||
error:(NSError **)error {
|
error:(NSError **)error {
|
||||||
std::optional<PacketMap> inputPacketMap = [self inputPacketMapWithMPPImage:image
|
std::optional<PacketMap> inputPacketMap = [self inputPacketMapWithMPPImage:image
|
||||||
timestampInMilliseconds:timestampInMilliseconds
|
timestampInMilliseconds:timestampInMilliseconds
|
||||||
error:error];
|
error:error];
|
||||||
|
@ -239,9 +239,9 @@ static NSString *const kTaskName = @"objectDetector";
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
return [MPPObjectDetectionResult
|
return [MPPObjectDetectorResult
|
||||||
objectDetectionResultWithDetectionsPacket:outputPacketMap
|
objectDetectorResultWithDetectionsPacket:outputPacketMap
|
||||||
.value()[kDetectionsStreamName.cppString]];
|
.value()[kDetectionsStreamName.cppString]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)detectAsyncInImage:(MPPImage *)image
|
- (BOOL)detectAsyncInImage:(MPPImage *)image
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
#import "mediapipe/tasks/ios/core/sources/MPPTaskOptions.h"
|
#import "mediapipe/tasks/ios/core/sources/MPPTaskOptions.h"
|
||||||
#import "mediapipe/tasks/ios/vision/core/sources/MPPRunningMode.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
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ NS_SWIFT_NAME(ObjectDetectorLiveStreamDelegate)
|
||||||
*
|
*
|
||||||
* @param objectDetector The object detector which performed the object detection.
|
* @param objectDetector The object detector which performed the object detection.
|
||||||
* This is useful to test equality when there are multiple instances of `MPPObjectDetector`.
|
* 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
|
* 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
|
* coordinates system, i.e. in `[0,image_width) x [0,image_height)`, which are the dimensions of the
|
||||||
* underlying image data.
|
* underlying image data.
|
||||||
|
@ -54,7 +54,7 @@ NS_SWIFT_NAME(ObjectDetectorLiveStreamDelegate)
|
||||||
* detection on the input live stream image data.
|
* detection on the input live stream image data.
|
||||||
*/
|
*/
|
||||||
- (void)objectDetector:(MPPObjectDetector *)objectDetector
|
- (void)objectDetector:(MPPObjectDetector *)objectDetector
|
||||||
didFinishDetectionWithResult:(nullable MPPObjectDetectionResult *)result
|
didFinishDetectionWithResult:(nullable MPPObjectDetectorResult *)result
|
||||||
timestampInMilliseconds:(NSInteger)timestampInMilliseconds
|
timestampInMilliseconds:(NSInteger)timestampInMilliseconds
|
||||||
error:(nullable NSError *)error
|
error:(nullable NSError *)error
|
||||||
NS_SWIFT_NAME(objectDetector(_:didFinishDetection:timestampInMilliseconds:error:));
|
NS_SWIFT_NAME(objectDetector(_:didFinishDetection:timestampInMilliseconds:error:));
|
||||||
|
|
|
@ -19,8 +19,8 @@
|
||||||
NS_ASSUME_NONNULL_BEGIN
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
/** Represents the detection results generated by `MPPObjectDetector`. */
|
/** Represents the detection results generated by `MPPObjectDetector`. */
|
||||||
NS_SWIFT_NAME(ObjectDetectionResult)
|
NS_SWIFT_NAME(ObjectDetectorResult)
|
||||||
@interface MPPObjectDetectionResult : MPPTaskResult
|
@interface MPPObjectDetectorResult : MPPTaskResult
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The array of `MPPDetection` objects each of which has a bounding box that is expressed in the
|
* 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;
|
@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).
|
* milliseconds).
|
||||||
*
|
*
|
||||||
* @param detections An array of `MPPDetection` objects each of which has a bounding box that is
|
* @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.
|
* x [0,image_height)`, which are the dimensions of the underlying image data.
|
||||||
* @param timestampInMilliseconds The timestamp (in milliseconds) for this result.
|
* @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).
|
* and timestamp (in milliseconds).
|
||||||
*/
|
*/
|
||||||
- (instancetype)initWithDetections:(NSArray<MPPDetection *> *)detections
|
- (instancetype)initWithDetections:(NSArray<MPPDetection *> *)detections
|
|
@ -12,9 +12,9 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// 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
|
- (instancetype)initWithDetections:(NSArray<MPPDetection *> *)detections
|
||||||
timestampInMilliseconds:(NSInteger)timestampInMilliseconds {
|
timestampInMilliseconds:(NSInteger)timestampInMilliseconds {
|
|
@ -31,12 +31,12 @@ objc_library(
|
||||||
)
|
)
|
||||||
|
|
||||||
objc_library(
|
objc_library(
|
||||||
name = "MPPObjectDetectionResultHelpers",
|
name = "MPPObjectDetectorResultHelpers",
|
||||||
srcs = ["sources/MPPObjectDetectionResult+Helpers.mm"],
|
srcs = ["sources/MPPObjectDetectorResult+Helpers.mm"],
|
||||||
hdrs = ["sources/MPPObjectDetectionResult+Helpers.h"],
|
hdrs = ["sources/MPPObjectDetectorResult+Helpers.h"],
|
||||||
deps = [
|
deps = [
|
||||||
"//mediapipe/framework:packet",
|
"//mediapipe/framework:packet",
|
||||||
"//mediapipe/tasks/ios/components/containers/utils:MPPDetectionHelpers",
|
"//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
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// 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"
|
#include "mediapipe/framework/packet.h"
|
||||||
|
|
||||||
|
@ -20,17 +20,17 @@ NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
static const int kMicroSecondsPerMilliSecond = 1000;
|
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>`.
|
* `std::vector<DetectionProto>`.
|
||||||
*
|
*
|
||||||
* @param packet a MediaPipe packet wrapping 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;
|
(const mediapipe::Packet &)packet;
|
||||||
|
|
||||||
@end
|
@end
|
|
@ -12,7 +12,7 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// 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"
|
#import "mediapipe/tasks/ios/components/containers/utils/sources/MPPDetection+Helpers.h"
|
||||||
|
|
||||||
|
@ -21,9 +21,9 @@ using DetectionProto = ::mediapipe::Detection;
|
||||||
using ::mediapipe::Packet;
|
using ::mediapipe::Packet;
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
@implementation MPPObjectDetectionResult (Helpers)
|
@implementation MPPObjectDetectorResult (Helpers)
|
||||||
|
|
||||||
+ (nullable MPPObjectDetectionResult *)objectDetectionResultWithDetectionsPacket:
|
+ (nullable MPPObjectDetectorResult *)objectDetectorResultWithDetectionsPacket:
|
||||||
(const Packet &)packet {
|
(const Packet &)packet {
|
||||||
if (!packet.ValidateAsType<std::vector<DetectionProto>>().ok()) {
|
if (!packet.ValidateAsType<std::vector<DetectionProto>>().ok()) {
|
||||||
return nil;
|
return nil;
|
||||||
|
@ -37,10 +37,10 @@ using ::mediapipe::Packet;
|
||||||
[detections addObject:[MPPDetection detectionWithProto:detectionProto]];
|
[detections addObject:[MPPDetection detectionWithProto:detectionProto]];
|
||||||
}
|
}
|
||||||
|
|
||||||
return [[MPPObjectDetectionResult alloc]
|
return
|
||||||
initWithDetections:detections
|
[[MPPObjectDetectorResult alloc] initWithDetections:detections
|
||||||
timestampInMilliseconds:(NSInteger)(packet.Timestamp().Value() /
|
timestampInMilliseconds:(NSInteger)(packet.Timestamp().Value() /
|
||||||
kMicroSecondsPerMilliSecond)];
|
kMicroSecondsPerMilliSecond)];
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
Loading…
Reference in New Issue
Block a user