cat_detection library
On-device cat detection and landmark estimation using TensorFlow Lite.
This library provides a Flutter plugin for cat detection using a unified multi-stage TFLite pipeline: SSD body detection, species classification, body pose estimation, and face landmark extraction.
Quick Start:
import 'package:cat_detection/cat_detection.dart';
final detector = CatDetector(mode: CatDetectionMode.full);
await detector.initialize();
final cats = await detector.detect(imageBytes);
for (final cat in cats) {
print('Cat at ${cat.boundingBox} score=${cat.score}');
if (cat.pose != null) {
final tail = cat.pose!.getLandmark(AnimalPoseLandmarkType.tailEnd);
print('Tail: (${tail?.x}, ${tail?.y})');
}
if (cat.face != null && cat.face!.hasLandmarks) {
final nose = cat.face!.getLandmark(CatLandmarkType.noseTipLeft);
print('Nose tip: (${nose?.x}, ${nose?.y})');
}
}
await detector.dispose();
Main Classes:
- CatDetectorIsolate: Background isolate wrapper for cat detection
- CatDetector: Main API for cat detection
- Cat: Top-level detection result with body, pose and face info
- CatFace: Detected cat face with bounding box and landmarks
- CatLandmark: Single face keypoint with 2D coordinates
- BoundingBox: Axis-aligned rectangle in pixel coordinates
Detection Modes:
- CatDetectionMode.full: SSD body detection + species + body pose + face landmarks
- CatDetectionMode.poseOnly: Body detection + species + body pose only
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:
- CatLandmarkModel.full: Single model at 256px input resolution (bundled)
- CatLandmarkModel.ensemble: 3-model ensemble (256px + 320px + 384px) with multi-scale + flip TTA. Extra models downloaded on-demand from GitHub Releases.
Skeleton Connections:
- catLandmarkConnections: Face landmark skeleton edges (CatFLW 48-landmark 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 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.
- Cat
- Top-level result for a single detected cat.
- CatDetectionDart
- CatDetector
- On-device cat detection using a unified multi-stage TensorFlow Lite pipeline.
- CatDetectorIsolate
- A wrapper that runs the entire cat detection pipeline in a background isolate.
- CatFace
- Detected cat face with bounding box and optional landmarks.
- CatLandmark
- A single cat face keypoint with 2D coordinates.
- CropMetadata
- Metadata for mapping landmark coordinates from crop space back to original image space.
- Mat
- ModelDownloader
- Downloads and caches the HRNet body pose model from GitHub Releases.
- PerformanceConfig
- Configuration for interpreter hardware acceleration and threading.
- Point
- A point with x, y, and optional z coordinates.
Enums
- AnimalPoseLandmarkType
- SuperAnimal body keypoint types (indices 15–38 in the full SuperAnimal topology).
- AnimalPoseModel
- Body pose model variant for SuperAnimal keypoint extraction.
- CatDetectionMode
- Detection mode controlling the full pipeline behavior.
- CatLandmarkModel
- Cat landmark model variant for landmark extraction.
- CatLandmarkType
- Cat face landmark types based on the CatFLW dataset topology.
- PerformanceMode
- Hardware acceleration mode for LiteRT inference.
Constants
-
animalPoseConnections
→ const List<
List< AnimalPoseLandmarkType> > - Defines the standard skeleton connections between SuperAnimal body keypoints.
-
catLandmarkConnections
→ const List<
List< CatLandmarkType> > - Defines the standard skeleton connections between cat face landmarks.
-
catLandmarkFlipIndex
→ const List<
int> - Landmark index permutation for horizontal flip (CatFLW convention).
- IMREAD_COLOR → const int
- numCatLandmarks → const int
- Number of cat face landmarks (48 for the CatFLW model).
Functions
-
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.