Admit observed crossing ground between zebra markings
This commit is contained in:
@@ -0,0 +1,120 @@
|
||||
"""Crossing permission covers asphalt gaps, never unrelated road or obstacles."""
|
||||
import importlib
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def module(monkeypatch):
|
||||
monkeypatch.syspath_prepend(str(Path(__file__).parents[1] / 'simulation/ai-polygon'))
|
||||
return importlib.import_module('urban_crossing')
|
||||
|
||||
|
||||
def scene():
|
||||
x, y = np.meshgrid(np.arange(.4, 8, .2), np.arange(-3, 3, .2), indexing='ij')
|
||||
points = np.column_stack((x.ravel(), y.ravel(), np.zeros(x.size)))
|
||||
pixels = np.unravel_index(np.arange(len(points)), (512, 512))
|
||||
labels = np.zeros((512, 512), np.uint8)
|
||||
near = (np.abs(points[:, 1]) <= 1.05)
|
||||
paint = near & (points[:, 0] >= 1) & (points[:, 0] <= 6.1) & (np.mod(points[:, 0]+.01, 1) < .45)
|
||||
sidewalk = near & ((points[:, 0] < 1) | (points[:, 0] >= 6.5))
|
||||
labels[pixels[0][paint], pixels[1][paint]] = 3
|
||||
labels[pixels[0][sidewalk], pixels[1][sidewalk]] = 1
|
||||
return labels, points, pixels, np.array([0, 0, .37, 0, 0, 0, 1.])
|
||||
|
||||
|
||||
def gate(module):
|
||||
return module.MarkedCrossing(dict(length_m=1.16, width_m=.905,
|
||||
body_contact_height_m=.37, max_slope_degrees=25))
|
||||
|
||||
|
||||
def enter(g, data):
|
||||
g.observe(*data, 10.)
|
||||
g.observe(*data, 10.4)
|
||||
return g.observe(*data, 10.8)
|
||||
|
||||
|
||||
def test_stripes_admit_connected_ground_gaps_only_after_entry_stop(module):
|
||||
data = scene(); labels, points, pixels, _ = data; g = gate(module)
|
||||
mask, status = g.observe(*data, 10.)
|
||||
assert not mask.any() and status['state'] == 'waiting-for-stop'
|
||||
g.observe(*data, 10.4)
|
||||
mask, status = g.observe(*data, 10.8)
|
||||
assert status['admitted'] and status['speed_limit_mps'] is None
|
||||
inside = (points[:, 0] > 1.1) & (points[:, 0] < 6.1) & (np.abs(points[:, 1]) < .9)
|
||||
assert mask[pixels][inside].all()
|
||||
assert mask[pixels][inside & (labels[pixels] == 0)].any()
|
||||
assert not mask[pixels][np.abs(points[:, 1]) > 1.1].any()
|
||||
|
||||
|
||||
def test_exit_evidence_and_ground_area_are_required(module):
|
||||
data = scene(); labels, _, pixels, _ = data
|
||||
labels[labels == 1] = 0
|
||||
mask, status = enter(gate(module), data)
|
||||
assert not mask.any() and not status['admitted']
|
||||
labels[:] = 0
|
||||
labels[pixels[0][:8], pixels[1][:8]] = 3
|
||||
assert not enter(gate(module), data)[0].any()
|
||||
|
||||
|
||||
def test_active_crossing_survives_paint_flicker_but_not_obstacles_or_new_road(module):
|
||||
data = scene(); labels, points, pixels, pose = data; g = gate(module)
|
||||
original, status = enter(g, data)
|
||||
assert status['admitted']
|
||||
labels[labels == 3] = 0
|
||||
mask, _ = g.observe(*data, 11.)
|
||||
np.testing.assert_array_equal(mask, original)
|
||||
ix = np.flatnonzero(mask[pixels])[:3]
|
||||
# Unknown raised object, explicit wall, and explicit conflict each veto.
|
||||
points[ix[0], 2] = 1.
|
||||
labels[pixels[0][ix[1]], pixels[1][ix[1]]] = 4
|
||||
labels[pixels[0][ix[2]], pixels[1][ix[2]]] = 5
|
||||
mask, _ = g.observe(*data, 11.2)
|
||||
assert not mask[pixels][ix].any()
|
||||
assert not mask[pixels][np.abs(points[:, 1]) > 1.1].any()
|
||||
assert not g.observe(*data, 9.)[0].any() # out-of-order input
|
||||
pose[0] = 10.
|
||||
mask, status = g.observe(*data, 12.)
|
||||
assert not mask.any() and not status['active']
|
||||
|
||||
|
||||
def test_grouping_does_not_join_distant_markings(module):
|
||||
g = gate(module)
|
||||
local = np.array([[1, 0], [1, .2], [2, 0], [2, .2], [8, 0], [8, .2]])
|
||||
groups = g._groups(local, np.ones(len(local), bool))
|
||||
assert sorted(map(len, groups)) == [2, 4]
|
||||
|
||||
|
||||
def test_unknown_crossing_ground_reaches_semantic_memory(monkeypatch, module):
|
||||
composition = importlib.import_module('continuous_composition')
|
||||
labels, points, pixels, pose = scene(); g = gate(module)
|
||||
enter(g, (labels, points, pixels, pose))
|
||||
# Isolate the integration boundary: calibrated point projection/model input
|
||||
# stay fixed while original unknown confidence remains false.
|
||||
obj = object.__new__(composition.ContinuousComposition)
|
||||
obj.environment, obj.segmenter_id = 'urban', 'simulation-sam3-surfaces'
|
||||
obj.crossing = g
|
||||
obj.optics = SimpleNamespace(lens_axes=np.array([np.eye(3)]),
|
||||
rectify_forward=lambda *a: (np.zeros((600,800,3),np.uint8), None))
|
||||
obj.camera_source = SimpleNamespace(indices=lambda *a:pixels,
|
||||
semantic_pixels=lambda *a:np.ones(len(points),bool))
|
||||
monkeypatch.setattr(composition, 'project', lambda *a:(None, np.zeros(len(points)),
|
||||
np.zeros(len(points)), np.ones(len(points),bool)))
|
||||
obj.models = SimpleNamespace(labels={}, surface=lambda rgb:{'segmentation.labels':labels,
|
||||
'segmentation.surface':np.isin(labels, (1,2,3)), 'segmentation.known':labels != 0})
|
||||
observation = dict(calibration={'lens_axes':[np.eye(3)], 'intrinsics':[1,1,1,1]},
|
||||
captured_at=11., points=points, pose=pose,
|
||||
camera_sources={'insta360_left':None,'insta360_right':None}, lens_depths=[])
|
||||
with ThreadPoolExecutor(max_workers=1) as pool:
|
||||
obj.pool = pool
|
||||
result = obj.perceive_view(observation, 1, 0, detect=False)
|
||||
samples = np.asarray(result['samples']['samples'])
|
||||
expected_unknown = result['values']['source.crossing-mask'][pixels] & (labels[pixels] == 0)
|
||||
assert expected_unknown.any()
|
||||
permitted_points = set(map(tuple, samples[samples[:,3] == 1, :3]))
|
||||
assert all(tuple(p) in permitted_points for p in points[expected_unknown])
|
||||
assert not any(tuple(p) in permitted_points for p in points[np.abs(points[:,1]) > 1.1])
|
||||
Reference in New Issue
Block a user