Added iOS region of interest helpers

This commit is contained in:
Prianka Liz Kariat 2023-11-30 02:31:11 +05:30
parent 4137dbcbf5
commit 4c02980b3f
3 changed files with 104 additions and 0 deletions

View File

@ -16,6 +16,7 @@ package(default_visibility = ["//mediapipe/tasks:internal"])
licenses(["notice"])
objc_library(
name = "MPPCategoryHelpers",
srcs = ["sources/MPPCategory+Helpers.mm"],
@ -84,3 +85,15 @@ objc_library(
"//mediapipe/tasks/ios/components/containers:MPPLandmark",
],
)
objc_library(
name = "MPPRegionOfInterestHelpers",
srcs = ["sources/MPPRegionOfInterest+Helpers.mm"],
hdrs = ["sources/MPPRegionOfInterest+Helpers.h"],
deps = [
"//mediapipe/util:render_data_cc_proto",
"//mediapipe/tasks/ios/common:MPPCommon",
"//mediapipe/tasks/ios/common/utils:MPPCommonUtils",
"//mediapipe/tasks/ios/components/containers:MPPRegionOfInterest",
],
)

View File

@ -0,0 +1,35 @@
// Copyright 2023 The MediaPipe Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "mediapipe/util/render_data.pb.h"
#import "mediapipe/tasks/ios/components/containers/sources/MPPRegionOfInterest.h"
NS_ASSUME_NONNULL_BEGIN
@interface MPPRegionOfInterest (Helpers)
/**
* Creates a `RenderData` from the region of interest.
*
* @param error Pointer to the memory location where errors if any should be saved. If @c NULL, no
* error will be saved.
*
* @return A `RenderData1 proto created from the region of interest.
*/
- (std::optional<mediapipe::RenderData>)getRenderDataWithError:(NSError **)error;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,56 @@
// Copyright 2023 The MediaPipe Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#import "mediapipe/tasks/ios/common/sources/MPPCommon.h"
#import "mediapipe/tasks/ios/common/utils/sources/MPPCommonUtils.h"
#import "mediapipe/tasks/ios/components/containers/utils/sources/MPPRegionOfInterest+Helpers.h"
namespace {
using RenderData = ::mediapipe::RenderData;
using RenderAnnotation = ::mediapipe::RenderAnnotation;
} // namespace
@implementation MPPRegionOfInterest (Helpers)
- (std::optional<mediapipe::RenderData>)getRenderDataWithError:(NSError**)error {
RenderData result;
if (self.keypoint) {
auto* annotation = result.add_render_annotations();
annotation->mutable_color()->set_r(255);
auto* point = annotation->mutable_point();
point->set_normalized(true);
point->set_x(self.keypoint.location.x);
point->set_y(self.keypoint.location.y);
return result;
} else if (self.scribbles) {
auto* annotation = result.add_render_annotations();
annotation->mutable_color()->set_r(255);
for (MPPNormalizedKeypoint* keypoint in self.scribbles) {
auto* point = annotation->mutable_scribble()->add_point();
point->set_normalized(true);
point->set_x(self.keypoint.location.x);
point->set_y(self.keypoint.location.y);
}
return result;
}
[MPPCommonUtils createCustomError:error
withCode:MPPTasksErrorCodeInvalidArgumentError
description:@"RegionOfInterest does not include a valid user interaction."];
return std::nullopt;
}
@end