animal_detection library

On-device animal detection, species classification, and body pose estimation using TensorFlow Lite.

This library provides a Flutter plugin for detecting animals in images using a multi-stage TFLite pipeline: SSD body detection, species classification, and body pose estimation using SuperAnimal keypoints.

Quick Start:

import 'package:animal_detection/animal_detection.dart';

final detector = AnimalDetector();
await detector.initialize();

final animals = await detector.detect(imageBytes);
for (final animal in animals) {
  print('${animal.species} at ${animal.boundingBox} score=${animal.score}');
  if (animal.pose != null) {
    final tail = animal.pose!.getLandmark(AnimalPoseLandmarkType.tailEnd);
    print('Tail: (${tail?.x}, ${tail?.y})');
  }
}

await detector.dispose();

Main Classes:

  • AnimalDetector: Main API for animal detection
  • Animal: Top-level detection result with body, species and pose info
  • AnimalPose: Body pose result with 24 SuperAnimal keypoints
  • AnimalPoseLandmark: Single body keypoint with 2D coordinates and confidence
  • BoundingBox: Axis-aligned rectangle in pixel coordinates

Pose Model Variants:

Skeleton Connections:

Classes

Animal
Top-level result for a single detected animal.
AnimalDetectionDart
Dart plugin registration for animal_detection.
AnimalDetector
On-device animal detection using a multi-stage TensorFlow Lite pipeline.
AnimalPose
Full-body pose result for a single detected animal.
AnimalPoseLandmark
A single body pose keypoint with 2D coordinates and a confidence score.
BoundingBox
An axis-aligned or rotated bounding box defined by four corner points.
CropMetadata
Metadata for mapping landmark coordinates from crop space back to original image space.
EnsembleLandmarkModelBase
3-model ensemble landmark runner with multi-scale + flip TTA.
FaceLocalizerModel
Generic face bounding box regression model using letterbox preprocessing.
ImageUtils
Utility functions for image preprocessing using OpenCV.
LandmarkModelRunnerBase
Generic face landmark regression model runner.
LetterboxParams
Parameters for aspect-preserving resize with centered padding.
Mat
ModelDownloader
Downloads and caches the HRNet body pose model from GitHub Releases.
PerformanceConfig
Point
A point with x, y, and optional z coordinates.
SingleInterpreterModel
Base class for TFLite model classes that use a single interpreter.
SpeciesModelDownloader
Downloads and caches species-specific ensemble landmark models from GitHub Releases.

Enums

AnimalPoseLandmarkType
SuperAnimal body keypoint types (indices 15–38 in the full SuperAnimal topology).
AnimalPoseModel
Body pose model variant for SuperAnimal keypoint extraction.
PerformanceMode

Constants

animalPoseConnections → const List<List<AnimalPoseLandmarkType>>
Defines the standard skeleton connections between SuperAnimal body keypoints.
IMREAD_COLOR → const int

Functions

argmaxSoftmax(List<double> logits) → (int, double)
Returns the argmax index and its softmax probability from logits.
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.
imdecode(Uint8List buf, int flags, {Mat? dst}) Mat
imdecode reads an image from a buffer in memory. The function imdecode reads an image from the specified buffer in memory. If the buffer is too short or contains invalid data, the function returns an empty matrix. @param buf Input array or vector of bytes. @param flags The same flags as in cv::imread, see cv::ImreadModes.
scaleFromLetterbox(List<double> xyxy, double ratio, int dw, int dh) List<double>
Transforms bounding box coordinates from letterbox space back to original image space.
softmaxConfidence(List<double> logits, int peakIndex) double
Numerically stable softmax confidence at a specific index.

Typedefs

EnsembleModelGetter = Future<(Uint8List, Uint8List)> Function({void onProgress(String model, int received, int total)?})
Callback type for downloading ensemble model weights.