Add FaceLandmarkerOptions API
PiperOrigin-RevId: 535292669
This commit is contained in:
		
							parent
							
								
									952021f497
								
							
						
					
					
						commit
						c7703bfb21
					
				
							
								
								
									
										27
									
								
								mediapipe/tasks/ios/vision/face_landmarker/BUILD
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								mediapipe/tasks/ios/vision/face_landmarker/BUILD
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,27 @@
 | 
			
		|||
# 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.
 | 
			
		||||
 | 
			
		||||
package(default_visibility = ["//mediapipe/tasks:internal"])
 | 
			
		||||
 | 
			
		||||
licenses(["notice"])
 | 
			
		||||
 | 
			
		||||
objc_library(
 | 
			
		||||
    name = "MPPFaceLandmarkerOptions",
 | 
			
		||||
    srcs = ["sources/MPPFaceLandmarkerOptions.m"],
 | 
			
		||||
    hdrs = ["sources/MPPFaceLandmarkerOptions.h"],
 | 
			
		||||
    deps = [
 | 
			
		||||
        "//mediapipe/tasks/ios/core:MPPTaskOptions",
 | 
			
		||||
        "//mediapipe/tasks/ios/vision/core:MPPRunningMode",
 | 
			
		||||
    ],
 | 
			
		||||
)
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,64 @@
 | 
			
		|||
// 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/core/sources/MPPTaskOptions.h"
 | 
			
		||||
#import "mediapipe/tasks/ios/vision/core/sources/MPPRunningMode.h"
 | 
			
		||||
 | 
			
		||||
NS_ASSUME_NONNULL_BEGIN
 | 
			
		||||
 | 
			
		||||
/** Options for setting up a `MPPFaceLandmarker`. */
 | 
			
		||||
NS_SWIFT_NAME(FaceLandmarkerOptions)
 | 
			
		||||
@interface MPPFaceLandmarkerOptions : MPPTaskOptions <NSCopying>
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Running mode of the face landmark dection task. Defaults to `MPPRunningModeImage`.
 | 
			
		||||
 * `MPPFaceLandmarker` can be created with one of the following running modes:
 | 
			
		||||
 *  1. `MPPRunningModeImage`: The mode for performing face detection on single image inputs.
 | 
			
		||||
 *  2. `MPPRunningModeVideo`: The mode for performing face detection on the decoded frames of a
 | 
			
		||||
 *      video.
 | 
			
		||||
 *  3. `MPPRunningModeLiveStream`: The mode for performing face detection on a live stream of
 | 
			
		||||
 *      input data, such as from the camera.
 | 
			
		||||
 */
 | 
			
		||||
@property(nonatomic) MPPRunningMode runningMode;
 | 
			
		||||
 | 
			
		||||
/** The maximum number of faces can be detected by the FaceLandmarker. Defaults to 1. */
 | 
			
		||||
@property(nonatomic) NSInteger numFaces;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * The minimum confidence score for the face detection to be considered successful. Defaults to 0.5.
 | 
			
		||||
 */
 | 
			
		||||
@property(nonatomic) float minFaceDetectionConfidence;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * The minimum confidence score of face presence score in the face landmark detection. Defaults to
 | 
			
		||||
 * 0.5.
 | 
			
		||||
 */
 | 
			
		||||
@property(nonatomic) float minFacePresenceConfidence;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * The minimum confidence score for the face tracking to be considered successful. Defaults to 0.5.
 | 
			
		||||
 */
 | 
			
		||||
@property(nonatomic) float minTrackingConfidence;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Whether FaceLandmarker outputs face blendshapes classification. Face blendshapes are used for
 | 
			
		||||
 * rendering the 3D face model.
 | 
			
		||||
 */
 | 
			
		||||
@property(nonatomic) BOOL outputFaceBlendshapes;
 | 
			
		||||
 | 
			
		||||
@end
 | 
			
		||||
 | 
			
		||||
NS_ASSUME_NONNULL_END
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,43 @@
 | 
			
		|||
// 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/vision/face_landmarker/sources/MPPFaceLandmarkerOptions.h"
 | 
			
		||||
 | 
			
		||||
@implementation MPPFaceLandmarkerOptions
 | 
			
		||||
 | 
			
		||||
- (instancetype)init {
 | 
			
		||||
  self = [super init];
 | 
			
		||||
  if (self) {
 | 
			
		||||
    _numFaces = 1;
 | 
			
		||||
    _minFaceDetectionConfidence = 0.5f;
 | 
			
		||||
    _minFacePresenceConfidence = 0.5f;
 | 
			
		||||
    _minTrackingConfidence = 0.5f;
 | 
			
		||||
    _outputFaceBlendshapes = NO;
 | 
			
		||||
  }
 | 
			
		||||
  return self;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (id)copyWithZone:(NSZone *)zone {
 | 
			
		||||
  MPPFaceLandmarkerOptions *faceLandmarkerOptions = [super copyWithZone:zone];
 | 
			
		||||
 | 
			
		||||
  faceLandmarkerOptions.numFaces = self.numFaces;
 | 
			
		||||
  faceLandmarkerOptions.minFaceDetectionConfidence = self.minFaceDetectionConfidence;
 | 
			
		||||
  faceLandmarkerOptions.minFacePresenceConfidence = self.minFacePresenceConfidence;
 | 
			
		||||
  faceLandmarkerOptions.minTrackingConfidence = self.minTrackingConfidence;
 | 
			
		||||
  faceLandmarkerOptions.outputFaceBlendshapes = self.outputFaceBlendshapes;
 | 
			
		||||
 | 
			
		||||
  return faceLandmarkerOptions;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@end
 | 
			
		||||
							
								
								
									
										33
									
								
								mediapipe/tasks/ios/vision/face_landmarker/utils/BUILD
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								mediapipe/tasks/ios/vision/face_landmarker/utils/BUILD
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,33 @@
 | 
			
		|||
# 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.
 | 
			
		||||
 | 
			
		||||
package(default_visibility = ["//mediapipe/tasks:internal"])
 | 
			
		||||
 | 
			
		||||
licenses(["notice"])
 | 
			
		||||
 | 
			
		||||
objc_library(
 | 
			
		||||
    name = "MPPFaceLandmarkerOptionsHelpers",
 | 
			
		||||
    srcs = ["sources/MPPFaceLandmarkerOptions+Helpers.mm"],
 | 
			
		||||
    hdrs = ["sources/MPPFaceLandmarkerOptions+Helpers.h"],
 | 
			
		||||
    deps = [
 | 
			
		||||
        "//mediapipe/framework:calculator_options_cc_proto",
 | 
			
		||||
        "//mediapipe/tasks/cc/vision/face_detector/proto:face_detector_graph_options_cc_proto",
 | 
			
		||||
        "//mediapipe/tasks/cc/vision/face_landmarker/proto:face_landmarker_graph_options_cc_proto",
 | 
			
		||||
        "//mediapipe/tasks/cc/vision/face_landmarker/proto:face_landmarks_detector_graph_options_cc_proto",
 | 
			
		||||
        "//mediapipe/tasks/ios/common/utils:NSStringHelpers",
 | 
			
		||||
        "//mediapipe/tasks/ios/core:MPPTaskOptionsProtocol",
 | 
			
		||||
        "//mediapipe/tasks/ios/core/utils:MPPBaseOptionsHelpers",
 | 
			
		||||
        "//mediapipe/tasks/ios/vision/face_landmarker:MPPFaceLandmarkerOptions",
 | 
			
		||||
    ],
 | 
			
		||||
)
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,36 @@
 | 
			
		|||
// 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.
 | 
			
		||||
 | 
			
		||||
#ifndef __cplusplus
 | 
			
		||||
#error "This file requires Objective-C++."
 | 
			
		||||
#endif  // __cplusplus
 | 
			
		||||
 | 
			
		||||
#include "mediapipe/framework/calculator_options.pb.h"
 | 
			
		||||
#import "mediapipe/tasks/ios/core/sources/MPPTaskOptionsProtocol.h"
 | 
			
		||||
#import "mediapipe/tasks/ios/vision/face_landmarker/sources/MPPFaceLandmarkerOptions.h"
 | 
			
		||||
 | 
			
		||||
NS_ASSUME_NONNULL_BEGIN
 | 
			
		||||
 | 
			
		||||
@interface MPPFaceLandmarkerOptions (Helpers) <MPPTaskOptionsProtocol>
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Populates the provided `CalculatorOptions` proto container with the current settings.
 | 
			
		||||
 *
 | 
			
		||||
 * @param optionsProto The `CalculatorOptions` proto object to copy the settings to.
 | 
			
		||||
 */
 | 
			
		||||
- (void)copyToProto:(::mediapipe::CalculatorOptions *)optionsProto;
 | 
			
		||||
 | 
			
		||||
@end
 | 
			
		||||
 | 
			
		||||
NS_ASSUME_NONNULL_END
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,53 @@
 | 
			
		|||
// 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/vision/face_landmarker/utils/sources/MPPFaceLandmarkerOptions+Helpers.h"
 | 
			
		||||
 | 
			
		||||
#import "mediapipe/tasks/ios/common/utils/sources/NSString+Helpers.h"
 | 
			
		||||
#import "mediapipe/tasks/ios/core/utils/sources/MPPBaseOptions+Helpers.h"
 | 
			
		||||
 | 
			
		||||
#include "mediapipe/tasks/cc/vision/face_detector/proto/face_detector_graph_options.pb.h"
 | 
			
		||||
#include "mediapipe/tasks/cc/vision/face_landmarker/proto/face_landmarker_graph_options.pb.h"
 | 
			
		||||
#include "mediapipe/tasks/cc/vision/face_landmarker/proto/face_landmarks_detector_graph_options.pb.h"
 | 
			
		||||
 | 
			
		||||
using CalculatorOptionsProto = ::mediapipe::CalculatorOptions;
 | 
			
		||||
using FaceDetectorGraphOptionsProto =
 | 
			
		||||
    ::mediapipe::tasks::vision::face_detector::proto::FaceDetectorGraphOptions;
 | 
			
		||||
using FaceLandmarkerGraphOptionsProto =
 | 
			
		||||
    ::mediapipe::tasks::vision::face_landmarker::proto::FaceLandmarkerGraphOptions;
 | 
			
		||||
using FaceLandmarksDetectorGraphOptionsProto =
 | 
			
		||||
    ::mediapipe::tasks::vision::face_landmarker::proto::FaceLandmarksDetectorGraphOptions;
 | 
			
		||||
 | 
			
		||||
@implementation MPPFaceLandmarkerOptions (Helpers)
 | 
			
		||||
 | 
			
		||||
- (void)copyToProto:(CalculatorOptionsProto *)optionsProto {
 | 
			
		||||
  FaceLandmarkerGraphOptionsProto *faceLandmarkerGraphOptions =
 | 
			
		||||
      optionsProto->MutableExtension(FaceLandmarkerGraphOptionsProto::ext);
 | 
			
		||||
 | 
			
		||||
  faceLandmarkerGraphOptions->Clear();
 | 
			
		||||
 | 
			
		||||
  [self.baseOptions copyToProto:faceLandmarkerGraphOptions->mutable_base_options()];
 | 
			
		||||
  faceLandmarkerGraphOptions->set_min_tracking_confidence(self.minTrackingConfidence);
 | 
			
		||||
 | 
			
		||||
  FaceLandmarksDetectorGraphOptionsProto *faceLandmarkerDetectorGraphOptions =
 | 
			
		||||
      faceLandmarkerGraphOptions->mutable_face_landmarks_detector_graph_options();
 | 
			
		||||
  faceLandmarkerDetectorGraphOptions->set_min_detection_confidence(self.minFacePresenceConfidence);
 | 
			
		||||
 | 
			
		||||
  FaceDetectorGraphOptionsProto *faceDetctorGraphOptions =
 | 
			
		||||
      faceLandmarkerGraphOptions->mutable_face_detector_graph_options();
 | 
			
		||||
  faceDetctorGraphOptions->set_num_faces(self.numFaces);
 | 
			
		||||
  faceDetctorGraphOptions->set_min_detection_confidence(self.minFaceDetectionConfidence);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@end
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user