"""Display helpers shared by the pipeline examples. These exist so an example can show a result without hand-rolling OpenCV arithmetic. Everything here is presentation only: the SDK never draws, and nothing in ``orisys`` imports this module. The examples import it through a sibling import, which works when the examples are run from the examples directory or with ``examples/`` on ``sys.path``. """ from __future__ import annotations import cv2 import numpy as np def draw_flow_arrows(image, flow, *, threshold=0.4, grid_spacing=10, arrow_scale=1.0, valid_mask=None): """Return the deformation field drawn over ``image``.""" import orisys return orisys.util.draw_arrows( image, flow, threshold=threshold, grid_spacing=grid_spacing, arrow_scale=arrow_scale, valid_mask=valid_mask, ) def depth_to_color(depth_map): """Normalise a depth/divergence map to 8-bit and apply a colormap for the ``depth`` window. Returns ``None`` for an empty map, which is what ``read_info`` gives when the field was never generated, so a caller can skip the window instead of showing saturated noise. """ if depth_map is None or not isinstance(depth_map, np.ndarray) or depth_map.size == 0: return None lo = float(depth_map.min()) hi = float(depth_map.max()) if hi <= lo: scaled = np.zeros_like(depth_map, dtype=np.uint8) else: scaled = ((depth_map - lo) / (hi - lo) * 255.0).astype(np.uint8) return cv2.applyColorMap(scaled, cv2.COLORMAP_JET) def draw_contact(image, contour, centroid): """Return ``image`` with the contact region and centroid drawn on it.""" import orisys return orisys.util.draw_contact(image, contour, centroid)