Merge pull request #4456 from priankakariatyml:ios-code-review-fixes

PiperOrigin-RevId: 534957807
This commit is contained in:
Copybara-Service 2023-05-24 13:22:31 -07:00
commit b84e6f97dd
2 changed files with 12 additions and 9 deletions

View File

@ -80,7 +80,7 @@ NS_SWIFT_NAME(ObjectDetector)
* Creates a new instance of `MPPObjectDetector` from the given `MPPObjectDetectorOptions`. * Creates a new instance of `MPPObjectDetector` from the given `MPPObjectDetectorOptions`.
* *
* @param options The options of type `MPPObjectDetectorOptions` to use for configuring the * @param options The options of type `MPPObjectDetectorOptions` to use for configuring the
* `MPPImageClassifMPPObjectDetectorier`. * `MPPObjectDetector`.
* @param error An optional error parameter populated when there is an error in initializing the * @param error An optional error parameter populated when there is an error in initializing the
* object detector. * object detector.
* *
@ -96,7 +96,7 @@ NS_SWIFT_NAME(ObjectDetector)
* `MPPImage`. Only use this method when the `MPPObjectDetector` is created with * `MPPImage`. Only use this method when the `MPPObjectDetector` is created with
* `MPPRunningModeImage`. * `MPPRunningModeImage`.
* *
* This method supports classification of RGBA images. If your `MPPImage` has a source type of * This method supports detecting objects in RGBA images. If your `MPPImage` has a source type of
* `MPPImageSourceTypePixelBuffer` or `MPPImageSourceTypeSampleBuffer`, the underlying pixel buffer * `MPPImageSourceTypePixelBuffer` or `MPPImageSourceTypeSampleBuffer`, the underlying pixel buffer
* must have one of the following pixel format types: * must have one of the following pixel format types:
* 1. kCVPixelFormatType_32BGRA * 1. kCVPixelFormatType_32BGRA
@ -123,7 +123,7 @@ NS_SWIFT_NAME(ObjectDetector)
* the provided `MPPImage`. Only use this method when the `MPPObjectDetector` is created with * the provided `MPPImage`. Only use this method when the `MPPObjectDetector` is created with
* `MPPRunningModeVideo`. * `MPPRunningModeVideo`.
* *
* This method supports classification of RGBA images. If your `MPPImage` has a source type of * This method supports detecting objects in of RGBA images. If your `MPPImage` has a source type of
* `MPPImageSourceTypePixelBuffer` or `MPPImageSourceTypeSampleBuffer`, the underlying pixel buffer * `MPPImageSourceTypePixelBuffer` or `MPPImageSourceTypeSampleBuffer`, the underlying pixel buffer
* must have one of the following pixel format types: * must have one of the following pixel format types:
* 1. kCVPixelFormatType_32BGRA * 1. kCVPixelFormatType_32BGRA
@ -161,7 +161,7 @@ NS_SWIFT_NAME(ObjectDetector)
* It's required to provide a timestamp (in milliseconds) to indicate when the input image is sent * It's required to provide a timestamp (in milliseconds) to indicate when the input image is sent
* to the object detector. The input timestamps must be monotonically increasing. * to the object detector. The input timestamps must be monotonically increasing.
* *
* This method supports classification of RGBA images. If your `MPPImage` has a source type of * This method supports detecting objects in RGBA images. If your `MPPImage` has a source type of
* `MPPImageSourceTypePixelBuffer` or `MPPImageSourceTypeSampleBuffer`, the underlying pixel buffer * `MPPImageSourceTypePixelBuffer` or `MPPImageSourceTypeSampleBuffer`, the underlying pixel buffer
* must have one of the following pixel format types: * must have one of the following pixel format types:
* 1. kCVPixelFormatType_32BGRA * 1. kCVPixelFormatType_32BGRA
@ -170,8 +170,8 @@ NS_SWIFT_NAME(ObjectDetector)
* If the input `MPPImage` has a source type of `MPPImageSourceTypeImage` ensure that the color * If the input `MPPImage` has a source type of `MPPImageSourceTypeImage` ensure that the color
* space is RGB with an Alpha channel. * space is RGB with an Alpha channel.
* *
* If this method is used for classifying live camera frames using `AVFoundation`, ensure that you * If this method is used for detecting objects in live camera frames using `AVFoundation`, ensure
* request `AVCaptureVideoDataOutput` to output frames in `kCMPixelFormat_32RGBA` using its * that you request `AVCaptureVideoDataOutput` to output frames in `kCMPixelFormat_32RGBA` using its
* `videoSettings` property. * `videoSettings` property.
* *
* @param image A live stream image data of type `MPPImage` on which object detection is to be * @param image A live stream image data of type `MPPImage` on which object detection is to be

View File

@ -25,8 +25,12 @@ using ::mediapipe::Packet;
+ (nullable MPPObjectDetectorResult *)objectDetectorResultWithDetectionsPacket: + (nullable MPPObjectDetectorResult *)objectDetectorResultWithDetectionsPacket:
(const Packet &)packet { (const Packet &)packet {
NSInteger timestampInMilliseconds = (NSInteger)(packet.Timestamp().Value() /
kMicroSecondsPerMilliSecond);
if (!packet.ValidateAsType<std::vector<DetectionProto>>().ok()) { if (!packet.ValidateAsType<std::vector<DetectionProto>>().ok()) {
return nil; return [[MPPObjectDetectorResult alloc] initWithDetections:@[]
timestampInMilliseconds:timestampInMilliseconds];
} }
const std::vector<DetectionProto> &detectionProtos = packet.Get<std::vector<DetectionProto>>(); const std::vector<DetectionProto> &detectionProtos = packet.Get<std::vector<DetectionProto>>();
@ -39,8 +43,7 @@ using ::mediapipe::Packet;
return return
[[MPPObjectDetectorResult alloc] initWithDetections:detections [[MPPObjectDetectorResult alloc] initWithDetections:detections
timestampInMilliseconds:(NSInteger)(packet.Timestamp().Value() / timestampInMilliseconds:timestampInMilliseconds];
kMicroSecondsPerMilliSecond)];
} }
@end @end