dog_detection library
On-device dog detection and landmark estimation using TensorFlow Lite.
This library provides a Flutter plugin for dog detection using a unified multi-stage TFLite pipeline: SSD body detection, species classification, body pose estimation, face localization, and face landmark extraction.
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 at ${dog.boundingBox} score=${dog.score}');
if (dog.pose != null) {
final tail = dog.pose!.getLandmark(AnimalPoseLandmarkType.tailEnd);
print('Tail: (${tail?.x}, ${tail?.y})');
}
if (dog.face != null && dog.face!.hasLandmarks) {
final nose = dog.face!.getLandmark(DogLandmarkType.noseBridgeBottom);
print('Nose: (${nose?.x}, ${nose?.y})');
}
}
await detector.dispose();
Main Classes:
- DogDetector: Main API for dog detection. Runs the whole pipeline in a background isolate it owns, so detection never blocks the UI thread.
- Dog: Top-level detection result with body, pose and face info
- DogFace: Detected dog face with bounding box and landmarks
- DogLandmark: Single face keypoint with 2D coordinates
- BoundingBox: Axis-aligned rectangle in pixel coordinates
Detection Modes:
- DogDetectionMode.full: SSD body detection + species + body pose + face landmarks
- DogDetectionMode.poseOnly: Body detection + species + body pose only
- DogDetectionMode.faceOnly: Face localizer + face landmarks only (legacy)
Pose Model Variants:
- AnimalPoseModel.rtmpose: RTMPose-S (11.6MB, bundled). Fast SimCC-based decoder.
- AnimalPoseModel.hrnet: HRNet-w32 (54.6MB, downloaded on demand). Most accurate.
Face Landmark Model Variants:
- DogLandmarkModel.full: Single model at 384px input resolution (bundled)
- flip TTA (18 passes). Extra models downloaded on-demand from GitHub Releases (~110MB)
Skeleton Connections:
- dogLandmarkConnections: Face landmark skeleton edges (DogFLW topology)
- animalPoseConnections: Body pose skeleton edges (SuperAnimal topology)
Classes
- Animal
- Top-level result for a single detected animal.
- AnimalDetector
- On-device animal detection using a multi-stage LiteRT 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.
- CameraFrame
- A camera frame packaged for off-thread colour conversion and inference.
- CropMetadata
- Metadata for mapping landmark coordinates from crop space back to original image space.
- Dog
- Top-level result for a single detected dog.
- DogDetectionDart
- Dart plugin registration for dog_detection.
- DogDetector
- On-device dog detection using a unified multi-stage TensorFlow Lite pipeline.
- DogFace
- Detected dog face with bounding box and optional landmarks.
- DogLandmark
- A single dog face keypoint with 2D coordinates.
- FpsCounter
- A simple 1-second rolling FPS counter for camera-preview apps.
- FrameThrottle
- A single-slot gate for camera-frame processing that drops frames arriving while a previous frame is still being processed.
- Mat
- ModelDownloader
- Downloads and caches the HRNet body pose model from GitHub Releases.
- OneEuroFilter
- One Euro filter for low-latency smoothing of a noisy 1D signal sampled at an irregular rate.
- PerformanceConfig
- Configuration for interpreter hardware acceleration and threading.
- Point
- A point with x, y, and optional z coordinates.
Enums
- Accelerator
- Hardware accelerator requested for LiteRT Next compilation.
- AnimalPoseLandmarkType
- SuperAnimal body keypoint types (indices 15-38 in the full SuperAnimal topology).
- AnimalPoseModel
- Body pose model variant for SuperAnimal keypoint extraction.
- CameraFrameConversion
-
The colour conversion a CameraFrame's bytes need before being used as a
3-channel BGR image. Detector packages map this to an opencv
COLOR_*code at the point of decode, inside their existing detection isolate. - CameraFrameRotation
-
Optional rotation applied after colour conversion. Detector packages map
this to an opencv
ROTATE_*code. - DogDetectionMode
- Detection mode controlling the full pipeline behavior.
- DogLandmarkModel
- Dog landmark model variant for landmark extraction.
- DogLandmarkType
- Dog face landmark types based on the DogFLW dataset topology.
- PerformanceMode
- Hardware acceleration mode for LiteRT inference.
- Precision
- GPU precision mode for LiteRT Next compilation.
Constants
-
animalPoseConnections
→ const List<
List< AnimalPoseLandmarkType> > - Defines the standard skeleton connections between SuperAnimal body keypoints.
-
dogLandmarkConnections
→ const List<
List< DogLandmarkType> > - Defines the standard skeleton connections between dog face landmarks.
-
dogLandmarkFlipIndex
→ const List<
int> - Landmark index permutation for horizontal flip (DogFLW convention).
- IMREAD_COLOR → const int
- numDogLandmarks → const int
- Number of dog face landmarks (46 for the DogFLW model).
Functions
-
barQuarterTurns(
DeviceOrientation orientation) → int -
Quarter-turns (clockwise) to rotate a top-bar widget so it reads upright
when the device is in landscape. Use with
RotatedBox(quarterTurns: ...). -
detectionSize(
{required int width, required int height, required CameraFrameRotation? rotation, required int maxDim}) → Size - Compute the final detection-image size used by overlay painters to map detector coordinates back onto the widget coord space.
-
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.
-
iouLTRB(
double aLeft, double aTop, double aRight, double aBottom, double bLeft, double bTop, double bRight, double bBottom) → double - Exact intersection-over-union of two axis-aligned boxes in left/top/right/ bottom coordinates. Returns 0.0 when the boxes are degenerate or disjoint.
-
prepareCameraFrame(
{required int width, required int height, required List< CameraPlane> planes, CameraFrameRotation? rotation, bool isBgra = true}) → CameraFrame? -
Prepare a CameraFrame descriptor from raw camera planes, for use with a
detector package's
detectFromCameraFrame(...)method. -
prepareCameraFrameFromImage(
Object cameraImage, {CameraFrameRotation? rotation, bool? isBgra}) → CameraFrame? -
Convenience wrapper around prepareCameraFrame that accepts any object
duck-typed to
package:camera'sCameraImage(i.e. exposingwidth,height, and aplanesiterable of objects withbytes,bytesPerRow, andbytesPerPixelgetters). -
rotationForFrame(
{required int width, required int height, required int sensorOrientation, required bool isFrontCamera, required DeviceOrientation deviceOrientation}) → CameraFrameRotation? - Compute the rotation needed to present a camera frame upright to an on-device detection model, given the camera's sensor orientation and the device's current physical orientation.