Repository navigation
feat(depth): add DepthMap and DepthAnnotator - #2691
Merged
Merged
Conversation
Colour any depth array over an image. Wrap a stereo disparity, metric depth or relative depth array in sv.DepthMap with the kind of value it holds, then draw it with sv.DepthAnnotator: near objects come out warm, far ones cool, and pixels without depth stay unpainted so the image shows through. It works on NumPy and Pillow images without OpenCV. - sv.DepthKind names what the values measure. NaN, infinities and values at or below 0 (below 0 for relative maps) are no depth, and valid_mask marks the rest. - sv.DepthAnnotator takes a colour table (sv.DepthColormap: Turbo, Viridis, Cividis, Inferno, Magma or grayscale), a display_range of "auto" (the map's own 2nd to 98th percentile) or a fixed (low, high) tuple, and an opacity. A metric map is coloured as inverse depth, so near detail gets most of the colours. - Reference pages, a how-to guide and a changelog entry. Closes #1313 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #2691 +/- ##
========================================
Coverage 93% 93%
========================================
Files 78 81 +3
Lines 11996 12228 +232
========================================
+ Hits 11117 11349 +232
Misses 879 879 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Narrow valid display ranges are normalized incorrectly, and public examples recommend a private API.
3 open findings
What changed in this PR
Adds first-class depth-map storage and OpenCV-free visualization.
Changes:
- Introduces
DepthMap, depth kinds, colormaps, andDepthAnnotator. - Exports the APIs and adds comprehensive tests.
- Adds reference docs, a how-to, navigation, and changelog entry.
Review scores: Code quality 3/5 · Testing 4/5 · Documentation 3/5
| File | Description |
|---|---|
src/supervision/depth/core.py |
Defines depth-map types and range calculation. |
src/supervision/depth/colormaps.py |
Adds vendored color tables and interpolation. |
src/supervision/depth/annotators.py |
Implements depth coloring, resizing, and blending. |
src/supervision/depth/__init__.py |
Initializes the depth package. |
src/supervision/__init__.py |
Exports the new public APIs. |
tests/depth/test_core.py |
Tests depth-map behavior. |
tests/depth/test_colormaps.py |
Verifies color tables and mapping. |
tests/depth/test_annotators.py |
Tests annotation, ranges, resizing, and Pillow support. |
tests/depth/__init__.py |
Initializes the test package. |
docs/depth/core.md |
Adds core API reference. |
docs/depth/annotators.md |
Adds annotator reference and examples. |
docs/how_to/visualize_depth.md |
Adds a depth visualization guide. |
mkdocs.yml |
Adds depth pages to navigation. |
docs/changelog.md |
Records the new feature. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
The how-to and the DepthAnnotator example read the image through supervision._cv2, which the OpenCV migration guide marks private and not application API. They now open it with Pillow, so the examples stay OpenCV-free like the feature itself. A fixed display_range narrower than 1e-20 no longer gets stretched by a floor on its width; every range is already validated as low < high. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The six colour tables now come from matplotlib, already a dependency, instead of 140 lines of vendored hex. Colours are byte-identical to the old tables on matplotlib 3.6.3 and 3.10.3. Co-Authored-By: Claude Opus 5.5 <[email protected]>
No other annotator validates opacity, so DepthAnnotator no longer does either. Also fixes a test docstring that mentioned cameras, which this PR does not add. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The changelog says the annotator does not require OpenCV rather than that it runs without it, and uses the ([#N](...)) link style. The DepthKind docstring says relative_inverse only promises larger is nearer. Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # docs/changelog.md
Borda
added a commit
that referenced
this pull request
Oct 8, 2026
[resolve No.5] Review by foundry:sw-engineer (PR #2691): "**[high] `display_range=(low, high)` is read in the coloured unit (1/m f..." Challenge: evidence=VALID suggestion=VALID resolution=as-suggested --- Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Borda
added a commit
that referenced
this pull request
Oct 8, 2026
[resolve No.6] Review by foundry:sw-engineer (PR #2691): "**[medium] Flat or single-valid-pixel map colour depends on `kind` and f..." Challenge: evidence=VALID suggestion=VALID resolution=as-suggested --- Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Borda
added a commit
that referenced
this pull request
Oct 8, 2026
[resolve No.7] Review by foundry:sw-engineer (PR #2691): "**[medium] Explicit `display_range` validation gaps: wrong arity or `Non..." Challenge: evidence=VALID suggestion=VALID resolution=as-suggested --- Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Borda
added a commit
that referenced
this pull request
Oct 8, 2026
[resolve No.22] Review by foundry:solution-architect (PR #2691): "**[low] Colour-range policy lives on the container and is consumed throu..." Challenge: evidence=VALID suggestion=VALID resolution=as-suggested --- Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Borda
added a commit
that referenced
this pull request
Oct 8, 2026
[resolve No.18] Review by foundry:perf-optimizer (PR #2691): "**[low] `valid_mask` recomputed three times per annotate, plus extra flo..." Challenge: evidence=VALID suggestion=REJECT resolution=self-resolved --- Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Borda
added a commit
that referenced
this pull request
Oct 8, 2026
[resolve No.20] Review by foundry:solution-architect (PR #2691): "**[medium] `DepthKind.RELATIVE_INVERSE` name and contract disagree; no k..." Challenge: evidence=VALID suggestion=VALID resolution=as-suggested --- Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Borda
added a commit
that referenced
this pull request
Oct 8, 2026
[resolve No.21] Review by foundry:solution-architect (PR #2691): "**[low] `DepthMap` invariants unprotected and float32 input aliased** — ..." Challenge: evidence=VALID suggestion=REJECT resolution=self-resolved --- Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Borda
added a commit
that referenced
this pull request
Oct 8, 2026
[resolve No.15] Review by foundry:perf-optimizer (PR #2691): "**[medium] Resize via 2-D broadcast fancy index is the slow path** — `sr..." Challenge: evidence=VALID suggestion=VALID resolution=as-suggested --- Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Borda
added a commit
that referenced
this pull request
Oct 8, 2026
[resolve No.16] Review by foundry:perf-optimizer (PR #2691): "**[medium] Masked copy with a broadcast `(H,W,1)` mask** — `src/supervis..." Challenge: evidence=VALID suggestion=VALID resolution=as-suggested --- Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Borda
added a commit
that referenced
this pull request
Oct 8, 2026
[resolve No.9] Review by foundry:sw-engineer (PR #2691): "**[medium] `_blend` re-implements the weighted sum available as `supervi..." Challenge: evidence=VALID suggestion=VALID resolution=as-suggested --- Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Borda
added a commit
that referenced
this pull request
Oct 8, 2026
[resolve No.8] Review by foundry:sw-engineer (PR #2691): "**[medium] `opacity` unvalidated: out-of-range values silently no-op or ..." Challenge: evidence=VALID suggestion=REJECT resolution=self-resolved --- Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Borda
added a commit
that referenced
this pull request
Oct 8, 2026
[resolve No.23] Review by foundry:solution-architect (PR #2691): "**[low] Map and scene aspect-ratio mismatch stretched silently** — `src/..." Challenge: evidence=VALID suggestion=REJECT resolution=self-resolved --- Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Borda
added a commit
that referenced
this pull request
Oct 8, 2026
[resolve No.4] Review by codecov[bot] (PR #2691): "## [Codecov](https://app.codecov.io/gh/roboflow/supervision/pull/2691?dr..." Challenge: evidence=VALID suggestion=REJECT resolution=self-resolved --- Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Borda
added a commit
that referenced
this pull request
Oct 8, 2026
[resolve No.9] Review by foundry:sw-engineer (PR #2691): "add a one-line docstring note on why _index_map samples pixel centres in..." Challenge: evidence=VALID suggestion=VALID resolution=as-suggested --- Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
DepthMap and DepthAnnotator
- fix(depth): read display_range in the map's own unit - fix(depth): paint flat maps at the far end for all kinds - fix(depth): validate display_range length and float32 span - docs(depth): document the opacity clamp [resolve group] PR #2691 — items 5 6 7 8 --- Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
- refactor(depth): move auto range policy into annotators - docs(depth): fix RELATIVE_INVERSE contract, add guidance - docs(depth): document DepthMap aliasing and mask rules - docs(depth): note per-axis stretch of other ratios - docs(depth): explain centre sampling in _index_map [resolve group] PR #2691 — items 22 20 21 23 9 --- Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
- perf(depth): compute the valid mask once per annotate - perf(depth): resample the map with 1-D takes - perf(depth): copy blended pixels with a full mask - refactor(depth): blend through _cv2.addWeighted [resolve group] PR #2691 — items 18 15 16 9 --- Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
- test(depth): cover TypeError, drop dead branch - test(depth): cover kinds under auto and relative - test(depth): cover annotator boundary inputs - test(depth): widen DepthMap and enum tests - test(depth): pin colours with literal oracles - test(depth): tidy test names and docstrings [resolve group] PR #2691 — items 4 10 11 12 13 14 --- Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Borda
force-pushed
the
feat/depth-1-show
branch
from
October 8, 2026 21:45
711cc55 to
20af081
Compare
- `DepthAnnotator.annotate` raises `ValueError` for a scene that is not uint8, so OpenCV and the NumPy fallback blend the same input and `opacity >= 1` no longer writes 0-255 into a float scene - `display_range` that is not a pair of numbers (`5`, `None`, `"12"`, non-numeric bounds) raises `ValueError` naming the parameter instead of `TypeError` - the reciprocal in `_Conversion.apply` ignores float32 overflow, so a depth near zero inverts to infinity without a `RuntimeWarning` - tests cover opacity outside 0 to 1, partial opacity over a map without holes, holes under a stretched map, list/int/array ranges and a metric range whose inverse overflows float32 --- Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Borda
approved these changes
Oct 8, 2026
cfviotti
added a commit
that referenced
this pull request
Oct 9, 2026
Brings in the squash-merged #2691 with Jirka's follow-ups. Adaptations: - DepthMap._percentile_range stays removed (it now lives in annotators.py as _percentile_range); the loaders never called it. - visualize_depth.md: the relative-depth inversion example imports numpy itself, since the loading section now imports numpy only in the Stereo tab. - from_transformers docstring: relative_inverse is suggested for Depth Anything V1 and V2 (not V3, whose map grows with distance per DepthKind). Co-Authored-By: Claude Opus 5.5 <[email protected]>
cfviotti
added a commit
that referenced
this pull request
Oct 9, 2026
Brings in the squash-merged #2691 with the maintainer's edits. Adaptations: - DepthClipRange moves from depth/core.py to depth/annotators.py, next to the range helpers it reuses (_check_percentiles, _values_at_ranks), which #2691 moved there; sv.DepthClipRange is unchanged. Its docs entry and tests follow it to depth/annotators.md and tests/depth/test_annotators.py. - A clip range is read in the maps' own unit and converted like a tuple through _convert_display_range, so an unusable one raises ValueError at annotate instead of falling back to the percentile range. - A flat clip (equal ends) is accepted and paints every pixel the far-end colour, as "auto" does on a flat map; the old one-step widening is gone. - DepthClipRange also rejects a span that does not fit in float32. Co-Authored-By: Claude Opus 5.5 <[email protected]>
cfviotti
added a commit
that referenced
this pull request
Oct 9, 2026
Brings in #2691 as squash-merged with the maintainer's edits. Adaptations: - display_range stays in the map's own unit for every quantity: with quantity="depth" on a disparity map with a camera it is read in pixels and converted to metres; a range with low + doffs_px <= 0 is rejected. - The auto range comes from annotators._percentile_range with the quantity's conversion; DepthMap._percentile_range(quantity=...) is gone. - A flat range paints the far end for quantity="depth" too: the near_is_low flip runs after the maintainer's flat-range early return. - DepthMap.resize("nearest") samples with 1-D takes per axis. - Docs and docstrings describe display_range in the map's unit. Co-Authored-By: Claude Opus 5.5 <[email protected]>
cfviotti
added a commit
that referenced
this pull request
Oct 9, 2026
Brings in #2691 and #2692 (DepthClipRange) as merged, with the maintainer's edits. Adaptations: - changelog: loaders bullet (#2694) sits above the new #2692 and #2697 bullets. - visualize_depth.md front matter: description covers loading and colouring over images and video. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Top: one moment seen by two cameras 6.5 cm apart (Spring dataset). Bottom left: the depth a stereo matcher computes from the two views, coloured over the left view. Near things are warm, far things are cool, and pixels the matcher could not match stay uncoloured instead of being painted as far away. Bottom right: the dataset's true depth, for comparison.
The same depth in each colour table. Turbo is the default. Viridis and Cividis stay readable in grayscale and for colour-blind readers.
Description
supervision cannot show a depth map. Depth models (Depth Anything, YOLO26 depth, stereo matchers) all return one, and the usual fix is a hand-written
cv2.applyColorMapcall: it needs OpenCV, which supervision no longer requires, takes only 8-bit input, and paints pixels the model could not measure as if they were far away.This PR adds a depth map type and an annotator that colours it. It does not require OpenCV:
Near objects come out warm and far ones cool, and pixels without depth stay uncoloured so the image shows through.
This is part 1 of 4. Later parts, each built only on this one: one colour range across a video, distance in metres per detection, and loaders for model outputs and dataset files.
Motivation and Context
Part of #1313: this covers depth maps. Normal and gradient maps from that issue are not included. Follows the note there to do it without cv2.
Changes Made
sv.DepthMap(values, kind): one frame of depth as float32.sv.DepthKindsays what the values measure:disparity_px,depth_morrelative_inverse(a monocular model's normalised output).valid_maskmarks the pixels that hold depth.sv.DepthAnnotator(colormap, display_range, opacity):colormap: Turbo (default), Viridis, Cividis, Inferno, Magma or grayscale (sv.DepthColormap), with near always at the warm or bright end.display_range:"auto"(the map's 2nd to 98th percentile) or a fixed(low, high).docs/depth/, a how-to (docs/how_to/visualize_depth.md) and a changelog entry.Testing
docs/changelog.mdunderUnreleasedAdditional Notes
media.roboflow.comwith the other annotator examples.opencv-pythonis not needed. Stretching the map to the scene uses NumPy indexing.