Skip to main content
FaceNet Android supports two face detection backends: Google MLKit and MediaPipe Face Detector. Both detect faces in images and provide bounding boxes for cropping.

Available detectors

MLKit Face Detector

MLKit provides Google’s on-device face detection API with two performance modes:
  • Fast mode - Used for real-time camera frame detection
  • Accurate mode - Used for processing user-selected images
The MLKit detector automatically switches between modes based on the operation.

MediaPipe Face Detector

MediaPipe uses the BlazeFace short-range model for face detection. It runs in IMAGE mode and processes both camera frames and static images with the same configuration.

Switching detectors

To change the face detection backend, modify AppModule.kt:15:
AppModule.kt
MLKit is enabled by default and provides better performance on most devices through its dual-mode approach.

MLKit configuration

The MLKit detector creates two detector instances in MLKitFaceDetector.kt:20-28:
MLKitFaceDetector.kt

Customizing MLKit options

You can configure additional MLKit options:
Enabling additional features like landmarks or classification increases processing time and is not required for face recognition.

MediaPipe configuration

The MediaPipe detector uses the BlazeFace short-range model in MediapipeFaceDetector.kt:23-31:
MediapipeFaceDetector.kt

Customizing MediaPipe options

You can adjust MediaPipe detection parameters:

Performance comparison

MLKit relies on Google Play Services and may download models on first use. MediaPipe bundles the model in your APK, increasing app size but ensuring offline availability.

When to use each detector

Use MLKit when:
  • You need the fastest real-time detection
  • Your app targets devices with Google Play Services
  • You want to minimize APK size
Use MediaPipe when:
  • You need guaranteed offline functionality
  • You’re targeting devices without Google Play Services
  • You want consistent performance across modes