Android Face Detection & Verification
An Android computer vision project demonstrating real-time face detection with TensorFlow Lite, C++ JNI, MediaPipe, and face-position validation implemented with Jetpack Compose.
On-device pipeline
Face Detection
Project Overview
Real-time face processing on Android
The project explores two complementary approaches for running face-related computer vision tasks on Android: a native C++ JNI implementation for MediaPipe/TensorFlow Lite face detection and a Kotlin-based validation layer for preparing a face before verification.
MediaPipe Face Detection
Real-time face detection using the MediaPipe short-range face detection model through a native C++ JNI pipeline.
Face Verification Preparation
A Kotlin utility layer validates the number, position, keypoints, and orientation of the detected face before a verification process.
01 · Face Detection
MediaPipe Face Detection with C++ JNI
The detection implementation moves the core TensorFlow Lite and MediaPipe processing into native C++, while the resulting detections are exposed to the Kotlin Android application through JNI.
Camera Input
Frames from the Android camera are prepared as input for the face detection pipeline.
Image Processing
The native MediaPipe pipeline adjusts and converts the image into the tensor representation required by the model.
TFLite Inference
TensorFlow Lite inference runs through the C++ implementation using the MediaPipe short-range face detection model.
Detection Processing
Raw model outputs are converted into detections, filtered with non-maximum suppression, and converted into Kotlin-compatible results.
Native MediaPipe pipeline
The C++ implementation contains the main processing stages required to transform camera images into face detections, including image adjustment, tensor conversion, inference, detection decoding, anchor generation, non-maximum suppression, and conversion back to Kotlin-compatible objects.
02 · Face Verification
Validate the face before verification
FaceVerificationPage provides a lightweight positioning and orientation validation layer. Its purpose is to make sure the detected face satisfies the expected conditions before the actual face verification process is performed.
Single Face
The system requires exactly one detected face before verification can continue.
Center Position
The center of the face bounding box is compared against the center of the target area.
Circular Target
A circle is used as the target region for determining whether the face is sufficiently centered.
Facial Keypoints
Five facial keypoints are checked to ensure the important parts of the face remain inside the target area.
Orientation
Eye and nose coordinates are analyzed to estimate whether the face is facing forward, left, or right.
Intersection Score
The system calculates an intersection score based on how close the detected face is to the target center.
Position Validation
A simple geometric approach to face alignment
The face verification utility does not simply check whether a face exists. It evaluates the detected face relative to a target area, using the bounding box center and facial keypoints to determine whether the face is positioned correctly.
The target is represented as a circle. The system then checks the distance between the detected face and the target center and uses the facial keypoints as additional constraints.
Face Orientation
Estimate whether the face is looking forward
The verification utility also analyzes the relationship between the detected eye and nose coordinates. This provides a simple geometric signal for determining whether the face is facing forward, left, or right.
Forward
Eyes and nose maintain the expected relative position.
Left
Coordinate relationships indicate a left-facing orientation.
Right
Coordinate relationships indicate a right-facing orientation.
Validation Result
Clear states before verification
The validation layer exposes understandable states that can be used by the Android UI to guide the user into the correct position before proceeding.
Architecture
Native inference with Kotlin application logic
The project separates the computationally intensive face detection pipeline from the Android-facing verification and UI logic.
Android Camera
Camera frames provide the real-time image input for the detection pipeline.
C++ JNI
MediaPipe and TensorFlow Lite processing runs natively before the detection results are returned to Kotlin.
Kotlin UI
Jetpack Compose displays detections while the verification layer validates position and orientation.
Tech Stack
Technologies used
The project combines native Android development with on-device machine learning inference.
Explore the implementation
See the complete Android project, including the Kotlin face verification utilities and the native C++ MediaPipe/TensorFlow Lite pipeline.
View on GitHub