The open_vocab engine now accepts an update_vocabulary input event carrying a UTF-8 comma-separated label string. Labels are re-encoded immediately via the CLIP text encoder; the next tick uses the new vocabulary. ZedNative ignores the input via a no-op base class method.
5.4 KiB
AGENTS.md
This file provides guidance to AI coding assistants when working with code in this repository.
What this is
A dora-rs C++ node that interfaces with ZED stereo cameras. On each tick it grabs a frame, runs object detection, and publishes four outputs over the dora dataflow: a BGR image, an XYZRGBA point cloud, camera intrinsics, and detected objects with 3D positions. Camera management lives in src/zed/, detection engines in src/engines/, and the dora event loop in src/main.cc.
Build
mkdir -p build && cd build && cmake .. && make install
The binary is installed to bin/dora_zed relative to the repo root.
Requirements: CMake 3.21+, ZED SDK 5.x (at /usr/local/zed), CUDA Toolkit, ONNX Runtime 1.20+ (system install), Rust stable toolchain (for dora-rs C++ bindings).
The first build clones dora-rs from GitHub and compiles dora-node-api-cxx via Cargo. This takes a while. Subsequent builds are incremental. If DORA_ROOT_DIR is set to a local dora checkout, it builds against that instead.
Run
dora up
dora start dataflow.yml
Camera and detection behavior is configured entirely through environment variables (see README.md for the full list: ZED_RESOLUTION, ZED_FPS, ZED_DEPTH_MODE, ZED_DETECTION_MODEL, etc.).
Architecture
src/util/env.h— Shared inline env-variable parsing helpers (get_env_int,get_env_str,get_env_bool,get_env_float).src/zed/camera.h—zed::Config,zed::Calibration, andzed::Cameraclass. Camera wraps the ZED SDK lifecycle: open (with retry loop), warmup, grab (image + point cloud), calibration, and close. Exposeshandle()for engine access.src/zed/camera.cc— Implementation. SDK enum parsers live in an anonymous namespace.src/engines/engine.h—engines::DetectedObjectstruct andengines::Engineabstract base class (enable,detect,objects,label_names).src/engines/zed_native.h/cc—engines::ZedNative: wraps ZED SDK's TensorRT-optimized object detection module.src/engines/open_vocab.h/cc—engines::OpenVocab: YOLO-World open-vocabulary detection via ONNX Runtime. Supports two modes: single-input (fixed vocab, legacy) and two-input (open-vocab,images+text_feats). In two-input mode, readsZED_ONNX_LABELSon every tick; when the labels change, re-tokenizes and re-encodes via the CLIP text encoder ONNX session, then passes the resulting(1, N, 512)L2-normalized embeddings to the visual model. Preprocesses images (letterbox, normalize, CHW), runs inference, applies NMS, then fuses 2D detections with the ZED point cloud to compute 3D positions and bounding boxes.src/util/clip_tokenizer.h— Header-only C++ CLIP BPE tokenizer (no external deps). Implements the GPT-2bytes_to_unicode()byte encoder + iterative BPE merge algorithm. Loadsclip_vocab.txtandclip_merges.txtgenerated byscripts/export_clip_text_encoder.py. Returns 77int64token IDs (BOS=49406, EOS=49407, padded with 0).src/main.cc— Dora event loop. Selects engine viaZED_ENGINEenv var, holds astd::unique_ptr<engines::Engine>. Ontickinput: callscamera.grab()anddetector->detect(), then sendsimage_bgr,point_cloud,camera_info, andobjectsoutputs. Onupdate_vocabularyinput: decodes payload as a UTF-8 label string and callsdetector->set_labels()for immediate re-encoding. Handles reconnection on grab failure.DoraTargets.cmake— Handles building or fetching dora-rs and generating the CXX bridge files. Two paths: local (DORA_ROOT_DIR) or git clone. Producesdora_node_api_cxxlibrary and thenode_bridge.ccglue.dataflow.yml— Example dora dataflow definition using thegit:source format.scripts/export_yoloworld.py— PEP 723 uv script. Exports a YOLOv8-worldv2 model to ONNX with N class slots (labels arbitrary at runtime). Run:uv run scripts/export_yoloworld.py --model s --num-classes 10.scripts/export_clip_text_encoder.py— PEP 723 uv script. Exports CLIP ViT-B/32 text encoder to ONNX and savesclip_vocab.txt/clip_merges.txt. Run once; reused across all YOLO-World model sizes. Run:uv run scripts/export_clip_text_encoder.py --output-dir models/.src/test_open_vocab.cc— Standalone C++ test binary (bin/test_open_vocab). Exercises theOpenVocabengine with images fromtest/assets/yolo.pngandtest/assets/yoloworld.png(paths overridable via argv). No dora and no live camera required —enable()ignores the camera for this engine. Uses the same env vars as the main binary. Saves annotated result images alongside inputs.
Key APIs
- dora C++ API (
<dora-node-api.h>):init_dora_node(),dora_node.events->next(),event_type(),send_output_with_metadata(),new_metadata(). - ZED SDK (
<sl/Camera.hpp>):sl::Camera,sl::InitParameters,sl::RuntimeParameters,sl::Mat,sl::ObjectDetectionParameters,sl::Objects. - ONNX Runtime (
<onnxruntime_cxx_api.h>):Ort::Env,Ort::Session,Ort::SessionOptions,Ort::Value. Used by theopen_vocabengine. - Output data is sent as raw byte slices (
rust::Slice<const uint8_t>) with typed metadata (shape, dtype, encoding).
Tools
- Issue tracker: Gitea. Use the Gitea MCP tools (
mcp__gitea__*) to read and manage issues, pull requests, and other repository operations.
Rules
- Do not mention AI tools in commit messages or documentation.