Skip to content

hylo.manip.perception

Package: hylo-manip · Core contracts

perception

Perception from RGB-D: back-projection and fusion, the table plane (RANSAC), segmenters behind one interface (environment segmentation, named colours, VLM marks), per-object point clouds, oriented boxes and ICP.

COLOURS module-attribute

COLOURS: dict[str, tuple[float, float, float, float, float, float]] = {'red': (345, 15, 0.45, 1, 0.25, 1), 'orange': (15, 40, 0.45, 1, 0.6, 1), 'brown': (10, 45, 0.35, 1, 0.15, 0.6), 'yellow': (40, 70, 0.45, 1, 0.35, 1), 'green': (70, 165, 0.35, 1, 0.2, 1), 'cyan': (165, 195, 0.35, 1, 0.3, 1), 'blue': (195, 255, 0.35, 1, 0.2, 1), 'purple': (255, 290, 0.3, 1, 0.2, 1), 'pink': (290, 345, 0.3, 1, 0.3, 1), 'magenta': (290, 345, 0.3, 1, 0.3, 1), 'white': (0, 360, 0, 0.15, 0.8, 1), 'black': (0, 360, 0, 1, 0, 0.18), 'gray': (0, 360, 0, 0.15, 0.25, 0.8), 'grey': (0, 360, 0, 0.15, 0.25, 0.8)}

Segmenter

Bases: Protocol

segment

segment(view: View, labels: Sequence[str]) -> list[Mask]

Instance masks answering each text label.

EnvSegmenter

EnvSegmenter(min_pixels: int = 15)

The environment's instance segmentation (<cam>.seg with extra["segments"] labels). A query matches the segment labels with equal content words; failing that, those sharing the most words (score = overlap).

min_pixels instance-attribute

min_pixels = min_pixels

segment

segment(view: View, labels: Sequence[str]) -> list[Mask]

ColourSegmenter

ColourSegmenter(min_pixels: int = 30)

Named colours in HSV (red, orange, brown, yellow, green, cyan, blue, purple, pink, magenta, white, black, gray): a label's colour word selects pixels, split into connected components (one Mask each, score 1.0). Other words of the label are ignored, so "red block" and "red bowl" both match every red region.

min_pixels instance-attribute

min_pixels = min_pixels

segment

segment(view: View, labels: Sequence[str]) -> list[Mask]

MarkSegmenter

MarkSegmenter(choose: Callable[[ndarray, list[ndarray], str], list[int]], propose: Callable[[View], dict[str, list[ndarray]]] | None = None, min_pixels: int = 20)

A vision-language model picks among numbered regions (set-of-marks). propose(view) gives candidate regions per camera ({camera: [mask, ...]}; default: connected regions standing above the table in depth); choose(rgb, regions, label) is the model adapter: it draws the numbers, asks the model and returns the chosen indices.

depth_regions

depth_regions(view: View) -> dict[str, list[np.ndarray]]

segment

segment(view: View, labels: Sequence[str]) -> list[Mask]

backproject

backproject(cam: CameraView, mask: ndarray | None = None, max_depth: float = 4.0) -> np.ndarray

World points of the camera's valid depth pixels (optionally only inside mask).

fuse

fuse(cams: dict[str, CameraView], voxel: float = 0.005) -> np.ndarray

remove_outliers

remove_outliers(points: ndarray, k: int = 8, std: float = 2.0) -> np.ndarray

Statistical outlier removal: drop points whose mean distance to k neighbours exceeds mean + std * sigma.

components

components(points: ndarray, radius: float) -> list[np.ndarray]

Index arrays of the groups of points connected by steps shorter than radius, largest first.

ransac_table

ransac_table(points: ndarray, rng: Generator, iters: int = 300, thresh: float = 0.008, max_tilt_deg: float = 15.0, hint: float | None = None) -> Table

The near-horizontal plane with the most inliers (within 0.15 m of hint when given), refined by least squares; height is the inliers' mean z.

above_table

above_table(points: ndarray, table: Table, min_height: float = 0.006) -> np.ndarray

Points higher than min_height above the table plane.

tokens

tokens(text: str) -> list[str]

label_score

label_score(query: str, label: str) -> float

1.0 when the content words are equal; else their Jaccard overlap (0 when none shared).

hsv

hsv(rgb: ndarray) -> tuple[np.ndarray, np.ndarray, np.ndarray]

detect_objects

detect_objects(view: View, masks: Sequence[Mask], table: Table, voxel: float = 0.004, merge_radius: float = 0.015, min_points: int = 15) -> list[Detection]

Per label (and instance when known): masked depth back-projected (mask eroded by one pixel against edge pixels), points on or under the table and statistical outliers dropped (a flat marking on the table keeps its points within 1 cm of the plane), cameras merged, then split into 3D connected components: one Detection each, largest first.

fit_box

fit_box(points: ndarray, table: Table | None = None) -> Box

Minimum-area rectangle of the xy footprint (convex hull, rotating edges; extents from the 1st and 99th percentiles), z from the top of the points down to the table (or the lowest point without one).

icp

icp(model: ndarray, observed: ndarray, init: ndarray | None = None, iters: int = 40, tol: float = 0.005, yaw_steps: int = 12) -> Fit

Point-to-point ICP of model onto observed (each observed point to its nearest model point, so a partial view fits). Without init: centroids aligned and yaw_steps yaws about +z tried, the best refined.