-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bb93b77
commit 21d0004
Showing
2 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
mediapipe/tasks/ios/vision/face_stylizer/sources/MPPFaceStylizer.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
// 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 <Foundation/Foundation.h> | ||
|
||
#import "mediapipe/tasks/ios/vision/core/sources/MPPImage.h" | ||
#import "mediapipe/tasks/ios/vision/face_stylizer/sources/MPPFaceStylizerOptions.h" | ||
#import "mediapipe/tasks/ios/vision/face_stylizer/sources/MPPFaceStylizerResult.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
/** | ||
* Class that performs face stylization on images. | ||
*/ | ||
NS_SWIFT_NAME(FaceStylizer) | ||
@interface MPPFaceStylizer : NSObject | ||
|
||
/** | ||
* Creates a new instance of `FaceStylizer` from an absolute path to a TensorFlow Lite model file | ||
* stored locally on the device and the default `FaceStylizer`. | ||
* | ||
* @param modelPath An absolute path to a TensorFlow Lite model file stored locally on the device. | ||
* | ||
* @return A new instance of `FaceStylizer` with the given model path. `nil` if there is an error in | ||
* initializing the face stylizer. | ||
*/ | ||
- (nullable instancetype)initWithModelPath:(NSString *)modelPath error:(NSError **)error; | ||
|
||
/** | ||
* Creates a new instance of `FaceStylizer` from the given `FaceStylizerOptions`. | ||
* | ||
* @param options The options of type `FaceStylizerOptions` to use for configuring the | ||
* `FaceStylizer`. | ||
* | ||
* @return A new instance of `FaceStylizer` with the given options. `nil` if there is an error in | ||
* initializing the face stylizer. | ||
*/ | ||
- (nullable instancetype)initWithOptions:(MPPFaceStylizerOptions *)options | ||
error:(NSError **)error NS_DESIGNATED_INITIALIZER; | ||
|
||
/** | ||
* Performs face stylization on the provided `MPImage` and returns a `MPPFaceStylizerResult` | ||
* containing a copy of the stylized image. This method should not be used in high-throughput | ||
* applications since the returned image is copied. Rotation will be applied according to the | ||
* `orientation` property of the provided `MPImage`. | ||
* | ||
* This method supports RGBA images. If your `MPPImage` has a source type of `.pixelBuffer` or | ||
* `.sampleBuffer`, the underlying pixel buffer must have one of the following pixel format types: | ||
* 1. kCVPixelFormatType_32BGRA | ||
* 2. kCVPixelFormatType_32RGBA | ||
* | ||
* If your `MPImage` has a source type of `.image` ensure that the color space is RGB with an | ||
* Alpha channel. | ||
* | ||
* @param image The `MPImage` on which face stylization is to be performed. | ||
* | ||
* @return A `FaceStylizerResult` that contains the stylized image of the most visible face. The | ||
* returned image is copied. The stylized output image size is the same as the model output | ||
* size. The `stylizedImage` of the `FaceStylizerResult` is `nil` if there is no face detected in | ||
* the imput image. `FaceStylizerResult` is `nil` if there is an error in initializing the face | ||
* stylizer. | ||
*/ | ||
- (nullable MPPFaceStylizerResult *)stylizeImage:(MPPImage *)image | ||
error:(NSError **)error NS_SWIFT_NAME(stylize(image:)); | ||
|
||
/** | ||
* Performs face stylization on the provided `MPImage` using the whole image as region of interest | ||
* and provides zero-copied results via the given completion handler block. The lifetime of the | ||
* stylized image is only guaranteed for the duration of the block. The method returns synchronously | ||
* once the completion handler returns. | ||
* | ||
* Rotation will be applied according to the `orientation` property of the provided `MPImage`. | ||
* | ||
* This method supports RGBA images. If your `MPImage` has a source type of `.pixelBuffer` or | ||
* `.sampleBuffer`, the underlying pixel buffer must have one of the following pixel format types: | ||
* 1. kCVPixelFormatType_32BGRA | ||
* 2. kCVPixelFormatType_32RGBA | ||
* | ||
* If your `MPImage` has a source type of `.image` ensure that the color space is RGB with an Alpha | ||
* channel. | ||
* | ||
* @param image The `MPImage` on which face stylization is to be performed. | ||
* @param completionHandler A block to be invoked with the results of performing face stylization on | ||
* the imput image. The block takes two arguments, the optional `FaceStylizerResult` that contains | ||
* the zero-copied stylized image if face stylization was successful and an optional error populated | ||
* upon failure. The lifetime of the stylized image is only guaranteed for the duration of the | ||
* block. | ||
*/ | ||
- (void)stylizeImage:(MPPImage *)image | ||
withCompletionHandler:(void (^)(MPPFaceStylizerResult *_Nullable result, | ||
NSError *_Nullable error))completionHandler | ||
NS_SWIFT_NAME(stylize(image:completion:)); | ||
|
||
- (instancetype)init NS_UNAVAILABLE; | ||
|
||
+ (instancetype)new NS_UNAVAILABLE; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |