Skip to main content

vision_payload

Function vision_payload 

Source
pub fn vision_payload(source: &str, wake: &VisualWake) -> Value
Expand description

The payload of wake from the stream source, as compact JSON within WAKE_PAYLOAD_LIMIT bytes: kind (vision), source, session, condition, event, label, score, track, frames, frame (index, capturedAt, digest, width, height, artifact), regions (each box, label, score, track) and moreRegions, the count of regions left out.

Texts are cut to 64 characters (the digest to 80, the frame’s file name to 128) and boxes rounded to a tenth of a pixel, so the fixed part stays under 3.5 KiB; the regions kept are the longest prefix of wake.regions that fits.

§Example

use adk_kernel::{VisualFrame, VisualRegion, VisualWake, WAKE_PAYLOAD_LIMIT, vision_payload};

let frame = VisualFrame::new(9, chrono::Utc::now(), "sha256:0f3a", 1280, 720);
let many = (0..500).map(|i| VisualRegion::new([i as f32, 0.0, i as f32 + 10.0, 10.0]).with_label("scratch"));
let wake = VisualWake::new("s1", "scratch", "detected", 1, "scratch", 0.7, frame).with_regions(many);
let payload = vision_payload("conveyor-1", &wake);
assert!(payload.to_string().len() <= WAKE_PAYLOAD_LIMIT);
let kept = payload["regions"].as_array().unwrap().len() as u64;
assert_eq!(kept + payload["moreRegions"].as_u64().unwrap(), 500);