BaseFaceDetector abstract class.
BaseFaceDetector
Abstract base class that defines the face detection interface and provides common utility methods.Methods
getCroppedFace
Detects a single face from an image URI and returns the cropped face bitmap.URI of the image to detect faces from
Success with cropped face bitmap, or failure with:
ErrorCode.NO_FACE: No face detectedErrorCode.MULTIPLE_FACES: More than one face detectedErrorCode.FACE_DETECTOR_FAILURE: Detection failed or invalid bounding box
getAllCroppedFaces
Detects multiple faces from a bitmap and returns cropped faces with bounding boxes.Bitmap image to detect faces from
List of pairs containing cropped face bitmaps and their bounding box rectangles. Only returns valid faces with bounding boxes within image bounds
Protected utility methods
getBitmapFromUri
Loads a bitmap from URI with automatic EXIF orientation correction.validateRect
Checks if a bounding box fits within image dimensions.rotateBitmap
Rotates a bitmap by specified degrees.MLKitFaceDetector
Face detector implementation using Google ML Kit’s face detection API.Constructor
Android application context
Detection modes
The class uses two different detector configurations:Fast performance mode for real-time detection. Used by
getAllCroppedFaces()Accurate performance mode for single image detection. Used by
getCroppedFace()Usage example
domain/face_detection/MLKitFaceDetector.kt:16
MediapipeFaceDetector
Face detector implementation using Google MediaPipe’s face detection solution.Constructor
Android application context for loading the MediaPipe model
Configuration
MediaPipe model file loaded from the assets folder
MediaPipe running mode configured for static image processing
Usage example
domain/face_detection/MediapipeFaceDetector.kt:19
Comparison
| Feature | MLKitFaceDetector | MediapipeFaceDetector |
|---|---|---|
| Library | Google ML Kit | Google MediaPipe |
| Model | Built-in | blaze_face_short_range.tflite |
| Performance modes | Fast & Accurate | IMAGE mode |
| Setup | No model file needed | Requires model in assets |
- Handle EXIF orientation automatically
- Validate bounding boxes
- Support single and multiple face detection
- Run on IO dispatcher for non-blocking operation