face_detection_tflite library

Face detection and landmark inference utilities backed by MediaPipe-style TFLite models for Flutter apps.

This is the package's public entry point. It conditionally re-exports the native or web implementation depending on the host platform:

  • Web (Chrome / Edge / Firefox / Safari): web implementation backed by LiteRT.js (auto WebGPU/WASM) and Canvas preprocessing.
  • Everything else (mobile, desktop): the native implementation backed by flutter_litert + opencv_dart.

Classes

AlignedRoi
Rotation-aware ROI used for iris alignment.
BoundingBox
An axis-aligned or rotated bounding box defined by four corner points.
DecodedBox
Decoded detection box and keypoints straight from the TFLite model.
Detection
Raw detection output: bounding box + 6 keypoints.
DetectionWithSegmentationResult
Result combining face detection and segmentation from parallel processing.
Eye
Eye tracking data: iris center + iris contour + eye mesh.
EyePair
Eye tracking data for both eyes.
Face
Outputs for a single detected face.
FaceBlendshapes
All 52 MediaPipe Blendshape V2 coefficients for a detected face.
FaceDetectionTfliteDart
Flutter plugin registration stub for Dart-only initialization.
FaceDetector
Web implementation of FaceDetector.
FaceLandmarks
Facial landmark points with named access.
FaceMesh
468-point face mesh with optional depth information.
FpsCounter
A simple 1-second rolling FPS counter for camera-preview apps.
HeadEulerAngles
Head orientation as Euler angles in degrees, matching the sign conventions documented by Google ML Kit's Face:
ImageTensor
Image tensor plus padding metadata used to undo letterboxing.
LetterboxParams
Parameters for aspect-preserving resize with centered padding.
MulticlassSegmentationMask
Multiclass segmentation mask with per-class probabilities.
PerformanceConfig
Configuration for interpreter hardware acceleration and threading.
Point
A point with x, y, and optional z coordinates.
RectF
Axis-aligned rectangle with normalized coordinates (0..1).
SegmentationClass
Segmentation class indices for the multiclass model output.
SegmentationConfig
Configuration for segmentation operations.
SegmentationMask
A segmentation probability mask indicating foreground vs background.
WebDetectTimings
Per-stage timing accumulator for the web pipeline (microseconds). Populated by FaceDetector.detectFacesFromBytes when FaceDetector.debugTimings is true.

Enums

Blendshape
The 52 MediaPipe Blendshape V2 expression coefficients, in tensor order.
FaceContourType
Named facial contours, mirroring Google ML Kit's FaceContourType.
FaceDetectionMode
Detection mode controls which features are computed.
FaceDetectionModel
Face detection model variants.
FaceLandmarkType
Identifies specific facial landmarks returned by face detection.
IsolateOutputFormat
Output format options for isolate-based segmentation transfer.
PerformanceMode
Hardware acceleration mode for LiteRT inference.
PixelFormat
Pixel format for RGBA output from segmentation masks.
SegmentationError
Error codes for segmentation operations.
SegmentationModel
Selects which segmentation model variant to use.

Constants

eyeLandmarkConnections → const List<List<int>>
Connections between eye contour landmarks for rendering the eyeball outline.
faceContourMeshIndices → const Map<FaceContourType, List<int>>
Ordered 468-point face-mesh indices for each FaceContourType.
kBlendshapeCount → const int
Number of blendshape coefficients the model outputs.
kMaxEyeLandmark → const int
Number of eye contour points that form the visible eyeball outline.
kMeshPoints → const int
The expected number of landmark points in a complete face mesh.

Properties

kBlendshapeNames List<String>
The 52 official blendshape coefficient names, in tensor order.
final

Functions

clamp01(double v) double
Clamps v to the range 0.0..1.0. Returns 0.0 for NaN inputs.
clip(double v, double lo, double hi) double
Clamps v to the range lo..hi.
computeLetterboxParams({required int srcWidth, required int srcHeight, required int targetWidth, required int targetHeight, bool roundDimensions = true}) LetterboxParams
Computes letterbox parameters for resizing srcWidthxsrcHeight to fit within targetWidthxtargetHeight while preserving aspect ratio.
drawBoundingBoxOutline({required Canvas canvas, required BoundingBox bbox, required double scaleX, required double scaleY, required double offsetX, required double offsetY, required Paint paint}) → void
Draw the axis-aligned outline of a BoundingBox transformed by a linear scale + offset. Use a stroked Paint for an outline, or a filled one to tint the interior.
drawLandmarkMarker(Canvas canvas, double x, double y, {double glowRadius = 8, double pointRadius = 5, double centerRadius = 2, Paint? glowPaint, Paint? pointPaint, Paint? centerPaint}) → void
Draw a standard "glow + point + center dot" triple-circle landmark marker at (x, y) in canvas coordinates.
drawSkeletonConnections({required Canvas canvas, required List<Offset> scaledPoints, required List<(int, int)> connections, required Paint paint}) → void
Draw straight-line connections between pre-scaled landmark points.
irisCenterFromPoints(List<Point> pts) Point
Returns the iris point closest to the centroid.
sigmoid(double x) double
Sigmoid activation function.
sigmoidClipped(double x, {double limit = 80.0}) double
Sigmoid with input clipping to prevent overflow.

Exceptions / Errors

SegmentationException
Exception thrown by segmentation operations.