Configure and Instantiate the model with FaceDetectionModelBuilder
@interface FaceDetectionModelBuilder : NSObject
- (instancetype _Nonnull)init;
/**
* \brief Sets the preferred model to use based on the use-case.
*
* \param type One of the available \a FaceDetectionModelType.
* Default is \a FaceDetectionModelType_ShortRange.
* \returns Pointer to the \a FaceDetectionModelBuilder
*/
- (FaceDetectionModelBuilder* _Nonnull)setFaceDetectionModelType:(FaceDetectionModelType)type;
/**
* \brief Creates a new instance of \a FaceDetectionModel.
*
* \param error Object containing error information if model instantiation fails.
*
* \returns Pointer to the new instance of \a FaceDetectionModel if instantiation
* is successful, \a nil otherwise.
*
* \note Model instantiation is a blocking call which can take some time, therefore
* this should be done on a separate serial dispatch queue.
* That won't block the main queue which keeps the UI responsive.
*/
- (FaceDetectionModel* _Nullable)build:(NSError* _Nullable* _Nonnull)error;
@end
Example:
do { self.faceDetectionModel =tryFaceDetectionModelBuilder() .setFaceDetectionModelType(.shortRange) .build()} catch {fatalError("Failed to instantiate face detection model: \(error.localizedDescription)")}
Model instantiation is a blocking call that can take some time, therefore this should be done on a separate serial dispatch queue. That won't block the main queue which keeps the UI responsive.
Schedule the task with FaceDetectionModel.detect method when the model is instantiated
Each FaceDetection instance is represented with the following class
@interface FaceDetection : NSObject
/**
* \brief Confidence of the detected face.
*/
@property (readonly, nonatomic) float score;
/**
* \brief Face bounding box, normalized to [0.0, 1.0] range
*/
@property (readonly, nonatomic) CGRect boundingBox;
/**
* \brief Collection of 6 face landmarks.
*
* Specific landmark can be accessed by \a FaceLandmarkType RAW value or
* using \a faceLandmarkOfType method.
* Each landmark is a 2D Point with coordinates normalized to [0.0, 1.0] range.
*/
@property (readonly, nonatomic, nonnull) NSArray<Landmark*>* landmarks;
/**
* \brief Specific face landmark access
*
* \param type Type of the face Landmark. One of the \a FaceLandmarkType.
*
* \returns Landmark corresponding to the passed type.
*/
- (Landmark* _Nonnull)faceLandmarkOfType:(FaceLandmarkType)type;
@end