Preserve offline geometry, marking, replay and evaluation pipelines with source manifests and synthetic tests. Research qualification does not activate these methods as production navigation.
58 lines
2.6 KiB
Python
58 lines
2.6 KiB
Python
import unittest
|
|
import numpy as np
|
|
from material_regions import road_material
|
|
from boundary_anchors import PhysicalFields,refine_chain
|
|
|
|
|
|
def image_case(cell=.1):
|
|
y,x=np.mgrid[:round(20/cell),:round(36/cell)]*cell
|
|
side=y>=10
|
|
rgb=np.repeat(np.where(side,155,65)[:,:,None],3,axis=2).astype('uint8')
|
|
return x,y,side,rgb
|
|
|
|
|
|
class MaterialTests(unittest.TestCase):
|
|
def test_appearance_recovers_offset_class_boundary(self):
|
|
x,y,side,rgb=image_case();old=y>=9
|
|
m,report=road_material(rgb,(~old).astype(float),old.astype(float),np.ones_like(y),np.zeros_like(y),.1)
|
|
self.assertEqual(report['status'],'grabcut')
|
|
self.assertGreater(m[(y>9.3)&(y<9.7)].mean(),.95)
|
|
self.assertLess(m[y>10.5].mean(),.05)
|
|
|
|
def test_enclosed_paint_does_not_cut_a_hole_in_road(self):
|
|
x,y,side,rgb=image_case();paint=(x>12)&(x<18)&(y>7)&(y<8.3);rgb[paint]=250
|
|
m,_=road_material(rgb,(~side).astype(float),side.astype(float),np.ones_like(y),np.zeros_like(y),.1)
|
|
self.assertGreater(m[paint].mean(),.95)
|
|
|
|
def test_missing_class_seeds_explicitly_returns_no_material_decision(self):
|
|
x,y,side,rgb=image_case()
|
|
m,report=road_material(rgb,np.ones_like(y),np.zeros_like(y),np.ones_like(y),np.zeros_like(y),.1)
|
|
self.assertIsNone(m);self.assertEqual(report['status'],'insufficient-automatic-seeds')
|
|
|
|
def test_region_context_ranks_boundary_above_equal_internal_edge(self):
|
|
x,y,side,rgb=image_case()
|
|
f=PhysicalFields(rgb,np.zeros_like(y),np.ones_like(y),np.zeros_like(y),~side,side,.1)
|
|
f.material=(~side).astype(float)
|
|
uv=np.array([[120.,50.],[120.,100.]])
|
|
scores=f.ranked_score(np.full(2,.8),uv,np.array([0.,1.]))
|
|
self.assertGreater(scores[1],scores[0]+.4)
|
|
|
|
def test_wrong_material_prediction_cannot_delete_observed_curb(self):
|
|
x,y,side,rgb=image_case()
|
|
f=PhysicalFields(rgb,np.where(side,.12,0),np.ones_like(y),np.zeros_like(y),~side,side,.1)
|
|
f.material=np.zeros_like(y)
|
|
seed=np.c_[np.linspace(3,33,160),np.full(160,9.)]/.1
|
|
out=refine_chain(seed,f);self.assertEqual(len(out),1)
|
|
self.assertLess(np.median(abs(out[0][0][:,1]*.1-10)),.25)
|
|
|
|
def test_region_context_keeps_physical_boundary(self):
|
|
x,y,side,rgb=image_case()
|
|
f=PhysicalFields(rgb,np.where(side,.12,0),np.ones_like(y),np.zeros_like(y),~side,side,.1)
|
|
f.material=(~side).astype(float)
|
|
seed=np.c_[np.linspace(3,33,160),np.full(160,9.)]/.1
|
|
out=refine_chain(seed,f);self.assertEqual(len(out),1)
|
|
self.assertLess(np.median(abs(out[0][0][:,1]*.1-10)),.25)
|
|
|
|
|
|
if __name__=='__main__':unittest.main()
|