Bounding Box Overlay
Color-coded detection boxes positioned over an image as percentage offsets from natural dimensions, with a companion label legend. Serves object / face / hand / pose output.
Bounding Box Overlay
The Bounding Box Overlay renders detection results ({ label, score, box }) as absolutely-positioned, color-coded boxes with label chips over a parent image. Pixel-coordinate boxes are converted to percentage offsets using the image's natural width/height, so placement is correct at any display size — resize the container and the boxes stay aligned. A companion DetectionLabelLegend renders a wrapping strip of color → class pills that match the overlay colors.
The overlay consumes one shape — { label, score, box }, where box is { x, y, width, height } in natural image pixels. useDetectObjects returns this directly (DetectObjectsResult.objects, each a DetectedObject). useDetectFace returns boxes too (FaceDetectionResultItem has box + score, but no label), and useDetectHands / useDetectPose return landmark sets ({ landmarks, worldLandmarks, … }, no box) — for those, derive a label (and, for hands/pose, a box from the landmark extents) before passing them in.
When to use it: object/face detection viewers, pose/hand annotation, anything that draws boxes over a still image. (For real-time webcam landmark drawing, use the Video Canvas instead.)
Preview
Installation
pnpm dlx shadcn@latest add @localmode/ui/media-vision/bounding-box-overlaynpx shadcn@latest add @localmode/ui/media-vision/bounding-box-overlayyarn dlx shadcn@latest add @localmode/ui/media-vision/bounding-box-overlaybunx --bun shadcn@latest add @localmode/ui/media-vision/bounding-box-overlayDependencies
-
Data source: renders the
{ label, score, box }detections you pass — works with any backend that returns boxes. Recommended LocalMode producer:useDetectObjectsfrom@localmode/react(itsDetectedObjectmatches this shape directly).useDetectFaceboxes (nolabel) anduseDetectHands/useDetectPoselandmark output map in with a small adapter (optional). -
clsx+tailwind-merge— via the sharedcn()util (installed automatically as a registry dependency)
Files installed
bounding-box-overlay.tsx—BoundingBoxOverlay+DetectionLabelLegendlib/utils.ts— thecn()helper (if not already present)
Props
BoundingBoxOverlay
Prop
Type
DetectionLabelLegend
Prop
Type
Backing hooks
Feed it { label, score, box } detections plus the image's naturalWidth / naturalHeight (read off the rendered <img>). useDetectObjects from @localmode/react returns objects in this shape directly; useDetectFace returns boxes without a label, and useDetectHands / useDetectPose return landmark sets (no box) — map those to { label, score, box } before passing them in.
Examples
Over a detection result
import { BoundingBoxOverlay, DetectionLabelLegend } from '@/components/bounding-box-overlay';
import { useDetectObjects } from '@localmode/react';
export function Example({ src }: { src: string }) {
const imgRef = useRef<HTMLImageElement>(null);
const { data } = useDetectObjects({ model });
return (
<>
<div className="relative">
<img ref={imgRef} src={src} alt="" className="w-full" />
{data && (
<BoundingBoxOverlay
detections={data.objects}
naturalWidth={imgRef.current?.naturalWidth ?? 0}
naturalHeight={imgRef.current?.naturalHeight ?? 0}
/>
)}
</div>
{data && <DetectionLabelLegend labels={data.objects.map((o) => o.label)} />}
</>
);
}Boxes without label chips (dense output)
// `detections` is already shaped as { label, score, box }[]
<BoundingBoxOverlay detections={detections} naturalWidth={w} naturalHeight={h} hideLabels />Customization
Colors come from Tailwind palette classes in the internal COLOR_SLOTS array — edit them in the copied bounding-box-overlay.tsx to match your design system; the legend reads the same map so the two stay in sync. The overlay is non-interactive (pointer-events-none) and fills its relative parent.
Media Dropzone
A drag-and-drop + click-to-browse image upload zone with accept-list / max-size validation, idle / drag-over / processing states, and an "add another" variant.
Before / After Image Viewer
Compare an original image with a transformed result — a two-panel grid with checkerboard transparency or a segmented Original / Enhanced toggle.