<!--
SPDX-FileCopyrightText: 2026 James Harton

SPDX-License-Identifier: Apache-2.0
-->

<img src="https://github.com/beam-bots/bb/blob/main/logos/beam_bots_logo.png?raw=true" alt="Beam Bots Logo" width="250" />

# bb_estimator_object_detection

[![CI](https://github.com/beam-bots/bb_estimator_object_detection/actions/workflows/ci.yml/badge.svg)](https://github.com/beam-bots/bb_estimator_object_detection/actions/workflows/ci.yml)
[![License: Apache 2.0](https://img.shields.io/badge/License-Apache--2.0-green.svg)](https://opensource.org/licenses/Apache-2.0)
[![Hex version badge](https://img.shields.io/hexpm/v/bb_estimator_object_detection.svg)](https://hex.pm/packages/bb_estimator_object_detection)
[![Hexdocs badge](https://img.shields.io/badge/docs-hexdocs-purple)](https://hexdocs.pm/bb_estimator_object_detection)
[![REUSE status](https://api.reuse.software/badge/github.com/beam-bots/bb_estimator_object_detection)](https://api.reuse.software/info/github.com/beam-bots/bb_estimator_object_detection)
[![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/beam-bots/bb_estimator_object_detection)

A [Beam Bots](https://github.com/beam-bots/bb) estimator that finds objects
in camera frames with any object-detection model declared through
[`bb_inference`](https://github.com/beam-bots/bb_inference).

```elixir
inference do
  model :detector do
    runtime BB.Inference.TFLite
    source "https://storage.googleapis.com/download.tensorflow.org/models/tflite/coco_ssd_mobilenet_v1_1.0_quant_2018_06_29.zip"
    archive_member "detect.tflite"
    sha256 "e4b118e5e4531945de2e659742c7c590f7536f8d0ed26d135abcfe83b4779d13"
    codec {BB.Estimator.ObjectDetection.FinalDetections, mean: 127.5, std: 127.5}
  end
end

topology do
  link :head do
    sensor :camera, {BB.Camera.V4L, device: "/dev/video0"} do
      estimator :objects, {BB.Estimator.ObjectDetection, model: :detector}
    end
  end
end
```

The estimator names only the model. For every frame it examines it publishes
a `BB.Message.Vision.Detections` at its own path - labelled boxes in frame
pixels, highest score first, stamped with the frame's capture time - which
[`bb_liveview`](https://github.com/beam-bots/bb_liveview) draws over the
camera's preview.

## What's in it

- **`BB.Estimator.ObjectDetection`** - the estimator: runs the model's codec,
  suppresses overlapping boxes when the codec says it should, applies
  labels, publishes.
- **The `:object_detection` task** (`BB.Estimator.ObjectDetection.Codec`) -
  what a detection codec takes and gives.
- **`BB.Estimator.ObjectDetection.Image`** - the one image-preparation path
  every image codec uses: I420 to RGB or BGR, stretch or letterbox,
  per-channel normalisation, and quantisation, all in OpenCV.
- **`BB.Estimator.ObjectDetection.FinalDetections`** - a codec for any model
  that does its own decode and suppression, such as TFLite's SSD
  post-processing.
- **`BB.Message.Vision.Detections`** - the message, and its camera overlay.

Codecs for particular model families live in their own packages, such as
[`bb_estimator_yolo`](https://github.com/beam-bots/bb_estimator_yolo).

## Options

| Option | Default | |
|---|---|---|
| `model` | required | An object-detection model declared in `inference` |
| `score_threshold` | `0.3` | Minimum score to publish |
| `nms_threshold` | `0.45` | IoU above which the lower-scoring of two boxes is dropped, whatever their classes |

## Installation

```bash
mix igniter.install bb_estimator_object_detection
```
