Skip to content

Commit 3626d62

Browse files
committed
Add depth to the web wrapper Results and annotate
Expose depth (RGBA overlay) and depth_range on the Results type and draw the colorized depth map in annotate, mirroring the mask overlay path. Signed-off-by: Onuralp SEZER <onuralp@ultralytics.com>
1 parent 44056d7 commit 3626d62

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

web/src/index.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@ export interface Results {
105105
* class-filtered pixels. The `masks` overlay is its renderable form.
106106
*/
107107
semantic_mask?: Uint16Array;
108+
/**
109+
* Depth map as an opaque INFERNO-colorized RGBA image (`width*height*4`),
110+
* empty for other tasks. Drawable straight onto a canvas via `ImageData`.
111+
*/
112+
depth: Uint8Array;
113+
/** Depth range `[min, max]` in meters over valid pixels, for depth models. */
114+
depth_range?: [number, number];
108115
speed: Speed;
109116
}
110117

@@ -742,6 +749,15 @@ export async function annotate(
742749
ctx.drawImage(tmp as CanvasImageSource, 0, 0, width, height);
743750
}
744751

752+
// Depth: the engine returns an opaque INFERNO-colorized depth image; draw it
753+
// over the frame so the canvas shows the depth map.
754+
const depth = results.depth;
755+
if (depth && depth.length === width * height * 4) {
756+
const tmp = makeCanvas(width, height);
757+
get2d(tmp).putImageData(new ImageData(new Uint8ClampedArray(depth), width, height), 0, 0);
758+
ctx.drawImage(tmp as CanvasImageSource, 0, 0, width, height);
759+
}
760+
745761
const lineWidth = options?.lineWidth ?? Math.max(2, Math.round(width / 320));
746762
const fontSize = Math.max(12, Math.round(width / 40));
747763
const font = options?.font ?? `${fontSize}px sans-serif`;

0 commit comments

Comments
 (0)