scene_service.scene_graph.image_relations

Image-grounded relation inference.

Tracked objects are projected into the current RGB keyframe as numbered boxes, and one VLM call names the relations between the numbers. Contact and containment are read far better from pixels than from boxes; the metric relations (near, reachable_by) stay with the geometric loop.

Functions

annotate_frame(rgb_bgr, boxes, *[, max_dim])

Numbered rectangles drawn on a copy of the frame, downscaled to max_dim after drawing, as base64 JPEG; None if encoding fails.

build_image_relation_user_text(legend)

The box-number → label legend and the instruction.

parse_image_relations(raw, box_to_oid)

Validated edges from the VLM's {"edges": [...]}; unknown boxes, self-edges, duplicates and off-vocabulary relations are skipped.

project_box(T_cam_map, K, center, extent, ...)

Clipped pixel rect (u0, v0, u1, v1) of a 3D box, or None when fewer than two corners are in front of the camera or it is out of frame.

project_point(T_cam_map, K, p_world)

Map-frame point → (u, v, depth) pixels through the camera-optical→map transform and pinhole K; None behind the camera.

Classes

ImageRelationInferer(llm_client, *, max_dim, ...)

project → annotate → one VLM call → parse, reusing the last answer while the visible objects stay the same.

class scene_service.scene_graph.image_relations.ImageRelationInferer(llm_client, *, max_dim: int | None = None, frame_change_threshold: float | None = None, failure_backoff_base_s: float | None = None, failure_backoff_max_s: float | None = None, clock: Callable[[], float]=<built-in function monotonic>)[source]

Bases: object

project → annotate → one VLM call → parse, reusing the last answer while the visible objects stay the same.

async infer(nodes: list[SceneGraphNode], bundle: tuple[ndarray, Any, ndarray]) → ImageRelationResult | None[source]

This round’s result, or None when it cannot run. Failure and backoff stay distinct: only a real failed call ages the edges.

property inference_counts: dict[str, int]
class scene_service.scene_graph.image_relations.ImageRelationResult(edges: tuple[SceneGraphEdge, ...], outcome: Literal['processed', 'cached', 'failed', 'backoff'])[source]

Bases: object

Edges plus the decision that produced them.

edges: tuple[SceneGraphEdge, ...]
outcome: Literal['processed', 'cached', 'failed', 'backoff']
scene_service.scene_graph.image_relations.annotate_frame(rgb_bgr: ndarray, boxes: list[tuple[int, tuple[int, int, int, int]]], *, max_dim: int = 960) → str | None[source]

Numbered rectangles drawn on a copy of the frame, downscaled to max_dim after drawing, as base64 JPEG; None if encoding fails.

scene_service.scene_graph.image_relations.build_image_relation_user_text(legend: list[tuple[int, str]]) → str[source]

The box-number → label legend and the instruction.

scene_service.scene_graph.image_relations.parse_image_relations(raw: dict, box_to_oid: dict[int, str]) → list[SceneGraphEdge][source]

Validated edges from the VLM’s {“edges”: […]}; unknown boxes, self-edges, duplicates and off-vocabulary relations are skipped.

scene_service.scene_graph.image_relations.project_box(T_cam_map: ndarray, K: Any, center: tuple[float, float, float], extent: tuple[float, float, float], yaw: float, img_w: int, img_h: int) → tuple[int, int, int, int] | None[source]

Clipped pixel rect (u0, v0, u1, v1) of a 3D box, or None when fewer than two corners are in front of the camera or it is out of frame.

scene_service.scene_graph.image_relations.project_point(T_cam_map: ndarray, K: Any, p_world: tuple[float, float, float]) → tuple[float, float, float] | None[source]

Map-frame point → (u, v, depth) pixels through the camera-optical→map transform and pinhole K; None behind the camera.