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
- ObjectDetection
- Runs object detection on an input image and returns raw Detection records (normalized coordinates).
- 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).
- PackedYuv
- A contiguous YUV buffer produced by packYuv420, ready to hand to a native colour-conversion routine.
- 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.
- YuvLayout
- Memory layout of a packed YUV buffer produced by packYuv420.
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
-
allocTensorShape(
List< int> shape) → Object -
Allocates a nested list structure matching the given tensor
shape. -
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: ...). -
bgrBytesToRgbFloat32(
{required Uint8List bytes, required int totalPixels, Float32List? buffer}) → Float32List -
Converts BGR bytes to a flat Float32List with
0.0, 1.0normalization. -
bgrBytesToSignedFloat32(
{required Uint8List bytes, required int totalPixels, Float32List? buffer}) → Float32List -
Converts BGR bytes to a flat Float32List with
-1.0, 1.0normalization. -
boundsOf(
Iterable< Offset> pts) → Rect - Compute the axis-aligned bounding rect of a set of offsets.
-
clamp01(
double v) → double -
Clamps
vto the range0.0, 1.0. Returns 0.0 for NaN inputs. -
clip(
double v, double lo, double hi) → double -
Clamps
vto the rangelo, 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
srcWidthxsrcHeightto fit withintargetWidthxtargetHeightwhile 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.
-
coverFitScaleOffset(
int sourceW, int sourceH, double viewW, double viewH) → ({double offsetX, double offsetY, double scale}) -
Cover-fit scale + offset for rendering a source region of size
(
sourceW,sourceH) into a viewport of size (viewW,viewH). -
createNHWCTensor4D(
int height, int width) → List< List< List< >List< >double> > -
Creates a pre-allocated
[1][height][width][3]tensor structure. -
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.
-
drawBoundingBoxOutline(
{required Canvas canvas, required BoundingBox bbox, required double scaleX, required double scaleY, required double offsetX, required double offsetY, required Paint paint}) → void - Draw the axis-aligned outline of a BoundingBox transformed by a linear scale + offset. Use a stroked Paint for an outline, or a filled one to tint the interior.
-
drawLandmarkMarker(
Canvas canvas, double x, double y, {double glowRadius = 8, double pointRadius = 5, double centerRadius = 2, Paint? glowPaint, Paint? pointPaint, Paint? centerPaint}) → void -
Draw a standard "glow + point + center dot" triple-circle landmark marker
at (
x,y) in canvas coordinates. -
drawSkeletonConnections(
{required Canvas canvas, required List< Offset> scaledPoints, required List<(int, int)> connections, required Paint paint}) → void - Draw straight-line connections between pre-scaled landmark points.
-
fillNHWC4D(
Float32List flat, List< List< cache, int inH, int inW) → voidList< >List< >double> > - Fills an NHWC 4D tensor cache from a flat Float32List.
-
flattenDynamicTensor(
Object? out) → Float32List - Flattens an arbitrarily nested tensor to a flat Float32List.
-
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. -
packYuv420(
{required int width, required int height, required YuvPlane y, required YuvPlane u, YuvPlane? v}) → PackedYuv? -
Packs a YUV420 camera frame into a single contiguous buffer suitable for
native colour conversion (e.g. opencv's
cvtColorwith aCOLOR_YUV2BGR_NV21/COLOR_YUV2BGR_NV12/COLOR_YUV2BGR_I420code). -
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? -
prepareCameraFrameFromImage(
Object cameraImage, {CameraFrameRotation? rotation, bool isBgra = true}) → CameraFrame? -
Prepare a CameraFrame descriptor from raw camera planes, for use with a
detector package's
detectFromCameraFrame(...)method. -
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.
-
sigmoid(
double x) → double - Sigmoid activation function.
-
sigmoidClipped(
double x, {double limit = 80.0}) → double - Sigmoid with input clipping to prevent overflow.
-
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< boxes, List<double> >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.
Typedefs
- CameraPlane = ({Uint8List bytes, int pixelStride, int rowStride})
- A single camera frame plane exposed by a camera plugin.
- YuvPlane = ({Uint8List bytes, int pixelStride, int rowStride})
-
A single YUV plane exposed by a camera plugin, decoupled from any specific
Flutter plugin's type (e.g.
CameraImage.Plane).