object_detection library

Object detection inference utilities backed by MediaPipe-style TFLite models (EfficientDet-Lite, SSD MobileNetV2) for Flutter apps.

Classes

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.
Category
A single category prediction for a detection.
CompactCheckbox
Compact checkbox with an inline label, sized for dense settings panels.
CompactSlider
Compact slider with a fixed-width leading label, sized for dense settings panels.
DetectedObject
A single detected object with bounding box and category.
Detection
Raw detection output: bounding box + class index + score in normalized [0.0, 1.0] coordinates.
DetectionsPainter
Custom painter that renders detected object bounding boxes with class labels and confidence scores onto a canvas, mapped from original image coordinates to the rectangle the image is drawn in on screen.
FpsCounter
A simple 1-second rolling FPS counter for camera-preview apps.
ImageTensor
Image tensor plus padding metadata used to undo letterboxing.
LetterboxParams
Parameters for aspect-preserving resize with centered padding.
Mat
ObjectCameraDetectionPainter
Custom painter for the live-camera feed. Bounding boxes come in the detection image's pixel space (imageSize, post-rotation) and are mapped onto the display with a cover-fit transform plus optional horizontal mirror (front camera). Mirrors what DetectionsPainter does for still images, but without the still-image letterbox rect (the camera preview is cover-fitted).
ObjectDetection
Runs object detection on an input image and returns raw Detection records (normalized coordinates).
ObjectDetectionCameraOverlay
Composites a cameraPreview with a bounding-box overlay for live object detection. The preview is cover-fitted inside an AspectRatio box and the ObjectCameraDetectionPainter draws detection boxes on top.
ObjectDetectionDart
Flutter plugin registration stub for Dart-only initialization.
ObjectDetector
On-device object detection using MediaPipe TFLite models.
ObjectDetectorOptions
Per-call configuration for ObjectDetector.detect and friends.
OutputTensorInfo
Holds metadata for an output tensor (shape plus its writable buffer).
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.0, 1.0].
TimingBadge
Compact tappable badge that displays the total processing time plus a color-coded performance indicator (via performanceLevel). Tapping opens a dialog with the timing breakdown.

Enums

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.
ObjectDetectionModel
Specifies which object detection model variant to use.
PerformanceMode
Hardware acceleration mode for LiteRT inference.

Constants

IMREAD_COLOR → const int
kDetectionPalette → const List<Color>
Default per-class colors. The list cycles through 12 distinct hues so that adjacent COCO classes get visually different overlay strokes.
kEfficientDetLite0Size → const int
EfficientDet-Lite0 input size (square).
kEfficientDetLite2Size → const int
EfficientDet-Lite2 input size (square).
kLabelCount → const int
The label map (90 entries, ordered by COCO class ID; some entries are "???" placeholders to keep ID alignment with the original COCO IDs).

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: ...).
bgrBytesToSignedFloat32({required Uint8List bytes, required int totalPixels, Float32List? buffer}) Float32List
Converts BGR bytes to a flat Float32List with -1.0..1.0 normalization.
boundsOf(Iterable<Offset> pts) Rect
Compute the axis-aligned bounding rect of a set of offsets.
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.
collectOutputTensorInfo(Interpreter itp) Map<int, OutputTensorInfo>
Collects output tensor shapes (and their backing buffers) for an interpreter.
colorForClass(int classIndex) Color
Returns a deterministic color from kDetectionPalette for a given class index. Useful for keeping the same color across frames.
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.
convertImageToTensor(Mat src, {required int outW, required int outH, Float32List? buffer}) ImageTensor
Converts a cv.Mat image to a normalized float32 tensor with letterboxing.
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.
generateEfficientDetAnchors({required int imageSize, int minLevel = 3, int maxLevel = 7, int numScales = 3, List<double> aspectRatios = const [1.0, 2.0, 0.5], double anchorScale = 4.0}) List<List<double>>
Generates EfficientDet RetinaNet-style multi-scale anchors.
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.
loadLabelMap() Future<List<String>>
Reads the bundled COCO labelmap (labelmap.txt) from package assets.
parseLabelMap(String content) List<String>
Parses labelmap text content into a list of strings. Useful for tests and when label data has already been loaded from another source.
performanceLevel(int ms) → ({Color color, IconData icon, String label})
Classify detection-time in milliseconds into a display-friendly bucket (label, color, icon) for overlay status indicators.
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's CameraImage (i.e. exposing width, height, and a planes iterable of objects with bytes, bytesPerRow, and bytesPerPixel getters).
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.
testApplyOptions(List<Detection> detections, ObjectDetectorOptions options, List<String> labels) List<Detection>
Test-only: exposes the private filter pipeline for unit tests.
testCollectOutputTensorInfo(Interpreter itp) Map<int, OutputTensorInfo>
Test-only access to collectOutputTensorInfo for verifying output tensor collection.
testDetectionLetterboxRemoval(List<Detection> dets, List<double> padding) List<Detection>
Test-only: exposes the private letterbox-removal logic for unit tests.
testGenerateEfficientDetAnchors({required int imageSize}) List<List<double>>
Test-only access to anchor generation.
testNameFor(ObjectDetectionModel m) String
Test-only: exposes the private model-name mapping for unit tests.
weightedNms(List<List<double>> boxes, List<double> scores, {double iouThres = 0.45, int maxDet = 100}) List<({List<double> box, int index, double score})>
Weighted Non-Maximum Suppression over XYXY-format bounding boxes.