Skip to main content

warden_vision/
lib.rs

1//! `warden-vision`: reusable computer vision building blocks for
2//! detection, tracking, and annotation, mirroring the API shape of
3//! Roboflow's Python `supervision` library.
4//!
5//! # Modules
6//! - [`core`]: [`core::Detection`] / [`core::Detections`], the shared
7//!   currency between detectors, trackers, zones, and annotators, plus
8//!   [`core::KeyPoints`] (pose/landmark data, [`core::COCO_17_EDGES`]
9//!   skeleton), [`core::Classifications`] (whole-image classification),
10//!   [`core::InferenceSlicer`] (tiled/SAHI-style inference), and
11//!   [`core::Detections::from_ultralytics_onnx`] /
12//!   [`core::Detections::from_transformers_onnx`] for parsing raw
13//!   detector output tensors (see their docs for why these parse tensors
14//!   rather than binding to `ultralytics`/`transformers` objects).
15//! - [`geometry`]: [`geometry::Point`], [`geometry::Rect`], the anchor-point
16//!   [`geometry::Position`] enum, polygon utilities
17//!   ([`geometry::polygon_area`], [`geometry::polygon_centroid`],
18//!   [`geometry::polygon_to_rect`]), the [`geometry::Zone`] trait, and its
19//!   [`geometry::LineZone`] / [`geometry::PolygonZone`] implementations.
20//! - [`tracker`]: [`tracker::SortTracker`] (single-stage Kalman + IoU) and
21//!   [`tracker::ByteTracker`] (two-stage high/low-confidence matching,
22//!   after Zhang et al.'s ByteTrack), both assigning
23//!   [`core::Detection::tracker_id`]; [`tracker::DetectionsSmoother`] to
24//!   damp jitter in a tracked box across frames.
25//! - [`annotators`]: the [`annotators::Annotator`] trait and a family of
26//!   drawing configs — boxes (round-cornered, corner-only), masks,
27//!   polygons, labels (bitmap font, or under `annotate-image` real
28//!   TTF/OTF via `annotators::RichLabelAnnotator`), circles, dots,
29//!   triangles, ellipses, motion traces, heat maps, halos, percentage
30//!   bars, icon overlays, background dimming, blur/pixelate redaction,
31//!   zone outlines, and keypoint skeletons — with pure-Rust
32//!   (`annotate-image`) and OpenCV (`annotate-opencv`) rendering
33//!   backends (`RichLabelAnnotator` is pure-Rust only; see its docs for
34//!   why).
35//! - [`metrics`]: [`metrics::Precision`], [`metrics::Recall`],
36//!   [`metrics::F1Score`], [`metrics::ConfusionMatrix`],
37//!   [`metrics::MeanAveragePrecision`], and
38//!   [`metrics::MeanAverageRecall`] for scoring predicted
39//!   [`core::Detections`] against ground truth.
40//! - [`utils`]: [`utils::FPSMonitor`] for throughput reporting, plus
41//!   (under `annotate-image`) `utils::resize_keeping_aspect_ratio`,
42//!   `utils::letterbox`, `utils::crop_image`, `utils::overlay_image`, and
43//!   `utils::ImageSink` for writing a numbered frame sequence.
44//! - `dataset` (under `datasets`): `dataset::DetectionDataset` plus COCO
45//!   (`dataset::coco`), YOLO (`dataset::yolo`), and Pascal VOC
46//!   (`dataset::pascal_voc`) loaders/exporters, and
47//!   `dataset::ClassificationDataset` with an image-folder-per-class
48//!   loader/exporter (`dataset::classification`).
49//! - `video` (under `annotate-opencv`): `video::VideoInfo`,
50//!   `video::frames`, and `video::VideoSink` for reading and writing
51//!   video files via OpenCV's `videoio`.
52//!
53//! (Items behind a non-default feature are written above as plain
54//! `code text` rather than intra-doc links, since those links only
55//! resolve when this crate's docs are built with that feature enabled.
56//! The published docs build with `annotate-image` and `datasets` — see
57//! `[package.metadata.docs.rs]` in `Cargo.toml` — but not
58//! `annotate-opencv`, since docs.rs has no system OpenCV install; read
59//! `video`'s module docs directly in `src/video/mod.rs` instead.)
60//!
61//! # Scope
62//! This crate targets the core, dependency-light building blocks of
63//! Roboflow's `supervision`: detection/keypoint/classification data
64//! structures, geometry, tracking, annotation, evaluation metrics,
65//! dataset I/O, image utilities, and OpenCV-backed video I/O. Remaining
66//! known gaps: `RichLabelAnnotator` has no `annotate-opencv`
67//! implementation (OpenCV has no built-in TTF rendering without
68//! FreeType); a dedicated `OrientedBoxAnnotator` doesn't exist since
69//! [`annotators::PolygonAnnotator`] already draws an arbitrary 4-point
70//! rotated box stored in [`core::Detection::mask`]; and detector-output
71//! parsing covers Ultralytics YOLO and DETR-family `transformers` models
72//! (the two most common) rather than every framework `supervision` has
73//! an adapter for.
74
75pub mod annotators;
76pub mod core;
77#[cfg(feature = "datasets")]
78pub mod dataset;
79pub mod error;
80pub mod geometry;
81pub mod metrics;
82pub mod tracker;
83pub mod utils;
84#[cfg(feature = "annotate-opencv")]
85pub mod video;
86
87pub use error::{Error, Result};