On-Device AI · Android

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.

TensorFlow LiteC++ JNIMediaPipeKotlinJetpack Compose

On-device pipeline

Face Detection

1
Camera Frame
2
C++ JNI
3
MediaPipe Pipeline
4
TFLite Inference
5
Kotlin Detection Result

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.

1

Camera Input

Frames from the Android camera are prepared as input for the face detection pipeline.

2

Image Processing

The native MediaPipe pipeline adjusts and converts the image into the tensor representation required by the model.

3

TFLite Inference

TensorFlow Lite inference runs through the C++ implementation using the MediaPipe short-range face detection model.

4

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.

adjust_image_calculator.cc
adjust_image_calculator.h
config.h
convert_detection_calculator.cc
convert_detection_calculator.h
convert_to_kotlin_class_list.cc
convert_to_kotlin_class_list.h
image_to_tensor_calculator.cc
image_to_tensor_calculator.h
inference_calculator.cc
inference_calculator.h
non_max_suppression_calculator.cc
non_max_suppression_calculator.h
ssd_anchors_calculator.cc
ssd_anchors_calculator.h
tensors_to_detections_calculator.cc
tensors_to_detections_calculator.h
to_image_calculator.cc
to_image_calculator.h
types.h

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.

No face detected
Multiple faces detected
Face is outside the target
Face is not sufficiently centered
Face successfully positioned inside the target

Architecture

Native inference with Kotlin application logic

The project separates the computationally intensive face detection pipeline from the Android-facing verification and UI logic.

Layer 01

Android Camera

Camera frames provide the real-time image input for the detection pipeline.

Layer 02

C++ JNI

MediaPipe and TensorFlow Lite processing runs natively before the detection results are returned to Kotlin.

Layer 03

Kotlin UI

Jetpack Compose displays detections while the verification layer validates position and orientation.

CameraC++ JNIMediaPipeTFLiteKotlinVerification

Tech Stack

Technologies used

The project combines native Android development with on-device machine learning inference.

Android
Kotlin
Jetpack Compose
C++
JNI
TensorFlow Lite
MediaPipe
Face Detection
On-device AI

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