AI-generated Key Takeaways
-
MLKFaceDetectoris a class used for detecting faces within images. -
It provides methods for creating a face detector instance with default or custom options using
faceDetectorWithOptions:orfaceDetector. -
processImage:completion:enables asynchronous face detection, providing results via a completion handler. -
resultsInImage:error:offers synchronous face detection, returning results or an error immediately but should be called off the main thread.
MLKFaceDetector
@interface MLKFaceDetector : NSObjectA face detector that detects faces in an image.
-
Returns a face detector with the given options.
Declaration
Objective-C
+ (nonnull instancetype)faceDetectorWithOptions: (nonnull MLKFaceDetectorOptions *)options;Parameters
optionsOptions for configuring the face detector.
Return Value
A face detector configured with the given options.
-
Returns a face detector with default options.
Declaration
Objective-C
+ (nonnull instancetype)faceDetector;Return Value
A face detector configured with default options.
-
Unavailable. Use the class methods.
Declaration
Objective-C
- (nonnull instancetype)init; -
Processes the given image for face detection.
Declaration
Objective-C
- (void)processImage:(nonnull id<MLKCompatibleImage>)image completion:(nonnull MLKFaceDetectionCallback)completion;Parameters
imageThe image to process.
completionHandler to call back on the main thread with faces detected or error.
-
Returns face results in the given image or
nilif there was an error. The face detection is performed synchronously on the calling thread.It is advised to call this method off the main thread to avoid blocking the UI. As a result, an
NSExceptionis raised if this method is called on the main thread.Declaration
Objective-C
- (nullable NSArray<MLKFace *> *) resultsInImage:(nonnull id<MLKCompatibleImage>)image error:(NSError *_Nullable *_Nullable)error;Parameters
imageThe image to get results in.
errorAn optional error parameter populated when there is an error getting results.
Return Value
Array of face results in the given image or
nilif there was an error.