Packages

A BB.Inference runtime that runs ONNX models through OpenCV's DNN module, via evision.

Current section

Files

Jump to
Raw

README.md

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

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

A [`bb_inference`](https://github.com/beam-bots/bb_inference) runtime that
runs ONNX models through OpenCV's DNN module, via
[evision](https://hex.pm/packages/evision).

```elixir
inference do
  model :detector do
    runtime BB.Inference.OpenCV
    source "https://github.com/Megvii-BaseDetection/YOLOX/releases/download/0.1.1rc0/yolox_nano.onnx"
    sha256 "c789161ed43c8269fcd4e67c67eeeb4e80c622da2eb296a20bc6007bd18a0b7d"
    codec BB.Estimator.Yolo.YoloX
  end
end
```

## What it can describe

OpenCV has no API for a network's declared inputs, so `describe/1` parses the
text of `Evision.DNN.Net.dump/1`. That gives every input and output's name,
element type and shape, in the graph's order, with dynamic dimensions as
`nil`. It is a debugging format rather than an API and may change between
OpenCV versions; tested with OpenCV 5.1 through evision 1.1.

It can't report quantisation or layout: both are always `nil`.

## Options

- `:backend` - an OpenCV DNN backend id
- `:target` - an OpenCV DNN target id. OpenCV 5's new graph engine ignores
  it, with a warning.

OpenCV falls back to the CPU silently, so the runtime can't confirm an
accelerator is in use.

## Installation

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