<!--
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_aruco

[![CI](https://github.com/beam-bots/bb_estimator_aruco/actions/workflows/ci.yml/badge.svg)](https://github.com/beam-bots/bb_estimator_aruco/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_aruco.svg)](https://hex.pm/packages/bb_estimator_aruco)
[![Hexdocs badge](https://img.shields.io/badge/docs-hexdocs-purple)](https://hexdocs.pm/bb_estimator_aruco)
[![REUSE status](https://api.reuse.software/badge/github.com/beam-bots/bb_estimator_aruco)](https://api.reuse.software/info/github.com/beam-bots/bb_estimator_aruco)
[![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/beam-bots/bb_estimator_aruco)

A [Beam Bots](https://github.com/beam-bots/bb) estimator that finds
[ArUco](https://docs.opencv.org/4.x/d5/dae/tutorial_aruco_detection.html)
fiducial markers in camera frames, using OpenCV through
[evision](https://hex.pm/packages/evision).

Nest it inside any [`bb_camera`](https://github.com/beam-bots/bb_camera)
camera:

```elixir
topology do
  link :head do
    sensor :camera, {BB.Camera.V4L, device: "/dev/video0", width: 640, height: 480} do
      estimator :markers, {BB.Estimator.ArUco, dictionary: :dict_4x4_50}
    end
  end
end
```

For every frame it examines it publishes a `BB.Message.Vision.Fiducials` at
`[:sensor, :head, :camera, :markers]`: each marker's ID and its four corners
in pixels, stamped with the frame's capture time. A frame with no markers in
it publishes an empty list.

```elixir
BB.subscribe(MyRobot, [:sensor, :head, :camera, :markers])

receive do
  {:bb, _path, %BB.Message{payload: %BB.Message.Vision.Fiducials{markers: markers}}} ->
    Enum.map(markers, & &1.id)
end
```

## Installation

```elixir
def deps do
  [
    {:bb_estimator_aruco, "~> 0.1.0"}
  ]
end
```

`evision` downloads a precompiled OpenCV for your platform when it compiles.

## Printing markers

Print markers from the dictionary the estimator is configured with; a marker
from any other dictionary is not detected. `mix bb_estimator_aruco.gen.markers`
writes them as PNGs, each with the white border the detector needs:

```bash
mix bb_estimator_aruco.gen.markers --dictionary dict_4x4_50 --ids 0..3,7 --output markers --sheet
```

That writes `markers/dict_4x4_50_0.png` and so on, plus
`markers/dict_4x4_50_sheet.png` with all of them on one page.
`mix help bb_estimator_aruco.gen.markers` lists the options for marker size,
border width and the rest.
