dog_detection 0.0.1 copy "dog_detection: ^0.0.1" to clipboard
dog_detection: ^0.0.1 copied to clipboard

Dog face and landmark detection using on-device TFLite models.

dog_detection

Platform Language: Dart
Pub Version pub points License

[Demo]

On-device dog detection using TFLite models. Detects dogs in images with breed identification, body pose estimation, face localization, and 46-point facial landmarks — all running locally with no remote API.

Features #

  • Dog body detection with bounding box (SSD-based)
  • Breed identification with confidence score
  • Body pose estimation via SuperAnimal keypoints
  • Face localization and 46-point facial landmark extraction (DogFLW)
  • Truly cross-platform: compatible with Android, iOS, macOS, Windows, and Linux
  • Background isolate support via DogDetectorIsolate for guaranteed non-blocking UI
  • Configurable performance with XNNPACK, GPU, and CoreML acceleration

Quick Start #

import 'package:dog_detection/dog_detection.dart';

final detector = DogDetector(mode: DogDetectionMode.full);
await detector.initialize();

final dogs = await detector.detect(imageBytes);
for (final dog in dogs) {
  print('${dog.species} at ${dog.boundingBox}');
  print('Breed: ${dog.breed} (${(dog.speciesConfidence! * 100).toStringAsFixed(0)}%)');
  print('Pose keypoints: ${dog.pose?.landmarks.length}');
  print('Face landmarks: ${dog.face?.landmarks.length}');
}

await detector.dispose();

Dog Face Landmarks (46-Point) #

The landmarks property returns a list of 46 DogLandmark objects representing key points on the detected dog face.

Landmark Groups #

Group Count Points
Left ear 7 Ear outline and tip
Right ear 7 Ear outline and tip
Left eye 4 Eye corners and center
Right eye 4 Eye corners and center
Nose bridge 2 Bridge top and bottom
Nose ring 8 Nostril outline
Mouth/chin 14 Lips, jaw, and chin

Accessing Landmarks #

final DogFace face = faces.first;

// Iterate through all landmarks
for (final landmark in face.landmarks) {
  print('${landmark.type.name}: (${landmark.x}, ${landmark.y})');
}

Breed Identification #

In full and poseOnly modes, each detected dog includes a predicted breed label and confidence score from the species classifier.

final dogs = await detector.detect(imageBytes);
for (final dog in dogs) {
  if (dog.breed != null) {
    print('Breed: ${dog.breed}');
    print('Confidence: ${(dog.speciesConfidence! * 100).toStringAsFixed(1)}%');
  }
}

Bounding Boxes #

The boundingBox property returns a BoundingBox object representing the dog face bounding box in absolute pixel coordinates.

final BoundingBox boundingBox = face.boundingBox;

// Access edges
final double left = boundingBox.left;
final double top = boundingBox.top;
final double right = boundingBox.right;
final double bottom = boundingBox.bottom;

// Calculate dimensions
final double width = boundingBox.right - boundingBox.left;
final double height = boundingBox.bottom - boundingBox.top;

print('Box: ($left, $top) to ($right, $bottom)');
print('Size: $width x $height');

Model Details #

Model Size Input Purpose
Face localizer 16 MB 224×224 Dog face detection and bounding box
Landmark model (full) 55 MB 384×384 46-point facial landmark extraction

Configuration Options #

The DogDetector constructor accepts several configuration options:

final detector = DogDetector(
  mode: DogDetectionMode.full,               // Detection mode
  poseModel: AnimalPoseModel.rtmpose,        // Body pose model variant
  landmarkModel: DogLandmarkModel.full,      // Face landmark model variant
  cropMargin: 0.20,                          // Margin around detected body for crop
  detThreshold: 0.5,                         // SSD detection confidence threshold
  interpreterPoolSize: 1,                    // TFLite interpreter pool size
  performanceConfig: PerformanceConfig.disabled, // Performance optimization
);
Option Type Default Description
mode DogDetectionMode full Detection mode
poseModel AnimalPoseModel rtmpose Body pose model variant
landmarkModel DogLandmarkModel full Face landmark model variant
cropMargin double 0.20 Margin around detected body crop (0.0–1.0)
detThreshold double 0.5 SSD detection confidence threshold
interpreterPoolSize int 1 TFLite interpreter pool size
performanceConfig PerformanceConfig disabled Hardware acceleration config

Detection Modes #

Mode Features Speed
full Body detection + breed ID + body pose + face landmarks Standard
poseOnly Body detection + breed ID + body pose (no face) Faster
faceOnly Face localizer + face landmarks only (legacy, no SSD) Fastest

Background Isolate Detection #

For applications that require guaranteed non-blocking UI, use DogDetectorIsolate. This runs the entire detection pipeline in a background isolate, ensuring all processing happens off the main thread.

import 'package:dog_detection/dog_detection.dart';

// Spawn isolate (loads models in background)
final detector = await DogDetectorIsolate.spawn(
  mode: DogDetectionMode.full,
);

// All detection runs in background isolate - UI never blocked
final dogs = await detector.detectDogs(imageBytes);

for (final dog in dogs) {
  print('${dog.breed} at ${dog.boundingBox}');
  print('Face landmarks: ${dog.face?.landmarks.length}');
}

// Cleanup when done
await detector.dispose();

When to Use DogDetectorIsolate #

Use Case Recommended
Live camera with 60fps UI requirement DogDetectorIsolate
Processing images in a batch queue DogDetectorIsolate
Simple single-image detection DogDetector
Maximum control over pipeline stages DogDetector

Performance #

XNNPACK can be enabled for 2-5x CPU speedup via SIMD vectorization (NEON on ARM, AVX on x86):

final detector = DogDetector(
  performanceConfig: PerformanceConfig.xnnpack(),
);
await detector.initialize();

Credits #

Models trained on the DogFLW dataset.

Example #

The sample code from the pub.dev example tab includes a Flutter app that paints detections onto an image: bounding boxes and 46-point dog facial landmarks.

1
likes
150
points
--
downloads

Publisher

verified publisherhugocornellier.com

Weekly Downloads

Dog face and landmark detection using on-device TFLite models.

License

Apache-2.0 (license)

Dependencies

animal_detection, flutter, flutter_litert, http, meta, opencv_dart, path_provider

More

Packages that depend on dog_detection

Packages that implement dog_detection