Updated iOS vision/core to add methods for processing region of interest

This commit is contained in:
Prianka Liz Kariat 2023-11-30 02:31:48 +05:30
parent 4c02980b3f
commit f5ac0637a2
4 changed files with 53 additions and 0 deletions

View File

@ -55,6 +55,8 @@ objc_library(
"//mediapipe/framework/formats:image",
"//mediapipe/framework/formats:rect_cc_proto",
"//mediapipe/tasks/ios/vision/core/utils:MPPImageUtils",
"//mediapipe/tasks/ios/components/containers:MPPRegionOfInterest",
"//mediapipe/tasks/ios/components/containers/utils:MPPRegionOfInterestHelpers",
],
)

View File

@ -14,6 +14,7 @@
#import <Foundation/Foundation.h>
#import "mediapipe/tasks/ios/components/containers/sources/MPPRegionOfInterest.h"
#import "mediapipe/tasks/ios/vision/core/sources/MPPImage.h"
#include "mediapipe/framework/formats/rect.pb.h"
@ -73,4 +74,18 @@
+ (mediapipe::Packet)createPacketWithNormalizedRect:(mediapipe::NormalizedRect &)normalizedRect
timestampInMilliseconds:(NSInteger)timestampInMilliseconds;
/**
* Creates a MediapPipe Packet wrapping a `RenderData` constructed from an `MPPRegionOfInterest`.
*
* @param regionOfInterest The `MPPRegionOfInterest` to send to the MediaPipe graph.
* @param error Pointer to the memory location where errors if any should be saved. If @c NULL, no
* error will be saved.
*
* @return The MediaPipe packet containing the `RenderData` constructed from the given
* `MPPRegionOfInterest`.
*/
+ (std::optional<mediapipe::Packet>)createRenderDataPacketWithRegionOfInterest:
(MPPRegionOfInterest *)regionOfInterest
error:(NSError **)error;
@end

View File

@ -13,6 +13,7 @@
// limitations under the License.
#import "mediapipe/tasks/ios/vision/core/sources/MPPVisionPacketCreator.h"
#import "mediapipe/tasks/ios/components/containers/utils/sources/MPPRegionOfInterest+Helpers.h"
#import "mediapipe/tasks/ios/vision/core/utils/sources/MPPImage+Utils.h"
#include "mediapipe/framework/formats/image.h"
@ -26,6 +27,7 @@ using ::mediapipe::ImageFrame;
using ::mediapipe::MakePacket;
using ::mediapipe::NormalizedRect;
using ::mediapipe::Packet;
using ::mediapipe::RenderData;
using ::mediapipe::Timestamp;
} // namespace
@ -64,4 +66,16 @@ using ::mediapipe::Timestamp;
.At(Timestamp(int64(timestampInMilliseconds * kMicrosecondsPerMillisecond)));
}
+ (std::optional<Packet>)createRenderDataPacketWithRegionOfInterest:
(MPPRegionOfInterest *)regionOfInterest
error:(NSError **)error {
std::optional<RenderData> renderData = [regionOfInterest getRenderDataWithError:error];
if (!renderData.has_value()) {
return std::nullopt;
}
return MakePacket<RenderData>(std::move(renderData.value()));
}
@end

View File

@ -20,6 +20,8 @@
#import "mediapipe/tasks/ios/vision/core/sources/MPPImage.h"
#import "mediapipe/tasks/ios/vision/core/sources/MPPRunningMode.h"
#include "mediapipe/framework/packet.h"
NS_ASSUME_NONNULL_BEGIN
/**
@ -190,6 +192,26 @@ NS_ASSUME_NONNULL_BEGIN
timestampInMilliseconds:(NSInteger)timeStampInMilliseconds
error:(NSError **)error;
/**
* This method creates an input packet map to the C++ task runner with the image and normalized rect
* calculated from the region of interest specified within the bounds of an image. Tasks which need
* to add more entries to the input packet map and build their own custom logic for processing
* images can use this method.
*
* @param image An `MPPImage` input to the task.
* @param regionOfInterest A `CGRect` specifying the region of interest within the given image data
* of type `MPPImage`, on which inference should be performed.
* @param error Pointer to the memory location where errors if any should be saved. If @c NULL, no
* error will be saved.
*
* @return A `BOOL` indicating if the creation of the input packet map with the image and the
* normalized rect calculated from the region of interest was successful.
*/
- (std::optional<std::map<std::string, mediapipe::Packet>>)
inputPacketMapWithMPPImage:(MPPImage *)image
regionOfInterest:(CGRect)roi
error:(NSError **)error;
/**
* This method returns a unique dispatch queue name by adding the given suffix and a `UUID` to the
* pre-defined queue name prefix for vision tasks. The vision tasks can use this method to get