Implementation snapshot supporting the published lesson. Only cited line ranges are included; this is not a runnable source file. Configuration and recorded examples describe this project snapshot.
… uncited lines omitted …125def prepare_depth(raw, scale, near, far, fov_keep):126 """Convert sensor units to mm and apply distance and central-ROI masks."""127 metres = raw.astype(np.float32) * scale128 valid = (metres >= near) & (metres <= far) & (raw > 0)129 h, w = raw.shape130 y, x = int(round(h * (1 - fov_keep) / 2)), int(round(w * (1 - fov_keep) / 2))131 roi = np.zeros_like(valid)132 roi[y:h-y, x:w-x] = True133 return np.ascontiguousarray(134 np.where(valid & roi, np.rint(np.clip(metres * 1000, 0, 65535)), 0).astype(np.uint16))